The Dial widget is a graphical object which displays
an analog value. This is a direct port of the Gtk
tutorial about creating
graphical
widgets
Details
The Dial widget can display a value from
-120 to 120. This could be changed, just write the right
mathematical operations (I'm a bit lazy, guys). This widget can
draw directly into a Window (direct drawing) or draw into a
pixmap, which we can then refresh as needed ; just look at
the class source code to see how it is done.
Direct draw is much faster for large windows ; I can't see
differences for small ones. The actual graphical part
(drawing the dial) is a php-gtk port from the Gtk
tutorial.
This widget is a good start
when you need to build dynamic graphical widgets like this
one.
Example of use
<?php
$dial = new Dial(); # (1)
$dial->set_size_request(80, 80);
$dial->set_value(0);
$window = new GtkWindow();
$window->connect_simple('destroy', array('gtk', 'main_quit'));
$window->set_title('Dial demo');
$window->set_position(Gtk::WIN_POS_CENTER);
$window->set_border_width(8);
$window->add($dial); # (2)
$window->show_all();
Gtk::timeout_add(100, 'dial_timeout', $dial); # (3)
Gtk::main();
/**
* a timeout function to change the dial value from -120 to 120
* giving an animation to the widget.
*/
function dial_timeout($dial)
{
static $value = 0;
static $increment = 4;
if ($value < -120)
$increment *= -1 ;
if ($value > 120)
$increment *= -1;
$value += $increment;
# $dial->set_value($value / 180*PI);
$dial->set_value($value); # (4)
Gtk::timeout_add(20, 'dial_timeout', $dial);
return FALSE;
}
?>
Highlights
- create a dial widget,
- add this widget to a composite widget (any composite
can be used)
- setup a timeout function to update the dial value
- set the dial value with
$dial->set_value($val)
Full source code
See the attached sources file below
Recent comments
6 weeks 2 days ago
12 weeks 1 day ago
13 weeks 6 days ago
20 weeks 2 days ago
21 weeks 4 days ago
21 weeks 5 days ago
22 weeks 6 days ago
23 weeks 5 days ago
34 weeks 3 days ago
34 weeks 4 days ago