📄 z132.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html> <head> <title> Drawing </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="Graphics Contexts" href= "sec-gc.html"> <link rel="NEXT" title="GDK Resource Management" href= "sec-gdkresourcemgmt.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-gc.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="sec-gdkresourcemgmt.html"><font color= "#0000ff" size="2"><b>Next >>></b></font></a> </td> </tr> </table> </div> <div class="SECT1"> <h1 class="SECT1"> <a name="Z132">Drawing</a> </h1> <p> Once you understand drawables, colors, visuals, graphics contexts, and fonts, actually drawing is very simple. This section is a quick summary of the GDK drawing routines. Remember that drawing is a server-side operation; for example, if you ask to draw a line, Xlib will send the line's endpoints to the server, and the server will do the actual drawing using the specified GC (the GC is also a server-side resource). Often this is an important performance consideration. </p> <div class="SECT2"> <h2 class="SECT2"> <a name="Z133">Points</a> </h2> <p> You can draw a single point with <tt class="FUNCTION"> gdk_draw_point()</tt>, or multiple points with <tt class= "FUNCTION">gdk_draw_points()</tt> (<a href= "z132.html#FL-GDKPOINTS">Figure 17</a>). The point is drawn in the current foreground color. Multiple points are given as an array. A <span class="STRUCTNAME"> GdkPoint</span> looks like this: </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> typedef struct _GdkPoint GdkPoint;struct _GdkPoint{ gint16 x; gint16 y;}; </pre> </td> </tr> </table> <p> Remember that X coordinates start in the top left corner, are relative to the drawable, and may not overflow a signed sixteen-bit integer. </p> <div class="FIGURE"> <a name="FL-GDKPOINTS"></a> <div class="FUNCSYNOPSIS"> <a name="FL-GDKPOINTS.SYNOPSIS"></a> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="FUNCSYNOPSISINFO">#include <gdk/gdk.h></pre> </td> </tr> </table> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION">gdk_draw_point</tt></code>(GdkDrawable* <tt class="PARAMETER"><i>drawable</i></tt>, GdkGC* <tt class="PARAMETER"><i>gc</i></tt>, gint <tt class= "PARAMETER"><i>x</i></tt>, gint <tt class= "PARAMETER"><i>y</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION">gdk_draw_points</tt></code>(GdkDrawable* <tt class="PARAMETER"><i>drawable</i></tt>, GdkGC* <tt class="PARAMETER"><i>gc</i></tt>, GdkPoint* <tt class="PARAMETER"><i>points</i></tt>, gint <tt class= "PARAMETER"><i>npoints</i></tt>);</code> </p> </div> <p> <b>Figure 17. Drawing Points</b> </p> </div> </div> <div class="SECT2"> <h2 class="SECT2"> <a name="Z134">Lines</a> </h2> <p> To draw a single line, pass its endpoints as arguments to <tt class="FUNCTION">gdk_draw_line()</tt> (<a href= "z132.html#FL-GDKLINES">Figure 18</a>). To draw connected lines, you pass a list of points to <tt class="FUNCTION"> gdk_draw_lines()</tt>; GDK will "connect the dots." To draw multiple lines that aren't necessarily connected, pass a list of segments to <tt class="FUNCTION"> gdk_draw_segments()</tt>; a <span class="STRUCTNAME"> GdkSegment</span> is: </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> typedef struct _GdkSegment GdkSegment;struct _GdkSegment{ gint16 x1; gint16 y1; gint16 x2; gint16 y2;}; </pre> </td> </tr> </table> <p> If lines or segments drawn in the same request meet at their endpoints, they are joined with the join style from the GC. </p> <div class="FIGURE"> <a name="FL-GDKLINES"></a> <div class="FUNCSYNOPSIS"> <a name="FL-GDKLINES.SYNOPSIS"></a> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="FUNCSYNOPSISINFO">#include <gdk/gdk.h></pre> </td> </tr> </table> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION">gdk_draw_line</tt></code>(GdkDrawable* <tt class="PARAMETER"><i>drawable</i></tt>, GdkGC* <tt class="PARAMETER"><i>gc</i></tt>, gint <tt class= "PARAMETER"><i>x1</i></tt>, gint <tt class= "PARAMETER"><i>y1</i></tt>, gint <tt class= "PARAMETER"><i>x2</i></tt>, gint <tt class= "PARAMETER"><i>y2</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION">gdk_draw_lines</tt></code>(GdkDrawable* <tt class="PARAMETER"><i>drawable</i></tt>, GdkGC* <tt class="PARAMETER"><i>gc</i></tt>, GdkPoint* <tt class="PARAMETER"><i>points</i></tt>, gint <tt class= "PARAMETER"><i>npoints</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION">gdk_draw_segments</tt></code>(GdkDrawable* <tt class="PARAMETER"><i>drawable</i></tt>, GdkGC* <tt class="PARAMETER"><i>gc</i></tt>, GdkSegment* <tt class="PARAMETER"><i>segments</i></tt>, gint <tt class="PARAMETER"><i>nsegments</i></tt>);</code> </p> </div> <p> <b>Figure 18. Drawing Lines</b> </p> </div> </div> <div class="SECT2"> <h2 class="SECT2"> <a name="Z135">Rectangles</a> </h2> <p> Rectangles are drawn with <tt class="FUNCTION"> gdk_draw_rectangle()</tt> (<a href= "z132.html#FL-GDKRECT">Figure 19</a>). The <span class= "STRUCTNAME">filled</span> argument indicates whether to fill the rectangle; <span class="STRUCTNAME">TRUE</span> means to fill it. </p> <div class="FIGURE"> <a name="FL-GDKRECT"></a> <div class="FUNCSYNOPSIS"> <a name="FL-GDKRECT.SYNOPSIS"></a> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="FUNCSYNOPSISINFO">#include <gdk/gdk.h></pre> </td> </tr> </table> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION"> gdk_draw_rectangle</tt></code>(GdkDrawable* <tt class="PARAMETER"><i>drawable</i></tt>, GdkGC* <tt class="PARAMETER"><i>gc</i></tt>, gint <tt class= "PARAMETER"><i>filled</i></tt>, gint <tt class= "PARAMETER"><i>x</i></tt>, gint <tt class= "PARAMETER"><i>y</i></tt>, gint <tt class= "PARAMETER"><i>width</i></tt>, gint <tt class= "PARAMETER"><i>height</i></tt>);</code> </p> </div> <p> <b>Figure 19. Drawing Rectangles</b> </p> </div> </div> <div class="SECT2"> <h2 class="SECT2"> <a name="Z136">Arcs</a> </h2> <p> <tt class="FUNCTION">gdk_draw_arc()</tt> draws an ellipse
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -