Re: Get position of cursor in widget?



On Tue, 2007-07-17 at 13:53 +0200, CÃdric Lucantis wrote:
Le lundi 16 juillet 2007 12:50, charlesvpacker a Ãcrit :
I'm a GTK newbie who has successfully taken the very first
steps toward building a custom image processing application.
I've figured out how to read and display an image using
a GtkImage and GtkPixbuf. I've also modified a block of pixels
in the existing pixbuf and updated the displayed image
via gtk_image_set_from_pixbuf. Now I want to get the pixel
position of the mouse cursor resting on the image. I don't recall
seeing a GTK tutorial on capturing pointer position or motion.
Could somebody, um, point me to one?


If you want this from within a mouse event handler, you can use the 
(x,y) and (x_root,y_root) members provided by all the mouse event 
types. The first pair gives the position of the mouse relative to the 
event window and the second the position relative to the screen origin. 

If you're not in a handler, you still have gdk_window_get_pointer() and 
gdk_display_get_pointer(). See the Gdk reference manual for more infos 
(sections 'Event structures', 'Windows' and 'Display').

You can also use gtk_widget_get_pointer(), which has the advantage of
providing the position in widget co-ordinates.  The gdk functions,
including the gdk event callbacks, provide it in (Gdk/X) window
co-ordinates.  The two can be different in, for example, TreeView
columns with headers, and some Gtk functions (such as for example
gtk_tree_view_get_dest_row_at_pos()) expect widget co-ordinates.

Chris





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