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 gdk.Cairo;
26 
27 private import cairo.Context;
28 private import cairo.Region;
29 private import cairo.Surface;
30 private import gdk.Color;
31 private import gdk.DrawingContext;
32 private import gdk.RGBA;
33 private import gdk.Window;
34 private import gdk.c.functions;
35 public  import gdk.c.types;
36 private import gdkpixbuf.Pixbuf;
37 private import gobject.ObjectG;
38 public  import gtkc.gdktypes;
39 
40 
41 /** */
42 
43 /**
44  * Creates a Cairo context for drawing to @window.
45  *
46  * Note that calling cairo_reset_clip() on the resulting #cairo_t will
47  * produce undefined results, so avoid it at all costs.
48  *
49  * Typically, this function is used to draw on a #GdkWindow out of the paint
50  * cycle of the toolkit; this should be avoided, as it breaks various assumptions
51  * and optimizations.
52  *
53  * If you are drawing on a native #GdkWindow in response to a %GDK_EXPOSE event
54  * you should use gdk_window_begin_draw_frame() and gdk_drawing_context_get_cairo_context()
55  * instead. GTK will automatically do this for you when drawing a widget.
56  *
57  * Deprecated: Use gdk_window_begin_draw_frame() and
58  * gdk_drawing_context_get_cairo_context() instead
59  *
60  * Params:
61  *     window = a #GdkWindow
62  *
63  * Returns: A newly created Cairo context. Free with
64  *     cairo_destroy() when you are done drawing.
65  *
66  * Since: 2.8
67  */
68 public Context createContext(Window window)
69 {
70 	auto p = gdk_cairo_create((window is null) ? null : window.getWindowStruct());
71 
72 	if(p is null)
73 	{
74 		return null;
75 	}
76 
77 	return new Context(cast(cairo_t*) p);
78 }
79 
80 /**
81  * This is the main way to draw GL content in GTK+. It takes a render buffer ID
82  * (@source_type == #GL_RENDERBUFFER) or a texture id (@source_type == #GL_TEXTURE)
83  * and draws it onto @cr with an OVER operation, respecting the current clip.
84  * The top left corner of the rectangle specified by @x, @y, @width and @height
85  * will be drawn at the current (0,0) position of the cairo_t.
86  *
87  * This will work for *all* cairo_t, as long as @window is realized, but the
88  * fallback implementation that reads back the pixels from the buffer may be
89  * used in the general case. In the case of direct drawing to a window with
90  * no special effects applied to @cr it will however use a more efficient
91  * approach.
92  *
93  * For #GL_RENDERBUFFER the code will always fall back to software for buffers
94  * with alpha components, so make sure you use #GL_TEXTURE if using alpha.
95  *
96  * Calling this may change the current GL context.
97  *
98  * Params:
99  *     cr = a cairo context
100  *     window = The window we're rendering for (not necessarily into)
101  *     source = The GL ID of the source buffer
102  *     sourceType = The type of the @source
103  *     bufferScale = The scale-factor that the @source buffer is allocated for
104  *     x = The source x position in @source to start copying from in GL coordinates
105  *     y = The source y position in @source to start copying from in GL coordinates
106  *     width = The width of the region to draw
107  *     height = The height of the region to draw
108  *
109  * Since: 3.16
110  */
111 public void drawFromGl(Context cr, Window window, int source, int sourceType, int bufferScale, int x, int y, int width, int height)
112 {
113 	gdk_cairo_draw_from_gl((cr is null) ? null : cr.getContextStruct(), (window is null) ? null : window.getWindowStruct(), source, sourceType, bufferScale, x, y, width, height);
114 }
115 
116 /**
117  * This is a convenience function around cairo_clip_extents().
118  * It rounds the clip extents to integer coordinates and returns
119  * a boolean indicating if a clip area exists.
120  *
121  * Params:
122  *     cr = a cairo context
123  *     rect = return location for the clip, or %NULL
124  *
125  * Returns: %TRUE if a clip rectangle exists, %FALSE if all of @cr is
126  *     clipped and all drawing can be skipped
127  */
128 public bool getClipRectangle(Context cr, out GdkRectangle rect)
129 {
130 	return gdk_cairo_get_clip_rectangle((cr is null) ? null : cr.getContextStruct(), &rect) != 0;
131 }
132 
133 /**
134  * Adds the given rectangle to the current path of @cr.
135  *
136  * Params:
137  *     cr = a cairo context
138  *     rectangle = a #GdkRectangle
139  *
140  * Since: 2.8
141  */
142 public void rectangle(Context cr, GdkRectangle* rectangle)
143 {
144 	gdk_cairo_rectangle((cr is null) ? null : cr.getContextStruct(), rectangle);
145 }
146 
147 /**
148  * Adds the given region to the current path of @cr.
149  *
150  * Params:
151  *     cr = a cairo context
152  *     region = a #cairo_region_t
153  *
154  * Since: 2.8
155  */
156 public void region(Context cr, Region region)
157 {
158 	gdk_cairo_region((cr is null) ? null : cr.getContextStruct(), (region is null) ? null : region.getRegionStruct());
159 }
160 
161 /**
162  * Creates region that describes covers the area where the given
163  * @surface is more than 50% opaque.
164  *
165  * This function takes into account device offsets that might be
166  * set with cairo_surface_set_device_offset().
167  *
168  * Params:
169  *     surface = a cairo surface
170  *
171  * Returns: A #cairo_region_t; must be freed with cairo_region_destroy()
172  */
173 public Region regionCreateFromSurface(Surface surface)
174 {
175 	auto p = gdk_cairo_region_create_from_surface((surface is null) ? null : surface.getSurfaceStruct());
176 
177 	if(p is null)
178 	{
179 		return null;
180 	}
181 
182 	return new Region(cast(cairo_region_t*) p);
183 }
184 
185 /**
186  * Sets the specified #GdkColor as the source color of @cr.
187  *
188  * Deprecated: Use gdk_cairo_set_source_rgba() instead
189  *
190  * Params:
191  *     cr = a cairo context
192  *     color = a #GdkColor
193  *
194  * Since: 2.8
195  */
196 public void setSourceColor(Context cr, Color color)
197 {
198 	gdk_cairo_set_source_color((cr is null) ? null : cr.getContextStruct(), (color is null) ? null : color.getColorStruct());
199 }
200 
201 /**
202  * Sets the given pixbuf as the source pattern for @cr.
203  *
204  * The pattern has an extend mode of %CAIRO_EXTEND_NONE and is aligned
205  * so that the origin of @pixbuf is @pixbuf_x, @pixbuf_y.
206  *
207  * Params:
208  *     cr = a cairo context
209  *     pixbuf = a #GdkPixbuf
210  *     pixbufX = X coordinate of location to place upper left corner of @pixbuf
211  *     pixbufY = Y coordinate of location to place upper left corner of @pixbuf
212  *
213  * Since: 2.8
214  */
215 public void setSourcePixbuf(Context cr, Pixbuf pixbuf, double pixbufX, double pixbufY)
216 {
217 	gdk_cairo_set_source_pixbuf((cr is null) ? null : cr.getContextStruct(), (pixbuf is null) ? null : pixbuf.getPixbufStruct(), pixbufX, pixbufY);
218 }
219 
220 /**
221  * Sets the specified #GdkRGBA as the source color of @cr.
222  *
223  * Params:
224  *     cr = a cairo context
225  *     rgba = a #GdkRGBA
226  *
227  * Since: 3.0
228  */
229 public void setSourceRgba(Context cr, RGBA rgba)
230 {
231 	gdk_cairo_set_source_rgba((cr is null) ? null : cr.getContextStruct(), (rgba is null) ? null : rgba.getRGBAStruct());
232 }
233 
234 /**
235  * Sets the given window as the source pattern for @cr.
236  *
237  * The pattern has an extend mode of %CAIRO_EXTEND_NONE and is aligned
238  * so that the origin of @window is @x, @y. The window contains all its
239  * subwindows when rendering.
240  *
241  * Note that the contents of @window are undefined outside of the
242  * visible part of @window, so use this function with care.
243  *
244  * Params:
245  *     cr = a cairo context
246  *     window = a #GdkWindow
247  *     x = X coordinate of location to place upper left corner of @window
248  *     y = Y coordinate of location to place upper left corner of @window
249  *
250  * Since: 2.24
251  */
252 public void setSourceWindow(Context cr, Window window, double x, double y)
253 {
254 	gdk_cairo_set_source_window((cr is null) ? null : cr.getContextStruct(), (window is null) ? null : window.getWindowStruct(), x, y);
255 }
256 
257 /**
258  * Creates an image surface with the same contents as
259  * the pixbuf.
260  *
261  * Params:
262  *     pixbuf = a #GdkPixbuf
263  *     scale = the scale of the new surface, or 0 to use same as @window
264  *     forWindow = The window this will be drawn to, or %NULL
265  *
266  * Returns: a new cairo surface, must be freed with cairo_surface_destroy()
267  *
268  * Since: 3.10
269  */
270 public Surface surfaceCreateFromPixbuf(Pixbuf pixbuf, int scale, Window forWindow)
271 {
272 	auto p = gdk_cairo_surface_create_from_pixbuf((pixbuf is null) ? null : pixbuf.getPixbufStruct(), scale, (forWindow is null) ? null : forWindow.getWindowStruct());
273 
274 	if(p is null)
275 	{
276 		return null;
277 	}
278 
279 	return new Surface(cast(cairo_surface_t*) p);
280 }
281 
282 /**
283  * Retrieves the #GdkDrawingContext that created the Cairo
284  * context @cr.
285  *
286  * Params:
287  *     cr = a Cairo context
288  *
289  * Returns: a #GdkDrawingContext, if any is set
290  *
291  * Since: 3.22
292  */
293 public DrawingContext getDrawingContext(Context cr)
294 {
295 	auto p = gdk_cairo_get_drawing_context((cr is null) ? null : cr.getContextStruct());
296 
297 	if(p is null)
298 	{
299 		return null;
300 	}
301 
302 	return ObjectG.getDObject!(DrawingContext)(cast(GdkDrawingContext*) p);
303 }