OxyScripts.com
Menu spacer Home Tutorials Articles Code Forums irc.freenode.net #oxyscripts
Main (PHP)
Home Forums PHP News PHP Tutorials Articles PHP Code Snippets Contact Us Sysadmin Resources Books Template Shop
3rd Party Streams
SlashDot PHPDeveloper.org PHP.Net
Resources
PHP Manual MySQL Manual Smarty Manual PEAR Manual PHP-GTK Manual Symfony Manual
Code Snippets
Authentication Database Graphics HTTP Miscellaneous Time/Date
Affiliates
Scripts TutorialMan TutorialGuide CodingForums.com PHP Scripts Cheap Web Hosting Affordable Web Hosting Dreamweaver Templates

Search This Site :     PHP Function Reference :
 
GtkDrawingArea Constructor

GtkDrawingArea Constructor

Example 14. Drawing to a GtkDrawingArea

<?php

dl('php_gtk.'.(strstr(PHP_OS, 'WIN') ? 'dll' : 'so'));

function draw_it($drawingarea, $event, $style, $gdkwindow) {
  /* access the GdkWindow's colormap to associate a color with a GdkGC */
  $colormap = $gdkwindow->colormap;
  $yellow = $gdkwindow->new_gc();
  $yellow->foreground = $colormap->alloc('yellow');
  $red = $gdkwindow->new_gc();
  $red->foreground = $colormap->alloc('red');
  $red->line_width = 7;

  /* set up fonts.  The first font here is set as part of the drawingarea's
     style property so that it will be used in gtk::draw_string(). */
  $font = 
  gdk::font_load('-unknown-Arial-bold-r-normal--*-120-*-*-p-0-iso8859-1');
  $style->font = $font;
  $font2 = 
  gdk::font_load('-unknown-Arial-bold-r-normal--*-720-*-*-p-0-iso8859-1');

  /* call the appropriate drawing functions */
  gdk::draw_rectangle($gdkwindow, $style->white_gc, true, 0, 0, 200, 220);
  gdk::draw_rectangle($gdkwindow, $yellow, true, 50, 50, 100, 100);
  gdk::draw_string($gdkwindow, $font2, $style->white_gc, 75, 130, '?');
  gdk::draw_line($gdkwindow, $red, 20, 20, 180, 180);
  gdk::draw_line($gdkwindow, $red, 20, 180, 180, 20);
  gtk::draw_string($style, $gdkwindow, GTK_STATE_NORMAL, 12, 210, 
                   'SAY       TO SQUARE EGGS!');
  gdk::draw_string($gdkwindow, $font, $red, 42, 210, 'NO');
}

function press_it($drawingarea, $event, $style, $gdkwindow) {
  /* make the drawingarea look like it has been pressed down */
  $rectangle = &new GdkRectangle(0, 0, 200, 220);
  gtk::paint_focus($style, $gdkwindow, $rectangle, $drawingarea, null, 0, 0, 
                    200, 220);
}

function redraw_it($drawingarea, $event) {
  /* trigger a new expose event */
  $drawingarea->queue_draw();
}

/* set up the main window that will hold the drawing area */
$window = &new GtkWindow();
$window->set_position(GTK_WIN_POS_CENTER);
$window->connect_object('destroy', array('gtk', 'main_quit'));

/* set up the drawing area.  Sizing is taken from the parent, unless set. 
   We need to add events so that the drawingarea is sensitive to the mouse,
   using set_events() to do this because the widget is not realized yet. */
$drawingarea = &new GtkDrawingArea();
$drawingarea->size(200, 220);
$drawingarea->set_events(GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
$window->add($drawingarea);

/* once the drawing area has been added to the window we can realize() it, 
   which means that we can now access its properties */
$drawingarea->realize();
$style = $drawingarea->style;
$gdkwindow = $drawingarea->window;

/* drawing should always follow an expose event */
$drawingarea->connect('expose-event', 'draw_it', $style, $gdkwindow);
$drawingarea->connect('button-press-event', 'press_it', $style, 
$gdkwindow);
$drawingarea->connect('button-release-event', 'redraw_it');

$window->show_all();
gtk::main();

?>

 
   Print this page

Top Sponsor
Symantec\'s Norton SystemWorks 2006
Sponsors
CA
Sponsors
AdWords Dominator 125*125
Advertisting

Affiliates
VertexTemplates PHPFreaks CodeWalkers StarGeek DevScripts CGI & PHP Scripts PHP CMS

Shopping Rebates   Sell It 4 You   Flash Page Counters   Get Insured
GPS Tracking Service   Charity Donate Info   Web Site Hosting   VOIP Service

Privacy Policy | Links | Site Map | Advertising

All content on OxyScripts.com is (©)2002-2007

 
Powered by Adrastea - Version 1.0.0. Copyright © Rune Solutions, 2004-2005