Re: Rotating an item in gnomecanvas.............



No, the gnome_canvas_item_rotate is not implemented. 

You have to use the affine to to this. In gcompris
(http://ofset.sf.net/gcompris) You can find these functions
(src/gcompris/gameutils.c) that should help you.

Good luck.

/* ======================================= */
/* As gnome does not implement its own API : gnome_canvas_item_rotate
   we have to do it ourselves ....
   IMPORTANT NOTE : This is designed for an item with "anchor" = 
GTK_ANCHOR_CENTER
   rotation is clockwise if angle > 0 */
void item_rotate(GnomeCanvasItem *item, double angle) {
	double r[6],t[6], x1, x2, y1, y2;

  gnome_canvas_item_get_bounds( item, &x1, &y1, &x2, &y2 );
  art_affine_translate( t , -(x2+x1)/2, -(y2+y1)/2 );
  art_affine_rotate( r, angle );
  art_affine_multiply( r, t, r);
	art_affine_translate( t , (x2+x1)/2, (y2+y1)/2 );
  art_affine_multiply( r, r, t);

  gnome_canvas_item_affine_absolute( item, r );
}

/* rotates an item around the center (x,y), relative to the widget's
coordinates */
void	item_rotate_with_center(GnomeCanvasItem *item, double angle, int x,
int y) {
	double r[6],t[6], x1, x2, y1, y2, tx, ty;
  gnome_canvas_item_get_bounds( item, &x1, &y1, &x2, &y2 );
	tx = x1 + x;
  ty = y1 + y;
  art_affine_translate( t , -tx, -ty );
  art_affine_rotate( r, angle );
  art_affine_multiply( r, t, r);
	art_affine_translate( t , tx, ty );
  art_affine_multiply( r, r, t);
  gnome_canvas_item_affine_absolute( item, r );
}


Le lun 29/09/2003 à 12:14, Suresh Kumar a écrit :
> Hi,
> 
>      I have drwan a rectangle in the canvas. When i used
> gnome_canvas_item_rotate() to rotate the rectangle, i got the
> error message "undefine reference to gnome_canvas_item_rotate".
> Is gnomecanvas doesnt support this command? Does i have to use
> affine transforms for this?
> 
>      I want to rotate the rectangle to some degree based on some
> origin points. For example, rotate the rectangle, which has the
> boundary points (100,100) (200,200), to 45.0 degree based on the
> point (100,100 ). How can i do it?
> 
>     My code is given below.
> 
> static void
> create_canvas_items(GtkWidget* canvas)
> {
>    GnomeCanvasGroup* group;
>    GnomeCanvasItem* item;
> 
>    group = gnome_canvas_root(GNOME_CANVAS(canvas));
> 
>    /* A translucent rectangle */
>    item = gnome_canvas_item_new (group,
> 
> gnome_canvas_rect_get_type(),
>                                       "x1", 100.0,
>                                       "y1", 100.0,
>                                       "x2", 200.0,
>                                       "y2", 200.0,
>                                       "fill_color_rgba",
> 0x3cb37180,
>                                       "outline_color", "black",
>                                       "width_units", 4.0,
>                                       NULL);
> 
>     /*  Rotate  the rectangle */
> 
>    gnome_canvas_item_rotate(item,100.0,100.0,45.0);
> }
> 
> 
> Thanx.
> 
> 
> ___________________________________________________
> Television meets Accounts; Jyoti Weds Rajaram.
> Rediff Matchmaker strikes another interesting match !!
> Visit http://matchmaker.rediff.com?1
> 
> _______________________________________________
> gnome-devel-list mailing list
> gnome-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/gnome-devel-list
> 




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]