Get co-ordnates. (1 viewing) (1) Guest
Favoured: 0
|
|
|
TOPIC: Get co-ordnates.
|
neil (User)
Junior Boarder
Posts: 20
|
|
Get co-ordnates. 3 Months, 3 Weeks ago
|
Karma: 0
|
|
Hi,
Can I find the position (x,y co-ordinates) of an eventbox, or a label ??
Neil.
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
kksou (Admin)
Admin
Posts: 391
|
|
Re:Get co-ordnates. 3 Months, 3 Weeks ago
|
Karma: 8
|
|
You want to be a bit more specific? x-y co-ordinate of the top, left corner? of the eventbox/label?
Regards,
/kksou
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
neil (User)
Junior Boarder
Posts: 20
|
|
Re:Get co-ordnates. 3 Months, 3 Weeks ago
|
Karma: 0
|
|
x-y co-ordinate of the top, left corner? of the eventbox/label ??
yes please, kksou.
(I really want the left/middle, but i expect given the left top, I can use height/2 to work it out).
Neil.
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
kksou (Admin)
Admin
Posts: 391
|
|
Re:Get co-ordnates. 3 Months, 3 Weeks ago
|
Karma: 8
|
|
Use $label->window->get_geometry()
It will return a 5-tuple containing the window's location and size (x, y, width, height) and the bit depth of the window.
Here's a sample code you can try. Take a look in the command window to see the output.
I find that it only works when you stuff the label in an eventbox. If you just use a GtkLabel without GtkEventBox, for some reason, the value does not seem to be correct.
Regards,
/kksou
$window = new GtkWindow();
$window->set_size_request(400, 200);
$window->connect_simple('destroy', array('Gtk','main_quit'));
$window->add($vbox = new GtkVBox());
$vbox->pack_start(new GtkLabel());
$vbox->pack_start($hbox = new GtkHBox());
$hbox->pack_start(new GtkLabel());
$label = new GtkLabel('this is the label');
$hbox->pack_start($eventbox = new GtkEventBox, 0);
$eventbox->add($label);
$eventbox->modify_bg(Gtk::STATE_NORMAL, GdkColor::parse("#aaaaaa"));
$hbox->pack_start(new GtkLabel());
$vbox->pack_start(new GtkLabel());
$window->show_all();
$label_pos = $label->window->get_geometry();
print_r($label_pos);
Gtk::main();
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
|
|
|
|