Exemple #1
0
static void
gst_editor_link_get_property (GObject * object, guint prop_id, GValue * value,
    GParamSpec * pspec)
{
  GooCanvas * canvas;
  if ((object==NULL)||(!GST_IS_EDITOR_LINK(object))){
    g_print("Warning: gst_editor_link_realize failed because citem %p is no gst_editor_link\n",object);
    return;
  }
  GstEditorLink *link = GST_EDITOR_LINK (object);
  gdouble d = 0.0, blah = 0.0;

  switch (prop_id) {
    case PROP_X:
      g_value_set_double (value, link->x);
      break;

    case PROP_Y:
      g_value_set_double (value, link->y);
      break;

    case PROP_X1:
      if (link->srcpad) {
        d = link->srcpad->width;
        canvas = goo_canvas_item_get_canvas (GOO_CANVAS_ITEM (link->srcpad));
        goo_canvas_convert_from_item_space (
            canvas, GOO_CANVAS_ITEM (link->srcpad), &d, &blah);
        if (canvas)
          goo_canvas_convert_to_pixels (canvas, &d, &blah);
        else
          g_print (
              "fixme: Canvas Item (X2, srcpad) got no Canvas:%p, Pixels d: %f, "
              "blah: %f\n",
              canvas, d, blah);
      } else if (link->dragging) {
        d = link->x;
      } else {
        g_warning ("no src pad");
      }
      g_value_set_double (value, d);
      break;

    case PROP_X2:
      if (link->sinkpad) {
        d = 0;
        canvas = goo_canvas_item_get_canvas (GOO_CANVAS_ITEM (link->sinkpad));
        // g_print("Canvas:%p, Pixels d: %f, blah: %f\n",canvas, d,blah);
        goo_canvas_convert_from_item_space (
            canvas, GOO_CANVAS_ITEM (link->sinkpad), &d, &blah);
        // FIXME: Segfaults here
        // g_print("Canvas:%p, Pixels d: %f, blah: %f\n",canvas, d,blah);
        if (canvas)
          goo_canvas_convert_to_pixels (canvas, &d, &blah);
        else {
          g_print (
              "fixme: Canvas Item (X2, sinkpad) got no Canvas:%p, Pixels d: "
              "%f, blah: %f\n",
              canvas, d, blah);
          d = d + 5;
        }
        // g_print("Canvas:%p, Pixels d: %f, blah: %f\n",canvas, d,blah);
      } else if (link->dragging) {
        d = link->x;
      } else {
        g_warning ("no sink pad");
      }

      g_value_set_double (value, d);
      break;

    case PROP_Y1:
      if (link->srcpad) {
        d = link->srcpad->height / 2;
        canvas = goo_canvas_item_get_canvas (GOO_CANVAS_ITEM (link->srcpad));
        goo_canvas_convert_from_item_space (
            canvas, GOO_CANVAS_ITEM (link->srcpad), &blah, &d);
        if (canvas)
          goo_canvas_convert_to_pixels (canvas, &blah, &d);
        else
          g_print (
              "fixme: Canvas Item (Y1, srcpad) got no Canvas:%p, Pixels d: %f, "
              "blah: %f\n",
              canvas, d, blah);
      } else if (link->dragging) {
        d = link->y;
      } else {
        g_warning ("no src pad");
      }
      g_value_set_double (value, d);
      break;

    case PROP_Y2:
      if (link->sinkpad) {
        d = link->sinkpad->height / 2;
        canvas = goo_canvas_item_get_canvas (GOO_CANVAS_ITEM (link->sinkpad));
        goo_canvas_convert_from_item_space (
            canvas, GOO_CANVAS_ITEM (link->sinkpad), &blah, &d);
        if (canvas) {
          goo_canvas_convert_to_pixels (canvas, &blah, &d);
        } else {
          g_print (
              "fixme: Canvas Item (Y2, sinkpad) got no Canvas:%p, Pixels d: "
              "%f, blah: %f\n",
              canvas, d, blah);
          d = d + 5;
        }
      } else if (link->dragging) {
        d = link->y;
      } else {
        g_warning ("no sink pad");
      }
      g_value_set_double (value, d);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}
Exemple #2
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);
}
Exemple #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;
}
Exemple #4
0
/* ==================================== */
static gint
item_event(GooCanvasItem *item,
	   GooCanvasItem *target,
	   GdkEvent *event,
	   PieceItem *data)
{
  double item_x, item_y;

  if(!gcomprisBoard)
    return FALSE;

  if(board_paused)
    return FALSE;

  if(data && !data->on_top)
    return FALSE;

  switch (event->type)
    {
    case GDK_ENTER_NOTIFY:
      g_object_set(item,
		   "stroke-color", "white",
		   "line-width", (double)3,
		   NULL);
      break;
    case GDK_LEAVE_NOTIFY:
      g_object_set(item,
		   "stroke-color", "black",
		   "line-width", (double)1,
		   NULL);
      break;
    case GDK_BUTTON_PRESS:
      switch(event->button.button)
	{
	case 1:
	  gc_sound_play_ogg ("sounds/bleep.wav", NULL);
	  gc_drag_offset_save(event);
	  goo_canvas_item_raise(data->group, NULL);
	  break;
	}
      break;

    case GDK_MOTION_NOTIFY:
      gc_drag_item_move(event, data->group);
      break;

    case GDK_BUTTON_RELEASE:
	{
	  gint i;
	  gint tmpi, tmpj;
	  double tmpx, tmpy;
	  PieceItem *piece_src;
	  PieceItem *piece_dst;
	  gint col = 0, line;

	  item_x = event->button.x;
	  item_y = event->button.y;
	  goo_canvas_convert_from_item_space(goo_canvas_item_get_canvas(item),
					     item,
					     &item_x, &item_y);

	  /* Search the column (x) where this item is ungrabbed */
	  for(i=0; i<=number_of_item_x; i++)
	    if(position[i][0]->x   < item_x &&
	       position[i+1][0]->x > item_x)
	      col = i;

	  /* Bad drop / Outside of column area */
	  /* Bad drop / On the same column */
	  if(col<0 || col > number_of_item_x || col == data->i)
	    {
	      gc_sound_play_ogg ("sounds/eraser2.wav", NULL);

	      /* Return to the original position */
	      gc_item_absolute_move (data->group, data->x , data->y);
	      return FALSE;
	    }


	  /* Now search the free line (y) */
	  line = number_of_item_y;
	  for(i=number_of_item_y-1; i>=0; i--)
	    if(position[col][i]->color == -1)
	      line = i;

	  /* Bad drop / Too many pieces here */
	  if(line >= number_of_item_y)
	    {
	      gc_sound_play_ogg ("sounds/eraser2.wav", NULL);

	      /* Return to the original position */
	      gc_item_absolute_move (data->group, data->x , data->y);

	      return FALSE;
	    }

	  /* Update ontop values for the piece under the grabbed one */
	  if(data->j>0)
	    position[data->i][data->j-1]->on_top = TRUE;

	  /* Update ontop values for the piece under the ungrabbed one */
	  if(line>0)
	    position[col][line-1]->on_top = FALSE;

	  /* Move the piece */
	  piece_dst = position[col][line];
	  piece_src = data;
	  gc_item_absolute_move (data->group, piece_dst->x , piece_dst->y);

	  gc_sound_play_ogg ("sounds/scroll.wav", NULL);

	  /* Swap values in the pieces */
	  tmpx    = data->x;
	  tmpy    = data->y;
	  piece_src->x = piece_dst->x;
	  piece_src->y = piece_dst->y;
	  piece_dst->x = tmpx;
	  piece_dst->y = tmpy;

	  tmpi    = data->i;
	  tmpj    = data->j;
	  position[tmpi][tmpj]->i = piece_dst->i;
	  position[tmpi][tmpj]->j = piece_dst->j;
	  piece_dst->i  = tmpi;
	  piece_dst->j  = tmpj;

	  position[piece_src->i][piece_src->j] = piece_src;
	  position[piece_dst->i][piece_dst->j] = piece_dst;

	  //	  dump_solution();
	  if(is_completed())
	    {
	      gamewon = TRUE;
	      hanoi_destroy_all_items();
	      gc_bonus_display(gamewon, GC_BONUS_SMILEY);
	    }
	}
      break;

    default:
      break;
    }


  return FALSE;
}