Пример #1
0
/*static*/ void
gst_editor_link_realize (GooCanvasItem * citem)
{
  GooCanvasLineDash * dash;
  if ((citem == NULL) || (!GST_EDITOR_LINK (citem))) {
    g_print (
        "Warning: gst_editor_link_realize failed because citem %p is no "
        "gst_editor_link",
        citem);
    return;
  }
  GstEditorLink * link = GST_EDITOR_LINK (citem);

  link->points->coords[0] = 0.0;
  link->points->coords[1] = 0.0;
  link->points->coords[2] = 0.0;
  link->points->coords[3] = 0.0;

/* we need to be realized before setting properties */
  dash = goo_canvas_line_dash_new (2, 5.0, 5.0);

  /* see goo-canvas-line.h for the docs */
  g_object_set (G_OBJECT (citem), "points", link->points, "line-width", 2.0,
      "line-dash", dash, "start-arrow", TRUE, NULL);
  goo_canvas_line_dash_unref (dash);

  //  goo_canvas_item_raise_pos (citem, 10);
  goo_canvas_item_raise (citem, NULL);
}
Пример #2
0
static void
create_events_area (GtkWidget              *canvas,
		    gint                    area_num,
		    GooCanvasPointerEvents  pointer_events,
		    gchar                  *label)
{
  gint row = area_num / 3, col = area_num % 3;
  gdouble x = col * 200, y = row * 150;
  GooCanvasItem *root, *rect;
  char *view_id;
  GooCanvasLineDash *dash;

  root = goo_canvas_get_root_item (GOO_CANVAS (canvas));

  dash = goo_canvas_line_dash_new (2, 5.0, 5.0);

  /* Create invisible item. */
  rect = goo_canvas_rect_new (root, x + 45, y + 35, 30, 30,
			      "fill-color", "red",
			      "visibility", GOO_CANVAS_ITEM_INVISIBLE,
			      "line-width", 5.0,
			      "pointer-events", pointer_events,
			      NULL);
  view_id = g_strdup_printf ("%s invisible", label);
  g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free);
  setup_item_signals (rect);

  /* Display a thin rect around it to indicate it is there. */
#if 1
  rect = goo_canvas_rect_new (root, x + 42.5, y + 32.5, 36, 36,
			      "line-dash", dash,
			      "line-width", 1.0,
			      "stroke-color", "gray",
			      NULL);
#endif

  /* Create unpainted item. */
  rect = goo_canvas_rect_new (root, x + 85, y + 35, 30, 30,
			      "stroke-pattern", NULL,
			      "line-width", 5.0,
			      "pointer-events", pointer_events,
			      NULL);
  view_id = g_strdup_printf ("%s unpainted", label);
  g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free);
  setup_item_signals (rect);

  /* Display a thin rect around it to indicate it is there. */
#if 1
  rect = goo_canvas_rect_new (root, x + 82.5, y + 32.5, 36, 36,
			      "line-dash", dash,
			      "line-width", 1.0,
			      "stroke-color", "gray",
			      NULL);
#endif

  /* Create stroked item. */
  rect = goo_canvas_rect_new (root, x + 125, y + 35, 30, 30,
			      "line-width", 5.0,
			      "pointer-events", pointer_events,
			      NULL);
  view_id = g_strdup_printf ("%s stroked", label);
  g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free);
  setup_item_signals (rect);

  /* Create filled item. */
  rect = goo_canvas_rect_new (root, x + 60, y + 75, 30, 30,
			      "fill-color", "red",
			      "stroke-pattern", NULL,
			      "line-width", 5.0,
			      "pointer-events", pointer_events,
			      NULL);
  view_id = g_strdup_printf ("%s filled", label);
  g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free);
  setup_item_signals (rect);

  /* Create stroked & filled item. */
  rect = goo_canvas_rect_new (root, x + 100, y + 75, 30, 30,
			      "fill-color", "red",
			      "line-width", 5.0,
			      "pointer-events", pointer_events,
			      NULL);
  view_id = g_strdup_printf ("%s stroked & filled", label);
  g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free);
  setup_item_signals (rect);

  goo_canvas_text_new (root, label, x + 100, y + 130, -1, GOO_CANVAS_ANCHOR_CENTER,
		       "font", "Sans 12",
		       "fill-color", "blue",
		       NULL);

  goo_canvas_line_dash_unref (dash);
}
Пример #3
0
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;
}