*/
#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
#include "score.h"
}
static int
-on_expose_event_draw (GtkWidget *widget,
- unused (GdkEventExpose *event),
+on_expose_event_draw (GtkWidget *widget,
+ unused (GdkEventExpose *expose),
void * user_data)
{
scherzo_t *scherzo = user_data;
/* Add some padding on the left/right */
cairo_translate (cr, pad, pad);
+ score_set_staff_height (score, scherzo->staff_height);
score_set_width (score, widget_width - 2 * pad);
score_draw (score, cr);
return TRUE;
}
+static int
+on_key_press_event (GtkWidget *widget,
+ GdkEventKey *key,
+ void *user_data)
+{
+ scherzo_t *scherzo = user_data;
+
+ switch (key->keyval) {
+ case GDK_KEY_plus:
+ case GDK_KEY_KP_Add:
+ case GDK_KEY_equal:
+ case GDK_KEY_KP_Equal:
+ scherzo->staff_height += 4;
+ gtk_widget_queue_draw (widget);
+ return TRUE;
+ break;
+ case GDK_KEY_minus:
+ case GDK_KEY_KP_Subtract:
+ scherzo->staff_height -= 4;
+ gtk_widget_queue_draw (widget);
+ return TRUE;
+ break;
+ case GDK_KEY_q:
+ case GDK_KEY_Q:
+ case GDK_KEY_Escape:
+ gtk_main_quit ();
+ return FALSE;
+ }
+
+ /* Allow the event to propagate to other handlers. */
+ return FALSE;
+}
+
int
main (int argc, char *argv[])
{
gtk_init (&argc, &argv);
scherzo.score = score_create (NULL);
- scherzo.staff_height = 20;
+ scherzo.staff_height = 24;
score_set_staff_height (scherzo.score, scherzo.staff_height);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (drawing_area, "expose-event",
G_CALLBACK (on_expose_event_draw),
&scherzo);
+
+ g_signal_connect (window, "key-press-event",
+ G_CALLBACK (on_key_press_event),
+ &scherzo);
gtk_widget_show_all (window);
/* Height of one space within a staff */
int space_height;
+ /* Minimal line width for staff lines */
+ int line_width;
+
/* Full width of staff */
int width;
};
{
score->space_height = (int) height / 4;
score->staff_height = score->space_height * 4;
+
+ score->line_width = score->space_height / 15;
+ if (score->line_width == 0)
+ score->line_width = 1;
+
return score->staff_height;
}
cairo_show_glyphs (cr, &glyph, 1);
cairo_rectangle (cr,
- 0.5, 0.5,
- score->width - 1.0, score->space_height * 4);
+ score->line_width / 2.0,
+ score->line_width / 2.0,
+ score->width - score->line_width,
+ score->space_height * 4);
for (i = 1; i < 4; i++) {
- cairo_move_to (cr, 0, i * score->space_height + 0.5);
+ cairo_move_to (cr, 0, i * score->space_height + score->line_width / 2.0);
cairo_rel_line_to (cr, score->width, 0);
}
- cairo_set_line_width (cr, 1.0);
+ cairo_set_line_width (cr, score->line_width);
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
cairo_stroke (cr);
/* Vertical lines at each end */
cairo_rectangle (cr,
- 0.5, 0.5,
- score->width - 1.0,
+ score->line_width / 2.0,
+ score->line_width / 2.0,
+ score->width - score->line_width,
score->staff_height * 3);
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
- cairo_set_line_width (cr, 1.0);
+ cairo_set_line_width (cr, score->line_width);
cairo_stroke (cr);
/* Top staff */