All pastes #268387 Raw Edit

mq

public php v1 · immutable
·published 2006-12-05 18:17 UTC
rendered paste body
<?phpclass Graph_Core extends GtkDrawingArea {  # prefix class attributes with "_" to avoid collisions   # with GtkDrawingArea attributes.  protected $_pixmap;  protected $_gc;  protected $_realized;  function __construct() {    parent::__construct();    $this->connect('expose_event',       array($this, 'expose_event'));    $this->connect('configure_event',       array($this, 'configure_event'));    $this->connect('realize',       array($this, 'realize'));    $this->set_events(Gdk::EXPOSURE_MASK       | Gdk::LEAVE_NOTIFY_MASK);    $this->_pixmap = null;    $this->_gc = null;    $this->_realized = false;  }  function realize() {    $this->_realized = true;  }  function realized() {    return $this->_realized;  }  function configure_event($widget, $event) {    $w = $this->width();    $h = $this->height();    # allocate a new pixmap of the requested size ($this->allocation)    $this->_pixmap = new GdkPixmap($this->window, $w, $h, -1);    # clear pixmap (white color)    $this->_pixmap->draw_rectangle($this->style->white_gc, true,       0, 0, $w, $h);    return true;  }  function expose_event($widget, $event) {    $this->window->draw_drawable($this->style->fg_gc[$this->state],      $this->pixmap(),      $event->area->x, $event->area->y,      $event->area->x, $event->area->y,      $event->area->width, $event->area->height    );    return false;  }  function set_color($color) {    $col = $this->colormap()->alloc_color($color);    if ($col === false)      return $this->foreground('black');    return $this->gc()->set_foreground($col);  }  function colormap() {    return $this->gc()->get_colormap();  }  function pixmap() {    if (!$this->realized()) {      trigger_error("Widget not realized ; can't get pixmap");      return null;    }    return $this->_pixmap;  }  function gc() {    if (!$this->realized()) {      trigger_error("Widget not realized ; can't get GC");      return null;    }    if ($this->_gc == null)      $this->_gc = new GdkGc($this->pixmap());    return $this->_gc;  }  function width() {    return $this->allocation->width;  }  function height() {    return $this->allocation->height;  }  function w() {    return $this->width();  }  function h() {    return $this->height();  }}class Grapher extends Graph_Core{	function draw_line($x1, $y1, $x2, $y2){		$this->pixmap()->draw_line($this->gc(), $x1, $y1, $x2, $y2);	}}$grapher = new Grapher();  // note 1$grapher->set_size_request(600, 600);Gtk::timeout_add(100, 'graph_draw_test', $grapher); // note 2$window = new GtkWindow();$window->connect_simple('destroy', array('gtk', 'main_quit'));$window->set_title('Graph demo');$window->set_position(Gtk::WIN_POS_CENTER);$window->set_border_width(8);$window->add($grapher);$window->show_all();Gtk::main();function  graph_draw_test($graph){	echo "graph draw - start\n";	$graph->set_color('black');	for ($i=0 ; $i< 10000 ; $i++){		$graph->draw_line(0, 0, 500, 500);	}	echo "graph draw - done\n";}?>