1 /* scherzo - Music notation training
3 * Copyright © 2010 Carl Worth
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see http://www.gnu.org/licenses/ .
20 #include <gdk/gdkkeysyms.h>
24 #define unused(foo) foo __attribute__((unused))
26 typedef struct scherzo
33 on_delete_event_quit (unused (GtkWidget *widget),
34 unused (GdkEvent *event),
35 unused (gpointer user_data))
39 /* Returning FALSE allows the default handler for delete-event
40 * to proceed to cleanup the widget. */
45 on_expose_event_draw (GtkWidget *widget,
46 unused (GdkEventExpose *expose),
49 scherzo_t *scherzo = user_data;
50 score_t *score = scherzo->score;
52 GtkAllocation allocation;
53 static const int pad = 10;
56 gtk_widget_get_allocation (widget, &allocation);
57 widget_width = allocation.width;
59 cr = gdk_cairo_create (widget->window);
61 /* White background */
62 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
65 /* Add some padding on the left/right */
66 cairo_translate (cr, pad, pad);
67 score_set_staff_height (score, scherzo->staff_height);
68 score_set_width (score, widget_width - 2 * pad);
70 score_draw (score, cr);
76 on_key_press_event (GtkWidget *widget,
80 scherzo_t *scherzo = user_data;
82 switch (key->keyval) {
86 case GDK_KEY_KP_Equal:
87 scherzo->staff_height += 4;
88 gtk_widget_queue_draw (widget);
92 case GDK_KEY_KP_Subtract:
93 scherzo->staff_height -= 4;
94 gtk_widget_queue_draw (widget);
104 /* Allow the event to propagate to other handlers. */
109 main (int argc, char *argv[])
112 GtkWidget *drawing_area;
115 gtk_init (&argc, &argv);
117 scherzo.score = score_create (NULL);
118 scherzo.staff_height = 24;
119 score_set_staff_height (scherzo.score, scherzo.staff_height);
121 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
123 gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
125 g_signal_connect (window, "delete-event",
126 G_CALLBACK (on_delete_event_quit), NULL);
128 drawing_area = gtk_drawing_area_new ();
130 gtk_container_add (GTK_CONTAINER (window), drawing_area);
132 g_signal_connect (drawing_area, "expose-event",
133 G_CALLBACK (on_expose_event_draw),
136 g_signal_connect (window, "key-press-event",
137 G_CALLBACK (on_key_press_event),
140 gtk_widget_show_all (window);