alternative to assert
[gtkD.git] / gtkD / src / gdk / Cursor.d
blob2fbbdafd162fc996ed1e5a71a99fd0ecf8bb5c22
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = gdk-Cursors.html
26 * outPack = gdk
27 * outFile = Cursor
28 * strct = GdkCursor
29 * realStrct=
30 * ctorStrct=
31 * clss = Cursor
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gdk_cursor_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * - glib.Str
45 * - gdk.Pixmap
46 * - gdk.Color
47 * - gdk.Display
48 * - gdk.Pixbuf
49 * - gdk.Cursor
50 * structWrap:
51 * - GdkColor* -> Color
52 * - GdkCursor* -> Cursor
53 * - GdkDisplay* -> Display
54 * - GdkPixbuf* -> Pixbuf
55 * - GdkPixmap* -> Pixmap
56 * module aliases:
57 * local aliases:
60 module gdk.Cursor;
62 version(noAssert)
64 version(Tango)
66 import tango.io.Stdout; // use the tango loging?
70 private import gtkc.gdktypes;
72 private import gtkc.gdk;
75 private import glib.Str;
76 private import gdk.Pixmap;
77 private import gdk.Color;
78 private import gdk.Display;
79 private import gdk.Pixbuf;
80 private import gdk.Cursor;
85 /**
86 * Description
87 * These functions are used to create and destroy cursors.
88 * There is a number of standard cursors, but it is also
89 * possible to construct new cursors from pixmaps and
90 * pixbufs. There may be limitations as to what kinds of
91 * cursors can be constructed on a given display, see
92 * gdk_display_supports_cursor_alpha(),
93 * gdk_display_supports_cursor_color(),
94 * gdk_display_get_default_cursor_size() and
95 * gdk_display_get_maximal_cursor_size().
96 * Cursors by themselves are not very interesting, they must be be
97 * bound to a window for users to see them. This is done with
98 * gdk_window_set_cursor() or by setting the cursor member of the
99 * GdkWindowAttr struct passed to gdk_window_new().
101 public class Cursor
104 /** the main Gtk struct */
105 protected GdkCursor* gdkCursor;
108 public GdkCursor* getCursorStruct()
110 return gdkCursor;
114 /** the main Gtk struct as a void* */
115 protected void* getStruct()
117 return cast(void*)gdkCursor;
121 * Sets our main struct and passes it to the parent class
123 public this (GdkCursor* gdkCursor)
125 version(noAssert)
127 if ( gdkCursor is null )
129 int zero = 0;
130 version(Tango)
132 Stdout("struct gdkCursor is null on constructor").newline;
134 else
136 printf("struct gdkCursor is null on constructor");
138 zero = zero / zero;
141 else
143 assert(gdkCursor !is null, "struct gdkCursor is null on constructor");
145 this.gdkCursor = gdkCursor;
154 * Creates a new cursor from the set of builtin cursors for the default display.
155 * See gdk_cursor_new_for_display().
156 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
157 * a cursor with no pixels in it.
158 * cursor_type:
159 * cursor to create
160 * Returns:
161 * a new GdkCursor
163 public this (GdkCursorType cursorType)
165 // GdkCursor* gdk_cursor_new (GdkCursorType cursor_type);
166 this(cast(GdkCursor*)gdk_cursor_new(cursorType) );
170 * Creates a new cursor from a given pixmap and mask. Both the pixmap and mask
171 * must have a depth of 1 (i.e. each pixel has only 2 values - on or off).
172 * The standard cursor size is 16 by 16 pixels. You can create a bitmap
173 * from inline data as in the below example.
174 * Example6.Creating a custom cursor
175 * /+* This data is in X bitmap format, and can be created with the 'bitmap'
176 * utility. +/
177 * #define cursor1_width 16
178 * #define cursor1_height 16
179 * static unsigned char cursor1_bits[] = {
180 * 0x80, 0x01, 0x40, 0x02, 0x20, 0x04, 0x10, 0x08, 0x08, 0x10, 0x04, 0x20,
181 * 0x82, 0x41, 0x41, 0x82, 0x41, 0x82, 0x82, 0x41, 0x04, 0x20, 0x08, 0x10,
182 * 0x10, 0x08, 0x20, 0x04, 0x40, 0x02, 0x80, 0x01};
183 * static unsigned char cursor1mask_bits[] = {
184 * 0x80, 0x01, 0xc0, 0x03, 0x60, 0x06, 0x30, 0x0c, 0x18, 0x18, 0x8c, 0x31,
185 * 0xc6, 0x63, 0x63, 0xc6, 0x63, 0xc6, 0xc6, 0x63, 0x8c, 0x31, 0x18, 0x18,
186 * 0x30, 0x0c, 0x60, 0x06, 0xc0, 0x03, 0x80, 0x01};
187 * GdkCursor *cursor;
188 * GdkPixmap *source, *mask;
189 * GdkColor fg = { 0, 65535, 0, 0 }; /+* Red. +/
190 * GdkColor bg = { 0, 0, 0, 65535 }; /+* Blue. +/
191 * source = gdk_bitmap_create_from_data (NULL, cursor1_bits,
192 * cursor1_width, cursor1_height);
193 * mask = gdk_bitmap_create_from_data (NULL, cursor1mask_bits,
194 * cursor1_width, cursor1_height);
195 * cursor = gdk_cursor_new_from_pixmap (source, mask, fg, bg, 8, 8);
196 * gdk_pixmap_unref (source);
197 * gdk_pixmap_unref (mask);
198 * gdk_window_set_cursor (widget->window, cursor);
199 * source:
200 * the pixmap specifying the cursor.
201 * mask:
202 * the pixmap specifying the mask, which must be the same size as
203 * source.
204 * fg:
205 * the foreground color, used for the bits in the source which are 1.
206 * The color does not have to be allocated first.
207 * bg:
208 * the background color, used for the bits in the source which are 0.
209 * The color does not have to be allocated first.
210 * x:
211 * the horizontal offset of the 'hotspot' of the cursor.
212 * y:
213 * the vertical offset of the 'hotspot' of the cursor.
214 * Returns:
215 * a new GdkCursor.
217 public this (Pixmap source, Pixmap mask, Color fg, Color bg, int x, int y)
219 // GdkCursor* gdk_cursor_new_from_pixmap (GdkPixmap *source, GdkPixmap *mask, const GdkColor *fg, const GdkColor *bg, gint x, gint y);
220 this(cast(GdkCursor*)gdk_cursor_new_from_pixmap((source is null) ? null : source.getPixmapStruct(), (mask is null) ? null : mask.getPixmapStruct(), (fg is null) ? null : fg.getColorStruct(), (bg is null) ? null : bg.getColorStruct(), x, y) );
224 * Creates a new cursor from a pixbuf.
225 * Not all GDK backends support RGBA cursors. If they are not
226 * supported, a monochrome approximation will be displayed.
227 * The functions gdk_display_supports_cursor_alpha() and
228 * gdk_display_supports_cursor_color() can be used to determine
229 * whether RGBA cursors are supported;
230 * gdk_display_get_default_cursor_size() and
231 * gdk_display_get_maximal_cursor_size() give information about
232 * cursor sizes.
233 * On the X backend, support for RGBA cursors requires a
234 * sufficently new version of the X Render extension.
235 * display:
236 * the GdkDisplay for which the cursor will be created
237 * pixbuf:
238 * the GdkPixbuf containing the cursor image
239 * x:
240 * the horizontal offset of the 'hotspot' of the cursor.
241 * y:
242 * the vertical offset of the 'hotspot' of the cursor.
243 * Returns:
244 * a new GdkCursor.
245 * Since 2.4
247 public this (Display display, Pixbuf pixbuf, int x, int y)
249 // GdkCursor* gdk_cursor_new_from_pixbuf (GdkDisplay *display, GdkPixbuf *pixbuf, gint x, gint y);
250 this(cast(GdkCursor*)gdk_cursor_new_from_pixbuf((display is null) ? null : display.getDisplayStruct(), (pixbuf is null) ? null : pixbuf.getPixbufStruct(), x, y) );
254 * Creates a new cursor by looking up name in the current cursor
255 * theme.
256 * display:
257 * the GdkDisplay for which the cursor will be created
258 * name:
259 * the name of the cursor
260 * Returns:
261 * a new GdkCursor, or NULL if there is no cursor with
262 * the given name
263 * Since 2.8
265 public this (Display display, char[] name)
267 // GdkCursor* gdk_cursor_new_from_name (GdkDisplay *display, const gchar *name);
268 this(cast(GdkCursor*)gdk_cursor_new_from_name((display is null) ? null : display.getDisplayStruct(), Str.toStringz(name)) );
272 * Creates a new cursor from the set of builtin cursors.
273 * Some useful ones are:
274 * GDK_RIGHT_PTR (right-facing arrow)
275 * GDK_CROSSHAIR (crosshair)
276 * GDK_XTERM (I-beam)
277 * GDK_WATCH (busy)
278 * GDK_FLEUR (for moving objects)
279 * GDK_HAND1 (a right-pointing hand)
280 * GDK_HAND2 (a left-pointing hand)
281 * GDK_LEFT_SIDE (resize left side)
282 * GDK_RIGHT_SIDE (resize right side)
283 * GDK_TOP_LEFT_CORNER (resize northwest corner)
284 * GDK_TOP_RIGHT_CORNER (resize northeast corner)
285 * GDK_BOTTOM_LEFT_CORNER (resize southwest corner)
286 * GDK_BOTTOM_RIGHT_CORNER (resize southeast corner)
287 * GDK_TOP_SIDE (resize top side)
288 * GDK_BOTTOM_SIDE (resize bottom side)
289 * GDK_SB_H_DOUBLE_ARROW (move vertical splitter)
290 * GDK_SB_V_DOUBLE_ARROW (move horizontal splitter)
291 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
292 * a cursor with no pixels in it.
293 * display:
294 * the GdkDisplay for which the cursor will be created
295 * cursor_type:
296 * cursor to create
297 * Returns:
298 * a new GdkCursor
299 * Since 2.2
301 public this (Display display, GdkCursorType cursorType)
303 // GdkCursor* gdk_cursor_new_for_display (GdkDisplay *display, GdkCursorType cursor_type);
304 this(cast(GdkCursor*)gdk_cursor_new_for_display((display is null) ? null : display.getDisplayStruct(), cursorType) );
308 * Returns the display on which the GdkCursor is defined.
309 * cursor:
310 * a GdkCursor.
311 * Returns:
312 * the GdkDisplay associated to cursor
313 * Since 2.2
315 public Display getDisplay()
317 // GdkDisplay* gdk_cursor_get_display (GdkCursor *cursor);
318 return new Display( gdk_cursor_get_display(gdkCursor) );
322 * Returns a GdkPixbuf with the image used to display the cursor.
323 * Note that depending on the capabilities of the windowing system and
324 * on the cursor, GDK may not be able to obtain the image data. In this
325 * case, NULL is returned.
326 * cursor:
327 * a GdkCursor
328 * Returns:
329 * a GdkPixbuf representing cursor, or NULL
330 * Since 2.8
332 public Pixbuf getImage()
334 // GdkPixbuf* gdk_cursor_get_image (GdkCursor *cursor);
335 return new Pixbuf( gdk_cursor_get_image(gdkCursor) );
339 * Adds a reference to cursor.
340 * cursor:
341 * a GdkCursor
342 * Returns:
343 * Same cursor that was passed in
345 public Cursor doref()
347 // GdkCursor* gdk_cursor_ref (GdkCursor *cursor);
348 return new Cursor( gdk_cursor_ref(gdkCursor) );
352 * Removes a reference from cursor, deallocating the cursor
353 * if no references remain.
354 * cursor:
355 * a GdkCursor
357 public void unref()
359 // void gdk_cursor_unref (GdkCursor *cursor);
360 gdk_cursor_unref(gdkCursor);