2 * Copyright (C) 2008 Carl Worth
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see http://www.gnu.org/licenses/ .
17 * Author: Carl Worth <cworth@cworth.org>
34 on_delete_event_quit (GtkWidget *widget,
40 /* Returning FALSE allows the default handler for delete-event
41 * to proceed to cleanup the widget. */
46 on_expose_event_draw (GtkWidget *widget,
47 GdkEventExpose *event,
51 layout_t *layout = user_data;
54 if (layout->width != widget->allocation.width ||
55 layout->height != widget->allocation.height)
59 layout->width = widget->allocation.width;
60 layout->height = widget->allocation.height;
62 size = MIN (layout->width, layout->height);
63 /* Size must be a multiple of the integer cell_size */
64 layout->cell_size = size / BOARD_SIZE;
65 size = layout->cell_size * BOARD_SIZE;
67 layout->x_offset = (layout->width - size) / 2;
68 layout->y_offset = (layout->height - size) / 2;
71 cr = gdk_cairo_create (widget->window);
73 cairo_translate (cr, layout->x_offset, layout->y_offset);
75 for (y = 0; y < BOARD_SIZE; y++) {
76 for (x = 0; x < BOARD_SIZE; x++) {
78 cairo_set_source_rgb (cr, 0.89, 0.70, 0.40);
80 cairo_set_source_rgb (cr, 0.26, 0.02, 0.01);
82 x * layout->cell_size, y * layout->cell_size,
83 layout->cell_size, layout->cell_size);
94 main (int argc, char *argv[])
97 GtkWidget *drawing_area;
103 gtk_init (&argc, &argv);
105 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
107 gtk_window_set_default_size (GTK_WINDOW (window), 100, 100);
109 g_signal_connect (window, "delete-event",
110 G_CALLBACK (on_delete_event_quit), NULL);
112 drawing_area = gtk_drawing_area_new ();
114 gtk_container_add (GTK_CONTAINER (window), drawing_area);
116 g_signal_connect (drawing_area, "expose-event",
117 G_CALLBACK (on_expose_event_draw), &layout);
119 gtk_widget_show_all (window);