Weird behaviour with declared PHP classes and GDK drawing functions
| From: | Steph Fox | Date: | Sat, 22 Oct 2005 16:22:09 +0000 |
| Subject: | Weird behaviour with declared PHP classes and GDK drawing functions | ||
| Groups: | php.gtk.dev | ||
| Request: | Send a blank email to php-gtk-dev+get-1891@lists.php.net to get a copy of this message | ||
Andrei, can you look into this please? It's very, very weird.
Try adding the line
class Scribble {}
to the top of the enclosed working script.
That's all you have to do to break the 3 drawing functions in it and cause
PHP-GTK to crash on exit. You don't even need to instantiate the class (or
make it instatiatable, if that's a word).
Outcomment the drawing functions, and it stops crashing. Bizarre.
PHP bug, GTK bug or PHP-GTK bug?
- Steph
<?php /* $Id: scribble.php,v 1.7 2002/12/04 17:31:50 fmk Exp $ */ $pixmap = null; function configure_event($widget, $event) { global $pixmap; $pixmap = new GdkPixmap($widget->window, $widget->allocation->width, $widget->allocation->height, -1); $pixmap->draw_rectangle($widget->style->white_gc, true, 0, 0, $widget->allocation->width, $widget->allocation->height); return true; } function expose_event($widget, $event) { global $pixmap; $widget->window->draw_drawable($widget->style->fg_gc[$widget->state], $pixmap, $event->area->x, $event->area->y, $event->area->x, $event->area->y, $event->area->width, $event->area->height); return false; } function button_press_event($widget, $event) { global $pixmap; if ($event->button == 1 && $pixmap) draw_brush($widget, (int)$event->x, (int)$event->y); return true; } function motion_notify_event($widget, $event) { global $pixmap; $window = $event->window; $pointer = $window->get_pointer(); $x = $pointer[0]; $y = $pointer[1]; $state = $pointer[2]; if (($state & GDK::BUTTON1_MASK) && $pixmap) draw_brush($widget, $x, $y); return true; } function draw_brush($widget, $x, $y) { global $pixmap; $pixmap->draw_arc($widget->style->black_gc, true, $x - 4, $y - 4, 8, 8, 0, 64 * 360); $widget->queue_draw_area($x - 4, $y - 4, 8, 8); } $window = new GtkWindow(); $window->set_name('Test Input'); $window->set_position(GTK::WIN_POS_CENTER); $window->connect_simple('destroy', array('gtk', 'main_quit')); $vbox = new GtkVBox(); $window->add($vbox); $vbox->show(); $drawing_area = new GtkDrawingArea(); $drawing_area->set_size_request(300, 300); $vbox->pack_start($drawing_area); $drawing_area->show(); $drawing_area->connect('expose_event', 'expose_event'); $drawing_area->connect('configure_event', 'configure_event'); $drawing_area->connect('motion_notify_event', 'motion_notify_event'); $drawing_area->connect('button_press_event', 'button_press_event'); $drawing_area->set_events(GDK::EXPOSURE_MASK | GDK::LEAVE_NOTIFY_MASK | GDK::BUTTON_PRESS_MASK | GDK::POINTER_MOTION_MASK | GDK::POINTER_MOTION_HINT_MASK); $button = new GtkButton('Quit'); $vbox->pack_start($button, false, false); $button->connect_simple('clicked', array($window, 'destroy')); $button->show(); $window->show(); gtk::main(); ?>
<?php /* $Id: scribble.php,v 1.7 2002/12/04 17:31:50 fmk Exp $ */ $pixmap = null; function configure_event($widget, $event) { global $pixmap; $pixmap = new GdkPixmap($widget->window, $widget->allocation->width, $widget->allocation->height, -1); $pixmap->draw_rectangle($widget->style->white_gc, true, 0, 0, $widget->allocation->width, $widget->allocation->height); return true; } function expose_event($widget, $event) { global $pixmap; $widget->window->draw_drawable($widget->style->fg_gc[$widget->state], $pixmap, $event->area->x, $event->area->y, $event->area->x, $event->area->y, $event->area->width, $event->area->height); return false; } function button_press_event($widget, $event) { global $pixmap; if ($event->button == 1 && $pixmap) draw_brush($widget, (int)$event->x, (int)$event->y); return true; } function motion_notify_event($widget, $event) { global $pixmap; $window = $event->window; $pointer = $window->get_pointer(); $x = $pointer[0]; $y = $pointer[1]; $state = $pointer[2]; if (($state & GDK::BUTTON1_MASK) && $pixmap) draw_brush($widget, $x, $y); return true; } function draw_brush($widget, $x, $y) { global $pixmap; $pixmap->draw_arc($widget->style->black_gc, true, $x - 4, $y - 4, 8, 8, 0, 64 * 360); $widget->queue_draw_area($x - 4, $y - 4, 8, 8); } $window = new GtkWindow(); $window->set_name('Test Input'); $window->set_position(GTK::WIN_POS_CENTER); $window->connect_simple('destroy', array('gtk', 'main_quit')); $vbox = new GtkVBox(); $window->add($vbox); $vbox->show(); $drawing_area = new GtkDrawingArea(); $drawing_area->set_size_request(300, 300); $vbox->pack_start($drawing_area); $drawing_area->show(); $drawing_area->connect('expose_event', 'expose_event'); $drawing_area->connect('configure_event', 'configure_event'); $drawing_area->connect('motion_notify_event', 'motion_notify_event'); $drawing_area->connect('button_press_event', 'button_press_event'); $drawing_area->set_events(GDK::EXPOSURE_MASK | GDK::LEAVE_NOTIFY_MASK | GDK::BUTTON_PRESS_MASK | GDK::POINTER_MOTION_MASK | GDK::POINTER_MOTION_HINT_MASK); $button = new GtkButton('Quit'); $vbox->pack_start($button, false, false); $button->connect_simple('clicked', array($window, 'destroy')); $button->show(); $window->show(); gtk::main(); ?>