GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 23, 2014 7:14 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: GTK-2.0 signal for a click in an area of a grafic
PostPosted: Mon Feb 04, 2013 1:43 pm 
Offline
Familiar Face

Joined: Fri Oct 26, 2012 10:49 am
Posts: 37
Hello
I have a grafic in a dialog made with the cairo library.
The grafic contains little squares or circles. Their quantity depends on a configuration parameter.
There may be 4 squres in the grafic or 8, or 12.
The grafic has always the same width, the diimension of the squares depends on their quantity
My question is: is there a simple possibility to detect which square has been clicked, when somebody clicked on one of the squares?
Does the event "clicked" on a grafic exist and how can I retrieve the coordinate of the click?

I hope my question is comprehensible

Thanks a lot in advance

M.Boerner


Top
 Profile  
 
 Post subject: Re: GTK-2.0 signal for a click in an area of a grafic
PostPosted: Wed Feb 06, 2013 11:16 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
Yes you can do this. I have done it but the code https://github.com/pchilds/MOFsim/blob/master/src/drawcirc.c is in a bit of a sorry incomplete state that I may or may not get back to sometime. It's a lot of wading trying to read it through so here is a short summary:
You will need the following:
1. Have a data structure of the shapes from which you can determine the coordinates of all the shapes (I imagine you already have this).
2. Set up button_press/release or motion_notify events (e.g. you may want to make a shape highlight if the mouse goes over it, to make it clearer to the user that it can be clicked). In a custom widget this would be done e.g. by putting the following in the class_init and init functions:
Code:
static void gtk_your_widget_name_class_init(GtkYourWidgetNameClass *klass)
{
   ...
   (GTK_WIDGET_CLASS(klass))->button_press_event=gtk_your_widget_name_button_press;
}
static void gtk_your_widget_name_init(GtkYourWidgetName *name)
{
   gtk_widget_add_events(GTK_WIDGET(name), GDK_BUTTON_PRESS_MASK);
   ...
}

3. In the _button_press(GtkWidget *widget, GdkEventButton *event) function, iterate over all the data shapes to determine if the event occurred within the bounds of any of the shapes. Coordinates of the event are found as event->x and event->y


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group