1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.DrawingArea; 26 27 private import glib.ConstructionException; 28 private import gobject.ObjectG; 29 private import gtk.Widget; 30 private import gtkc.gtk; 31 public import gtkc.gtktypes; 32 33 34 /** 35 * The #GtkDrawingArea widget is used for creating custom user interface 36 * elements. It’s essentially a blank widget; you can draw on it. After 37 * creating a drawing area, the application may want to connect to: 38 * 39 * - Mouse and button press signals to respond to input from 40 * the user. (Use gtk_widget_add_events() to enable events 41 * you wish to receive.) 42 * 43 * - The #GtkWidget::realize signal to take any necessary actions 44 * when the widget is instantiated on a particular display. 45 * (Create GDK resources in response to this signal.) 46 * 47 * - The #GtkWidget::size-allocate signal to take any necessary 48 * actions when the widget changes size. 49 * 50 * - The #GtkWidget::draw signal to handle redrawing the 51 * contents of the widget. 52 * 53 * The following code portion demonstrates using a drawing 54 * area to display a circle in the normal widget foreground 55 * color. 56 * 57 * Note that GDK automatically clears the exposed area to the 58 * background color before sending the expose event, and that 59 * drawing is implicitly clipped to the exposed area. 60 * 61 * ## Simple GtkDrawingArea usage 62 * 63 * |[<!-- language="C" --> 64 * gboolean 65 * draw_callback (GtkWidget *widget, cairo_t *cr, gpointer data) 66 * { 67 * guint width, height; 68 * GdkRGBA color; 69 * 70 * width = gtk_widget_get_allocated_width (widget); 71 * height = gtk_widget_get_allocated_height (widget); 72 * cairo_arc (cr, 73 * width / 2.0, height / 2.0, 74 * MIN (width, height) / 2.0, 75 * 0, 2 * G_PI); 76 * 77 * gtk_style_context_get_color (gtk_widget_get_style_context (widget), 78 * 0, 79 * &color); 80 * gdk_cairo_set_source_rgba (cr, &color); 81 * 82 * cairo_fill (cr); 83 * 84 * return FALSE; 85 * } 86 * [...] 87 * GtkWidget *drawing_area = gtk_drawing_area_new (); 88 * gtk_widget_set_size_request (drawing_area, 100, 100); 89 * g_signal_connect (G_OBJECT (drawing_area), "draw", 90 * G_CALLBACK (draw_callback), NULL); 91 * ]| 92 * 93 * Draw signals are normally delivered when a drawing area first comes 94 * onscreen, or when it’s covered by another window and then uncovered. 95 * You can also force an expose event by adding to the “damage region” 96 * of the drawing area’s window; gtk_widget_queue_draw_area() and 97 * gdk_window_invalidate_rect() are equally good ways to do this. 98 * You’ll then get a draw signal for the invalid region. 99 * 100 * The available routines for drawing are documented on the 101 * [GDK Drawing Primitives][gdk3-Cairo-Interaction] page 102 * and the cairo documentation. 103 * 104 * To receive mouse events on a drawing area, you will need to enable 105 * them with gtk_widget_add_events(). To receive keyboard events, you 106 * will need to set the “can-focus” property on the drawing area, and you 107 * should probably draw some user-visible indication that the drawing 108 * area is focused. Use gtk_widget_has_focus() in your expose event 109 * handler to decide whether to draw the focus indicator. See 110 * gtk_render_focus() for one way to draw focus. 111 */ 112 public class DrawingArea : Widget 113 { 114 /** the main Gtk struct */ 115 protected GtkDrawingArea* gtkDrawingArea; 116 117 /** Get the main Gtk struct */ 118 public GtkDrawingArea* getDrawingAreaStruct() 119 { 120 return gtkDrawingArea; 121 } 122 123 /** the main Gtk struct as a void* */ 124 protected override void* getStruct() 125 { 126 return cast(void*)gtkDrawingArea; 127 } 128 129 protected override void setStruct(GObject* obj) 130 { 131 gtkDrawingArea = cast(GtkDrawingArea*)obj; 132 super.setStruct(obj); 133 } 134 135 /** 136 * Sets our main struct and passes it to the parent class. 137 */ 138 public this (GtkDrawingArea* gtkDrawingArea, bool ownedRef = false) 139 { 140 this.gtkDrawingArea = gtkDrawingArea; 141 super(cast(GtkWidget*)gtkDrawingArea, ownedRef); 142 } 143 144 /** 145 * Create a new DrawingArea and sets the SizeRequest 146 * Params: 147 * width = 148 * height = 149 */ 150 this(int width, int height) 151 { 152 this(); 153 setSizeRequest(width, height); 154 } 155 156 /** 157 */ 158 159 public static GType getType() 160 { 161 return gtk_drawing_area_get_type(); 162 } 163 164 /** 165 * Creates a new drawing area. 166 * 167 * Return: a new #GtkDrawingArea 168 * 169 * Throws: ConstructionException GTK+ fails to create the object. 170 */ 171 public this() 172 { 173 auto p = gtk_drawing_area_new(); 174 175 if(p is null) 176 { 177 throw new ConstructionException("null returned by new"); 178 } 179 180 this(cast(GtkDrawingArea*) p); 181 } 182 }