Re: Obtaining a location on a Drawing Area via a mouse click.



Colin Thomas a écrit :
> 
> Hi,
> 
> I would like to be able to click on a Drawing area and extract
> the cursors position, and possibly drag-select over its suface.
> 
> Are there any tutorials on this?
> 
> I have connected a function to the button release on the Drawing
> Area (see below), this does not seem to trigger the function call,
> 
>   gtk_signal_connect (GTK_OBJECT (guiDrawingArea), "button_press_event",
>                       GTK_SIGNAL_FUNC (on_guiDrawingArea_button_press_event),
>                       NULL);
> 
> But even if I managed to get the function call to execute, from where do
> I extract the cursor's location..
> 
> I look forward to your collective wisdom..
> 
> Many thanks in advance..
> 
> Colin Thomas.
> 
Hi,
I never use a Drawing area but there is some rules that can be apply.
First if the widget don't catch the event you want, then you have to set
it :
  gtk_widget_set_events(GTK_WIDGET(glarea), 
                        GDK_BUTTON_PRESS_MASK|
			GDK_BUTTON_RELEASE_MASK);
if you want to catch only button_press, and button_release...
Then connect your function as you have done.

In this function you have a prototype. For example button_press have
this
prototype (You can find this in the GtkWidget doc) :
	gboolean    user_function      (GtkWidget *widget,
					GdkEventButton *event,
					gpointer user_data);
which mean that your function must be like this :
gboolean on_guiDrawingArea_button_press_event (GtkWidget *widget,
GdkEventButton *event,
	gpointer user_data);

In the field event, you have a GdkEventButton. This GdkEventButton has
this structure
	GdkEventType type;
	GdkWindow *window;
	gint8 send_event;
	guint32 time;
	gdouble x;
	gdouble y;
	gdouble pressure;
	gdouble xtilt;
	gdouble ytilt;
	guint state;
	guint button;
	GdkInputSource source;
	guint32 deviceid;
	gdouble x_root, y_root;
where x and y is where you have pressed
Should look to the GdkEvent doc.

Hope this help
-- 
Florent DEVIN




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