1 /** 2 * X Window System rendering using XLib 3 * 4 * License: 5 * $(TABLE 6 * $(TR $(TD cairoD wrapper/bindings) 7 * $(TD $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0))) 8 * $(TR $(TD $(LINK2 http://cgit.freedesktop.org/cairo/tree/COPYING, _cairo)) 9 * $(TD $(LINK2 http://cgit.freedesktop.org/cairo/tree/COPYING-LGPL-2.1, LGPL 2.1) / 10 * $(LINK2 http://cgit.freedesktop.org/cairo/plain/COPYING-MPL-1.1, MPL 1.1))) 11 * ) 12 * Authors: 13 * $(TABLE 14 * $(TR $(TD Johannes Pfau) $(TD cairoD)) 15 * $(TR $(TD $(LINK2 http://cairographics.org, _cairo team)) $(TD _cairo)) 16 * ) 17 */ 18 /* 19 * Distributed under the Boost Software License, Version 1.0. 20 * (See accompanying file LICENSE_1_0.txt or copy at 21 * http://www.boost.org/LICENSE_1_0.txt) 22 */ 23 module cairo.xlib; 24 25 import cairo.cairo; 26 import cairo.c.cairo; 27 28 static if(CAIRO_HAS_XLIB_SURFACE) 29 { 30 import cairo.c.xlib; 31 import x11.X, x11.Xlib; 32 33 /** 34 * The XLib surface is used to render cairo graphics to X Window 35 * System windows and pixmaps using the XLib library. 36 * 37 * Note that the XLib surface automatically takes advantage of 38 * X render extension if it is available. 39 */ 40 public class XlibSurface : Surface 41 { 42 public: 43 /** 44 * Create a $(D XlibSurface) from a existing $(D cairo_surface_t*). 45 * XlibSurface is a garbage collected class. It will call $(D cairo_surface_destroy) 46 * when it gets collected by the GC or when $(D dispose()) is called. 47 * 48 * Warning: 49 * $(D ptr)'s reference count is not increased by this function! 50 * Adjust reference count before calling it if necessary 51 * 52 * $(RED Only use this if you know what your doing! 53 * This function should not be needed for standard cairoD usage.) 54 */ 55 this(cairo_surface_t* ptr) 56 { 57 super(ptr); 58 } 59 60 /** 61 * Creates an Xlib surface that draws to the given drawable. 62 * The way that colors are represented in the drawable 63 * is specified by the provided visual. 64 * 65 * Note: If drawable is a Window, then the function 66 * $(D setSize()) must be called 67 * whenever the size of the window changes. 68 * 69 * When drawable is a Window containing child windows then 70 * drawing to the created surface will be clipped by 71 * those child windows. When the created surface is 72 * used as a source, the contents of the children 73 * will be included. 74 */ 75 this(Display* dpy, Drawable drawable, Visual* visual, int width, int height) 76 { 77 super(cairo_xlib_surface_create(dpy, drawable, visual, width, height)); 78 } 79 80 /** 81 * Creates an Xlib surface that draws to the given bitmap. 82 * This will be drawn to as a CAIRO_FORMAT_A1 object. 83 */ 84 this(Display* dpy, Pixmap bitmap, Screen* screen, int width, int height) 85 { 86 super(cairo_xlib_surface_create_for_bitmap(dpy, bitmap, 87 screen, width, height)); 88 } 89 90 /** 91 * Informs cairo of the new size of the X Drawable underlying 92 * the surface. For a surface created for a Window 93 * (rather than a Pixmap), this function must be called 94 * each time the size of the window changes. (For a 95 * subwindow, you are normally resizing the window yourself, 96 * but for a toplevel window, it is necessary to 97 * listen for ConfigureNotify events.) 98 * 99 * A Pixmap can never change size, so it is never necessary 100 * to call this function on a surface created for a Pixmap. 101 */ 102 void setSize(int width, int height) 103 { 104 cairo_xlib_surface_set_size(this.nativePointer, width, height); 105 checkError(); 106 } 107 108 /** 109 * Get the X Display for the underlying X Drawable. 110 */ 111 Display* getDisplay() 112 { 113 auto tmp = cairo_xlib_surface_get_display(this.nativePointer); 114 checkError(); 115 return tmp; 116 } 117 118 /** 119 * Get the X Screen for the underlying X Drawable. 120 */ 121 Screen* getScreen() 122 { 123 auto tmp = cairo_xlib_surface_get_screen(this.nativePointer); 124 checkError(); 125 return tmp; 126 } 127 128 /** 129 * Informs cairo of a new X Drawable underlying the surface. 130 * The drawable must match the display, screen and format 131 * of the existing drawable or the application will 132 * get X protocol errors and will probably terminate. 133 * No checks are done by this function to ensure this compatibility. 134 */ 135 void setDrawable(Drawable drawable, int width, int height) 136 { 137 cairo_xlib_surface_set_drawable(this.nativePointer, 138 drawable, width, height); 139 checkError(); 140 } 141 142 /** 143 * Get the underlying X Drawable used for the surface. 144 */ 145 Drawable getDrawable() 146 { 147 auto tmp = cairo_xlib_surface_get_drawable(this.nativePointer); 148 checkError(); 149 return tmp; 150 } 151 152 /** 153 * Gets the X Visual associated with surface, suitable 154 * for use with the underlying X Drawable. If surface 155 * was created by cairo_xlib_surface_create(), the return 156 * value is the Visual passed to that constructor. 157 */ 158 Visual* getVisual() 159 { 160 auto tmp = cairo_xlib_surface_get_visual(this.nativePointer); 161 checkError(); 162 return tmp; 163 } 164 165 /** 166 * Get the width of the X Drawable underlying the surface in pixels 167 */ 168 int getWidth() 169 { 170 auto tmp = cairo_xlib_surface_get_width(this.nativePointer); 171 checkError(); 172 return tmp; 173 } 174 175 /** 176 * Get the height of the X Drawable underlying the surface in pixels 177 */ 178 int getHeight() 179 { 180 auto tmp = cairo_xlib_surface_get_height(this.nativePointer); 181 checkError(); 182 return tmp; 183 } 184 185 /** 186 * Get the number of bits used to represent each pixel value. 187 */ 188 int getDepth() 189 { 190 auto tmp = cairo_xlib_surface_get_depth(this.nativePointer); 191 checkError(); 192 return tmp; 193 } 194 } 195 }