8 #include "../familia.h"
9 #include "drawing_area.h"
10 #include "../math/3d.h"
11 #include "../graphics/constants.h"
12 #include "../graphics/individual.h"
13 #include "../graphics/family.h"
14 #include "../storage/storage.h"
16 extern GLdouble camera_pos_x;
17 extern GLdouble camera_pos_y;
18 extern GLdouble camera_pos_z;
20 GtkDrawingArea * drawing_area = NULL;
23 * The "draw" signal handler. All the OpenGL re-drawing should
24 * be done here. This is repeatedly called as the painting routine
25 * every time the 'draw' event is signalled.
27 gboolean drawing_area_draw(GtkWidget *widget, cairo_t *cr, gpointer user_data)
30 unsigned int individuals_no;
31 unsigned int families_no;
32 struct familia_storage * storage;
33 struct position * pos;
35 /*** OpenGL BEGIN ***/
36 if (!gtk_widget_begin_gl (widget)) {
40 glMatrixMode (GL_MODELVIEW);
41 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
44 gluLookAt (camera_pos_x, camera_pos_y, camera_pos_z, 0.0, 0.0, -100.0, 0.0, 1.0, 0.0);
46 storage = familia_storage_get_current();
47 individuals_no = storage->individuals_no;
49 for (i = 0; i < individuals_no; i++) {
50 pos = calculate_individual_position(storage->individuals[i]);
54 (pos != NULL) ? pos->x : 0,
55 (pos != NULL) ? pos->y : 0,
56 (pos != NULL) ? pos->z : -10
58 glColor3f (1.0, 1.0, 1.0);
59 graphics_render_individual();
68 families_no = storage->families_no;
70 for (i = 0; i < families_no; i++) {
72 glTranslatef(i * (GR_FAM_RADIUS + 1), -3, -10);
73 glColor3f (1.0, 1.0, 1.0);
74 graphics_render_family();
78 gtk_widget_end_gl (widget, TRUE);
85 * The "configure_event" signal handler. Any processing required when
86 * the OpenGL-capable drawing area is re-configured should be done here.
87 * Almost always it will be used to resize the OpenGL viewport when
88 * the window is resized.
90 gboolean drawing_area_configure_event (GtkWidget *widget,
91 GdkEventConfigure *event, gpointer data)
93 GtkAllocation allocation;
95 /* OpenGL widget width */
97 /* OpenGL widget height */
102 gtk_widget_get_allocation (widget, &allocation);
103 w = allocation.width;
104 h = allocation.height;
107 /*** OpenGL BEGIN ***/
108 if (!gtk_widget_begin_gl (widget))
111 glViewport (0, 0, w, h);
113 glMatrixMode (GL_PROJECTION);
115 gluPerspective (60.0, aspect, 0.1, 60.0);
116 glMatrixMode(GL_MODELVIEW);
118 gtk_widget_end_gl (widget, FALSE);
125 * The "realize" signal handler. All the OpenGL initialization
126 * should be performed here, such as default background colour,
127 * certain states etc.
129 void drawing_area_realize (GtkWidget *widget, gpointer data)
131 /*** OpenGL BEGIN ***/
132 if (!gtk_widget_begin_gl (widget)) {
136 glClearColor (0.0, 0.0, 0.0, 0.0);
137 glShadeModel (GL_FLAT);
139 gtk_widget_end_gl (widget, FALSE);
146 * The "unrealize" signal handler. Any processing required when
147 * the OpenGL-capable window is unrealized should be done here.
149 void drawing_area_unrealize (GtkWidget *widget, gpointer data)
155 * The "scroll-event" signal handler. Responsible for correctly scrolling
156 * drawing area using mouse or touchpad.
158 void drawing_area_event_scroll (GtkWidget *widget,
159 GdkEventScroll *event, FamiliaData *data)
161 GtkAdjustment *adjustment = NULL;
165 assert(event->type == GDK_SCROLL);
167 switch(event->direction) {
169 adjustment = data->vadjustment;
172 case GDK_SCROLL_DOWN:
173 adjustment = data->vadjustment;
176 case GDK_SCROLL_LEFT:
177 adjustment = data->hadjustment;
180 case GDK_SCROLL_RIGHT:
181 adjustment = data->hadjustment;
186 if (adjustment != NULL) {
187 value = gtk_adjustment_get_value (adjustment);
188 step = step * gtk_adjustment_get_step_increment(adjustment);
191 gtk_adjustment_set_value (adjustment, value);
192 gtk_adjustment_value_changed (adjustment);