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 * Conversion parameters: 26 * inFile = gdk3-Cairo-Interaction.html 27 * outPack = gdk 28 * outFile = Cairo 29 * strct = 30 * realStrct= 31 * ctorStrct= 32 * clss = 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gdk_cairo_ 41 * - gdk_window_ 42 * omit structs: 43 * omit prefixes: 44 * omit code: 45 * omit signals: 46 * imports: 47 * - cairo.Context 48 * - cairo.Region 49 * - cairo.Surface 50 * - gdk.Color 51 * - gdk.Pixbuf 52 * - gdk.RGBA 53 * - gdk.Window 54 * structWrap: 55 * - GdkColor* -> Color 56 * - GdkPixbuf* -> Pixbuf 57 * - GdkRGBA* -> RGBA 58 * - GdkWindow* -> Window 59 * - cairo_region_t* -> Region 60 * - cairo_surface_t* -> Surface 61 * - cairo_t* -> Context 62 * module aliases: 63 * local aliases: 64 * - create -> createContext 65 * overrides: 66 */ 67 68 module gdk.Cairo; 69 70 public import gtkc.gdktypes; 71 72 private import gtkc.gdk; 73 private import glib.ConstructionException; 74 private import gobject.ObjectG; 75 76 private import cairo.Context; 77 private import cairo.Region; 78 private import cairo.Surface; 79 private import gdk.Color; 80 private import gdk.Pixbuf; 81 private import gdk.RGBA; 82 private import gdk.Window; 83 84 85 86 /** 87 * Use these functions in combination with UFCS. 88 */ 89 90 /** 91 */ 92 93 /** 94 * Create a new surface that is as compatible as possible with the 95 * given window. For example the new surface will have the same 96 * fallback resolution and font options as window. Generally, the new 97 * surface will also use the same backend as window, unless that is 98 * not possible for some reason. The type of the returned surface may 99 * be examined with cairo_surface_get_type(). 100 * Initially the surface contents are all 0 (transparent if contents 101 * have transparency, black otherwise.) 102 * Since 2.22 103 * Params: 104 * window = window to make new surface similar to 105 * content = the content for the new surface 106 * width = width of the new surface 107 * height = height of the new surface 108 * Returns: a pointer to the newly allocated surface. The caller owns the surface and should call cairo_surface_destroy() when done with it. This function always returns a valid pointer, but it will return a pointer to a "nil" surface if other is already in an error state or any other error occurs. 109 */ 110 public static Surface createSimilarSurface(Window window, cairo_content_t content, int width, int height) 111 { 112 // cairo_surface_t * gdk_window_create_similar_surface (GdkWindow *window, cairo_content_t content, int width, int height); 113 auto p = gdk_window_create_similar_surface((window is null) ? null : window.getWindowStruct(), content, width, height); 114 115 if(p is null) 116 { 117 return null; 118 } 119 120 return ObjectG.getDObject!(Surface)(cast(cairo_surface_t*) p); 121 } 122 123 /** 124 * Create a new image surface that is efficient to draw on the 125 * given window. 126 * Initially the surface contents are all 0 (transparent if contents 127 * have transparency, black otherwise.) 128 * Params: 129 * window = window to make new surface similar to, or NULL if none 130 * format = the format for the new surface. [type int] 131 * width = width of the new surface 132 * height = height of the new surface 133 * scale = the scale of the new surface, or 0 to use same as window 134 * Returns: a pointer to the newly allocated surface. The caller owns the surface and should call cairo_surface_destroy() when done with it. This function always returns a valid pointer, but it will return a pointer to a "nil" surface if other is already in an error state or any other error occurs. Since 3.10 135 */ 136 public static Surface createSimilarImageSurface(Window window, cairo_format_t format, int width, int height, int scale) 137 { 138 // cairo_surface_t * gdk_window_create_similar_image_surface (GdkWindow *window, cairo_format_t format, int width, int height, int scale); 139 auto p = gdk_window_create_similar_image_surface((window is null) ? null : window.getWindowStruct(), format, width, height, scale); 140 141 if(p is null) 142 { 143 return null; 144 } 145 146 return ObjectG.getDObject!(Surface)(cast(cairo_surface_t*) p); 147 } 148 149 /** 150 * Creates a Cairo context for drawing to window. 151 * Note 152 * Warning 153 * Note that calling cairo_reset_clip() on the resulting cairo_t will 154 * produce undefined results, so avoid it at all costs. 155 * Since 2.8 156 * Params: 157 * window = a GdkWindow 158 * Returns: A newly created Cairo context. Free with cairo_destroy() when you are done drawing. 159 */ 160 public static Context createContext(Window window) 161 { 162 // cairo_t * gdk_cairo_create (GdkWindow *window); 163 auto p = gdk_cairo_create((window is null) ? null : window.getWindowStruct()); 164 165 if(p is null) 166 { 167 return null; 168 } 169 170 return ObjectG.getDObject!(Context)(cast(cairo_t*) p); 171 } 172 173 /** 174 * This is a convenience function around cairo_clip_extents(). 175 * It rounds the clip extents to integer coordinates and returns 176 * a boolean indicating if a clip area exists. 177 * Params: 178 * cr = a cairo context 179 * rect = return location for the clip, or NULL. [out][allow-none] 180 * Returns: TRUE if a clip rectangle exists, FALSE if all of cr is clipped and all drawing can be skipped 181 */ 182 public static int getClipRectangle(Context cr, Rectangle* rect) 183 { 184 // gboolean gdk_cairo_get_clip_rectangle (cairo_t *cr, GdkRectangle *rect); 185 return gdk_cairo_get_clip_rectangle((cr is null) ? null : cr.getContextStruct(), rect); 186 } 187 188 /** 189 * Warning 190 * gdk_cairo_set_source_color has been deprecated since version 3.4 and should not be used in newly-written code. Use gdk_cairo_set_source_rgba() instead 191 * Sets the specified GdkColor as the source color of cr. 192 * Since 2.8 193 * Params: 194 * cr = a cairo context 195 * color = a GdkColor 196 */ 197 public static void setSourceColor(Context cr, Color color) 198 { 199 // void gdk_cairo_set_source_color (cairo_t *cr, const GdkColor *color); 200 gdk_cairo_set_source_color((cr is null) ? null : cr.getContextStruct(), (color is null) ? null : color.getColorStruct()); 201 } 202 203 /** 204 * Sets the specified GdkRGBA as the source color of cr. 205 * Params: 206 * cr = a cairo context 207 * rgba = a GdkRGBA 208 * Since 3.0 209 */ 210 public static void setSourceRgba(Context cr, RGBA rgba) 211 { 212 // void gdk_cairo_set_source_rgba (cairo_t *cr, const GdkRGBA *rgba); 213 gdk_cairo_set_source_rgba((cr is null) ? null : cr.getContextStruct(), (rgba is null) ? null : rgba.getRGBAStruct()); 214 } 215 216 /** 217 * Sets the given pixbuf as the source pattern for cr. 218 * The pattern has an extend mode of CAIRO_EXTEND_NONE and is aligned 219 * so that the origin of pixbuf is pixbuf_x, pixbuf_y. 220 * Since 2.8 221 * Params: 222 * cr = a cairo context 223 * pixbuf = a GdkPixbuf 224 * pixbufX = X coordinate of location to place upper left corner of pixbuf 225 * pixbufY = Y coordinate of location to place upper left corner of pixbuf 226 */ 227 public static void setSourcePixbuf(Context cr, Pixbuf pixbuf, double pixbufX, double pixbufY) 228 { 229 // void gdk_cairo_set_source_pixbuf (cairo_t *cr, const GdkPixbuf *pixbuf, gdouble pixbuf_x, gdouble pixbuf_y); 230 gdk_cairo_set_source_pixbuf((cr is null) ? null : cr.getContextStruct(), (pixbuf is null) ? null : pixbuf.getPixbufStruct(), pixbufX, pixbufY); 231 } 232 233 /** 234 * Sets the given window as the source pattern for cr. 235 * The pattern has an extend mode of CAIRO_EXTEND_NONE and is aligned 236 * so that the origin of window is x, y. The window contains all its 237 * subwindows when rendering. 238 * Note that the contents of window are undefined outside of the 239 * visible part of window, so use this function with care. 240 * Since 2.24 241 * Params: 242 * cr = a cairo context 243 * window = a GdkWindow 244 * x = X coordinate of location to place upper left corner of window 245 * y = Y coordinate of location to place upper left corner of window 246 */ 247 public static void setSourceWindow(Context cr, Window window, double x, double y) 248 { 249 // void gdk_cairo_set_source_window (cairo_t *cr, GdkWindow *window, gdouble x, gdouble y); 250 gdk_cairo_set_source_window((cr is null) ? null : cr.getContextStruct(), (window is null) ? null : window.getWindowStruct(), x, y); 251 } 252 253 /** 254 * Adds the given rectangle to the current path of cr. 255 * Since 2.8 256 * Params: 257 * cr = a cairo context 258 * rectangle = a GdkRectangle 259 */ 260 public static void rectangle(Context cr, Rectangle* rectangle) 261 { 262 // void gdk_cairo_rectangle (cairo_t *cr, const GdkRectangle *rectangle); 263 gdk_cairo_rectangle((cr is null) ? null : cr.getContextStruct(), rectangle); 264 } 265 266 /** 267 * Adds the given region to the current path of cr. 268 * Since 2.8 269 * Params: 270 * cr = a cairo context 271 * region = a cairo_region_t 272 */ 273 public static void region(Context cr, Region region) 274 { 275 // void gdk_cairo_region (cairo_t *cr, const cairo_region_t *region); 276 gdk_cairo_region((cr is null) ? null : cr.getContextStruct(), (region is null) ? null : region.getRegionStruct()); 277 } 278 279 /** 280 * Creates region that describes covers the area where the given 281 * surface is more than 50% opaque. 282 * This function takes into account device offsets that might be 283 * set with cairo_surface_set_device_offset(). 284 * Params: 285 * surface = a cairo surface 286 * Returns: A cairo_region_t; must be freed with cairo_region_destroy() 287 */ 288 public static Region regionCreateFromSurface(Surface surface) 289 { 290 // cairo_region_t * gdk_cairo_region_create_from_surface (cairo_surface_t *surface); 291 auto p = gdk_cairo_region_create_from_surface((surface is null) ? null : surface.getSurfaceStruct()); 292 293 if(p is null) 294 { 295 return null; 296 } 297 298 return ObjectG.getDObject!(Region)(cast(cairo_region_t*) p); 299 } 300 301 /** 302 * Creates an image surface with the same contents as 303 * the pixbuf. 304 * Params: 305 * pixbuf = a GdkPixbuf 306 * scale = the scale of the new surface, or 0 to use same as window 307 * forWindow = The window this will be drawn to, on NULL. 308 * Returns: a new cairo surface, must be freed with cairo_surface_destroy() Since 3.10 309 */ 310 public static Surface surfaceCreateFromPixbuf(Pixbuf pixbuf, int scale, Window forWindow) 311 { 312 // cairo_surface_t * gdk_cairo_surface_create_from_pixbuf (const GdkPixbuf *pixbuf, int scale, GdkWindow *for_window); 313 auto p = gdk_cairo_surface_create_from_pixbuf((pixbuf is null) ? null : pixbuf.getPixbufStruct(), scale, (forWindow is null) ? null : forWindow.getWindowStruct()); 314 315 if(p is null) 316 { 317 return null; 318 } 319 320 return ObjectG.getDObject!(Surface)(cast(cairo_surface_t*) p); 321 } 322