Sample Code 118: How to have a Screen Ruler - Part 2 - with mouse position displayed? |
|
Written by kksou
|
|
Thursday, 14 December 2006 |
|
Problem You have set up a basic screen ruler in Part 1. Now you would like to have the exact mouse position displayed in the title bar as shown below:

Solution
Sample Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <?php $window = new GtkWindow(); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox());
$ruler = new GtkHRuler(); $ruler->set_range(0, 800, 100, 1024); $ruler->set_size_request(800, 20);
$eventbox = new GtkEventBox(); // note 1
$eventbox->add($ruler); $eventbox->connect('motion-notify-event', 'on_motion', $window); // note 2
$vbox->pack_start($eventbox, 0, 0);
$window->show_all();
|
- Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
- Registration is free and immediate.
- Have some doubt about the registration? Please read this forum article.
Explanation This example makes use of the code in Part 1.
What's new here:
- Create an eventbox and stuff the ruler inside.
- Call the callback function
on_motion every time the user moves the mouse.
- Write the mouse position in the window's title bar.
Related Links
User reviews There are no user reviews yet. Note: You have to be a registered member to leave a comment. Free registration here. |