Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

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 

  1. <?php
  2. /**
  3. *   Scribble demo - simple painting with your mouse
  4. */
  5.  
  6. class Scribble extends GtkWindow
  7. {
  8.     protected $size_group = null;
  9.     protected $pixmap = null;
  10.  
  11.  
  12.     function __construct($parent = null)
  13.     {
  14.         parent::__construct();
  15.  
  16.         if (@$GLOBALS['framework']) {
  17.             return;
  18.         }
  19.  
  20.         if ($parent)
  21.             $this->set_screen($parent->get_screen());
  22.         else
  23.             $this->connect_simple('destroy', array('gtk', 'main_quit'));
  24.  
  25.         $this->set_title(__CLASS__);
  26.         $this->set_position(Gtk::WIN_POS_CENTER);
  27.         $this->set_default_size(-1, -1);
  28.         $this->set_border_width(8);
  29.  
  30.         $this->add($this->__create_box());
  31.         $this->show_all();
  32.     }//function __construct($parent = null)
  33.  
  34.  
  35.  
  36.     function __create_box()
  37.     {
  38.         $vbox = new GtkVBox();
  39.         $vbox->show();
  40.  
  41.         $drawing_area = new GtkDrawingArea();
  42.         $drawing_area->set_size_request(300, 300);
  43.         $vbox->pack_start($drawing_area);
  44. //        $drawing_area->realize();
  45.  
  46.         $drawing_area->connect('expose_event'       , array($this, 'expose_event'));
  47.         $drawing_area->connect('configure_event'    , array($this, 'configure_event'));
  48.  
  49.         $drawing_area->connect('motion_notify_event', array($this, 'motion_notify_event'));
  50.         $drawing_area->connect('button_press_event' , array($this, 'button_press_event'));
  51.  
  52.         $drawing_area->set_events(Gdk::EXPOSURE_MASK
  53.                                 | Gdk::LEAVE_NOTIFY_MASK
  54.                                 | Gdk::BUTTON_PRESS_MASK
  55.                                 | Gdk::POINTER_MOTION_MASK
  56.                                 | Gdk::POINTER_MOTION_HINT_MASK);
  57.  
  58.         return $vbox;
  59.     }//function __create_box()
  60.  
  61.  
  62.  
  63.     function configure_event($widget, $event)
  64.     {
  65.         $this->pixmap = new GdkPixmap($widget->window,
  66.                                 $widget->allocation->width,
  67.                                 $widget->allocation->height,
  68.                                 -1);
  69.         $this->pixmap->draw_rectangle($widget->style->white_gc,
  70.                             true, 0, 0,
  71.                             $widget->allocation->width,
  72.                             $widget->allocation->height);
  73.         return true;
  74.     }
  75.  
  76.  
  77.     function expose_event($widget, $event)
  78.     {
  79.         $widget->window->draw_drawable($widget->style->fg_gc[$widget->state],
  80.                         $this->pixmap,
  81.                         $event->area->x, $event->area->y,
  82.                         $event->area->x, $event->area->y,
  83.                         $event->area->width, $event->area->height);
  84.  
  85.         return false;
  86.     }
  87.  
  88.  
  89.  
  90.     function button_press_event($widget, $event)
  91.     {
  92.         if ($event->button == 1 && $this->pixmap) {
  93.             $this->draw_brush($widget, (int)$event->x, (int)$event->y);
  94.         }
  95.  
  96.         return true;
  97.     }
  98.  
  99.  
  100.  
  101.     function motion_notify_event($widget, $event)
  102.     {
  103.         $window  = $event->window;
  104.         $pointer = $window->get_pointer();
  105.         $x = $pointer[0];
  106.         $y = $pointer[1];
  107.         $state = $pointer[2];
  108.  
  109.         if (($state & Gdk::BUTTON1_MASK) && $this->pixmap) {
  110.             $this->draw_brush($widget, $x, $y);
  111.         }
  112.  
  113.         return true;
  114.     }
  115.  
  116.  
  117.  
  118.     function draw_brush($widget, $x, $y)
  119.     {
  120.         $this->pixmap->draw_arc($widget->style->black_gc, true, $x - 4, $y - 4, 8, 8, 0, 64 * 360);
  121.         $widget->queue_draw_area($x - 4, $y - 4, 8, 8);
  122.     }
  123. }//class Scribble extends GtkWindow
  124.  
  125.  
  126. $GLOBALS['class']       = 'Scribble';
  127. $GLOBALS['description'] = "Scribble lets you draw paintings with your mouse";
  128.  
  129. if (!@$GLOBALS['framework']) {
  130.     new Scribble();
  131.     Gtk::main();
  132. }
  133. ?>

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.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



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.

fantasy-obligation
fantasy-obligation