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

📄 z177.html

📁 gtk_text program sample&eg
💻 HTML
📖 第 1 页 / 共 3 页
字号:
          </tr>        </table>        <p>          Of course, a real callback would probably examine the          contents of the event and take some action in response to          some of them.        </p>      </div>      <div class="SECT2">        <h2 class="SECT2">          <a name="Z182">A Canvas Example</a>        </h2>        <p>          This section gives a brief example program, demonstrating          the user of the canvas. It does not explain the          particulars of the canvas items being created; see <a          href="sec-itemreference.html">the section called <i>          Standard Canvas Item Reference</i></a> for that. <a href=           "z177.html#FIG-CANVAS-EXAMPLE">Figure 9</a> shows the          example program in action. You can drag canvas items          around the screen with the left mouse button; clicking an          item with the Shift key held down destroys it.        </p>        <div class="FIGURE">          <a name="FIG-CANVAS-EXAMPLE"></a>          <p>            <img src="figures/canvas-example.png">          </p>          <p>            <b>Figure 9. Simple <tt class="CLASSNAME">            GnomeCanvas</tt> program</b>          </p>        </div>        <p>          Here is the code to create an antialiased canvas. Notice          the call to <tt class="FUNCTION">gdk_rgb_init()</tt>;          notice that the canvas's scroll region is set; finally,          notice that the GdkRGB colormap and visual are pushed          when creating the canvas.        </p>        <table border="0" bgcolor="#E0E0E0" width="100%">          <tr>            <td><pre class="PROGRAMLISTING">&#13;#include &lt;gnome.h&gt;static gint delete_event_cb(GtkWidget* window, GdkEventAny* e, gpointer data);static void create_canvas_items(GtkWidget* canvas);int main(int argc, char* argv[]){  GtkWidget* window;  GtkWidget* sw;  GtkWidget* canvas;  gnome_init("canvas-example", "0.0", argc, argv);    gdk_rgb_init();  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);  gtk_window_set_title(GTK_WINDOW(window), "Canvas Example");  gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, TRUE);  gtk_signal_connect(GTK_OBJECT(window),                     "delete_event",                     GTK_SIGNAL_FUNC(delete_event_cb),                     NULL);  sw = gtk_scrolled_window_new(NULL, NULL);  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),                                 GTK_POLICY_AUTOMATIC,                                 GTK_POLICY_AUTOMATIC);  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();  gnome_canvas_set_scroll_region(GNOME_CANVAS(canvas), 0, 0, 600, 450);  create_canvas_items(canvas);  gtk_container_add(GTK_CONTAINER(sw), canvas);  gtk_container_add(GTK_CONTAINER(window), sw);  gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);  gtk_widget_show_all(window);  gtk_main();  return 0;}static gint delete_event_cb(GtkWidget* window, GdkEventAny* e, gpointer data){  gtk_main_quit();  return FALSE;}      </pre>            </td>          </tr>        </table>        <p>          Once the canvas has been created, the program adds some          items to it, and connects a simple callback to the item's          <span class="SYMBOL">"event"</span> signal. Here's the          code:        </p>        <table border="0" bgcolor="#E0E0E0" width="100%">          <tr>            <td><pre class="PROGRAMLISTING">&#13;static gintitem_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data){  static double x, y;  double new_x, new_y;  GdkCursor *fleur;  static int dragging;  double item_x, item_y;  item_x = event-&gt;button.x;  item_y = event-&gt;button.y;  gnome_canvas_item_w2i(item-&gt;parent, &amp;item_x, &amp;item_y);  switch (event-&gt;type)     {    case GDK_BUTTON_PRESS:      switch(event-&gt;button.button)         {        case 1:          if (event-&gt;button.state &amp; GDK_SHIFT_MASK)            {              gtk_object_destroy(GTK_OBJECT(item));            }          else             {              x = item_x;              y = item_y;                            fleur = gdk_cursor_new(GDK_FLEUR);              gnome_canvas_item_grab(item,                                     GDK_POINTER_MOTION_MASK |                                      GDK_BUTTON_RELEASE_MASK,                                     fleur,                                     event-&gt;button.time);              gdk_cursor_destroy(fleur);              dragging = TRUE;            }          break;        default:          break;        }      break;    case GDK_MOTION_NOTIFY:      if (dragging &amp;&amp; (event-&gt;motion.state &amp; GDK_BUTTON1_MASK))         {          new_x = item_x;          new_y = item_y;                      gnome_canvas_item_move(item, new_x - x, new_y - y);          x = new_x;          y = new_y;        }      break;              case GDK_BUTTON_RELEASE:      gnome_canvas_item_ungrab(item, event-&gt;button.time);      dragging = FALSE;      break;              default:      break;    }          return FALSE;}static voidsetup_item(GnomeCanvasItem *item){  gtk_signal_connect(GTK_OBJECT(item), "event",                     (GtkSignalFunc) item_event,                     NULL);}static void create_canvas_items(GtkWidget* canvas){  GnomeCanvasPoints* points;  GnomeCanvasGroup* group;  GnomeCanvasItem* item;  double affine[6];  group = gnome_canvas_root(GNOME_CANVAS(canvas));  /* A polygon */  points = gnome_canvas_points_new(14);  points-&gt;coords[0] = 270.0;  points-&gt;coords[1] = 330.0;  points-&gt;coords[2] = 270.0;  points-&gt;coords[3] = 430.0;  points-&gt;coords[4] = 390.0;  points-&gt;coords[5] = 430.0;  points-&gt;coords[6] = 390.0;  points-&gt;coords[7] = 330.0;  points-&gt;coords[8] = 310.0;  points-&gt;coords[9] = 330.0;  points-&gt;coords[10] = 310.0;  points-&gt;coords[11] = 390.0;  points-&gt;coords[12] = 350.0;  points-&gt;coords[13] = 390.0;  points-&gt;coords[14] = 350.0;  points-&gt;coords[15] = 370.0;  points-&gt;coords[16] = 330.0;  points-&gt;coords[17] = 370.0;  points-&gt;coords[18] = 330.0;  points-&gt;coords[19] = 350.0;  points-&gt;coords[20] = 370.0;  points-&gt;coords[21] = 350.0;  points-&gt;coords[22] = 370.0;  points-&gt;coords[23] = 410.0;  points-&gt;coords[24] = 290.0;  points-&gt;coords[25] = 410.0;  points-&gt;coords[26] = 290.0;  points-&gt;coords[27] = 330.0;  item = gnome_canvas_item_new(group,                               gnome_canvas_polygon_get_type (),                               "points", points,                               "fill_color", "tan",                               "outline_color", "black",                               "width_units", 3.0,                               NULL);  setup_item(item);  gnome_canvas_points_unref(points);  /* Translate the polygon */  art_affine_translate(affine, -150.0, -300.0);  gnome_canvas_item_affine_relative(item, affine);  /* A translucent rectangle */  setup_item (gnome_canvas_item_new (group,                                     gnome_canvas_rect_get_type(),                                     "x1", 90.0,                                     "y1", 40.0,                                     "x2", 180.0,                                     "y2", 100.0,                                     "fill_color_rgba", 0x3cb37180,                                     "outline_color", "black",                                     "width_units", 4.0,                                     NULL));  /* A translucent ellipse */  setup_item (gnome_canvas_item_new (group,                                     gnome_canvas_ellipse_get_type(),                                     "x1", 210.0,                                     "y1", 80.0,                                     "x2", 280.0,                                     "y2", 140.0,                                     "fill_color_rgba", 0x5f9ea080,                                     "outline_color", "black",                                     "width_pixels", 0,                                     NULL));  /* Create ellipses arranged in a line; they're manipulated as a     single item. */  group =     GNOME_CANVAS_GROUP (gnome_canvas_item_new (group,                                               gnome_canvas_group_get_type(),                                               "x", 0.0,                                               "y", 0.0,                                               NULL));  setup_item(GNOME_CANVAS_ITEM(group));  {    double xpos = 20.0;    while (xpos &lt; 300.0)      {        gnome_canvas_item_new(group,                              gnome_canvas_ellipse_get_type(),                              "x1", xpos,                              "y1", 100.0,                              "x2", xpos + 10.0,                              "y2", 110.0,                              "fill_color_rgba", 0x0000FFFF,                              "outline_color_rgba", 0xFF,                              NULL);        xpos += 15.0;      }  }}      </pre>            </td>          </tr>        </table>      </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="z174.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="sec-itemreference.html"><font color="#0000ff"            size="2"><b>Next &gt;&gt;&gt;</b></font></a>          </td>        </tr>        <tr>          <td colspan="2" align="left">            <font color="#000000" size="2"><b>Basic Canvas            Architecture</b></font>          </td>          <td colspan="2" align="right">            <font color="#000000" size="2"><b>Standard Canvas Item            Reference</b></font>          </td>        </tr>      </table>    </div>  </body></html>

⌨️ 快捷键说明

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