static void make_dynamic_link (GstEditorLink * link) { GstElement *srce, *sinke; GstPadTemplate *src = NULL, *sink = NULL; if (GST_IS_EDITOR_PAD_SOMETIMES (link->srcpad)) src = GST_PAD_TEMPLATE (link->srcpad->object); if (GST_IS_EDITOR_PAD_SOMETIMES (link->sinkpad)) sink = GST_PAD_TEMPLATE (link->sinkpad->object); srce = GST_ELEMENT (GST_EDITOR_ITEM (goo_canvas_item_get_parent (GOO_CANVAS_ITEM (link->srcpad)))->object); sinke = GST_ELEMENT (GST_EDITOR_ITEM (goo_canvas_item_get_parent (GOO_CANVAS_ITEM (link->sinkpad)))->object); g_return_if_fail (src || sink); if (src) g_signal_connect_after (srce, "pad-added", G_CALLBACK (on_new_pad), link); if (sink) g_signal_connect_after (sinke, "pad-added", G_CALLBACK (on_new_pad), link); g_print ("dynamic link\n"); }
void gst_editor_link_destroy (GstEditorLink * link) { // g_print ("trying to destroy this half link"); GstEditorBin * padbin; if (link->srcpad) padbin = GST_EDITOR_BIN (goo_canvas_item_get_parent ( goo_canvas_item_get_parent (GOO_CANVAS_ITEM (link->srcpad)))); else padbin = GST_EDITOR_BIN (goo_canvas_item_get_parent ( goo_canvas_item_get_parent (GOO_CANVAS_ITEM (link->sinkpad)))); padbin->links = g_list_remove (padbin->links, link); if (link->srcpad) GST_EDITOR_PAD (link->srcpad)->link = NULL; if (link->sinkpad) GST_EDITOR_PAD (link->sinkpad)->link = NULL; // int killnumber; // killnumber=goo_canvas_item_find_child(goo_canvas_item_get_parent(GOO_CANVAS_ITEM(link)),GOO_CANVAS_ITEM(link)); // g_print ("found child at %d",killnumber); // ARGH, what am I doing here // g_realloc(link,sizeof(GooCanvasPolyline)); // g_realloc(link,sizeof(GooCanvasPolyline)); // goo_canvas_item_remove_child(goo_canvas_item_get_parent(GOO_CANVAS_ITEM(link)),killnumber); goo_canvas_item_remove (GOO_CANVAS_ITEM (link)); if (link->points) goo_canvas_points_unref (link->points); // g_print ("ready to crash:)"); // g_free(link); // g_print ("no warnings until now"); return; }
static DrawCanvasItem * draw_canvas_get_item_at (DrawCanvas *canvas, gdouble x, gdouble y, gboolean is_pointer_event) { GooCanvasItem *item; g_return_val_if_fail(DRAW_IS_CANVAS(canvas), NULL); /* * Fetch the item underneath the pointer. If the item is not a * DrawCanvasItem or the item is part of a selection group, work our way * up until we find that top-most grabbable item. */ item = goo_canvas_get_item_at(GOO_CANVAS(canvas), x, y, is_pointer_event); for (; item; item = goo_canvas_item_get_parent(item)) { /* * TODO: Check if part of a selection/group. */ if (DRAW_IS_CANVAS_ITEM(item)) { return DRAW_CANVAS_ITEM(item); } } return NULL; }
static gboolean on_button_press (GooCanvasItem *item, GooCanvasItem *target, GdkEventButton *event, gpointer data) { GooCanvasItem *parent1, *parent2, *parent; if (event->button != 1 || event->type != GDK_BUTTON_PRESS) return FALSE; g_print ("In on_button_press\n"); parent1 = g_object_get_data (G_OBJECT (item), "parent1"); parent2 = g_object_get_data (G_OBJECT (item), "parent2"); parent = goo_canvas_item_get_parent (item); g_object_ref (item); goo_canvas_item_remove (item); if (parent == parent1) goo_canvas_item_add_child (parent2, item, -1); else goo_canvas_item_add_child (parent1, item, -1); g_object_unref (item); return TRUE; }
static AtkObject* goo_canvas_item_accessible_get_parent (AtkObject *accessible) { GooCanvasItem *item, *parent; GooCanvas *canvas; GObject *object; g_return_val_if_fail (GOO_IS_CANVAS_ITEM_ACCESSIBLE (accessible), NULL); if (accessible->accessible_parent) return accessible->accessible_parent; object = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible)); if (object == NULL) return NULL; item = GOO_CANVAS_ITEM (object); parent = goo_canvas_item_get_parent (item); if (parent) return atk_gobject_accessible_for_object (G_OBJECT (parent)); canvas = goo_canvas_item_get_canvas (item); if (canvas) return gtk_widget_get_accessible (GTK_WIDGET (canvas)); return NULL; }
/* ==================================== */ static gboolean item_event (GooCanvasItem *item, GooCanvasItem *target, GdkEventButton *event, gpointer data) { gint button_id = GPOINTER_TO_INT(data); GooCanvasItem *button; if(board_paused) return FALSE; switch (event->type) { case GDK_BUTTON_PRESS: board_paused = TRUE; if ( button_id == right_word ) gamewon = TRUE; else gamewon = FALSE; button = (GooCanvasItem*)g_object_get_data(G_OBJECT(goo_canvas_item_get_parent(item)), "button"); highlight_selected(button); process_ok(); break; default: break; } return FALSE; }
static gint goo_canvas_item_accessible_get_index_in_parent (AtkObject *accessible) { GooCanvasItem *item, *parent; GooCanvas *canvas; GObject *object; g_return_val_if_fail (GOO_IS_CANVAS_ITEM_ACCESSIBLE (accessible), -1); if (accessible->accessible_parent) { gint n_children, i; gboolean found = FALSE; n_children = atk_object_get_n_accessible_children (accessible->accessible_parent); for (i = 0; i < n_children; i++) { AtkObject *child; child = atk_object_ref_accessible_child (accessible->accessible_parent, i); if (child == accessible) found = TRUE; g_object_unref (child); if (found) return i; } return -1; } object = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible)); if (object == NULL) return -1; item = GOO_CANVAS_ITEM (object); parent = goo_canvas_item_get_parent (item); if (parent) return goo_canvas_item_find_child (parent, item); canvas = goo_canvas_item_get_canvas (item); if (canvas) return 0; return -1; }
static gboolean on_motion_notify (GooCanvasItem *item, GooCanvasItem *target, GdkEventMotion *event, gpointer data) { GooCanvasItem *ancestor = target; gchar *id; while (ancestor) { id = g_object_get_data (G_OBJECT (ancestor), "id"); if (id) { g_print ("%s item received 'motion-notify' signal\n", id); return TRUE; } ancestor = goo_canvas_item_get_parent (ancestor); } return TRUE; }
gboolean gst_editor_link_link (GstEditorLink * link) { GObject * src, *sink; GstPad * srcpad = NULL, * sinkpad = NULL; GooCanvasItem * item; GooCanvasLineDash * dash; g_return_val_if_fail (GST_IS_EDITOR_LINK (link), FALSE); if (!link->srcpad || !link->sinkpad) goto error; src = (GObject *)GST_EDITOR_ITEM (link->srcpad)->object; sink = (GObject *)GST_EDITOR_ITEM (link->sinkpad)->object; if (!GST_EDITOR_PAD (link->srcpad)->istemplate) { if (!GST_EDITOR_PAD (link->sinkpad)->istemplate) { if (GST_PAD_PEER (src) || GST_PAD_PEER (sink)) { /*if (GST_PAD_PEER (src) != (GstPad *) sink) { g_warning ("The src pad is linked, but not to the sink pad"); goto error; } if (GST_PAD_PEER (sink) != (GstPad *) src) { g_warning ("The sink pad is linked, but not to the src pad"); goto error; } */ srcpad = GST_PAD (src); sinkpad = GST_PAD (sink); goto linked; /* yay goto */ } } else if (GST_PAD_PEER (src)) { /* the to pad is a template */ g_warning ("The src pad is linked, but not to the sink pad"); goto error; } } else if (!GST_EDITOR_PAD (link->sinkpad)->istemplate && GST_PAD_PEER (sink)) { /* from pad is a template */ g_warning ("The sink pad is linked, but not to the src pad"); goto error; } if (link->ghost) { g_object_set ( G_OBJECT (GOO_CANVAS_ITEM (link)), "fill-color", "grey70", NULL); goto linked; } else if (GST_IS_EDITOR_PAD_SOMETIMES (link->srcpad) || GST_IS_EDITOR_PAD_SOMETIMES (link->sinkpad)) { make_dynamic_link (link); g_object_set ( G_OBJECT (GOO_CANVAS_ITEM (link)), "fill-color", "grey50", NULL); goto linked; } else { if (!GST_EDITOR_PAD (link->srcpad)->istemplate) { srcpad = GST_PAD (src); } else if (GST_IS_EDITOR_PAD_REQUEST (link->srcpad)) { srcpad = gst_element_get_request_pad ( (GstElement *)GST_EDITOR_ITEM ( goo_canvas_item_get_parent (GOO_CANVAS_ITEM (link->srcpad))) ->object, GST_PAD_TEMPLATE (src)->name_template); /* the new_pad signal will cause a new pad to made automagically in the element */ g_object_set (G_OBJECT (GOO_CANVAS_ITEM (link)), "src-pad", gst_editor_item_get ((GstObject *)srcpad), NULL); } else { goto error; } if (!srcpad) goto error; if (!GST_EDITOR_PAD (link->sinkpad)->istemplate) { sinkpad = GST_PAD (sink); } else if (GST_IS_EDITOR_PAD_REQUEST (link->sinkpad)) { sinkpad = gst_element_get_request_pad ( (GstElement *)GST_EDITOR_ITEM ( goo_canvas_item_get_parent (GOO_CANVAS_ITEM (link->sinkpad))) ->object, GST_PAD_TEMPLATE (sink)->name_template); g_object_set (G_OBJECT (GOO_CANVAS_ITEM (link)), "sink-pad", gst_editor_item_get ((GstObject *)sinkpad), NULL); } else { goto error; } if (!sinkpad) goto error; if (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK) { GstEditorBin * srcbin, *sinkbin; g_object_set ( G_OBJECT (GOO_CANVAS_ITEM (link)), "fill-color", "black", NULL); linked: srcbin = sinkbin = NULL; dash = goo_canvas_line_dash_new (0, NULL); g_object_set (G_OBJECT (GOO_CANVAS_ITEM (link)), "line-dash", dash, NULL); goo_canvas_line_dash_unref (dash); g_signal_connect (link->srcpad, "position-changed", G_CALLBACK (on_editor_pad_position_changed), G_OBJECT (link)); g_signal_connect (link->sinkpad, "position-changed", G_CALLBACK (on_editor_pad_position_changed), G_OBJECT (link)); /* don't connect a signal on a ghost or dynamic link */ g_print ( "adding unlinked signal for src: %p and sink %p", srcpad, sinkpad); if (srcpad && sinkpad) { GST_CAT_DEBUG (gste_debug_cat, "link pad signal (%s:%s from %s:%s) with link %p", GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad), link); g_signal_connect (srcpad, "unlinked", G_CALLBACK (on_pad_unlink), link); g_signal_connect ( sinkpad, "unlinked", G_CALLBACK (on_pad_unlink), link); } item = goo_canvas_item_get_parent ( goo_canvas_item_get_parent (GOO_CANVAS_ITEM (link->srcpad))); if (GST_IS_EDITOR_BIN (item)) srcbin = GST_EDITOR_BIN (item); item = goo_canvas_item_get_parent ( goo_canvas_item_get_parent (GOO_CANVAS_ITEM (link->sinkpad))); if (GST_IS_EDITOR_BIN (item)) sinkbin = GST_EDITOR_BIN (item); if (sinkbin) sinkbin->links = g_list_prepend (sinkbin->links, link); if (srcbin && sinkbin != srcbin) srcbin->links = g_list_prepend (srcbin->links, link); return TRUE; } } error: g_message ("could not link"); if (link->srcpad) GST_EDITOR_PAD (link->srcpad)->link = NULL; if (link->sinkpad) GST_EDITOR_PAD (link->sinkpad)->link = NULL; return FALSE; }
static void on_pad_unlink (GstPad * pad, GstPad * peer, GstEditorLink * link) { GRWLock *globallock; if ((GST_IS_EDITOR_LINK (link)) && (GST_IS_EDITOR_PAD (link->srcpad))) { globallock = GST_EDITOR_ITEM (link->srcpad)->globallock; } else if ((GST_IS_EDITOR_LINK (link)) && (GST_IS_EDITOR_PAD (link->sinkpad))) { globallock = GST_EDITOR_ITEM (link->sinkpad)->globallock; } else { g_print ("Warning: On pad unlink without any valid Pads called!!!!"); return; } g_rw_lock_writer_lock (globallock); g_print ("Unlink pad signal (%s:%s from %s:%s) with link %p", GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (peer), link); GstEditorBin *srcbin = NULL, *sinkbin = NULL; /* this function is called when unlinking dynamic links as well */ if (peer && pad) GST_CAT_DEBUG (gste_debug_cat, "Unlink pad signal (%s:%s from %s:%s) with link %p", GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (peer), link); else GST_CAT_DEBUG (gste_debug_cat, "Unlinking dynamic link"); if (!GST_IS_EDITOR_PAD (link->srcpad)) g_print ("Warning: Unlink pad signals critical: Srcpad not valid\n"); if (link->srcpad) g_signal_handlers_disconnect_by_func ( link->srcpad, on_editor_pad_position_changed, link); if (!GST_IS_EDITOR_PAD (link->sinkpad)) g_print ("Warning: Unlink pad signals critical: Sinkpad not valid\n"); if (link->sinkpad) g_signal_handlers_disconnect_by_func ( link->sinkpad, on_editor_pad_position_changed, link); if (GST_IS_PAD (pad)) g_signal_handlers_disconnect_by_func (pad, on_pad_unlink, link); else g_print ("Warning: On_pad_unlink: Pad not valid\n"); if (GST_IS_PAD (peer)) g_signal_handlers_disconnect_by_func (peer, on_pad_unlink, link); else g_print ("Warning: On_pad_unlink: Peer not valid\n"); g_print ("Unlinked pad signals, get srcbin\n"); if (link->srcpad) srcbin = GST_EDITOR_BIN (goo_canvas_item_get_parent ( goo_canvas_item_get_parent (GOO_CANVAS_ITEM (link->srcpad)))); g_print ("Unlinked pad signals, get sinkbin\n"); if (link->sinkpad) sinkbin = GST_EDITOR_BIN (goo_canvas_item_get_parent ( goo_canvas_item_get_parent (GOO_CANVAS_ITEM (link->sinkpad)))); g_print ( "Removing links from bin; srcbin: %p, sinkbin %p\n", srcbin, sinkbin); if (sinkbin) sinkbin->links = g_list_remove (sinkbin->links, link); else g_print ("Warning: On_pad_unlink: Sinkbin not valid\n"); if ((sinkbin != srcbin) && (srcbin)) srcbin->links = g_list_remove (srcbin->links, link); else g_print ("Warning: On_pad_unlink: Srcbin not validor same as Sinkbin\n"); if (link->ghost) { if (link->srcpad) GST_EDITOR_PAD (link->srcpad)->ghostlink = NULL; if (link->sinkpad) GST_EDITOR_PAD (link->sinkpad)->ghostlink = NULL; } else { if (link->srcpad) GST_EDITOR_PAD (link->srcpad)->link = NULL; if (link->sinkpad) GST_EDITOR_PAD (link->sinkpad)->link = NULL; } g_rw_lock_writer_unlock (globallock); link->srcpad = NULL; link->sinkpad = NULL; /* i have bad luck with actually killing the GCI's */ // goo_canvas_item_simple_hide (GOO_CANVAS_ITEM_SIMPLE (link)); if (GOO_IS_CANVAS_ITEM (link)) goo_canvas_item_remove (GOO_CANVAS_ITEM (link)); g_print ("Finished on_pad_unlink\n"); }
static int scale_drag_event(GooCanvasItem *w, GooCanvasItem *target, GdkEvent *event, ScaleItem *scale) { double x, y; double item_x, item_y; if(answer_string) // disable, waiting a answer return FALSE; switch(event->type) { case GDK_BUTTON_PRESS: gc_drag_offset_save(event); goo_canvas_item_raise(goo_canvas_item_get_parent(scale->item), NULL); goo_canvas_item_raise(scale->item, NULL); break; case GDK_MOTION_NOTIFY: gc_drag_item_move(event, NULL); break; case GDK_BUTTON_RELEASE: { int plate; item_x = event->button.x; item_y = event->button.y; goo_canvas_convert_from_item_space(goo_canvas_item_get_canvas(w), scale->item, &item_x, &item_y); x = item_x; y = item_y; goo_canvas_convert_to_item_space(goo_canvas_item_get_canvas(w), group_g, &x, &y); if( -ITEM_W < x && x < PLATE_W + ITEM_W && abs(y - PLATE_Y) < ITEM_H) plate = 1; else { x = item_x; y = item_y; goo_canvas_convert_to_item_space(goo_canvas_item_get_canvas(w), group_d, &x, &y); if( -ITEM_W < x && x < PLATE_W + ITEM_W && abs(y - PLATE_Y) < ITEM_H) plate = -1; else plate=0; } scale_item_move_to(scale, plate); } break; default: break; } return FALSE; }
static gboolean piece_event (GooCanvasItem *item, GooCanvasItem *target, GdkEventButton *event, gpointer data) { GooCanvasItem **board; GooCanvasItem *text; int pos, newpos; int x, y; double dx = 0.0, dy = 0.0; int move; board = g_object_get_data (G_OBJECT (goo_canvas_item_get_parent(item)), "board"); pos = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "piece_pos")); text = g_object_get_data (G_OBJECT (item), "text"); switch (event->type) { case GDK_ENTER_NOTIFY: g_object_set (text, "fill-color", "white", NULL); break; case GDK_LEAVE_NOTIFY: g_object_set (text, "fill-color", "black", NULL); break; case GDK_BUTTON_PRESS: 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] = item; g_object_set_data (G_OBJECT (item), "piece_pos", GINT_TO_POINTER (newpos)); goo_canvas_item_translate (item, dx * PIECE_SIZE, dy * PIECE_SIZE); test_win (board); } break; default: break; } return FALSE; }