static gboolean button_press(GtkWidget *widget, GdkEventButton *event) { mesh_info *info = (mesh_info*)g_object_get_data(G_OBJECT(widget), "mesh_info"); if (info->animate) { if (event->button == 1) toggle_animation (widget); } else { info->dquat[0] = 0.0; info->dquat[1] = 0.0; info->dquat[2] = 0.0; info->dquat[3] = 1.0; } /* beginning of drag, reset mouse position */ info->beginx = event->x; info->beginy = event->y; return FALSE; }
/*** *** The "key_press_event" signal handler. Any processing required when key *** presses occur should be done here. ***/ static gboolean key_press_event (GtkWidget *widget, GdkEventKey *event, gpointer data) { g_print ("%s: \"key_press_event\": ", gtk_widget_get_name (widget)); switch (event->keyval) { /*** Fill in the details here. ***/ case GDK_KEY_a: g_print ("a key\n"); toggle_animation (widget); break; case GDK_KEY_Escape: g_print ("Escape key\n"); gtk_main_quit (); break; default: g_print("\n"); return FALSE; } return TRUE; }
/*** *** The "button_press_event" signal handler. Any processing required when *** mouse buttons (only left and middle buttons) are pressed on the OpenGL- *** capable drawing area should be done here. ***/ static gboolean button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer data) { /* Starts/Stops animation according mouse button clicks.*/ if (event->button == 1) { toggle_animation (widget); return TRUE; } return FALSE; }
/*** *** The "key_press_event" signal handler. Any processing required when key *** presses occur should be done here. ***/ static gboolean key_press_event (GtkWidget *widget, GdkEventKey *event, gpointer data) { GtkAllocation allocation; GdkWindow *window; window = gtk_widget_get_window (widget); gtk_widget_get_allocation (widget, &allocation); switch (event->keyval) { case GDK_KEY_Left: /* Rotate left. */ if (!animate) { spin += 2.0; if (spin > 360.0) spin -= 360.0; gdk_window_invalidate_rect (window, &allocation, FALSE); } break; case GDK_KEY_Right: /* Rotate right. */ if (!animate) { spin -= 2.0; if (spin < 360.0) spin += 360.0; gdk_window_invalidate_rect (window, &allocation, FALSE); } break; case GDK_KEY_a: /* Toggle animation. */ toggle_animation (widget); break; case GDK_KEY_Escape: /* Quit. */ gtk_main_quit (); break; default: return FALSE; } return TRUE; }
static gboolean key_press_event (GtkWidget *widget, GdkEventKey *event, gpointer data) { GtkAllocation allocation; switch (event->keyval) { case GDK_KEY_r: init_wireframe (widget); break; case GDK_KEY_a: toggle_animation (widget); break; case GDK_KEY_w: if (!animate) timeout (widget); break; case GDK_KEY_plus: sdepth -= 2.0; break; case GDK_KEY_minus: sdepth += 2.0; break; case GDK_KEY_Escape: gtk_main_quit (); break; default: return FALSE; } if (!animate) { gtk_widget_get_allocation (widget, &allocation); gdk_window_invalidate_rect (gtk_widget_get_window (widget), &allocation, FALSE); } return TRUE; }
static gboolean button_release(GtkWidget *widget, GdkEventButton *event) { mesh_info *info = (mesh_info*)g_object_get_data(G_OBJECT(widget), "mesh_info"); if (!info->animate) { if (event->button == 1 && ((info->dx*info->dx + info->dy*info->dy) > ANIMATE_THRESHOLD)) toggle_animation (widget); } info->dx = 0.0; info->dy = 0.0; return FALSE; }
static gboolean key_press_event (GtkWidget *widget, GdkEventKey *event, gpointer data) { switch (event->keyval) { case GDK_a: toggle_animation (widget); break; case GDK_i: init_logo_view (widget); break; case GDK_Escape: gtk_main_quit (); break; default: return TRUE; } return TRUE; }