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
Answertopia.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

Using the Canvas

GnomeCanvas is easy to use; this is its virtue compared to GtkDrawingArea or some other low-level approach. This section describes how to create a canvas, and work with canvas items. It ends with a programming example.

Preparing the GnomeCanvas Widget

The first decision you have to make is whether to use the canvas in GDK mode or antialiased mode. When you create a canvas widget, you must specify the mode you want; there is no way to change it later. gnome_canvas_new() creates a GDK canvas. gnome_canvas_new_aa() creates an antialiased canvas. These are shown in Figure 5.

Sometimes it matters which visual and colormap the canvas will use. In particular:

  • In GDK mode, if you want to use the GnomeCanvasImage item to display images, you must use Imlib's visual and colormap. GnomeCanvasImage uses Imlib to render images.

  • In antialiased mode, GDK's RGB buffer rendering facilities (see the section called RGB Buffers in the chapter called GDK Basics) are used to copy the RGB buffer to the screen. You must use the visual and colormap from the GDK RGB module.

To create a widget with a non-default visual and colormap, gtk_widget_push_visual() and gtk_widget_push_colormap() are used. Here is the code to create a GDK canvas that supports the image item:


  GtkWidget* canvas;
  gtk_widget_push_visual(gdk_imlib_get_visual());
  gtk_widget_push_colormap(gdk_imlib_get_colormap());
  canvas = gnome_canvas_new();
  gtk_widget_pop_visual();
  gtk_widget_pop_colormap();

      

To create an antialiased canvas, do this:


  GtkWidget* canvas;
  gtk_widget_push_visual(gdk_rgb_get_visual());
  gtk_widget_push_colormap(gdk_rgb_get_cmap());
  canvas = gnome_canvas_new_aa();
  gtk_widget_pop_colormap();
  gtk_widget_pop_visual();

      
       #include <libgnomeui/gnome-canvas.h>
      

GtkWidget* gnome_canvas_new(void);

GtkWidget* gnome_canvas_new_aa(void);

Figure 5. Canvas Constructors

Gtk+/Gnome Application Development
Prev Home Next

 
 
  Published under free license. Design by Interspire