forked from AuroraMiddleware/gtk
gtk-demo: Port the drawingarea demo to a gesture
Use a drag gesture here, just like in the drawing example.
This commit is contained in:
parent
c9267e70a9
commit
473bbeb475
@ -89,42 +89,38 @@ draw_brush (GtkWidget *widget,
|
||||
gtk_widget_queue_draw_area (widget, update_rect.x, update_rect.y, update_rect.width, update_rect.height);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
scribble_button_press_event (GtkWidget *widget,
|
||||
GdkEventButton *event,
|
||||
gpointer data)
|
||||
static double start_x;
|
||||
static double start_y;
|
||||
|
||||
static void
|
||||
drag_begin (GtkGestureDrag *gesture,
|
||||
double x,
|
||||
double y,
|
||||
GtkWidget *area)
|
||||
{
|
||||
double x, y;
|
||||
guint button;
|
||||
start_x = x;
|
||||
start_y = y;
|
||||
|
||||
gdk_event_get_button ((GdkEvent *)event, &button);
|
||||
gdk_event_get_coords ((GdkEvent *)event, &x, &y);
|
||||
|
||||
if (button == GDK_BUTTON_PRIMARY)
|
||||
draw_brush (widget, x, y);
|
||||
|
||||
/* We've handled the event, stop processing */
|
||||
return TRUE;
|
||||
draw_brush (area, x, y);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
scribble_motion_notify_event (GtkWidget *widget,
|
||||
GdkEventMotion *event,
|
||||
gpointer data)
|
||||
static void
|
||||
drag_update (GtkGestureDrag *gesture,
|
||||
double x,
|
||||
double y,
|
||||
GtkWidget *area)
|
||||
{
|
||||
double x, y;
|
||||
GdkModifierType state;
|
||||
|
||||
gdk_event_get_state ((GdkEvent *)event, &state);
|
||||
gdk_event_get_coords ((GdkEvent *)event, &x, &y);
|
||||
|
||||
if (state & GDK_BUTTON1_MASK)
|
||||
draw_brush (widget, x, y);
|
||||
|
||||
/* We've handled it, stop processing */
|
||||
return TRUE;
|
||||
draw_brush (area, start_x + x, start_y + y);
|
||||
}
|
||||
|
||||
static void
|
||||
drag_end (GtkGestureDrag *gesture,
|
||||
double x,
|
||||
double y,
|
||||
GtkWidget *area)
|
||||
{
|
||||
draw_brush (area, start_x + x, start_y + y);
|
||||
}
|
||||
|
||||
static void
|
||||
checkerboard_draw (GtkDrawingArea *da,
|
||||
@ -189,6 +185,7 @@ do_drawingarea (GtkWidget *do_widget)
|
||||
GtkWidget *vbox;
|
||||
GtkWidget *da;
|
||||
GtkWidget *label;
|
||||
GtkGesture *drag;
|
||||
|
||||
if (!window)
|
||||
{
|
||||
@ -247,11 +244,13 @@ do_drawingarea (GtkWidget *do_widget)
|
||||
g_signal_connect (da, "size-allocate",
|
||||
G_CALLBACK (scribble_size_allocate), NULL);
|
||||
|
||||
/* Event signals */
|
||||
g_signal_connect (da, "motion-notify-event",
|
||||
G_CALLBACK (scribble_motion_notify_event), NULL);
|
||||
g_signal_connect (da, "button-press-event",
|
||||
G_CALLBACK (scribble_button_press_event), NULL);
|
||||
drag = gtk_gesture_drag_new (da);
|
||||
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (drag), GDK_BUTTON_PRIMARY);
|
||||
g_object_set_data_full (G_OBJECT (da), "drag", drag, g_object_unref);
|
||||
|
||||
g_signal_connect (drag, "drag-begin", G_CALLBACK (drag_begin), da);
|
||||
g_signal_connect (drag, "drag-update", G_CALLBACK (drag_update), da);
|
||||
g_signal_connect (drag, "drag-begin", G_CALLBACK (drag_end), da);
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
|
Loading…
Reference in New Issue
Block a user