Paste Description for mq
The php-gtk2 scribble demo ; interesting example but this one is very far more rich : http://www.php-gtk.eu/code-snippets/extending-gtkdrawingarea-to-draw-animated-graphs
- mq
- Wednesday, November 29th, 2006 at 1:49:21pm MST
- <?php
- /**
- * Scribble demo - simple painting with your mouse
- */
- class Scribble extends GtkWindow
- {
- protected $size_group = null;
- protected $pixmap = null;
- function __construct($parent = null)
- {
- parent::__construct();
- if (@$GLOBALS['framework']) {
- return;
- }
- if ($parent)
- $this->set_screen($parent->get_screen());
- else
- $this->set_title(__CLASS__);
- $this->set_position(Gtk::WIN_POS_CENTER);
- $this->set_default_size(-1, -1);
- $this->set_border_width(8);
- $this->add($this->__create_box());
- $this->show_all();
- }//function __construct($parent = null)
- function __create_box()
- {
- $vbox = new GtkVBox();
- $vbox->show();
- $drawing_area = new GtkDrawingArea();
- $drawing_area->set_size_request(300, 300);
- $vbox->pack_start($drawing_area);
- // $drawing_area->realize();
- $drawing_area->set_events(Gdk::EXPOSURE_MASK
- | Gdk::LEAVE_NOTIFY_MASK
- | Gdk::BUTTON_PRESS_MASK
- | Gdk::POINTER_MOTION_MASK
- | Gdk::POINTER_MOTION_HINT_MASK);
- return $vbox;
- }//function __create_box()
- function configure_event($widget, $event)
- {
- $this->pixmap = new GdkPixmap($widget->window,
- $widget->allocation->width,
- $widget->allocation->height,
- -1);
- $this->pixmap->draw_rectangle($widget->style->white_gc,
- true, 0, 0,
- $widget->allocation->width,
- $widget->allocation->height);
- return true;
- }
- function expose_event($widget, $event)
- {
- $widget->window->draw_drawable($widget->style->fg_gc[$widget->state],
- $this->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)
- {
- if ($event->button == 1 && $this->pixmap) {
- $this->draw_brush($widget, (int)$event->x, (int)$event->y);
- }
- return true;
- }
- function motion_notify_event($widget, $event)
- {
- $window = $event->window;
- $pointer = $window->get_pointer();
- $x = $pointer[0];
- $y = $pointer[1];
- $state = $pointer[2];
- if (($state & Gdk::BUTTON1_MASK) && $this->pixmap) {
- $this->draw_brush($widget, $x, $y);
- }
- return true;
- }
- function draw_brush($widget, $x, $y)
- {
- $this->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);
- }
- }//class Scribble extends GtkWindow
- $GLOBALS['class'] = 'Scribble';
- $GLOBALS['description'] = "Scribble lets you draw paintings with your mouse";
- if (!@$GLOBALS['framework']) {
- new Scribble();
- Gtk::main();
- }
- ?>
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.