X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=src%2Fui%2Fdrawing_area.c;h=16448474091ed73e66c535cb5477e5ef3a713bbd;hb=HEAD;hp=ee915e941ac47f683f9139c146f3b40375d8c562;hpb=961bbb87dca7f5406440d32c06dfc7552044e08a;p=familia.git diff --git a/src/ui/drawing_area.c b/src/ui/drawing_area.c index ee915e9..1644847 100644 --- a/src/ui/drawing_area.c +++ b/src/ui/drawing_area.c @@ -2,9 +2,12 @@ #include #include #include +#include #include "../debug.h" +#include "../familia.h" #include "drawing_area.h" +#include "../math/3d.h" #include "../graphics/constants.h" #include "../graphics/individual.h" #include "../graphics/family.h" @@ -26,6 +29,8 @@ gboolean drawing_area_draw(GtkWidget *widget, cairo_t *cr, gpointer user_data) unsigned int i; unsigned int individuals_no; unsigned int families_no; + struct familia_storage * storage; + struct position * pos; /*** OpenGL BEGIN ***/ if (!gtk_widget_begin_gl (widget)) { @@ -38,17 +43,29 @@ gboolean drawing_area_draw(GtkWidget *widget, cairo_t *cr, gpointer user_data) gluLookAt (camera_pos_x, camera_pos_y, camera_pos_z, 0.0, 0.0, -100.0, 0.0, 1.0, 0.0); - individuals_no = familia_storage_get_current()->individuals_no; + storage = familia_storage_get_current(); + individuals_no = storage->individuals_no; for (i = 0; i < individuals_no; i++) { + pos = calculate_individual_position(storage->individuals[i]); + glPushMatrix (); - glTranslatef(i * (GR_IND_RADIUS + 1), 0, -10); + glTranslatef( + (pos != NULL) ? pos->x : 0, + (pos != NULL) ? pos->y : 0, + (pos != NULL) ? pos->z : -10 + ); glColor3f (1.0, 1.0, 1.0); graphics_render_individual(); glPopMatrix (); + + if (pos != NULL) { + free(pos); + pos = NULL; + } } - families_no = familia_storage_get_current()->families_no; + families_no = storage->families_no; for (i = 0; i < families_no; i++) { glPushMatrix (); @@ -133,3 +150,47 @@ void drawing_area_unrealize (GtkWidget *widget, gpointer data) { /* Code */ } + +/** + * The "scroll-event" signal handler. Responsible for correctly scrolling + * drawing area using mouse or touchpad. + */ +void drawing_area_event_scroll (GtkWidget *widget, + GdkEvent *event, FamiliaData *data) +{ + GtkAdjustment *adjustment = NULL; + gdouble value = 0; + gdouble step = 0; + + assert(event->type == GDK_SCROLL); + + switch(event->scroll.direction) { + case GDK_SCROLL_UP: + adjustment = data->vadjustment; + step = 1; + break; + case GDK_SCROLL_DOWN: + adjustment = data->vadjustment; + step = -1; + break; + case GDK_SCROLL_LEFT: + adjustment = data->hadjustment; + step = -1; + break; + case GDK_SCROLL_RIGHT: + adjustment = data->hadjustment; + step = 1; + break; + default: + break; + } + + if (adjustment != NULL) { + value = gtk_adjustment_get_value (adjustment); + step = step * gtk_adjustment_get_step_increment(adjustment); + value += step; + + gtk_adjustment_set_value (adjustment, value); + gtk_adjustment_value_changed (adjustment); + } +}