?? cha-canvasitem.html
字號(hào):
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html> <head> <title> Writing a GnomeCanvasItem </title> <meta name="GENERATOR" content= "Modular DocBook HTML Stylesheet Version 1.45"> <link rel="HOME" title="GTK+ / Gnome Application Development" href="ggad.html"> <link rel="UP" title="Advanced GTK+/Gnome Techniques" href= "advanced.html"> <link rel="PREVIOUS" title="Standard Canvas Item Reference" href="sec-itemreference.html"> <link rel="NEXT" title="Drawing Methods" href="z186.html"> <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink= "#840084" alink="#0000FF"> <div class="NAVHEADER"> <table width="100%" border="0" bgcolor="#ffffff" cellpadding= "1" cellspacing="0"> <tr> <th colspan="4" align="center"> <font color="#000000" size="2">GTK+ / Gnome Application Development</font> </th> </tr> <tr> <td width="25%" bgcolor="#ffffff" align="left"> <a href="sec-itemreference.html"><font color="#0000ff" size="2"><b><<< Previous</b></font></a> </td> <td width="25%" colspan="2" bgcolor="#ffffff" align= "center"> <font color="#0000ff" size="2"><b><a href="ggad.html"> <font color="#0000ff" size="2"><b> Home</b></font></a></b></font> </td> <td width="25%" bgcolor="#ffffff" align="right"> <a href="z186.html"><font color="#0000ff" size="2"><b> Next >>></b></font></a> </td> </tr> </table> </div> <div class="CHAPTER"> <h1> <a name="CHA-CANVASITEM">Writing a <span class= "STRUCTNAME">GnomeCanvasItem</span></a> </h1> <div class="TOC"> <dl> <dt> <b>Table of Contents</b> </dt> <dt> <a href="cha-canvasitem.html#Z184">Overview</a> </dt> <dt> <a href="z186.html">Drawing Methods</a> </dt> <dt> <a href="z192.html">Other Methods</a> </dt> </dl> </div> <p> This chapter explains how to write a <span class= "STRUCTNAME">GnomeCanvasItem</span>. Custom canvas items allows you to extend the canvas; consider writing a canvas item if the stock items (or some combination of them placed in a <span class="STRUCTNAME">GnomeCanvasGroup</span>) do not meet your needs. As an example, the chapter describes the implementation of <span class="STRUCTNAME"> GnomeCanvasRect</span>. </p> <div class="SECT1"> <h1 class="SECT1"> <a name="Z184">Overview</a> </h1> <p> To write a <span class="STRUCTNAME"> GnomeCanvasItem</span>, you create a concrete implemenation of the <span class="STRUCTNAME"> GnomeCanvasItem</span> abstract base class. This chapter assumes you've read <a href="cha-objects.html">the chapter called <i>The GTK+ Object and Type System</i></a> and understand how a <span class="STRUCTNAME"> GtkObject</span> works; you will need to understand objects to write your own. </p> <p> Canvas items can support GDK mode, antialiased mode, or both. The canvas has a flag indicating which kind of canvas it is; items can check this flag at runtime: </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> if (item->canvas->aa) { /* antialiased mode */ } else { /* Gdk mode */ } </pre> </td> </tr> </table> <p> However, most code will be the same for both canvas types. The only real difference is in the drawing process: GDK mode draws to a pixmap, antialiased mode draws to an RGB buffer. You do not have to support both kinds of canvas, just be careful not to use your item with the unsupported canvas type. </p> <p> Here is the <span class="STRUCTNAME"> GnomeCanvasItem</span> type you will be subclassing: </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> typedef struct _GnomeCanvasItem GnomeCanvasItem;typedef struct _GnomeCanvasItemClass GnomeCanvasItemClass;struct _GnomeCanvasItem { GtkObject object; /* Canvas we are on */ GnomeCanvas *canvas; /* Parent group */ GnomeCanvasItem *parent; /* Bounding box for this item */ double x1, y1, x2, y2; /* If NULL, the identity transform */ double *xform;};struct _GnomeCanvasItemClass { GtkObjectClass parent_class; void (* update) (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags); void (* realize) (GnomeCanvasItem *item); void (* unrealize) (GnomeCanvasItem *item); void (* map) (GnomeCanvasItem *item); void (* unmap) (GnomeCanvasItem *item); /* Unused in Gnome 1.0 */ ArtUta *(* coverage) (GnomeCanvasItem *item); /* Used only in Gdk mode */ void (* draw) (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height); /* Used only in RGB mode */ void (* render) (GnomeCanvasItem *item, GnomeCanvasBuf *buf); double (* point) (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item); /* Obsolete; not used in Gnome 1.0 */ void (* translate) (GnomeCanvasItem *item, double dx, double dy); /* Deprecated, but occasionally used in Gnome 1.0 */ void (* bounds) (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2); /* The only canvas item class function that is also a signal */ gint (* event) (GnomeCanvasItem *item, GdkEvent *event);}; </pre> </td> </tr> </table> <p> This chapter explains everything in more detail; keep reading. </p> <div class="SECT2"> <h2 class="SECT2"> <a name="Z185"><span class="STRUCTNAME"> GnomeCanvasRect</span></a> </h2> <p> <span class="STRUCTNAME">GnomeCanvasRect</span> and <span class="STRUCTNAME">GnomeCanvasEllipse</span> have almost identical implementations; in fact, all but three of <span class="STRUCTNAME"> GnomeCanvasItem</span>'s methods are implemented by the <span class="STRUCTNAME">GnomeCanvasRE</span> base class. <span class="STRUCTNAME">GnomeCanvasRE</span> handles their user-visible interface, as discussed in the previous chapter. </p> <p> To understand the implementation of <span class= "STRUCTNAME">GnomeCanvasRect</span> presented in this chapter, you should first read the previous chapter's discussion of the object arguments it supports. You'll also want to see the object itself: </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> typedef struct _GnomeCanvasRE GnomeCanvasRE;struct _GnomeCanvasRE { GnomeCanvasItem item; double x1, y1, x2, y2; /* Corners of item, item coordinates */ double width; /* Outline width, item coordinates */ guint fill_color; /* Fill color, RGBA */ guint outline_color; /* Outline color, RGBA */ gulong fill_pixel; /* Fill color */ gulong outline_pixel; /* Outline color */ GdkBitmap *fill_stipple; /* Stipple for fill */ GdkBitmap *outline_stipple; /* Stipple for outline */ GdkGC *fill_gc; /* GC for filling */ GdkGC *outline_gc; /* GC for outline */ /* Antialiased specific stuff follows */ ArtSVP *fill_svp; /* The SVP for the filled shape */ ArtSVP *outline_svp; /* The SVP for the outline shape */ /* Configuration flags */ unsigned int fill_set : 1; /* Is fill color set? */ unsigned int outline_set : 1; /* Is outline color set? */ unsigned int width_pixels : 1;/* Is outline width specified in pixels or units? */}; </pre> </td> </tr> </table> <p> <span class="STRUCTNAME">GnomeCanvasRect</span> adds no new members not found in <span class="STRUCTNAME"> GnomeCanvasRE</span>. The method implementations discussed in this chapter should make clear the purpose of the various struct members. </p> <p> This chapter discusses all the interesting parts of <span class="STRUCTNAME">GnomeCanvasRect</span>; complete source code comes with the Gnome libraries. </p> </div> </div> </div> <div class="NAVFOOTER"> <br> <br> <table width="100%" border="0" bgcolor="#ffffff" cellpadding= "1" cellspacing="0"> <tr> <td width="25%" bgcolor="#ffffff" align="left"> <a href="sec-itemreference.html"><font color="#0000ff" size="2"><b><<< Previous</b></font></a> </td> <td width="25%" colspan="2" bgcolor="#ffffff" align= "center"> <font color="#0000ff" size="2"><b><a href="ggad.html"> <font color="#0000ff" size="2"><b> Home</b></font></a></b></font> </td> <td width="25%" bgcolor="#ffffff" align="right"> <a href="z186.html"><font color="#0000ff" size="2"><b> Next >>></b></font></a> </td> </tr> <tr> <td colspan="2" align="left"> <font color="#000000" size="2"><b>Standard Canvas Item Reference</b></font> </td> <td colspan="2" align="right"> <font color="#000000" size="2"><b>Drawing Methods</b></font> </td> </tr> </table> </div> </body></html>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -