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