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