Unsymmetrical rotation

Blagoj Kupev <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <CAB=Grm0h6LFY7wBsX7zjJNgBTz+-OpBiYinGdF5+bU_Pnh4Ybw@mail.gmail.com>
Hello,
I'm trying to rotate a png image with origin in the centre of the image and
then try to put it to a gtk window with offset, but the placement does not
work as I'm expecting.

The code:
  cairo_t *cr;
  int w, h;
  int x_origin, y_origin;

  //Load an image from file
  cairo_surface_t *surf1 =
cairo_image_surface_create_from_png("./images/strelka_100_100.png");
  w = cairo_image_surface_get_width (surf1);
  h = cairo_image_surface_get_height (surf1);

  //Create the cairo context
  cr = gdk_cairo_create (widget->window);

  //Initialize the image to white transparent
  cairo_set_source_rgba(cr, 0, 0, 0, 1);
  cairo_paint(cr);

  x_origin = w/2;
  y_origin = h/2;
  x_offset = 0;

  cairo_translate (cr, x_origin, y_origin);
  cairo_rotate (cr, (2*3.14*angle/360));

  cairo_set_source_surface(cr, surf1, -x_origin+x_offset, -y_origin);
  cairo_paint(cr);


In this case for any angle the rotated image starts from the top left
corner and is symmetrical. But if I try to set value different than 0 in
x_offset the position of the image is offset differently according to the
angle. So if i set x_offset = 50 and angle = 20; then the image is moved
not only in x direction but in y as well. For same offset but different
angle the image is placed at different x and y offsets.

So, I'm wondering how to rotate the image and set it with offset that is
different than 0 and the image is always placed there regardless of the
value set in angle?

Thanks,
Blagoj

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.