⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sec-gc.html

📁 gtk_text program sample&eg
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>  <head>    <title>      Graphics Contexts    </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="GDK Basics" href="cha-gdk.html">    <link rel="PREVIOUS" title="Fonts" href="sec-gdkfont.html">    <link rel="NEXT" title="Drawing" href="z132.html">  </head>  <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-gdkfont.html"><font color="#0000ff" size=            "2"><b>&lt;&lt;&lt; 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="z132.html"><font color="#0000ff" size="2"><b>            Next &gt;&gt;&gt;</b></font></a>          </td>        </tr>      </table>    </div>    <div class="SECT1">      <h1 class="SECT1">        <a name="SEC-GC">Graphics Contexts</a>      </h1>      <p>        A <i class="FIRSTTERM">graphics context</i>, or GC, is        simply a set of parameters to be used when drawing (such as        color, clip mask, font, and so on). It is a server-side        resource, just as pixmaps and windows are. GCs reduce the        number of arguments to the GDK drawing functions, and also        reduce the number of parameters passed from client to        server with each drawing request.      </p>      <p>        A graphics context can be created with a <span class=         "STRUCTNAME">GdkGCValues</span> struct, analagous to <span        class="STRUCTNAME">GdkWindowAttr</span>; the struct        contains all the interesting features of a graphics        context, and you pass <tt class="FUNCTION">        gdk_gc_new_with_values()</tt> flags indicating which fields        are valid. The other fields retain their default value. You        can also create an all-default GC with <tt class=        "FUNCTION">gdk_gc_new()</tt> (this is usually easier).        Functions are provided to change GC settings after the GC        is created as well---but remember that each change requires        a message to the X server. These functions are summarized        in <a href="sec-gc.html#FL-GDKGC">Figure 16</a>. The        attributes of a GC, and the flags used as the final        argument to <tt class="FUNCTION">        gdk_gc_new_with_values()</tt>, are summarized in <a href=         "sec-gc.html#TAB-GDKGC">Table 6</a>.      </p>      <p>        All GCs are not interchangeable; they are tied to a        particular depth and visual. The GC's depth and visual must        match the depth and visual of the drawable you are drawing        to. A GC's depth and visual are taken from the <span class=         "STRUCTNAME">GdkWindow*</span> argument to <tt class=         "FUNCTION">gdk_gc_new()</tt>, so the easiest way to handle        this issue is to create the GC with the window you plan to        draw on.      </p>      <p>        <span class="STRUCTNAME">GdkGCValues</span> is a nice        summary of a GC's attributes:      </p>      <table border="0" bgcolor="#E0E0E0" width="100%">        <tr>          <td><pre class="PROGRAMLISTING">&#13;typedef struct _GdkGCValues GdkGCValues;struct _GdkGCValues{  GdkColor          foreground;  GdkColor          background;  GdkFont          *font;  GdkFunction       function;  GdkFill           fill;  GdkPixmap        *tile;  GdkPixmap        *stipple;  GdkPixmap        *clip_mask;  GdkSubwindowMode  subwindow_mode;  gint              ts_x_origin;  gint              ts_y_origin;  gint              clip_x_origin;  gint              clip_y_origin;  gint              graphics_exposures;  gint              line_width;  GdkLineStyle      line_style;  GdkCapStyle       cap_style;  GdkJoinStyle      join_style;};&#13;</pre>          </td>        </tr>      </table>      <p>        The <span class="STRUCTNAME">foreground</span> color is the        "pen color" used to draw lines, circles, and other shapes.        The purpose of the <span class="STRUCTNAME">        background</span> color depends on the particular drawing        operation. These colors must be allocated in the current        colormap with <tt class="FUNCTION">gdk_color_alloc()</tt>.      </p>      <p>        The <span class="STRUCTNAME">font</span> field is unused:        in Xlib, it specifies the font to use when drawing text. In        GDK, it used to have the same purpose; but now the GDK        routines for drawing text all require a <span class=         "STRUCTNAME">GdkFont*</span> argument instead. An Xlib        graphics context can only store plain fonts, but a <span        class="STRUCTNAME">GdkFont</span> can also represent a        fontset (used to render some foreign languages). GDK should        probably store a font field in its <span class=        "STRUCTNAME">GdkGC</span> instead of requiring a font        argument to the text-drawing functions, but it doesn't.      </p>      <p>        The <span class="STRUCTNAME">function</span> field        specifies how each pixel being drawn is combined with the        pixel that already exists in the drawable. There are many        possible values, but only two are ever used:      </p>      <ul>        <li>          <p>            <span class="STRUCTNAME">GDK_COPY</span> is the            default. It ignores the existing pixel (just writes the            new pixel over it).&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">GDK_XOR</span> combines the            old and new pixels in an invertable way. That is, if            you perform exactly the same <span class="STRUCTNAME">            GDK_XOR</span> operation twice, the first draw is            undone by the second. <span class="STRUCTNAME">            GDK_XOR</span> is often used for "rubberbanding," since            it makes it easy to restore the original contents of            the drawable once rubberbanding is complete.&#13;          </p>        </li>      </ul>      <p>        The <span class="STRUCTNAME">fill</span> field determines        how the <span class="STRUCTNAME">tile</span> and <span        class="STRUCTNAME">stipple</span> fields are used. A <span        class="STRUCTNAME">tile</span> is a pixmap with the same        depth as the destination drawable; it is copied over and        over into the destination drawable---the origin of the        first tile is (<span class="STRUCTNAME">ts_x_origin</span>,        <span class="STRUCTNAME">ts_y_origin</span>). A <span        class="STRUCTNAME">stipple</span> is a bitmap (pixmap with        depth 1); stipples are also tiled starting at (<span class=         "STRUCTNAME">ts_x_origin</span>, <span class="STRUCTNAME">        ts_y_origin</span>). Possible <span class="STRUCTNAME">        fill</span> values are:      </p>      <ul>        <li>          <p>            <span class="STRUCTNAME">GDK_SOLID</span> means to            ignore the <span class="STRUCTNAME">tile</span> and            <span class="STRUCTNAME">stipple</span>. Shapes are            drawn in the foreground and background colors.&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">GDK_TILED</span> means that            shapes are drawn with the tile, instead of the            foreground and background colors. Imagine a tiled            surface underneath your drawable; drawing in <span            class="STRUCTNAME">GDK_TILED</span> mode will scratch            away the contents of the drawable, revealing the tiled            surface underneath.&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">GDK_STIPPLED</span> is like            <span class="STRUCTNAME">GDK_SOLID</span> with a            bitmask defined by the stipple. That is, bits not set            in the stipple are not drawn.&#13;          </p>        </li>        <li>          <p>            <span class="STRUCTNAME">GDK_OPAQUE_STIPPLED</span>            draws bits set in the stipple with the foreground            color, and bits not set in the stipple with the            background color.&#13;          </p>        </li>      </ul>      <p>        Some X servers do not implement the more obscure function        and fill modes very efficiently. Don't be surprised if        using them noticeably slows down drawing.      </p>      <p>        The optional <span class="STRUCTNAME">clip_mask</span> is a        bitmap; only bits set in this bitmap will be drawn. The        mapping from the clip mask to the drawable is determined by        <span class="STRUCTNAME">clip_x_origin</span> and <span        class="STRUCTNAME">clip_y_origin</span>; these define the        drawable coordinates corresponding to (0,0) in the clip        mask. It is also possible to set a clip rectangle (the most        common and useful form of clipping) or a clip region (a        region is an arbitrary area on the screen, typically a        polygon or list of rectangles). To set a clip rectangle,        use <tt class="FUNCTION">gdk_gc_set_clip_rectangle()</tt>:      </p>      <table border="0" bgcolor="#E0E0E0" width="100%">        <tr>          <td><pre class="PROGRAMLISTING">&#13;  GdkRectangle clip_rect;  clip_rect.x = 10;  clip_rect.y = 20;  clip_rect.width = 200;  clip_rect.height = 100;  gdk_gc_set_clip_rectangle(gc, &amp;clip_rect);&#13;</pre>          </td>        </tr>      </table>      <p>        To turn off clipping, set the clip rectangle, clip region,        or clip mask to <span class="STRUCTNAME">NULL</span>.      </p>      <p>        The <span class="STRUCTNAME">subwindow_mode</span> of a GC        only matters if the drawable is a window. The default        setting is <span class="STRUCTNAME">        GDK_CLIP_BY_CHILDREN</span>; this means that child windows        are not affected by drawing on parent windows. This        preserves the illusion that child windows are "on top" of        parents, and child windows are opaque. <span class=         "STRUCTNAME">GDK_INCLUDE_INFERIORS</span> will draw right        over the top of any child windows, overwriting any graphics        the child windows may contain; normally this mode is not        used. If you do use <span class="STRUCTNAME">        GDK_INCLUDE_INFERIORS</span>, you will probably use <span        class="STRUCTNAME">GDK_XOR</span> as your drawing function,        since it allows you to restore the child windows' previous        contents.      </p>      <p>        <span class="STRUCTNAME">graphics_exposures</span> is a        boolean value which defaults to <span class="STRUCTNAME">        TRUE</span>; it determines whether <tt class="FUNCTION">        gdk_window_copy_area()</tt> sometimes generates expose        events. <a href="sec-gdkevent.html#SEC-EXPOSEEVENTS">the        section called <i>Expose Events</i></a> explained this in        more detail.      </p>      <p>        The final four GC values determine how lines are drawn.        These values are used for drawing lines, including the        borders of unfilled polygons and arcs. The <span class=         "STRUCTNAME">line_width</span> field specifies the width of        a line, in pixels. A line width of 0 specifies a "thin        line"; thin lines are one-pixel lines that can be drawn        very quickly (usually with hardware acceleration), but the        exact pixels drawn depend on the X server in use. For        consistent results, use a width of 1 instead.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -