Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Gtk+/Gnome Application Development
Prev Home Next

The Draw Method (GDK Mode)

Drawing with GDK is much less complicated than drawing with libart_lgpl, though it is also less flexible and produces lower-quality results. Here is the GnomeCanvasRect implementation of the draw method:


static void
gnome_canvas_rect_draw (GnomeCanvasItem *item, GdkDrawable *drawable, 
                        int x, int y, int width, int height)
{
  GnomeCanvasRE *re;
  double i2w[6], w2c[6], i2c[6];
  int x1, y1, x2, y2;
  ArtPoint i1, i2;
  ArtPoint c1, c2;

  re = GNOME_CANVAS_RE (item);

  /* Get canvas pixel coordinates */

  gnome_canvas_item_i2w_affine (item, i2w);
  gnome_canvas_w2c_affine (item->canvas, w2c);
  art_affine_multiply (i2c, i2w, w2c);

  i1.x = re->x1;
  i1.y = re->y1;
  i2.x = re->x2;
  i2.y = re->y2;
  art_affine_point (&c1, &i1, i2c);
  art_affine_point (&c2, &i2, i2c);
  x1 = c1.x;
  y1 = c1.y;
  x2 = c2.x;
  y2 = c2.y;
        
  if (re->fill_set) {
    if (re->fill_stipple)
      gnome_canvas_set_stipple_origin (item->canvas, re->fill_gc);

    gdk_draw_rectangle (drawable,
                        re->fill_gc,
                        TRUE,
                        x1 - x,
                        y1 - y,
                        x2 - x1 + 1,
                        y2 - y1 + 1);
  }

  if (re->outline_set) {
    if (re->outline_stipple)
      gnome_canvas_set_stipple_origin (item->canvas, re->outline_gc);

    gdk_draw_rectangle (drawable,
                        re->outline_gc,
                        FALSE,
                        x1 - x,
                        y1 - y,
                        x2 - x1,
                        y2 - y1);
  }
}
      

The draw method receives a drawable (the buffer), the buffer offsets (x and y---the canvas pixel coordinates of the buffer), and the buffer's size (width and height). GnomeCanvasRect's draw method obtains the item-to-world and world-to-canvas affines, then composes (multiplies) them to create an item-to-canvas affine. (See the section called Affine Transformations in the chapter called GnomeCanvas for more on affines.) Using this affine, it converts the rectangle's corner points to canvas pixel coordinates; then it draws the rectangle, converting the canvas coordinates to buffer coordinates by subtracting the buffer offsets.

Gtk+/Gnome Application Development
Prev Home Next

 
 
  Published under free license. Design by Interspire