static gboolean on_button_press (GooCanvasItem *item, GooCanvasItem *target, GdkEventButton *event, gpointer data) { GooCanvasItemModel *model = goo_canvas_item_get_model (target); char *item_id = g_object_get_data (G_OBJECT (model), "id"); g_print ("%s received 'button-press' signal\n", item_id); if (strstr (item_id, "explicit")) { GooCanvas *canvas; GdkGrabStatus status; GdkEventMask mask = GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK; canvas = goo_canvas_item_get_canvas (item); status = goo_canvas_pointer_grab (canvas, item, mask, NULL, event->time); if (status == GDK_GRAB_SUCCESS) g_print ("grabbed pointer\n"); else g_print ("pointer grab failed\n"); } return FALSE; }
static gboolean on_motion (GooCanvasItem *item, GooCanvasItem *target, GdkEventMotion *event, gpointer data) { GooCanvas *canvas = goo_canvas_item_get_canvas (item); GooCanvasItemModel *model = goo_canvas_item_get_model (target); int x, y, width, shape_a, shape_b, shape_c; gboolean change = FALSE; if (!(event->state & GDK_BUTTON1_MASK)) return FALSE; if (model == g_object_get_data (G_OBJECT (canvas), "width_drag_box")) { y = event->y; width = (MIDDLE - y) / 5; if (width < 0) return FALSE; g_object_set_data (G_OBJECT (canvas), "width", GINT_TO_POINTER (width)); set_arrow_shape (canvas); } else if (model == g_object_get_data (G_OBJECT (canvas), "shape_a_drag_box")) { x = event->x; width = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (canvas), "width")); shape_a = (RIGHT - x) / 10 / width; if ((shape_a < 0) || (shape_a > 30)) return FALSE; g_object_set_data (G_OBJECT (canvas), "shape_a", GINT_TO_POINTER (shape_a)); set_arrow_shape (canvas); } else if (model == g_object_get_data (G_OBJECT (canvas), "shape_b_c_drag_box")) { width = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (canvas), "width")); x = event->x; shape_b = (RIGHT - x) / 10 / width; if ((shape_b >= 0) && (shape_b <= 30)) { g_object_set_data (G_OBJECT (canvas), "shape_b", GINT_TO_POINTER (shape_b)); change = TRUE; } y = event->y; shape_c = (MIDDLE - y) * 2 / 10 / width; if (shape_c >= 0) { g_object_set_data (G_OBJECT (canvas), "shape_c", GINT_TO_POINTER (shape_c)); change = TRUE; } if (change) set_arrow_shape (canvas); } return TRUE; }
static gboolean on_motion_notify_event_cb (GooCanvasItem *item, GooCanvasItem *target_item, GdkEventMotion *event, gpointer user_data) { GooCanvasItemModel *model = goo_canvas_item_get_model (item); if (drag_item == item && drag_item != NULL) { gdouble rel_x = event->x - drag_x; gdouble rel_y = event->y - drag_y; if (drag_mode == MODE_MOVE) { g_object_set (G_OBJECT (model), "x", item_x + rel_x, "y", item_y + rel_y, NULL); } else { gdouble new_width = MAX (item_width + rel_x, 5.0); gdouble new_height = MAX (item_height + rel_y, 5.0); g_object_set (G_OBJECT (model), "width", new_width, "height", new_height, NULL); } return TRUE; } return FALSE; }
static gboolean on_button_press (GooCanvasItem *item, GooCanvasItem *target, GdkEventButton *event, gpointer data) { GooCanvasItemModel *model = goo_canvas_item_get_model (item); GooCanvasItemModel *parent1, *parent2, *parent; if (event->button != 1 || event->type != GDK_BUTTON_PRESS) return FALSE; parent1 = g_object_get_data (G_OBJECT (model), "parent1"); parent2 = g_object_get_data (G_OBJECT (model), "parent2"); parent = goo_canvas_item_model_get_parent (model); g_object_ref (model); goo_canvas_item_model_remove (model); if (parent == parent1) goo_canvas_item_model_add_child (parent2, model, -1); else goo_canvas_item_model_add_child (parent1, model, -1); g_object_unref (model); return TRUE; }
static gboolean on_button_press_event_cb (GooCanvasItem *item, GooCanvasItem *target_item, GdkEventButton *event, gpointer user_data) { GooCanvasItemModel *model = goo_canvas_item_get_model (item); if (event->state & GDK_CONTROL_MASK) { if (event->button == 1 || event->button == 3) { if (event->button == 1) drag_mode = MODE_MOVE; else drag_mode = MODE_RESIZE; drag_item = item; drag_x = event->x; drag_y = event->y; g_object_get (G_OBJECT (model), "x", &item_x, "y", &item_y, "width", &item_width, "height", &item_height, NULL); goo_canvas_pointer_grab (GOO_CANVAS (user_data), item, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_RELEASE_MASK, NULL, event->time); return TRUE; } } return FALSE; }
static gboolean on_motion_notify (GooCanvasItem *item, GooCanvasItem *target, GdkEventMotion *event, gpointer data) { GooCanvasItemModel *model = goo_canvas_item_get_model (target); char *item_id = g_object_get_data (G_OBJECT (model), "id"); g_print ("%s received 'motion-notify' signal\n", item_id); return FALSE; }
static gboolean on_key_press (GooCanvasItem *item, GooCanvasItem *target, GdkEventKey *event, gpointer data) { GooCanvasItemModel *model = goo_canvas_item_get_model (item); gchar *id = g_object_get_data (G_OBJECT (model), "id"); g_print ("%s received key-press event\n", id ? id : "unknown"); return FALSE; }
static gboolean on_leave_notify (GooCanvasItem *item, GooCanvasItem *target, GdkEvent *event, gpointer data) { GooCanvasItemModel *model = goo_canvas_item_get_model (target); g_object_set (model, "fill_color", "black", NULL); return TRUE; }
static gboolean on_focus_in (GooCanvasItem *item, GooCanvasItem *target, GdkEventFocus *event, gpointer data) { GooCanvasItemModel *model = goo_canvas_item_get_model (item); gchar *id = g_object_get_data (G_OBJECT (model), "id"); g_print ("%s received focus-in event\n", id ? id : "unknown"); /* Note that this is only for testing. Setting item properties to indicate focus isn't a good idea for real apps, as there may be multiple views. */ g_object_set (model, "stroke-color", "black", NULL); return FALSE; }
static gboolean on_button_press (GooCanvasItem *item, GooCanvasItem *target, GdkEventButton *event, gpointer data) { GooCanvasItemModel *model = goo_canvas_item_get_model (item); gchar *id = g_object_get_data (G_OBJECT (model), "id"); GooCanvas *canvas; g_print ("%s received button-press event\n", id ? id : "unknown"); canvas = goo_canvas_item_get_canvas (item); goo_canvas_grab_focus (canvas, item); return TRUE; }
static gboolean piece_leave_notify (GooCanvasItem *item, GooCanvasItem *target, GdkEvent *event, gpointer data) { GooCanvasItemModel *model, *text; #if 0 g_print ("In piece_leave_notify\n"); #endif model = goo_canvas_item_get_model (item); text = g_object_get_data (G_OBJECT (model), "text"); g_object_set (text, "fill_color", "black", NULL); return FALSE; }
static gboolean on_button_release (GooCanvasItem *item, GooCanvasItem *target, GdkEventButton *event, gpointer data) { GooCanvasItemModel *model = goo_canvas_item_get_model (target); char *item_id = g_object_get_data (G_OBJECT (model), "id"); g_print ("%s received 'button-release' signal\n", item_id); if (strstr (item_id, "explicit")) { GooCanvas *canvas; canvas = goo_canvas_item_get_canvas (item); goo_canvas_pointer_ungrab (canvas, item, event->time); g_print ("released pointer grab\n"); } return FALSE; }
static gboolean piece_button_press (GooCanvasItem *item, GooCanvasItem *target, GdkEventButton *event, gpointer data) { GooCanvas *canvas; GooCanvasItemModel **board; GooCanvasItemModel *model, *text G_GNUC_UNUSED; int num G_GNUC_UNUSED, pos, newpos; int x, y; double dx = 0.0, dy = 0.0; int move; model = goo_canvas_item_get_model (item); canvas = goo_canvas_item_get_canvas (item); board = g_object_get_data (G_OBJECT (canvas), "board"); num = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (model), "piece_num")); pos = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (model), "piece_pos")); text = g_object_get_data (G_OBJECT (model), "text"); #if 0 g_print ("In piece_event pos: %i,%i num: %i\n", pos % 4, pos / 4, num + 1); #endif y = pos / 4; x = pos % 4; move = TRUE; if ((y > 0) && (board[(y - 1) * 4 + x] == NULL)) { dx = 0.0; dy = -1.0; y--; } else if ((y < 3) && (board[(y + 1) * 4 + x] == NULL)) { dx = 0.0; dy = 1.0; y++; } else if ((x > 0) && (board[y * 4 + x - 1] == NULL)) { dx = -1.0; dy = 0.0; x--; } else if ((x < 3) && (board[y * 4 + x + 1] == NULL)) { dx = 1.0; dy = 0.0; x++; } else move = FALSE; if (move) { newpos = y * 4 + x; board[pos] = NULL; board[newpos] = model; g_object_set_data (G_OBJECT (model), "piece_pos", GINT_TO_POINTER (newpos)); goo_canvas_item_model_translate (model, dx * PIECE_SIZE, dy * PIECE_SIZE); test_win (board); } return FALSE; }