8 #include "drawing_area.h"
9 #include "../math/3d.h"
10 #include "../graphics/constants.h"
11 #include "../graphics/individual.h"
12 #include "../graphics/family.h"
13 #include "../storage/storage.h"
15 extern GLdouble camera_pos_x;
16 extern GLdouble camera_pos_y;
17 extern GLdouble camera_pos_z;
19 GtkDrawingArea * drawing_area = NULL;
22 * The "draw" signal handler. All the OpenGL re-drawing should
23 * be done here. This is repeatedly called as the painting routine
24 * every time the 'draw' event is signalled.
26 gboolean drawing_area_draw(GtkWidget *widget, cairo_t *cr, gpointer user_data)
29 unsigned int individuals_no;
30 unsigned int families_no;
31 struct familia_storage * storage;
32 struct position * pos;
34 /*** OpenGL BEGIN ***/
35 if (!gtk_widget_begin_gl (widget)) {
39 glMatrixMode (GL_MODELVIEW);
40 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
43 gluLookAt (camera_pos_x, camera_pos_y, camera_pos_z, 0.0, 0.0, -100.0, 0.0, 1.0, 0.0);
45 storage = familia_storage_get_current();
46 individuals_no = storage->individuals_no;
48 for (i = 0; i < individuals_no; i++) {
49 pos = calculate_individual_position(storage->individuals[i]);
53 (pos != NULL) ? pos->x : 0,
54 (pos != NULL) ? pos->y : 0,
55 (pos != NULL) ? pos->z : -10
57 glColor3f (1.0, 1.0, 1.0);
58 graphics_render_individual();
67 families_no = storage->families_no;
69 for (i = 0; i < families_no; i++) {
71 glTranslatef(i * (GR_FAM_RADIUS + 1), -3, -10);
72 glColor3f (1.0, 1.0, 1.0);
73 graphics_render_family();
77 gtk_widget_end_gl (widget, TRUE);
84 * The "configure_event" signal handler. Any processing required when
85 * the OpenGL-capable drawing area is re-configured should be done here.
86 * Almost always it will be used to resize the OpenGL viewport when
87 * the window is resized.
89 gboolean drawing_area_configure_event (GtkWidget *widget,
90 GdkEventConfigure *event, gpointer data)
92 GtkAllocation allocation;
94 /* OpenGL widget width */
96 /* OpenGL widget height */
101 gtk_widget_get_allocation (widget, &allocation);
102 w = allocation.width;
103 h = allocation.height;
106 /*** OpenGL BEGIN ***/
107 if (!gtk_widget_begin_gl (widget))
110 glViewport (0, 0, w, h);
112 glMatrixMode (GL_PROJECTION);
114 gluPerspective (60.0, aspect, 0.1, 60.0);
115 glMatrixMode(GL_MODELVIEW);
117 gtk_widget_end_gl (widget, FALSE);
124 * The "realize" signal handler. All the OpenGL initialization
125 * should be performed here, such as default background colour,
126 * certain states etc.
128 void drawing_area_realize (GtkWidget *widget, gpointer data)
130 /*** OpenGL BEGIN ***/
131 if (!gtk_widget_begin_gl (widget)) {
135 glClearColor (0.0, 0.0, 0.0, 0.0);
136 glShadeModel (GL_FLAT);
138 gtk_widget_end_gl (widget, FALSE);
145 * The "unrealize" signal handler. Any processing required when
146 * the OpenGL-capable window is unrealized should be done here.
148 void drawing_area_unrealize (GtkWidget *widget, gpointer data)
153 void drawing_area_event_scroll (GtkWidget *widget, GdkEventScroll *event, gpointer user_data)
155 assert(event->type == GDK_SCROLL);
157 switch(event->direction) {
160 gtk_widget_queue_draw(widget);
162 case GDK_SCROLL_DOWN:
164 gtk_widget_queue_draw(widget);