RES: RES: [PHP-GTK] Question about GtkDrawingArea

From: Date: Thu, 14 Jul 2005 19:57:03 +0000
Subject: RES: RES: [PHP-GTK] Question about GtkDrawingArea
References: 1  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-6027@lists.php.net to get a copy of this message
In my case, I use this procedure: $this->drawing_area->set_events( GDK_POINTER_MOTION_MASK | GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK ); $this->drawing_area->connect('expose_event', array(&$this,'expose_event')); $this->drawing_area->connect('configure_event', array(&$this,'configure_event')); $this->drawing_area->connect('motion_notify_event',array(&$this,'proc_x_ pos')); $this->drawing_area->connect('motion_notify_event',array(&$this,'proc_y_ pos')); $this->drawing_area->connect('motion_notify_event',array(&$this,'move_ob ject')); $this->drawing_area->connect('leave_notify_event',array(&$this,'deixando _janela')); $this->drawing_area->connect_object('button-press-event',array(&$this,'p roc_click')); $this->drawing_area->connect_object('button-release-event',array(&$this, 'proc_unclick')); This process almost every event you need to implement a GtkDrawingArea. Sorry about the line wrapping, Dont remenber how to turn it off ;) Piero -----Mensagem original----- De: Brian Stumm [mailto:bstumm@energytechnologysystems.com] Enviada em: quinta-feira, 14 de julho de 2005 14:39 Para: php-gtk-general@lists.php.net Assunto: Re: RES: [PHP-GTK] Question about GtkDrawingArea Could you explain this further? I've tried to implement the expose-event with no success by following the example used on the gtkdrawingarea man page. The difference I *think* is that the examples I've seen draw the entire image at once where what I'm doing is drawing very short lines once per second and I'm not re-drawing the old lines/data during each update. Must I redraw the entire graph each second? If I use the expose-event to call my "update" function then it draws the entire graph in one step but still the lines disappear after minimizing the window. Thanks again. "Piero B. Contezini" wrote: > Hi, > > Register a expose event on this window and do a update on the widget > when the event ocurrs. > > Piero > > -----Mensagem original----- > De: Brian Stumm [mailto:bstumm@energytechnologysystems.com] > Enviada em: quinta-feira, 14 de julho de 2005 12:57 > Para: php-gtk-general > Assunto: [PHP-GTK] Question about GtkDrawingArea > > Below is sample code using the GtkDrawingArea construct to do real time > time/temperature graphing. The code provided herein is a simulation > only. Problem I am having is that when minimizing the window or putting > the window to the background with other windows in front of it the > gdk::drawline's disappear. Any thoughts on preventing this? Perhaps I am > not doing things correctly here. Any input appreciated greatly. Thanks > in advance. > > <?php > > $oldx = 0; > $oldy1 = 550; > $oldy2 = 550; > $oldy3 = 550; > $oldy4 = 550; > > if (!extension_loaded('gtk')) { > dl( 'php_gtk.' . PHP_SHLIB_SUFFIX); > } > > function delete_event() > { > return false; > } > > function destroy() > { > Gtk::main_quit(); > } > > function update() > { > global $gdkwindow, $oldx, $oldy1, $oldy2, $oldy3, $oldy4; > > $colormap = $gdkwindow->colormap; > > $blue = $gdkwindow->new_gc(); > $blue->foreground = $colormap->alloc('blue'); > $blue->line_width = 1; > > $yellow = $gdkwindow->new_gc(); > $yellow->foreground = $colormap->alloc('yellow'); > $yellow->line_width = 1; > > $red = $gdkwindow->new_gc(); > $red->foreground = $colormap->alloc('red'); > $red->line_width = 1; > > $green = $gdkwindow->new_gc(); > $green->foreground = $colormap->alloc('green'); > $green->line_width = 1; > > $x = $oldx + 1; > if ($x < 30) { > $y1 = $oldy1 - rand(2, rand(3, 5)); > $y2 = $oldy2 - rand(2, rand(3, 5)); > $y3 = $oldy3 - rand(2, rand(3, 5)); > $y4 = $oldy4 - rand(2, rand(3, 5)); > } else if ($x < 25) { > $y1 = $oldy1 - rand(0, rand(-1, 2)); > $y2 = $oldy2 - rand(0, rand(-1, 2)); > $y3 = $oldy3 - rand(0, rand(-1, 2)); > $y4 = $oldy4 - rand(0, rand(-1, 2)); > } else if ($x < 50) { > $y1 = $oldy1 - rand(0, rand(0, 1)); > $y2 = $oldy2 - rand(0, rand(0, 1)); > $y3 = $oldy3 - rand(0, rand(0, 1)); > $y4 = $oldy4 - rand(0, rand(0, 1)); > } else if ($x < 260) { > $y1 = $oldy1 - rand(0, rand(-1, 1)); > $y2 = $oldy2 - rand(0, rand(-1, 1)); > $y3 = $oldy3 - rand(0, rand(-1, 1)); > $y4 = $oldy4 - rand(0, rand(-1, 1)); > } else if($x > 350) { > $y1 = $oldy1 - rand(2, rand(4, 5)); > $y2 = $oldy2 - rand(2, rand(4, 5)); > $y3 = $oldy3 - rand(2, rand(4, 5)); > $y4 = $oldy4 - rand(2, rand(4, 5)); > } else if($x > 220) { > $y1 = $oldy1 + rand(1, rand(5, 6)); > $y2 = $oldy2 + rand(1, rand(5, 6)); > $y3 = $oldy3 + rand(1, rand(5, 6)); > $y4 = $oldy4 + rand(1, rand(5, 6)); > } else { > $y1 = $oldy1 - rand(0, rand(-1, 1)); > $y2 = $oldy2 - rand(0, rand(-1, 1)); > $y3 = $oldy3 - rand(0, rand(-1, 1)); > $y4 = $oldy4 - rand(0, rand(-1, 1)); > } > > gdk::draw_line($gdkwindow, $red, $oldx, $oldy1, $x, $y1); > gdk::draw_line($gdkwindow, $yellow, $oldx, $oldy2, $x, $y2); > gdk::draw_line($gdkwindow, $blue, $oldx, $oldy3, $x, $y3); > gdk::draw_line($gdkwindow, $green, $oldx, $oldy4, $x, $y4); > > $oldx = $x; > $oldy1 = $y1; > $oldy2 = $y2; > $oldy3 = $y3; > $oldy4 = $y4; > > return TRUE; > } > > $window = &new GtkWindow(); > $window->connect('destroy', 'destroy'); > $window->connect('delete-event', 'delete_event'); > $window->set_border_width(10); > > $drawingarea = &new GtkDrawingArea(); > $drawingarea->size(800, 600); > $drawingarea->set_events(GDK_BUTTON_PRESS_MASK | > GDK_BUTTON_RELEASE_MASK); > $window->add($drawingarea); > > $drawingarea->realize(); > $style = $drawingarea->style; > $gdkwindow = $drawingarea->window; > > $window->show_all(); > > gtk::timeout_add(1000, 'update'); > > Gtk::main(); > > ?> > > -- > Brian Stumm > ETS - Energy Technology Systems, Inc > bstumm@energytechnologysystems.com > http://energytechnologysystems.com > > -- > PHP-GTK General Mailing List (http://gtk.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- Brian Stumm ETS - Energy Technology Systems, Inc bstumm@energytechnologysystems.com http://energytechnologysystems.com -- PHP-GTK General Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.gtk.general (#6027) next »