Re: Question about mouse coordinates in GDK images



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sun, Dec 10, 2006 at 06:43:07PM -0800, Erik Walter wrote:
I'm trying to do a fairly simple thing and I haven't been able to  
find any answers (that work) to my problem.

I just need to find the mouse (pointer) coordinates relative to a GDK  
image's origin (i.e. the pixel that would be set via a  
gdk_image_put_pixel() that corresponds to the pointer location).

the GDK Image I have is in a GtkImage, inside a GtkScrolledWindow  
(i.e. via gtk_scrolled_add_with_viewport()) and that's inside a  
GtkEventBox and that's inside a GtkWindow.

So basically....

GDKImage
GtkImage
GtkScrolledWindow
GtkEventBox
GtkWindow

Both gdk_window_get_pointer() and gtk_widget_get_pointer() always  
return coordinates relative to the base window.  But if you resize  
the window to be larger than the image, it centers it in the window  
and the coordinates are wrong.

The only way I can think to deal with this is REALLY hacky,   
basically attempting to "predict" where the image is based on the  
assumption that it's centered in the main window's dimensions and  
doing some guesswork.  But that seems like the wrong way to approach  
this.

Would this help (warning: untested):

  GtkImage *img;
  struct GtkAllocation alloc;
  gint imgx, imgy;
  ...
  imgx = GTK_WIDGET(img)->allocation.x;
  imgy = GTK_WIDGET(img)->allocation.y;
  
(or whatever equivalent code).

I would assume that the GtkImage's size matches the size of the
contained GdkImage (at least if you set its padding to zero).

Regards
- -- tomÃs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFFf44+Bcgs9XrR2kYRAhjLAJ9vBRrsGJjHXN6oZv0u8AjfDRj72wCfQNt+
RUu6vvsSuM6Kz4AWcM+rYx8=
=+kQF
-----END PGP SIGNATURE-----




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