1. ------------------------------------------------------------------------------ 
  2. --                                                                          -- 
  3. --      Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet       -- 
  4. --                     Copyright (C) 2000-2014, AdaCore                     -- 
  5. --                                                                          -- 
  6. -- This library is free software;  you can redistribute it and/or modify it -- 
  7. -- under terms of the  GNU General Public License  as published by the Free -- 
  8. -- Software  Foundation;  either version 3,  or (at your  option) any later -- 
  9. -- version. This library is distributed in the hope that it will be useful, -- 
  10. -- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- -- 
  11. -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            -- 
  12. --                                                                          -- 
  13. -- As a special exception under Section 7 of GPL version 3, you are granted -- 
  14. -- additional permissions described in the GCC Runtime Library Exception,   -- 
  15. -- version 3.1, as published by the Free Software Foundation.               -- 
  16. --                                                                          -- 
  17. -- You should have received a copy of the GNU General Public License and    -- 
  18. -- a copy of the GCC Runtime Library Exception along with this program;     -- 
  19. -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    -- 
  20. -- <http://www.gnu.org/licenses/>.                                          -- 
  21. --                                                                          -- 
  22. ------------------------------------------------------------------------------ 
  23.  
  24. --  <description> 
  25. --  The Gtk.Drawing_Area.Gtk_Drawing_Area widget is used for creating custom 
  26. --  user interface elements. It's essentially a blank widget; you can draw on 
  27. --  it. After creating a drawing area, the application may want to connect to: 
  28. -- 
  29. --  
  30. -- 
  31. --     * 
  32. -- 
  33. --  Mouse and button press signals to respond to input from the user. (Use 
  34. --  Gtk.Widget.Add_Events to enable events you wish to receive.) 
  35. -- 
  36. --     * 
  37. -- 
  38. --  The Gtk.Widget.Gtk_Widget::realize signal to take any necessary actions 
  39. --  when the widget is instantiated on a particular display. (Create GDK 
  40. --  resources in response to this signal.) 
  41. -- 
  42. --     * 
  43. -- 
  44. --  The Gtk.Widget.Gtk_Widget::configure-event signal to take any necessary 
  45. --  actions when the widget changes size. 
  46. -- 
  47. --     * 
  48. -- 
  49. --  The Gtk.Widget.Gtk_Widget::draw signal to handle redrawing the contents of 
  50. --  the widget. 
  51. -- 
  52. --  The following code portion demonstrates using a drawing area to display a 
  53. --  circle in the normal widget foreground color. 
  54. -- 
  55. --  Note that GDK automatically clears the exposed area to the background 
  56. --  color before sending the expose event, and that drawing is implicitly 
  57. --  clipped to the exposed area. 
  58. -- 
  59. --  == Simple GtkDrawingArea usage == 
  60. -- 
  61. --    gboolean 
  62. --    draw_callback (GtkWidget *widget, cairo_t *cr, gpointer data) 
  63. --    { 
  64. --       guint width, height; 
  65. --       GdkRGBA color; 
  66. --       width = gtk_widget_get_allocated_width (widget); 
  67. --       height = gtk_widget_get_allocated_height (widget); 
  68. --       cairo_arc (cr, 
  69. --          width / 2.0, height / 2.0, 
  70. --          MIN (width, height) / 2.0, 
  71. --          0, 2 * G_PI); 
  72. --       gtk_style_context_get_color (gtk_widget_get_style_context (widget), 
  73. --          0, 
  74. --          &amp;color); 
  75. --       gdk_cairo_set_source_rgba (cr, &amp;color); 
  76. --       cairo_fill (cr); 
  77. --       return FALSE; 
  78. --    } 
  79. --    [...] 
  80. --    GtkWidget *drawing_area = gtk_drawing_area_new (<!-- -->); 
  81. --       gtk_widget_set_size_request (drawing_area, 100, 100); 
  82. --          g_signal_connect (G_OBJECT (drawing_area), "draw", 
  83. --          G_CALLBACK (draw_callback), NULL); 
  84. -- 
  85. --  Draw signals are normally delivered when a drawing area first comes 
  86. --  onscreen, or when it's covered by another window and then uncovered. You 
  87. --  can also force an expose event by adding to the "damage region" of the 
  88. --  drawing area's window; Gtk.Widget.Queue_Draw_Area and 
  89. --  Gdk.Window.Invalidate_Rect are equally good ways to do this. You'll then 
  90. --  get a draw signal for the invalid region. 
  91. -- 
  92. --  The available routines for drawing are documented on the <link 
  93. --  linkend="gdk3-Cairo-Interaction">GDK Drawing Primitives</link> page and the 
  94. --  cairo documentation. 
  95. -- 
  96. --  To receive mouse events on a drawing area, you will need to enable them 
  97. --  with Gtk.Widget.Add_Events. To receive keyboard events, you will need to 
  98. --  set the "can-focus" property on the drawing area, and you should probably 
  99. --  draw some user-visible indication that the drawing area is focused. Use 
  100. --  Gtk.Widget.Has_Focus in your expose event handler to decide whether to draw 
  101. --  the focus indicator. See Gtk.Style_Context.Render_Focus for one way to draw 
  102. --  focus. 
  103. -- 
  104. --  </description> 
  105. --  <description> 
  106. --  See also the Double_Buffer widget provided in the GtkAda examples for an 
  107. --  advanced example that demonstrates how to use double buffering, to avoid 
  108. --  flickering in your drawings. 
  109. -- 
  110. --  </description> 
  111. --  <group>Drawing</group> 
  112. --  <testgtk>libart_demo.adb</testgtk> 
  113. pragma Ada_2005; 
  114.  
  115. pragma Warnings (Off, "*is already use-visible*"); 
  116. with Glib;          use Glib; 
  117. with Glib.Types;    use Glib.Types; 
  118. with Gtk.Buildable; use Gtk.Buildable; 
  119. with Gtk.Widget;    use Gtk.Widget; 
  120.  
  121. package Gtk.Drawing_Area is 
  122.  
  123.    type Gtk_Drawing_Area_Record is new Gtk_Widget_Record with null record; 
  124.    type Gtk_Drawing_Area is access all Gtk_Drawing_Area_Record'Class; 
  125.  
  126.    ------------------ 
  127.    -- Constructors -- 
  128.    ------------------ 
  129.  
  130.    procedure Gtk_New (Drawing_Area : out Gtk_Drawing_Area); 
  131.    procedure Initialize 
  132.       (Drawing_Area : not null access Gtk_Drawing_Area_Record'Class); 
  133.    --  Creates a new drawing area. 
  134.  
  135.    function Gtk_Drawing_Area_New return Gtk_Drawing_Area; 
  136.    --  Creates a new drawing area. 
  137.  
  138.    function Get_Type return Glib.GType; 
  139.    pragma Import (C, Get_Type, "gtk_drawing_area_get_type"); 
  140.  
  141.    ---------------- 
  142.    -- Interfaces -- 
  143.    ---------------- 
  144.    --  This class implements several interfaces. See Glib.Types 
  145.    -- 
  146.    --  - "Buildable" 
  147.  
  148.    package Implements_Gtk_Buildable is new Glib.Types.Implements 
  149.      (Gtk.Buildable.Gtk_Buildable, Gtk_Drawing_Area_Record, Gtk_Drawing_Area); 
  150.    function "+" 
  151.      (Widget : access Gtk_Drawing_Area_Record'Class) 
  152.    return Gtk.Buildable.Gtk_Buildable 
  153.    renames Implements_Gtk_Buildable.To_Interface; 
  154.    function "-" 
  155.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  156.    return Gtk_Drawing_Area 
  157.    renames Implements_Gtk_Buildable.To_Object; 
  158.  
  159. end Gtk.Drawing_Area;