gnome-devel-docs r598 - in trunk/gtk-drawing: . C examples
- From: davyd svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-devel-docs r598 - in trunk/gtk-drawing: . C examples
- Date: Fri, 26 Sep 2008 16:12:03 +0000 (UTC)
Author: davyd
Date: Fri Sep 26 16:12:02 2008
New Revision: 598
URL: http://svn.gnome.org/viewvc/gnome-devel-docs?rev=598&view=rev
Log:
2008-09-27 Davyd Madeley <davyd madeley id au>
* Initial import of Drawing with GTK+ into SVN
Added:
trunk/gtk-drawing/
trunk/gtk-drawing/C/
trunk/gtk-drawing/C/cairo-pango.xml
trunk/gtk-drawing/C/empty-section.xml
trunk/gtk-drawing/C/goocanvas.xml
trunk/gtk-drawing/C/gtk-drawing.xml
trunk/gtk-drawing/C/gtkdrawingarea.xml
trunk/gtk-drawing/C/introduction.xml
trunk/gtk-drawing/ChangeLog
trunk/gtk-drawing/examples/
trunk/gtk-drawing/examples/example.gtkdrawingarea.cairo.c
trunk/gtk-drawing/examples/example.gtkdrawingarea.setup.c
Added: trunk/gtk-drawing/C/cairo-pango.xml
==============================================================================
--- (empty file)
+++ trunk/gtk-drawing/C/cairo-pango.xml Fri Sep 26 16:12:02 2008
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
+"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
+]>
+
+<chapter id="chapter.cairo-pango">
+ <title>Cairo and Pango</title>
+
+ <para>
+ A paragraph.
+ </para>
+
+</chapter>
Added: trunk/gtk-drawing/C/empty-section.xml
==============================================================================
--- (empty file)
+++ trunk/gtk-drawing/C/empty-section.xml Fri Sep 26 16:12:02 2008
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
+"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
+]>
+
+<chapter id="chapter.x-empty">
+ <title>Empty Section</title>
+
+ <para>
+ A paragraph.
+ </para>
+
+</chapter>
Added: trunk/gtk-drawing/C/goocanvas.xml
==============================================================================
--- (empty file)
+++ trunk/gtk-drawing/C/goocanvas.xml Fri Sep 26 16:12:02 2008
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
+"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
+]>
+
+<chapter id="chapter.goocanvas">
+ <title>Drawing with GooCanvas</title>
+
+ <para>
+ A paragraph.
+ </para>
+
+</chapter>
Added: trunk/gtk-drawing/C/gtk-drawing.xml
==============================================================================
--- (empty file)
+++ trunk/gtk-drawing/C/gtk-drawing.xml Fri Sep 26 16:12:02 2008
@@ -0,0 +1,62 @@
+<?xml version="1.0"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
+"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
+]>
+<!-- =============Document Header ============================= -->
+<book id="index" lang="en"
+ xmlns:xi="http://www.w3.org/2001/XInclude">
+<!-- please do not change the id; for translations, change lang to -->
+<!-- appropriate code -->
+ <bookinfo>
+ <title>Drawing with GTK+</title>
+
+ <copyright>
+ <year>2008</year>
+ <holder>GNOME Foundation</holder>
+ <year>2008</year>
+ <holder>Davyd Madeley</holder>
+ </copyright>
+<!-- An address can be added to the publisher information. If a role is
+ not specified, the publisher/author is the same for all versions of the
+ document. -->
+ <publisher>
+ <publishername>GNOME Documentation Project</publishername>
+ </publisher>
+
+ <authorgroup>
+ <author>
+ <firstname>Davyd</firstname>
+ <surname>Madeley</surname>
+ <affiliation>
+ <orgname>GNOME</orgname>
+ <address><email>davyd madeley id au</email></address>
+ </affiliation>
+ </author>
+ </authorgroup>
+
+ <revhistory>
+ <revision>
+ <revnumber>Initial Draft</revnumber>
+ <date>September 2008</date>
+ <revdescription>
+ <para role="publisher">GNOME Documentation Project</para>
+ </revdescription>
+ </revision>
+ </revhistory>
+
+ <releaseinfo>
+ Initial draft of Drawing with GTK+
+ </releaseinfo>
+
+ <indexterm zone="index">
+ <primary>gtk</primary>
+ </indexterm>
+
+ </bookinfo>
+
+ <xi:include href="introduction.xml"/>
+ <xi:include href="gtkdrawingarea.xml"/>
+ <xi:include href="goocanvas.xml"/>
+ <xi:include href="cairo-pango.xml"/>
+
+</book>
Added: trunk/gtk-drawing/C/gtkdrawingarea.xml
==============================================================================
--- (empty file)
+++ trunk/gtk-drawing/C/gtkdrawingarea.xml Fri Sep 26 16:12:02 2008
@@ -0,0 +1,159 @@
+<?xml version="1.0"?>
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
+"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
+]>
+
+<chapter id="chapter.gtkdrawingarea">
+ <title>Drawing into a GtkDrawingArea</title>
+
+ <para>
+ A <classname>GtkDrawingArea</classname> is a
+ <classname>GtkWidget</classname> that provides a single, empty
+ <classname>GdkWindow</classname> that can be drawn into by a program by
+ connecting the widget's <function>expose-event</function> signal.
+ </para>
+
+ <para>
+ When drawing in this way, all drawing should be done in the
+ <function>expose-event</function> handler. This includes animation and
+ updates triggered by events other than expose event.
+ </para>
+
+ <sect1 id="sect.gtkdrawingarea.setup">
+ <title>Setting up a GtkDrawingArea</title>
+
+ <para>
+ Setting up a <classname>GtkDrawingArea</classname> is straightforward.
+ You can create the widget with <function>gtk_drawing_area_new</function>
+ or via Glade. Simply connect <function>expose-event</function>
+ (<xref linkend="example.gtkdrawingarea.setup"/>).
+ </para>
+
+ <example id="example.gtkdrawingarea.setup">
+ <title>A short GTK+ program that creates a GtkDrawingArea and hooks up expose-event</title>
+ <programlisting>
+<![CDATA[#include <gtk/gtk.h>
+
+static gboolean
+expose_callback (GtkWidget *da, GdkEventExpose *event, gpointer user_data)
+{
+ g_print ("Expose\n");
+
+ return TRUE;
+}
+
+int
+main (int argc, char **argv)
+{
+ gtk_init (&argc, &argv);
+
+ GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ GtkWidget *da = gtk_drawing_area_new ();
+
+ gtk_container_add (GTK_CONTAINER (window), da);
+
+ g_signal_connect_swapped (window, "delete-event",
+ G_CALLBACK (gtk_main_quit), NULL);
+ g_signal_connect (da, "expose-event",
+ G_CALLBACK (expose_callback), NULL);
+
+ gtk_widget_show_all (window);
+
+ gtk_main ();
+}]]></programlisting>
+ </example>
+ <para>
+ Running this program will cause the word
+ <computeroutput>Expose</computeroutput> to be printed on the screen.
+ </para>
+
+ </sect1>
+
+ <sect1 id="sect.gtkdrawingarea.expose">
+ <title>Expose</title>
+
+ <para>
+ As covered in <xref linkend="sect.introduction.how-it-works"/>, the
+ <function>expose-event</function> is sent to a
+ <classname>GtkWidget</classname> when one of its associated
+ <classname>GdkWindow</classname>s needs something drawn into it.
+ </para>
+
+ <para>
+ We receive the <function>expose-event</function> as a regular
+ <classname>GSignal</classname> callback with the prototype:
+ </para>
+
+ <funcsynopsis>
+ <funcprototype>
+ <funcdef>gboolean <function>expose_event</function></funcdef>
+ <paramdef>GtkWidget *<parameter>widget</parameter></paramdef>
+ <paramdef>GdkEventExpose *<parameter>event</parameter></paramdef>
+ <paramdef>gpointer <parameter>user_data</parameter></paramdef>
+ </funcprototype>
+ </funcsynopsis>
+
+ <para>
+ The <structname>GdkEventExpose</structname> structure contains two
+ important pieces of data:
+ </para>
+ <itemizedlist>
+ <listitem><para>
+ <structfield>window</structfield>, the <classname>GdkWindow</classname>
+ that requires exposing; and
+ </para></listitem>
+ <listitem><para>
+ <structfield>region</structfield>, the <classname>GdkRegion</classname>
+ that requires exposing (also available as
+ <structfield>area</structfield>, the bounding box of the region).
+ </para></listitem>
+ </itemizedlist>
+
+ <para>
+ Like with all GTK+ events, the callback also has a return type: boolean
+ true or false. Your expose handler should return either true or false.
+ Returning <returnvalue>TRUE</returnvalue> stops any other expose handlers
+ from being called to handle this event; this is normally what you will
+ want to do. Returning <returnvalue>FALSE</returnvalue> will propagate the
+ event further to find another handler.
+ </para>
+
+ <warning id="warning.gtkdrawingarea.expose">
+ <title>Make Sure Your Callback Returns Something</title>
+ <para>
+ If your callback fails to return either <returnvalue>TRUE</returnvalue>
+ or <returnvalue>FALSE</returnvalue>, you are going to get a strange,
+ undefined behaviour. If you're getting strange bugs, check your
+ event callbacks all return the correct value.
+ </para>
+ </warning>
+
+ <sect2 id="sect.gtkdrawingarea.expose.cairo">
+ <title>Drawing with Cairo</title>
+
+ <para>
+ To draw with Cairo, we need to create a Cairo context
+ (<classname>cairo_t</classname>) for the
+ <classname>GdkWindow</classname>. Once the Cairo context has been
+ created, it can be used for as much drawing as desired
+ (<xref linkend="example.gtkdrawingarea.cairo"/>). Remember to free the
+ context before leaving the callback.
+ </para>
+
+ <example id="example.gtkdrawingarea.cairo">
+ <title>Creating a Cairo context, drawing and then destroying the context</title>
+ <programlisting>
+<![CDATA[cairo_t *cr = gdk_cairo_create (event->window);
+
+/* draw a circle */
+cairo_arc (cr, 50., 50., 25, -M_PI, M_PI);
+cairo_stroke (cr);
+
+cairo_destroy (cr);]]></programlisting>
+ </example>
+
+ </sect2>
+
+ </sect1>
+
+</chapter>
Added: trunk/gtk-drawing/C/introduction.xml
==============================================================================
--- (empty file)
+++ trunk/gtk-drawing/C/introduction.xml Fri Sep 26 16:12:02 2008
@@ -0,0 +1,312 @@
+<?xml version="1.0"?>
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
+"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
+]>
+
+<chapter id="ch.introduction">
+ <title>Introduction</title>
+
+ <para>
+ The GTK+ toolkit provides many useful widgets for creating compelling user
+ interfaces. However, frequently an interface requires more than just
+ buttons and combo boxes to be functional. It might require a graph, or
+ dragable plots, or preview output. When this is the case, external
+ libraries can sometimes provide the additional functionality, but
+ sometimes the requirements are somewhat more unique and the developer
+ needs to prepare her own widgets or visualisations.
+ </para>
+
+ <!-- FIXME -->
+ <para>
+ This document is separated into several parts. First it discusses the
+ different levels of drawing APIs available to GTK+ developers, then it
+ discusses raw drawing, how drawing works in GTK+ and using Cairo and
+ Pango. It then discusses the canvas library GooCanvas.
+ </para>
+
+ <sect1 id="sect.introduction.how-it-works">
+ <title>How Drawing Works in GTK+</title>
+
+ <para>
+ GTK+'s origins are in X11 and the popular toolkits of the time (i.e.
+ Motif), so much of the architecture of how to draw with GTK+ originally
+ comes from X11.
+ </para>
+
+ <para>
+ GTK+'s draws into surfaces called <classname>GdkDrawable</classname>s.
+ These surfaces are stored in the (X) server, which might not be running
+ on the same computer as your program. There are two types of
+ <classname>GdkDrawable</classname>: onscreen
+ <classname>GdkWindow</classname>s and offscreen
+ <classname>GdkPixmap</classname>s.
+ </para>
+
+ <note id="note.introduction.gdkwindow-vs-gtkwindow">
+ <title>GdkWindow vs. GtkWindow</title>
+
+ <para>
+ Although similarly named, <classname>GdkWindow</classname>s and
+ <classname>GtkWindow</classname>s are not related.
+ </para>
+ <para>
+ A <classname>GtkWindow</classname> is a top-level widget, a window in
+ the user-interface sense with a titlebar and frame that you can drag
+ around in the window manager.
+ </para>
+ <para>
+ A <classname>GdkWindow</classname> is an onscreen rectangle of memory
+ that can be drawn into. It can contain other
+ <classname>GdkWindow</classname>s as children. It is named after the X11
+ <classname>Window</classname> class.
+ </para>
+ <para>
+ Several widgets, including <classname>GtkWindow</classname>,
+ draw into a <classname>GdkWindow</classname>.
+ </para>
+ </note>
+
+ <note id="note.introduction.gdkpixmap-vs-gdkpixbuf">
+ <title>GdkPixmap vs. GdkPixbuf</title>
+
+ <para>
+ Another common source of confusion is the difference between a
+ <classname>GdkPixmap</classname> and a <classname>GdkPixbuf</classname>.
+ </para>
+
+ <para>
+ A <classname>GdkPixmap</classname> is an offscreen
+ <classname>GdkDrawable</classname>, a server-side resource. This means
+ that it may be on a different computer to the running application and
+ that its contents may be stored in the video card for fast access.
+ Anything that is going to be frequently copied (blitted) into an onscreen
+ <classname>GdkWindow</classname> should be stored in a
+ <classname>GdkPixmap</classname>. <classname>GdkPixmap</classname>s have
+ the same display depth and colourspace as the monitors (usually 24-bit).
+ Accessing individual pixels of a <classname>GdkPixmap</classname> is
+ slow, and they should be drawn to using drawing operations.
+ </para>
+
+ <para>
+ A <classname>GdkPixbuf</classname> is a client-side memory buffer, it
+ supports RGB or RGBA pixels and an arbitrary number of bits per channel.
+ Its pixels are local memory and can be accessed quickly and directly.
+ A <classname>GdkPixbuf</classname> has to be copied to the server (and
+ possibly dithered) to be displayed on the screen.
+ </para>
+ </note>
+
+ <para>
+ The graphics server tracks the state of your
+ <classname>GdkWindow</classname>s and informs you when you need to draw
+ into them. It does this by sending you an event.
+ GTK+ sends this as the
+ <function>GtkWidget::expose-event</function> signal. The event provides
+ the <varname>window</varname> and <varname>region</varname> that needs to
+ be redrawn via the <structname>GdkEventExpose</structname> structure.
+ </para>
+
+ <para>
+ Something needs to handle this <function>expose-event</function> to draw
+ on the screen. This could be a canvas library (if you're letting a canvas
+ do the heavy lifting) or your own program.
+ </para>
+
+ <para>
+ The widgets inside GTK+ also work in this way. In fact, it is possible to
+ catch a widget's <function>expose-event</function> and then scribble in
+ the widget yourself, if you so desired.
+ </para>
+
+ <tip id="tip.introduction.expose-event">
+ <title>Expose Event Speed</title>
+
+ <para>
+ In some graphics servers, including non-composited X11, the contents of
+ a <classname>GdkWindow</classname> is lost when that window is obscured.
+ When window, or part window becomes visible again, your widget will be
+ sent another <function>expose-event</function> to redraw the region.
+ </para>
+
+ <para>
+ This can lead to a widget receiving lots of
+ <function>expose-event</function>s, so the expose really needs to be
+ quite fast. If your drawing routines are slow, it's best to cache the result
+ in a <classname>GdkPixmap</classname> that you can then copy (blit) back
+ to the <classname>GdkWindow</classname> on demand (this is very fast).
+ </para>
+ </tip>
+
+ <para>
+ Drawing into an exposed widget (or an offscreen pixmap) can be done in
+ several ways: you could
+ copy the contents of a <classname>GdkPixmap</classname>;
+ you could render a <classname>GdkPixbuf</classname> to the screen; you
+ could write text with Pango; or you could draw with Cairo. Or you could do
+ several of these things. Drawing is done using the painters method,
+ meaning that new content overlays old content.
+ </para>
+
+ <para>
+ In order to reduce flickering and ensure that the user sees only the
+ finished result of the <function>expose-event</function>, GDK uses
+ <emphasis>double buffering</emphasis>. That is to say, your drawing
+ operations are deferred to an offscreen buffer until the end of the
+ <function>expose-event</function> callback. At the end of the expose
+ callback, the offscreen buffer will be blitted back onscreen.
+ If required, this can be disabled with the function
+ <function>gtk_widget_set_double_buffered()</function> (e.g. because your
+ expose event is already just a blit).
+ </para>
+
+ </sect1>
+
+ <sect1 id="sect.introduction.choosing-api">
+ <title>Choosing How to Draw</title>
+
+ <para>
+ There are three main choices for doing your drawing in GTK+, depending on
+ how fast you need it to be and what external dependancies you're willing
+ to use. In short they are: draw an image, use a canvasing library or
+ do it all yourself.
+ </para>
+
+ <sect2 id="sect.introduction.choosing-api.image">
+ <title>Drawing an Image</title>
+
+ <para>
+ For simple scenarios, drawing an image can often be the easiest way to
+ add your custom graphics to GTK+. Images work best with static, or
+ infrequently updated data. They are easy to debug, easy to update and
+ don't require handling of any events like
+ <function>expose-event</function> (but you can still listen to
+ <function>button-press-event</function> and friends if you wish). GTK+
+ provides no convienient functions for drawing into an image using
+ settings from the GTK+ theme.
+ </para>
+ </sect2>
+
+ <sect2 id="sect.introduction.choosing-api.canvas">
+ <title>Using a Canvas Library</title>
+
+ <important id="important.introduction.choosing-api.canvas">
+ <title>External Dependancy Required</title>
+ <para>
+ As of GTK+ 2.14, GTK+ does not currently include a canvas library. An
+ external dependancy must be used.
+ </para>
+ </important>
+
+ <para>
+ Canvas libraries are designed to handle a lot of the heavy lifting
+ involved with drawing without having to involve the developer. Instead
+ the developer is provided with high-level objects that have positions,
+ orientations, colours, etc. Changing these automatically triggers a
+ redraw of the canvas. The canvas can also provide events when a user
+ interacts with the objects being displayed. Combined these two items
+ make using a canvas ideal for practically all custom drawing. There
+ exists several 2D and 3D canvas libraries.
+ </para>
+
+ <para>
+ One reasonably good 2D canvas library is
+ <ulink url="http://sourceforge.net/projects/goocanvas">GooCanvas</ulink>.
+ </para>
+
+ <para>
+ GooCanvas provides several useful features:
+ </para>
+ <itemizedlist>
+ <listitem><para>
+ all rendering is done using Cairo;
+ </para></listitem>
+ <listitem><para>
+ all canvas items are <classname>GObject</classname>s, they can be
+ inherited from, and handled in the same way as
+ <classname>GtkWidget</classname>s;
+ </para></listitem>
+ <listitem><para>
+ <classname>GooCanvasItem</classname>s emit many similar signals to
+ <classname>GtkWidget</classname>s such as
+ <function>enter-notify-event</function>,
+ <function>motion-notify-event</function>, and
+ <function>button-press-event</function>;
+ </para></listitem>
+ <listitem><para>
+ as well as graphic primatives, paths, images and labels, containers items
+ are also available, plus <classname>GtkWidget</classname>s can be
+ embedded into the canvas;
+ </para></listitem>
+ <listitem><para>
+ canvas items can be connected to models for MVC style programming; and
+ </para></listitem>
+ <listitem><para>
+ implementing new <classname>GooCanvasItem</classname>s is very
+ straightfoward.
+ </para></listitem>
+ </itemizedlist>
+ <para>
+ For more details see <xref linkend="chapter.goocanvas"/>.
+ </para>
+
+ <para>
+ Another canvas usable with GTK+ is
+ <ulink url="http://clutter-project.org/">Clutter</ulink>, which uses
+ OpenGL to handle its drawing.
+ </para>
+ </sect2>
+
+ <sect2 id="sect.introduction.choosing-api.yourself">
+ <title>Doing Everything Yourself</title>
+
+ <para>
+ Sometimes you cannot use an external library, or the abstraction of a
+ canvas is too much overhead, or you're implementing your own general UI
+ widget, and you need to handle all aspects of drawing yourself.
+ </para>
+
+ <para>
+ Depending on the precise requirements, there are two starting points
+ available: use a <classname>GtkDrawingArea</classname> (a widget which
+ provides a single blank <classname>GdkWindow</classname> to draw into);
+ or implement an entire widget (where you have to set everything up,
+ including creating your own <classname>GdkWindow</classname>s, this is
+ often required for implementing widgets that can be packed into a
+ <classname>GtkScrolledWindow</classname>).
+ </para>
+
+ <para>
+ When doing everything yourself, your application needs to handle
+ <function>expose-event</function>. If you want to be able to interact
+ with objects, you will need to be able to calculate intersections with
+ those objects from pixel coordinates. Often an understanding of
+ common optimisations in graphics and computational geometry algorithms
+ will be required.
+ </para>
+
+ <para>
+ For more details see <xref linkend="chapter.gtkdrawingarea"/>.
+ </para>
+ </sect2>
+
+ </sect1>
+
+ <sect1 id="sect.introduction.compiling">
+ <title>Compiling Examples</title>
+
+ <para>
+ Assuming that you have a working GTK+ development environment (if you
+ don't, this is probably not the tutorial for you), you can compile the
+ GTK+-only examples in this reference on a UNIX-like system with:
+ </para>
+ <screen>
+gcc -o example `pkg-config --cflags --libs gtk+-2.0` example.c</screen>
+
+ <para>
+ For the examples that use GooCanvas, use:
+ </para>
+ <screen>
+gcc -o example `pkg-config --cflags --libs gtk+-2.0 goocanvas` example.c</screen>
+ </sect1>
+
+</chapter>
Added: trunk/gtk-drawing/examples/example.gtkdrawingarea.cairo.c
==============================================================================
--- (empty file)
+++ trunk/gtk-drawing/examples/example.gtkdrawingarea.cairo.c Fri Sep 26 16:12:02 2008
@@ -0,0 +1,38 @@
+#include <math.h>
+#include <gtk/gtk.h>
+
+static gboolean
+expose_callback (GtkWidget *da, GdkEventExpose *event, gpointer user_data)
+{
+ g_print ("Expose\n");
+
+ cairo_t *cr = gdk_cairo_create (event->window);
+
+ /* draw a circle */
+ cairo_arc (cr, 50., 50., 25, -M_PI, M_PI);
+ cairo_stroke (cr);
+
+ cairo_destroy (cr);
+
+ return TRUE;
+}
+
+int
+main (int argc, char **argv)
+{
+ gtk_init (&argc, &argv);
+
+ GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ GtkWidget *da = gtk_drawing_area_new ();
+
+ gtk_container_add (GTK_CONTAINER (window), da);
+
+ g_signal_connect_swapped (window, "delete-event",
+ G_CALLBACK (gtk_main_quit), NULL);
+ g_signal_connect (da, "expose-event",
+ G_CALLBACK (expose_callback), NULL);
+
+ gtk_widget_show_all (window);
+
+ gtk_main ();
+}
Added: trunk/gtk-drawing/examples/example.gtkdrawingarea.setup.c
==============================================================================
--- (empty file)
+++ trunk/gtk-drawing/examples/example.gtkdrawingarea.setup.c Fri Sep 26 16:12:02 2008
@@ -0,0 +1,29 @@
+#include <gtk/gtk.h>
+
+static gboolean
+expose_callback (GtkWidget *da, GdkEventExpose *event, gpointer user_data)
+{
+ g_print ("Expose\n");
+
+ return TRUE;
+}
+
+int
+main (int argc, char **argv)
+{
+ gtk_init (&argc, &argv);
+
+ GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ GtkWidget *da = gtk_drawing_area_new ();
+
+ gtk_container_add (GTK_CONTAINER (window), da);
+
+ g_signal_connect_swapped (window, "delete-event",
+ G_CALLBACK (gtk_main_quit), NULL);
+ g_signal_connect (da, "expose-event",
+ G_CALLBACK (expose_callback), NULL);
+
+ gtk_widget_show_all (window);
+
+ gtk_main ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]