Beispiel #1
0
static void
gst_editor_link_resize (GstEditorLink * link)
{
  gdouble x1, y1, x2, y2;

  GooCanvas * canvas;

  g_object_get (link, "x1", &x1, "y1", &y1, "x2", &x2, "y2", &y2, NULL);
  canvas = goo_canvas_item_get_canvas (GOO_CANVAS_ITEM (link));
  if (!canvas) {
    g_print ("Warning: gst_editor_link_resize canvas null\n");
    return;
  }
  goo_canvas_convert_from_pixels (canvas, &x1, &y1);
  goo_canvas_convert_to_item_space (canvas, GOO_CANVAS_ITEM (link), &x1, &y1);

  // goo_canvas_item_get_parent(GOO_CANVAS_ITEM (link)),&x1, &y1);
  goo_canvas_convert_from_pixels (canvas, &x2, &y2);
  goo_canvas_convert_to_item_space (canvas, GOO_CANVAS_ITEM (link), &x2, &y2);

  // goo_canvas_item_get_parent(GOO_CANVAS_ITEM (link)), &x2, &y2);
  /* we do this in reverse so that with dot-dash lines it gives the illusion of
     pulling out a rope from the element */
  link->points->coords[2] = x1;
  link->points->coords[3] = y1;
  link->points->coords[0] = x2;
  link->points->coords[1] = y2;
  g_object_set (G_OBJECT (link), "points", link->points, NULL);
}
Beispiel #2
0
/*
 * Request score
 *
 */
static void request_score()
{
  double x_offset = 390;
  double y_offset = 150;
  gchar *tmpstr;

  /* Set the maximum text to calc the background */
  tmpstr =  g_strdup_printf(_("Points = %s"), "00000");
  answer_item = goo_canvas_text_new (boardRootItem,
				     tmpstr,
				     (double) x_offset,
				     (double) y_offset,
				     -1,
				     GTK_ANCHOR_CENTER,
				     "font", gc_skin_font_board_title_bold,
				     "fill-color", "white",
				     NULL);
  g_free(tmpstr);

  GooCanvasBounds bounds;
  goo_canvas_item_get_bounds (answer_item, &bounds);
  goo_canvas_convert_to_item_space(goo_canvas_item_get_canvas(answer_item),
				   answer_item,
				   &bounds.x1, &bounds.y1);
  goo_canvas_convert_to_item_space(goo_canvas_item_get_canvas(answer_item),
				   answer_item,
				   &bounds.x2, &bounds.y2);

  int gap = 15;
  GooCanvasItem *item =				\
    goo_canvas_rect_new (boardRootItem,
			 bounds.x1 - gap,
			 bounds.y1 - gap,
			 (bounds.x2 - bounds.x1) + gap*2,
			 (bounds.y2 - bounds.y1) + gap*2,
			 "stroke_color_rgba", 0xFFFFFFFFL,
			 "fill_color_rgba", 0X5599FFCCL,
			 "line-width", (double) 2,
			 "radius-x", (double) 10,
			 "radius-y", (double) 10,
			 NULL);
  goo_canvas_item_raise(answer_item, item);

  /* Set the correct initial text */
  tmpstr = g_strdup_printf(_("Points = %s"), answer_string);
  g_object_set(answer_item,
	       "text", tmpstr,
	       NULL);
  g_free(tmpstr);
}
Beispiel #3
0
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;
}
Beispiel #4
0
static void
paint_large_line (GooDemoLargeLine      *line,
		  cairo_t               *cr,
		  const GooCanvasBounds *bounds,
		  gdouble                line_width,
		  gdouble                x1,
		  gdouble                y1,
		  gdouble                x2,
		  gdouble                y2)
{
  GooCanvasItem *item = (GooCanvasItem*) line;
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) line;
  GooCanvas *canvas = simple->canvas;
  GooCanvasBounds tmp_bounds = *bounds;
  gdouble point1[2], point2[2], *p1, *p2;

  point1[0] = x1;
  point1[1] = y1;
  point2[0] = x2;
  point2[1] = y2;

  /* Transform the coordinates to the canvas device space, so we can clamp
     the line to the bounds to be painted. */
  goo_canvas_convert_from_item_space (canvas, item, &point1[0], &point1[1]);
  goo_canvas_convert_from_item_space (canvas, item, &point2[0], &point2[1]);

  /* Extend the bounds a bit to account for the line width. */
  tmp_bounds.x1 -= line_width;
  tmp_bounds.y1 -= line_width;
  tmp_bounds.x2 += line_width;
  tmp_bounds.y2 += line_width;

  /* Make p1 the left-most point. */
  if (point1[0] < point2[0])
    {
      p1 = point1;
      p2 = point2;
    }
  else
    {
      p1 = point2;
      p2 = point1;
    }

  /* Just return if the line is completely outside the bounds horizontally. */
  if (p2[0] < tmp_bounds.x1 || p1[0] > tmp_bounds.x2)
    return;

  /* Clamp each x coordinate to the bounds. */
  if (p1[0] < tmp_bounds.x1)
    clamp_x (p1, p2, tmp_bounds.x1);
  if (p2[0] > tmp_bounds.x2)
    clamp_x (p2, p1, tmp_bounds.x2);

  /* Now make p1 the top-most point. */
  if (point1[1] < point2[1])
    {
      p1 = point1;
      p2 = point2;
    }
  else
    {
      p1 = point2;
      p2 = point1;
    }

  /* Just return if the line is completely outside the bounds vertically. */
  if (p2[1] < tmp_bounds.y1 || p1[1] > tmp_bounds.y2)
    return;

  /* Clamp each y coordinate to the bounds. */
  if (p1[1] < tmp_bounds.y1)
    clamp_y (p1, p2, tmp_bounds.y1);
  if (p2[1] > tmp_bounds.y2)
    clamp_y (p2, p1, tmp_bounds.y2);

  /* Convert back to item space. */
  goo_canvas_convert_to_item_space (canvas, item, &point1[0], &point1[1]);
  goo_canvas_convert_to_item_space (canvas, item, &point2[0], &point2[1]);

  /* Draw the line. */
  cairo_move_to (cr, point1[0], point1[1]);
  cairo_line_to (cr, point2[0], point2[1]);
  cairo_stroke (cr);
}