]> git.cworth.org Git - scherzo/blob - scherzo.c
Start drawing something
[scherzo] / scherzo.c
1 /* scherzo - Music notation training
2  *
3  * Copyright © 2010 Carl Worth
4  *
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.
9  *
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.
14  *
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/ .
17  */
18
19 #include <gtk/gtk.h>
20
21 #include "score.h"
22
23 #define unused(foo) foo __attribute__((unused))
24
25 static int
26 on_delete_event_quit (unused (GtkWidget *widget),
27                       unused (GdkEvent *event),
28                       unused (gpointer user_data))
29 {
30     gtk_main_quit ();
31
32     /* Returning FALSE allows the default handler for delete-event
33      * to proceed to cleanup the widget. */
34     return FALSE;
35 }
36
37 static int
38 on_expose_event_draw (GtkWidget *widget,
39                       unused (GdkEventExpose *event),
40                       void * user_data)
41 {
42     score_t *score = user_data;
43     cairo_t *cr;
44     GtkAllocation allocation;
45     static const int pad = 10;
46     int widget_width, staff_width;
47
48     gtk_widget_get_allocation (widget, &allocation);
49     widget_width = allocation.width;
50
51     cr = gdk_cairo_create (widget->window);
52
53     /* White background */
54     cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
55     cairo_paint (cr);
56
57     /* Add some padding on the left/right */
58     cairo_translate (cr, pad, pad);
59
60     score_set_width (score, widget_width - 2 * pad);
61
62     score_draw (score, cr);
63  
64     return TRUE;
65 }
66
67 int
68 main (int argc, char *argv[])
69 {
70     GtkWidget *window;
71     GtkWidget *drawing_area;
72     score_t score;
73
74     gtk_init (&argc, &argv);
75
76     score_init (&score);
77
78     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
79
80     gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
81
82     g_signal_connect (window, "delete-event",
83                       G_CALLBACK (on_delete_event_quit), NULL);
84
85     drawing_area = gtk_drawing_area_new ();
86
87     gtk_container_add (GTK_CONTAINER (window), drawing_area);
88
89     g_signal_connect (drawing_area, "expose-event",  
90                       G_CALLBACK (on_expose_event_draw),
91                       &score);
92     
93     gtk_widget_show_all (window);
94     
95     gtk_main ();
96
97     return 0;
98 }