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