Mercurial > projects > dwt-linux
annotate dwt/graphics/GC.d @ 33:27324bbbac70
changed to regenerated BCD bindings
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 10 Jan 2008 02:18:07 +0100 |
parents | 10acbb123580 |
children | 93981635e709 |
rev | line source |
---|---|
18 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 *******************************************************************************/ | |
11 module dwt.graphics.GC; | |
12 | |
13 import dwt.graphics.Image; | |
14 | |
19 | 15 |
16 import dwt.SWT; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
17 import dwt.SWTException; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
18 import dwt.SWTError; |
21 | 19 import dwt.graphics.Color; |
19 | 20 import dwt.graphics.Drawable; |
21 import dwt.graphics.Resource; | |
22 import dwt.graphics.Device; | |
23 import dwt.graphics.Font; | |
24 import dwt.graphics.FontMetrics; | |
25 import dwt.graphics.GCData; | |
26 import dwt.graphics.Image; | |
27 import dwt.graphics.ImageData; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
28 import dwt.graphics.Path; |
19 | 29 import dwt.graphics.Pattern; |
30 import dwt.graphics.Point; | |
31 import dwt.graphics.RGB; | |
32 import dwt.graphics.Rectangle; | |
33 import dwt.graphics.Region; | |
34 import dwt.graphics.Resource; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
35 import dwt.graphics.Transform; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
36 import dwt.graphics.LineAttributes; |
21 | 37 |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
38 import dwt.internal.gtk.OS; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
39 import dwt.internal.cairo.Cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
40 import dwt.internal.Converter; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
41 import dwt.internal.Compatibility; |
21 | 42 |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
43 import tango.text.convert.Format; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
44 import tango.stdc.string; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
45 import tango.stdc.stringz; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
46 |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
47 |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
48 /+ |
21 | 49 class GC{ |
50 void drawImage(Image, int, int, int, int, int, int, int, int ){} | |
51 void dispose(){} | |
52 bool isDisposed(){ return false; } | |
53 static void setCairoPatternColor(cairo_pattern_t * pattern, int offset, Color c, int alpha) {} | |
54 static void addCairoString(cairo_t* cairo, char[] str, float x, float y, Font font) {} | |
55 void initCairo() {} | |
56 void checkGC (int mask) {} | |
57 const static int FOREGROUND = 1 << 0; | |
58 const static int BACKGROUND = 1 << 1; | |
59 const static int FONT = 1 << 2; | |
60 const static int LINE_STYLE = 1 << 3; | |
61 const static int LINE_CAP = 1 << 4; | |
62 const static int LINE_JOIN = 1 << 5; | |
63 const static int LINE_WIDTH = 1 << 6; | |
64 const static int LINE_MITERLIMIT = 1 << 7; | |
65 const static int BACKGROUND_BG = 1 << 8; | |
66 const static int DRAW_OFFSET = 1 << 9; | |
67 const static int DRAW = FOREGROUND | LINE_WIDTH | LINE_STYLE | LINE_CAP | LINE_JOIN | LINE_MITERLIMIT | DRAW_OFFSET; | |
68 const static int FILL = BACKGROUND; | |
69 | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
70 public GdkGC* handle; |
21 | 71 |
72 GCData data; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
73 public Rectangle getClipping() { return null; } |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
74 public void getClipping(Region) { } |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
75 void setClipping(GdkRegion* clipRgn) {} |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
76 //void setClipping(Path clipRgn) {} |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
77 void setClipping(Region clipRgn) {} |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
78 void setClipping(Rectangle clipRgn) {} |
21 | 79 } |
80 | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
81 +/ |
18 | 82 |
83 /** | |
84 * Class <code>GC</code> is where all of the drawing capabilities that are | |
85 * supported by SWT are located. Instances are used to draw on either an | |
86 * <code>Image</code>, a <code>Control</code>, or directly on a <code>Display</code>. | |
87 * <dl> | |
88 * <dt><b>Styles:</b></dt> | |
89 * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd> | |
90 * </dl> | |
91 * | |
92 * <p> | |
93 * The SWT drawing coordinate system is the two-dimensional space with the origin | |
94 * (0,0) at the top left corner of the drawing area and with (x,y) values increasing | |
95 * to the right and downward respectively. | |
96 * </p> | |
97 * | |
98 * <p> | |
99 * Application code must explicitly invoke the <code>GC.dispose()</code> | |
100 * method to release the operating system resources managed by each instance | |
101 * when those instances are no longer required. This is <em>particularly</em> | |
102 * important on Windows95 and Windows98 where the operating system has a limited | |
103 * number of device contexts available. | |
104 * </p> | |
105 * | |
106 * <p> | |
107 * Note: Only one of LEFT_TO_RIGHT and RIGHT_TO_LEFT may be specified. | |
108 * </p> | |
109 * | |
110 * @see dwt.events.PaintEvent | |
111 */ | |
19 | 112 public final class GC : Resource { |
18 | 113 /** |
114 * the handle to the OS device context | |
115 * (Warning: This field is platform dependent) | |
116 * <p> | |
117 * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT | |
118 * public API. It is marked public only so that it can be shared | |
119 * within the packages provided by SWT. It is not available on all | |
120 * platforms and should never be accessed from application code. | |
121 * </p> | |
122 */ | |
19 | 123 public GdkGC* handle; |
18 | 124 |
125 Drawable drawable; | |
126 GCData data; | |
127 | |
19 | 128 const static int FOREGROUND = 1 << 0; |
129 const static int BACKGROUND = 1 << 1; | |
130 const static int FONT = 1 << 2; | |
131 const static int LINE_STYLE = 1 << 3; | |
132 const static int LINE_CAP = 1 << 4; | |
133 const static int LINE_JOIN = 1 << 5; | |
134 const static int LINE_WIDTH = 1 << 6; | |
135 const static int LINE_MITERLIMIT = 1 << 7; | |
136 const static int BACKGROUND_BG = 1 << 8; | |
137 const static int DRAW_OFFSET = 1 << 9; | |
138 const static int DRAW = FOREGROUND | LINE_WIDTH | LINE_STYLE | LINE_CAP | LINE_JOIN | LINE_MITERLIMIT | DRAW_OFFSET; | |
139 const static int FILL = BACKGROUND; | |
18 | 140 |
19 | 141 static const float[] LINE_DOT = [1, 1]; |
142 static const float[] LINE_DASH = [3, 1]; | |
143 static const float[] LINE_DASHDOT = [3, 1, 1, 1]; | |
144 static const float[] LINE_DASHDOTDOT = [3, 1, 1, 1, 1, 1]; | |
145 static const float[] LINE_DOT_ZERO = [3, 3]; | |
146 static const float[] LINE_DASH_ZERO = [18, 6]; | |
147 static const float[] LINE_DASHDOT_ZERO = [9, 6, 3, 6]; | |
148 static const float[] LINE_DASHDOTDOT_ZERO = [9, 3, 3, 3, 3, 3]; | |
18 | 149 |
19 | 150 this() { |
18 | 151 } |
152 | |
153 /** | |
154 * Constructs a new instance of this class which has been | |
155 * configured to draw on the specified drawable. Sets the | |
156 * foreground color, background color and font in the GC | |
157 * to match those in the drawable. | |
158 * <p> | |
159 * You must dispose the graphics context when it is no longer required. | |
160 * </p> | |
161 * @param drawable the drawable to draw on | |
162 * @exception IllegalArgumentException <ul> | |
163 * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li> | |
164 * <li>ERROR_NULL_ARGUMENT - if there is no current device</li> | |
165 * <li>ERROR_INVALID_ARGUMENT | |
166 * - if the drawable is an image that is not a bitmap or an icon | |
167 * - if the drawable is an image or printer that is already selected | |
168 * into another graphics context</li> | |
169 * </ul> | |
170 * @exception SWTError <ul> | |
171 * <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li> | |
172 * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li> | |
173 * </ul> | |
174 */ | |
19 | 175 public this(Drawable drawable) { |
18 | 176 this(drawable, 0); |
177 } | |
178 | |
179 /** | |
180 * Constructs a new instance of this class which has been | |
181 * configured to draw on the specified drawable. Sets the | |
182 * foreground color, background color and font in the GC | |
183 * to match those in the drawable. | |
184 * <p> | |
185 * You must dispose the graphics context when it is no longer required. | |
186 * </p> | |
187 * | |
188 * @param drawable the drawable to draw on | |
189 * @param style the style of GC to construct | |
190 * | |
191 * @exception IllegalArgumentException <ul> | |
192 * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li> | |
193 * <li>ERROR_NULL_ARGUMENT - if there is no current device</li> | |
194 * <li>ERROR_INVALID_ARGUMENT | |
195 * - if the drawable is an image that is not a bitmap or an icon | |
196 * - if the drawable is an image or printer that is already selected | |
197 * into another graphics context</li> | |
198 * </ul> | |
199 * @exception SWTError <ul> | |
200 * <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li> | |
201 * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li> | |
202 * </ul> | |
203 * | |
204 * @since 2.1.2 | |
205 */ | |
19 | 206 public this(Drawable drawable, int style) { |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
207 if (drawable is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
18 | 208 GCData data = new GCData(); |
209 data.style = checkStyle(style); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
210 auto gdkGC = drawable.internal_new_GC(data); |
18 | 211 Device device = data.device; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
212 if (device is null) device = Device.getDevice(); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
213 if (device is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
18 | 214 this.device = data.device = device; |
215 init(drawable, data, gdkGC); | |
216 if (device.tracking) device.new_Object(this); | |
217 } | |
218 | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
219 static void addCairoString(cairo_t* cairo, char[] str, float x, float y, Font font) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
220 char[] buffer = str.dup; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
221 if (OS.GTK_VERSION >= OS.buildVERSION(2, 8, 0)) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
222 auto layout = OS.pango_cairo_create_layout(cairo); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
223 if (layout is null) SWT.error(SWT.ERROR_NO_HANDLES); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
224 OS.pango_layout_set_text(layout, buffer.ptr, -1); |
18 | 225 OS.pango_layout_set_font_description(layout, font.handle); |
226 Cairo.cairo_move_to(cairo, x, y); | |
227 OS.pango_cairo_layout_path(cairo, layout); | |
228 OS.g_object_unref(layout); | |
229 } else { | |
230 GC.setCairoFont(cairo, font); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
231 cairo_font_extents_t* extents = new cairo_font_extents_t(); |
18 | 232 Cairo.cairo_font_extents(cairo, extents); |
233 double baseline = y + extents.ascent; | |
234 Cairo.cairo_move_to(cairo, x, baseline); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
235 Cairo.cairo_text_path(cairo, buffer.ptr); |
18 | 236 } |
237 } | |
238 | |
239 static int checkStyle (int style) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
240 if ((style & SWT.LEFT_TO_RIGHT) !is 0) style &= ~SWT.RIGHT_TO_LEFT; |
18 | 241 return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT); |
242 } | |
243 | |
244 public static GC gtk_new(Drawable drawable, GCData data) { | |
245 GC gc = new GC(); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
246 auto gdkGC = drawable.internal_new_GC(data); |
18 | 247 gc.device = data.device; |
248 gc.init(drawable, data, gdkGC); | |
249 return gc; | |
250 } | |
251 | |
252 void checkGC (int mask) { | |
253 int state = data.state; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
254 if ((state & mask) is mask) return; |
18 | 255 state = (state ^ mask) & mask; |
256 data.state |= mask; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
257 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
258 if (cairo !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
259 if ((state & (BACKGROUND | FOREGROUND)) !is 0) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
260 GdkColor* color; |
18 | 261 Pattern pattern; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
262 if ((state & FOREGROUND) !is 0) { |
18 | 263 color = data.foreground; |
264 pattern = data.foregroundPattern; | |
265 data.state &= ~BACKGROUND; | |
266 } else { | |
267 color = data.background; | |
268 pattern = data.backgroundPattern; | |
269 data.state &= ~FOREGROUND; | |
270 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
271 if (pattern !is null) { |
18 | 272 Cairo.cairo_set_source(cairo, pattern.handle); |
273 } else { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
274 Cairo.cairo_set_source_rgba(cairo, (color.red & 0xFFFF) / cast(float)0xFFFF, (color.green & 0xFFFF) / cast(float)0xFFFF, (color.blue & 0xFFFF) / cast(float)0xFFFF, data.alpha / cast(float)0xFF); |
18 | 275 } |
276 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
277 if ((state & FONT) !is 0) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
278 if (data.layout !is null) { |
18 | 279 OS.pango_layout_set_font_description(data.layout, data.font); |
280 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
281 if (OS.GTK_VERSION < OS.buildVERSION(2, 8, 0)) { |
18 | 282 setCairoFont(cairo, data.font); |
283 } | |
284 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
285 if ((state & LINE_CAP) !is 0) { |
18 | 286 int cap_style = 0; |
287 switch (data.lineCap) { | |
288 case SWT.CAP_ROUND: cap_style = Cairo.CAIRO_LINE_CAP_ROUND; break; | |
289 case SWT.CAP_FLAT: cap_style = Cairo.CAIRO_LINE_CAP_BUTT; break; | |
290 case SWT.CAP_SQUARE: cap_style = Cairo.CAIRO_LINE_CAP_SQUARE; break; | |
291 } | |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
292 Cairo.cairo_set_line_cap(cairo, cap_style); |
18 | 293 } |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
294 if ((state & LINE_JOIN) !is 0) { |
18 | 295 int join_style = 0; |
296 switch (data.lineJoin) { | |
297 case SWT.JOIN_MITER: join_style = Cairo.CAIRO_LINE_JOIN_MITER; break; | |
298 case SWT.JOIN_ROUND: join_style = Cairo.CAIRO_LINE_JOIN_ROUND; break; | |
299 case SWT.JOIN_BEVEL: join_style = Cairo.CAIRO_LINE_JOIN_BEVEL; break; | |
300 } | |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
301 Cairo.cairo_set_line_join(cairo, join_style); |
18 | 302 } |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
303 if ((state & LINE_WIDTH) !is 0) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
304 Cairo.cairo_set_line_width(cairo, data.lineWidth is 0 ? 1 : data.lineWidth); |
18 | 305 switch (data.lineStyle) { |
306 case SWT.LINE_DOT: | |
307 case SWT.LINE_DASH: | |
308 case SWT.LINE_DASHDOT: | |
309 case SWT.LINE_DASHDOTDOT: | |
310 state |= LINE_STYLE; | |
311 } | |
312 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
313 if ((state & LINE_STYLE) !is 0) { |
18 | 314 float dashesOffset = 0; |
315 float[] dashes = null; | |
316 float width = data.lineWidth; | |
317 switch (data.lineStyle) { | |
318 case SWT.LINE_SOLID: break; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
319 case SWT.LINE_DASH: dashes = width !is 0 ? LINE_DASH : LINE_DASH_ZERO; break; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
320 case SWT.LINE_DOT: dashes = width !is 0 ? LINE_DOT : LINE_DOT_ZERO; break; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
321 case SWT.LINE_DASHDOT: dashes = width !is 0 ? LINE_DASHDOT : LINE_DASHDOT_ZERO; break; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
322 case SWT.LINE_DASHDOTDOT: dashes = width !is 0 ? LINE_DASHDOTDOT : LINE_DASHDOTDOT_ZERO; break; |
18 | 323 case SWT.LINE_CUSTOM: dashes = data.lineDashes; break; |
324 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
325 if (dashes !is null) { |
18 | 326 dashesOffset = data.lineDashesOffset; |
327 double[] cairoDashes = new double[dashes.length]; | |
328 for (int i = 0; i < cairoDashes.length; i++) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
329 cairoDashes[i] = width is 0 || data.lineStyle is SWT.LINE_CUSTOM ? dashes[i] : dashes[i] * width; |
18 | 330 } |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
331 Cairo.cairo_set_dash(cairo, cairoDashes.ptr, cairoDashes.length, dashesOffset); |
18 | 332 } else { |
333 Cairo.cairo_set_dash(cairo, null, 0, 0); | |
334 } | |
335 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
336 if ((state & LINE_MITERLIMIT) !is 0) { |
18 | 337 Cairo.cairo_set_miter_limit(cairo, data.lineMiterLimit); |
338 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
339 if ((state & DRAW_OFFSET) !is 0) { |
18 | 340 data.cairoXoffset = data.cairoYoffset = 0; |
341 double[] matrix = new double[6]; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
342 Cairo.cairo_get_matrix(cairo,cast(cairo_matrix_t*) matrix.ptr); |
18 | 343 double scaling = matrix[0]; |
344 if (scaling < 0) scaling = -scaling; | |
345 double strokeWidth = data.lineWidth * scaling; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
346 if (strokeWidth is 0 || (cast(int)strokeWidth % 2) is 1) { |
18 | 347 data.cairoXoffset = 0.5 / scaling; |
348 } | |
349 scaling = matrix[3]; | |
350 if (scaling < 0) scaling = -scaling; | |
351 strokeWidth = data.lineWidth * scaling; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
352 if (strokeWidth is 0 || (cast(int)strokeWidth % 2) is 1) { |
18 | 353 data.cairoYoffset = 0.5 / scaling; |
354 } | |
355 } | |
356 return; | |
357 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
358 if ((state & (BACKGROUND | FOREGROUND)) !is 0) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
359 GdkColor* foreground; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
360 if ((state & FOREGROUND) !is 0) { |
18 | 361 foreground = data.foreground; |
362 data.state &= ~BACKGROUND; | |
363 } else { | |
364 foreground = data.background; | |
365 data.state &= ~FOREGROUND; | |
366 } | |
367 OS.gdk_gc_set_foreground(handle, foreground); | |
368 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
369 if ((state & BACKGROUND_BG) !is 0) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
370 GdkColor* background = data.background; |
18 | 371 OS.gdk_gc_set_background(handle, background); |
372 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
373 if ((state & FONT) !is 0) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
374 if (data.layout !is null) { |
18 | 375 OS.pango_layout_set_font_description(data.layout, data.font); |
376 } | |
377 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
378 if ((state & (LINE_CAP | LINE_JOIN | LINE_STYLE | LINE_WIDTH)) !is 0) { |
18 | 379 int cap_style = 0; |
380 int join_style = 0; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
381 int width = cast(int)data.lineWidth; |
18 | 382 int line_style = 0; |
383 float[] dashes = null; | |
384 switch (data.lineCap) { | |
385 case SWT.CAP_ROUND: cap_style = OS.GDK_CAP_ROUND; break; | |
386 case SWT.CAP_FLAT: cap_style = OS.GDK_CAP_BUTT; break; | |
387 case SWT.CAP_SQUARE: cap_style = OS.GDK_CAP_PROJECTING; break; | |
388 } | |
389 switch (data.lineJoin) { | |
390 case SWT.JOIN_ROUND: join_style = OS.GDK_JOIN_ROUND; break; | |
391 case SWT.JOIN_MITER: join_style = OS.GDK_JOIN_MITER; break; | |
392 case SWT.JOIN_BEVEL: join_style = OS.GDK_JOIN_BEVEL; break; | |
393 } | |
394 switch (data.lineStyle) { | |
395 case SWT.LINE_SOLID: break; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
396 case SWT.LINE_DASH: dashes = width !is 0 ? LINE_DASH : LINE_DASH_ZERO; break; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
397 case SWT.LINE_DOT: dashes = width !is 0 ? LINE_DOT : LINE_DOT_ZERO; break; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
398 case SWT.LINE_DASHDOT: dashes = width !is 0 ? LINE_DASHDOT : LINE_DASHDOT_ZERO; break; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
399 case SWT.LINE_DASHDOTDOT: dashes = width !is 0 ? LINE_DASHDOTDOT : LINE_DASHDOTDOT_ZERO; break; |
18 | 400 case SWT.LINE_CUSTOM: dashes = data.lineDashes; break; |
401 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
402 if (dashes !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
403 if ((state & LINE_STYLE) !is 0) { |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
404 char[] dash_list = new char[dashes.length]; |
18 | 405 for (int i = 0; i < dash_list.length; i++) { |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
406 dash_list[i] = cast(char)(width is 0 || data.lineStyle is SWT.LINE_CUSTOM ? dashes[i] : dashes[i] * width); |
18 | 407 } |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
408 OS.gdk_gc_set_dashes(handle, 0, dash_list.ptr, dash_list.length); |
18 | 409 } |
410 line_style = OS.GDK_LINE_ON_OFF_DASH; | |
411 } else { | |
412 line_style = OS.GDK_LINE_SOLID; | |
413 } | |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
414 OS.gdk_gc_set_line_attributes(handle, width, line_style, cap_style, join_style); |
18 | 415 } |
416 } | |
417 | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
418 GdkRegion* convertRgn(GdkRegion* rgn, double[] matrix) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
419 auto newRgn = OS.gdk_region_new(); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
420 int nRects; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
421 GdkRectangle* rects; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
422 OS.gdk_region_get_rectangles(rgn, &rects, &nRects); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
423 GdkRectangle* rect = new GdkRectangle(); |
18 | 424 int[] pointArray = new int[8]; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
425 double x, y; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
426 for (int i=0; i<nRects; i++) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
427 *rect = rects[i]; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
428 x = rect.x; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
429 y = rect.y; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
430 Cairo.cairo_matrix_transform_point(cast(cairo_matrix_t*)matrix.ptr, &x, &y); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
431 pointArray[0] = cast(int)x; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
432 pointArray[1] = cast(int)y; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
433 x = rect.x + rect.width; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
434 y = rect.y; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
435 Cairo.cairo_matrix_transform_point(cast(cairo_matrix_t*)matrix.ptr, &x, &y); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
436 pointArray[2] = cast(int)Math.round(x); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
437 pointArray[3] = cast(int)y; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
438 x = rect.x + rect.width; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
439 y = rect.y + rect.height; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
440 Cairo.cairo_matrix_transform_point(cast(cairo_matrix_t*)matrix.ptr, &x, &y); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
441 pointArray[4] = cast(int)Math.round(x); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
442 pointArray[5] = cast(int)Math.round(y); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
443 x = rect.x; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
444 y = rect.y + rect.height; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
445 Cairo.cairo_matrix_transform_point(cast(cairo_matrix_t*)matrix.ptr, &x, &y); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
446 pointArray[6] = cast(int)x; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
447 pointArray[7] = cast(int)Math.round(y); |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
448 auto polyRgn = OS.gdk_region_polygon(cast(GdkPoint*)pointArray.ptr, pointArray.length / 2, OS.GDK_EVEN_ODD_RULE); |
18 | 449 OS.gdk_region_union(newRgn, polyRgn); |
450 OS.gdk_region_destroy(polyRgn); | |
451 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
452 if (rects !is null) OS.g_free(rects); |
18 | 453 return newRgn; |
454 } | |
455 | |
456 /** | |
457 * Copies a rectangular area of the receiver at the specified | |
458 * position into the image, which must be of type <code>SWT.BITMAP</code>. | |
459 * | |
460 * @param image the image to copy into | |
461 * @param x the x coordinate in the receiver of the area to be copied | |
462 * @param y the y coordinate in the receiver of the area to be copied | |
463 * | |
464 * @exception IllegalArgumentException <ul> | |
465 * <li>ERROR_NULL_ARGUMENT - if the image is null</li> | |
466 * <li>ERROR_INVALID_ARGUMENT - if the image is not a bitmap or has been disposed</li> | |
467 * </ul> | |
468 * @exception SWTException <ul> | |
469 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
470 * </ul> | |
471 */ | |
472 public void copyArea(Image image, int x, int y) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
473 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
474 if (image is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
475 if (image.type !is SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
18 | 476 Rectangle rect = image.getBounds(); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
477 auto gdkGC = OS.gdk_gc_new(image.pixmap); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
478 if (gdkGC is null) SWT.error(SWT.ERROR_NO_HANDLES); |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
479 OS.gdk_gc_set_subwindow(gdkGC, OS.GDK_INCLUDE_INFERIORS); |
18 | 480 OS.gdk_draw_drawable(image.pixmap, gdkGC, data.drawable, x, y, 0, 0, rect.width, rect.height); |
481 OS.g_object_unref(gdkGC); | |
482 } | |
483 | |
484 /** | |
485 * Copies a rectangular area of the receiver at the source | |
486 * position onto the receiver at the destination position. | |
487 * | |
488 * @param srcX the x coordinate in the receiver of the area to be copied | |
489 * @param srcY the y coordinate in the receiver of the area to be copied | |
490 * @param width the width of the area to copy | |
491 * @param height the height of the area to copy | |
492 * @param destX the x coordinate in the receiver of the area to copy to | |
493 * @param destY the y coordinate in the receiver of the area to copy to | |
494 * | |
495 * @exception SWTException <ul> | |
496 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
497 * </ul> | |
498 */ | |
499 public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY) { | |
500 copyArea(srcX, srcY, width, height, destX, destY, true); | |
501 } | |
502 /** | |
503 * Copies a rectangular area of the receiver at the source | |
504 * position onto the receiver at the destination position. | |
505 * | |
506 * @param srcX the x coordinate in the receiver of the area to be copied | |
507 * @param srcY the y coordinate in the receiver of the area to be copied | |
508 * @param width the width of the area to copy | |
509 * @param height the height of the area to copy | |
510 * @param destX the x coordinate in the receiver of the area to copy to | |
511 * @param destY the y coordinate in the receiver of the area to copy to | |
512 * @param paint if <code>true</code> paint events will be generated for old and obscured areas | |
513 * | |
514 * @exception SWTException <ul> | |
515 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
516 * </ul> | |
517 * | |
518 * @since 3.1 | |
519 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
520 public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY, bool paint) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
521 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 522 if (width <= 0 || height <= 0) return; |
523 int deltaX = destX - srcX, deltaY = destY - srcY; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
524 if (deltaX is 0 && deltaY is 0) return; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
525 auto drawable = data.drawable; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
526 if (data.image is null && paint) OS.gdk_gc_set_exposures(handle, true); |
18 | 527 OS.gdk_draw_drawable(drawable, handle, drawable, srcX, srcY, destX, destY, width, height); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
528 if (data.image is null & paint) { |
18 | 529 OS.gdk_gc_set_exposures(handle, false); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
530 bool disjoint = (destX + width < srcX) || (srcX + width < destX) || (destY + height < srcY) || (srcY + height < destY); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
531 GdkRectangle* rect = new GdkRectangle (); |
18 | 532 if (disjoint) { |
533 rect.x = srcX; | |
534 rect.y = srcY; | |
535 rect.width = width; | |
536 rect.height = height; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
537 OS.gdk_window_invalidate_rect (cast(GdkWindow*)drawable, rect, false); |
18 | 538 // OS.gdk_window_clear_area_e(drawable, srcX, srcY, width, height); |
539 } else { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
540 if (deltaX !is 0) { |
18 | 541 int newX = destX - deltaX; |
542 if (deltaX < 0) newX = destX + width; | |
543 rect.x = newX; | |
544 rect.y = srcY; | |
545 rect.width = Math.abs(deltaX); | |
546 rect.height = height; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
547 OS.gdk_window_invalidate_rect (cast(GdkWindow*)drawable, rect, false); |
18 | 548 // OS.gdk_window_clear_area_e(drawable, newX, srcY, Math.abs(deltaX), height); |
549 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
550 if (deltaY !is 0) { |
18 | 551 int newY = destY - deltaY; |
552 if (deltaY < 0) newY = destY + height; | |
553 rect.x = srcX; | |
554 rect.y = newY; | |
555 rect.width = width; | |
556 rect.height = Math.abs(deltaY); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
557 OS.gdk_window_invalidate_rect (cast(GdkWindow*)drawable, rect, false); |
18 | 558 // OS.gdk_window_clear_area_e(drawable, srcX, newY, width, Math.abs(deltaY)); |
559 } | |
560 } | |
561 } | |
562 } | |
563 | |
564 void createLayout() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
565 auto context = OS.gdk_pango_context_get(); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
566 if (context is null) SWT.error(SWT.ERROR_NO_HANDLES); |
18 | 567 data.context = context; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
568 auto layout = OS.pango_layout_new(context); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
569 if (layout is null) SWT.error(SWT.ERROR_NO_HANDLES); |
18 | 570 data.layout = layout; |
571 OS.pango_context_set_language(context, OS.gtk_get_default_language()); | |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
572 OS.pango_context_set_base_dir(context, OS.PANGO_DIRECTION_LTR); |
18 | 573 OS.gdk_pango_context_set_colormap(context, OS.gdk_colormap_get_system()); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
574 if (OS.GTK_VERSION >= OS.buildVERSION(2, 4, 0)) { |
18 | 575 OS.pango_layout_set_auto_dir(layout, false); |
576 } | |
577 } | |
578 | |
579 void disposeLayout() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
580 data.str = null; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
581 if (data.context !is null) OS.g_object_unref(data.context); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
582 if (data.layout !is null) OS.g_object_unref(data.layout); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
583 data.layout = null; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
584 data.context = null; |
18 | 585 } |
586 | |
587 /** | |
588 * Disposes of the operating system resources associated with | |
589 * the graphics context. Applications must dispose of all GCs | |
590 * which they allocate. | |
591 * | |
592 * @exception SWTError <ul> | |
593 * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li> | |
594 * </ul> | |
595 */ | |
596 public void dispose() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
597 if (handle is null) return; |
18 | 598 if (data.device.isDisposed()) return; |
599 | |
600 if (data.disposeCairo) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
601 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
602 if (cairo !is null) Cairo.cairo_destroy(cairo); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
603 data.cairo = null; |
18 | 604 } |
605 | |
606 /* Free resources */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
607 auto clipRgn = data.clipRgn; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
608 if (clipRgn !is null) OS.gdk_region_destroy(clipRgn); |
18 | 609 Image image = data.image; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
610 if (image !is null) { |
18 | 611 image.memGC = null; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
612 if (image.transparentPixel !is -1) image.createMask(); |
18 | 613 } |
614 | |
615 disposeLayout(); | |
616 | |
617 /* Dispose the GC */ | |
618 Device device = data.device; | |
619 drawable.internal_dispose_GC(handle, data); | |
620 | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
621 data.drawable = null; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
622 data.clipRgn = null; |
18 | 623 drawable = null; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
624 handle = null; |
18 | 625 data.image = null; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
626 data.str = null; |
18 | 627 if (device.tracking) device.dispose_Object(this); |
628 data.device = null; | |
629 data = null; | |
630 } | |
631 | |
632 /** | |
633 * Draws the outline of a circular or elliptical arc | |
634 * within the specified rectangular area. | |
635 * <p> | |
636 * The resulting arc begins at <code>startAngle</code> and extends | |
637 * for <code>arcAngle</code> degrees, using the current color. | |
638 * Angles are interpreted such that 0 degrees is at the 3 o'clock | |
639 * position. A positive value indicates a counter-clockwise rotation | |
640 * while a negative value indicates a clockwise rotation. | |
641 * </p><p> | |
642 * The center of the arc is the center of the rectangle whose origin | |
643 * is (<code>x</code>, <code>y</code>) and whose size is specified by the | |
644 * <code>width</code> and <code>height</code> arguments. | |
645 * </p><p> | |
646 * The resulting arc covers an area <code>width + 1</code> pixels wide | |
647 * by <code>height + 1</code> pixels tall. | |
648 * </p> | |
649 * | |
650 * @param x the x coordinate of the upper-left corner of the arc to be drawn | |
651 * @param y the y coordinate of the upper-left corner of the arc to be drawn | |
652 * @param width the width of the arc to be drawn | |
653 * @param height the height of the arc to be drawn | |
654 * @param startAngle the beginning angle | |
655 * @param arcAngle the angular extent of the arc, relative to the start angle | |
656 * | |
657 * @exception SWTException <ul> | |
658 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
659 * </ul> | |
660 */ | |
661 public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
662 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 663 checkGC(DRAW); |
664 if (width < 0) { | |
665 x = x + width; | |
666 width = -width; | |
667 } | |
668 if (height < 0) { | |
669 y = y + height; | |
670 height = -height; | |
671 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
672 if (width is 0 || height is 0 || arcAngle is 0) return; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
673 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
674 if (cairo !is null) { |
18 | 675 double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
676 if (width is height) { |
18 | 677 if (arcAngle >= 0) { |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
678 Cairo.cairo_arc_negative(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f, width / 2f, -startAngle * cast(float)Compatibility.PI / 180, -(startAngle + arcAngle) * cast(float)Compatibility.PI / 180); |
18 | 679 } else { |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
680 Cairo.cairo_arc(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f, width / 2f, -startAngle * cast(float)Compatibility.PI / 180, -(startAngle + arcAngle) * cast(float)Compatibility.PI / 180); |
18 | 681 } |
682 } else { | |
683 Cairo.cairo_save(cairo); | |
684 Cairo.cairo_translate(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f); | |
685 Cairo.cairo_scale(cairo, width / 2f, height / 2f); | |
686 if (arcAngle >= 0) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
687 Cairo.cairo_arc_negative(cairo, 0, 0, 1, -startAngle * cast(float)Compatibility.PI / 180, -(startAngle + arcAngle) * cast(float)Compatibility.PI / 180); |
18 | 688 } else { |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
689 Cairo.cairo_arc(cairo, 0, 0, 1, -startAngle * cast(float)Compatibility.PI / 180, -(startAngle + arcAngle) * cast(float)Compatibility.PI / 180); |
18 | 690 } |
691 Cairo.cairo_restore(cairo); | |
692 } | |
693 Cairo.cairo_stroke(cairo); | |
694 return; | |
695 } | |
696 OS.gdk_draw_arc(data.drawable, handle, 0, x, y, width, height, startAngle * 64, arcAngle * 64); | |
697 } | |
698 | |
699 /** | |
700 * Draws a rectangle, based on the specified arguments, which has | |
701 * the appearance of the platform's <em>focus rectangle</em> if the | |
702 * platform supports such a notion, and otherwise draws a simple | |
703 * rectangle in the receiver's foreground color. | |
704 * | |
705 * @param x the x coordinate of the rectangle | |
706 * @param y the y coordinate of the rectangle | |
707 * @param width the width of the rectangle | |
708 * @param height the height of the rectangle | |
709 * | |
710 * @exception SWTException <ul> | |
711 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
712 * </ul> | |
713 * | |
714 * @see #drawRectangle(int, int, int, int) | |
715 */ | |
716 public void drawFocus(int x, int y, int width, int height) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
717 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 718 /* |
719 * Feature in GTK. The function gtk_widget_get_default_style() | |
720 * can't be used here because gtk_paint_focus() uses GCs, which | |
721 * are not valid in the default style. The fix is to use a style | |
722 * from a widget. | |
723 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
724 auto style = OS.gtk_widget_get_style(data.device.shellHandle); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
725 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
726 if (cairo !is null) { |
18 | 727 checkGC(FOREGROUND); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
728 int lineWidth; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
729 OS.gtk_widget_style_get1(data.device.shellHandle, OS.focus_line_width.ptr, &lineWidth ); |
18 | 730 Cairo.cairo_save(cairo); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
731 Cairo.cairo_set_line_width(cairo, lineWidth); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
732 double[] dashes = [1, 1]; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
733 double dash_offset = -lineWidth / 2f; |
18 | 734 while (dash_offset < 0) dash_offset += 2; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
735 Cairo.cairo_set_dash(cairo, dashes.ptr, dashes.length, dash_offset); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
736 Cairo.cairo_rectangle(cairo, x + lineWidth / 2f, y + lineWidth / 2f, width, height); |
18 | 737 Cairo.cairo_stroke(cairo); |
738 Cairo.cairo_restore(cairo); | |
739 return; | |
740 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
741 char dummy; |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
742 OS.gtk_paint_focus(style,cast(GdkWindow *) data.drawable, OS.GTK_STATE_NORMAL, null, data.device.shellHandle, &dummy, x, y, width, height); |
18 | 743 } |
744 | |
745 /** | |
746 * Draws the given image in the receiver at the specified | |
747 * coordinates. | |
748 * | |
749 * @param image the image to draw | |
750 * @param x the x coordinate of where to draw | |
751 * @param y the y coordinate of where to draw | |
752 * | |
753 * @exception IllegalArgumentException <ul> | |
754 * <li>ERROR_NULL_ARGUMENT - if the image is null</li> | |
755 * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> | |
756 * <li>ERROR_INVALID_ARGUMENT - if the given coordinates are outside the bounds of the image</li> | |
757 * @exception SWTException <ul> | |
758 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
759 * </ul> | |
760 * @exception SWTError <ul> | |
761 * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li> | |
762 * </ul> | |
763 */ | |
764 public void drawImage(Image image, int x, int y) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
765 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
766 if (image is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
18 | 767 if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
768 drawImage(image, 0, 0, -1, -1, x, y, -1, -1, true); | |
769 } | |
770 | |
771 /** | |
772 * Copies a rectangular area from the source image into a (potentially | |
773 * different sized) rectangular area in the receiver. If the source | |
774 * and destination areas are of differing sizes, then the source | |
775 * area will be stretched or shrunk to fit the destination area | |
776 * as it is copied. The copy fails if any part of the source rectangle | |
777 * lies outside the bounds of the source image, or if any of the width | |
778 * or height arguments are negative. | |
779 * | |
780 * @param image the source image | |
781 * @param srcX the x coordinate in the source image to copy from | |
782 * @param srcY the y coordinate in the source image to copy from | |
783 * @param srcWidth the width in pixels to copy from the source | |
784 * @param srcHeight the height in pixels to copy from the source | |
785 * @param destX the x coordinate in the destination to copy to | |
786 * @param destY the y coordinate in the destination to copy to | |
787 * @param destWidth the width in pixels of the destination rectangle | |
788 * @param destHeight the height in pixels of the destination rectangle | |
789 * | |
790 * @exception IllegalArgumentException <ul> | |
791 * <li>ERROR_NULL_ARGUMENT - if the image is null</li> | |
792 * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> | |
793 * <li>ERROR_INVALID_ARGUMENT - if any of the width or height arguments are negative. | |
794 * <li>ERROR_INVALID_ARGUMENT - if the source rectangle is not contained within the bounds of the source image</li> | |
795 * </ul> | |
796 * @exception SWTException <ul> | |
797 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
798 * </ul> | |
799 * @exception SWTError <ul> | |
800 * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li> | |
801 * </ul> | |
802 */ | |
803 public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
804 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
805 if (srcWidth is 0 || srcHeight is 0 || destWidth is 0 || destHeight is 0) return; |
18 | 806 if (srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 || destWidth < 0 || destHeight < 0) { |
807 SWT.error (SWT.ERROR_INVALID_ARGUMENT); | |
808 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
809 if (image is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
18 | 810 if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
811 drawImage(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false); | |
812 } | |
813 | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
814 void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, bool simple) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
815 int width; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
816 int height; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
817 OS.gdk_drawable_get_size(srcImage.pixmap, &width, &height); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
818 int imgWidth = width; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
819 int imgHeight = height; |
18 | 820 if (simple) { |
821 srcWidth = destWidth = imgWidth; | |
822 srcHeight = destHeight = imgHeight; | |
823 } else { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
824 simple = srcX is 0 && srcY is 0 && |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
825 srcWidth is destWidth && destWidth is imgWidth && |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
826 srcHeight is destHeight && destHeight is imgHeight; |
18 | 827 if (srcX + srcWidth > imgWidth || srcY + srcHeight > imgHeight) { |
828 SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
829 } | |
830 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
831 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
832 if (cairo !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
833 if (data.alpha !is 0) { |
18 | 834 srcImage.createSurface(); |
835 Cairo.cairo_save(cairo); | |
836 Cairo.cairo_rectangle(cairo, destX , destY, destWidth, destHeight); | |
837 Cairo.cairo_clip(cairo); | |
838 Cairo.cairo_translate(cairo, destX - srcX, destY - srcY); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
839 if (srcWidth !is destWidth || srcHeight !is destHeight) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
840 Cairo.cairo_scale(cairo, destWidth / cast(float)srcWidth, destHeight / cast(float)srcHeight); |
18 | 841 } |
842 int filter = Cairo.CAIRO_FILTER_GOOD; | |
843 switch (data.interpolation) { | |
844 case SWT.DEFAULT: filter = Cairo.CAIRO_FILTER_GOOD; break; | |
845 case SWT.NONE: filter = Cairo.CAIRO_FILTER_NEAREST; break; | |
846 case SWT.LOW: filter = Cairo.CAIRO_FILTER_FAST; break; | |
847 case SWT.HIGH: filter = Cairo.CAIRO_FILTER_BEST; break; | |
848 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
849 auto pattern = Cairo.cairo_pattern_create_for_surface(srcImage.surface); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
850 if (pattern is null) SWT.error(SWT.ERROR_NO_HANDLES); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
851 if (srcWidth !is destWidth || srcHeight !is destHeight) { |
18 | 852 /* |
853 * Bug in Cairo. When drawing the image streched with an interpolation | |
854 * alghorithm, the edges of the image are faded. This is not a bug, but | |
855 * it is not desired. To avoid the faded edges, it should be possible to | |
856 * use cairo_pattern_set_extend() to set the pattern extend to either | |
857 * CAIRO_EXTEND_REFLECT or CAIRO_EXTEND_PAD, but these are not implemented | |
858 * in some versions of cairo (1.2.x) and have bugs in others (in 1.4.2 it | |
859 * draws with black edges). The fix is to implement CAIRO_EXTEND_REFLECT | |
860 * by creating an image that is 3 times bigger than the original, drawing | |
861 * the original image in every quadrant (with an appropriate transform) and | |
862 * use this image as the pattern. | |
863 * | |
864 * NOTE: For some reaons, it is necessary to use CAIRO_EXTEND_PAD with | |
865 * the image that was created or the edges are still faded. | |
866 */ | |
867 if (Cairo.cairo_version () >= Cairo.CAIRO_VERSION_ENCODE(1, 4, 0)) { | |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
868 auto surface = Cairo.cairo_image_surface_create(Cairo.CAIRO_FORMAT_ARGB32, imgWidth * 3, imgHeight * 3); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
869 auto cr = Cairo.cairo_create(surface); |
18 | 870 Cairo.cairo_set_source_surface(cr, srcImage.surface, imgWidth, imgHeight); |
871 Cairo.cairo_paint(cr); | |
872 Cairo.cairo_scale(cr, -1, -1); | |
873 Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth, -imgHeight); | |
874 Cairo.cairo_paint(cr); | |
875 Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth * 3, -imgHeight); | |
876 Cairo.cairo_paint(cr); | |
877 Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth, -imgHeight * 3); | |
878 Cairo.cairo_paint(cr); | |
879 Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth * 3, -imgHeight * 3); | |
880 Cairo.cairo_paint(cr); | |
881 Cairo.cairo_scale(cr, 1, -1); | |
882 Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth, imgHeight); | |
883 Cairo.cairo_paint(cr); | |
884 Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth * 3, imgHeight); | |
885 Cairo.cairo_paint(cr); | |
886 Cairo.cairo_scale(cr, -1, -1); | |
887 Cairo.cairo_set_source_surface(cr, srcImage.surface, imgWidth, -imgHeight); | |
888 Cairo.cairo_paint(cr); | |
889 Cairo.cairo_set_source_surface(cr, srcImage.surface, imgWidth, -imgHeight * 3); | |
890 Cairo.cairo_paint(cr); | |
891 Cairo.cairo_destroy(cr); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
892 auto newPattern = Cairo.cairo_pattern_create_for_surface(surface); |
18 | 893 Cairo.cairo_surface_destroy(surface); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
894 if (newPattern is null) SWT.error(SWT.ERROR_NO_HANDLES); |
18 | 895 Cairo.cairo_pattern_destroy(pattern); |
896 pattern = newPattern; | |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
897 Cairo.cairo_pattern_set_extend(pattern, Cairo.CAIRO_EXTEND_PAD); |
18 | 898 double[] matrix = new double[6]; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
899 Cairo.cairo_matrix_init_translate(cast(cairo_matrix_t*)matrix.ptr, imgWidth, imgHeight); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
900 Cairo.cairo_pattern_set_matrix(pattern, cast(cairo_matrix_t*)matrix.ptr); |
18 | 901 } |
902 // Cairo.cairo_pattern_set_extend(pattern, Cairo.CAIRO_EXTEND_REFLECT); | |
903 } | |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
904 Cairo.cairo_pattern_set_filter(pattern, filter); |
18 | 905 Cairo.cairo_set_source(cairo, pattern); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
906 if (data.alpha !is 0xFF) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
907 Cairo.cairo_paint_with_alpha(cairo, data.alpha / cast(float)0xFF); |
18 | 908 } else { |
909 Cairo.cairo_paint(cairo); | |
910 } | |
911 Cairo.cairo_restore(cairo); | |
912 Cairo.cairo_pattern_destroy(pattern); | |
913 } | |
914 return; | |
915 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
916 if (srcImage.alpha !is -1 || srcImage.alphaData !is null) { |
18 | 917 drawImageAlpha(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
918 } else if (srcImage.transparentPixel !is -1 || srcImage.mask !is null) { |
18 | 919 drawImageMask(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight); |
920 } else { | |
921 drawImage(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight); | |
922 } | |
923 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
924 void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, bool simple, int imgWidth, int imgHeight) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
925 if (srcWidth is destWidth && srcHeight is destHeight) { |
18 | 926 OS.gdk_draw_drawable(data.drawable, handle, srcImage.pixmap, srcX, srcY, destX, destY, destWidth, destHeight); |
927 } else { | |
928 if (device.useXRender) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
929 drawImageXRender(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, null, -1); |
18 | 930 return; |
931 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
932 auto pixbuf = scale(srcImage.pixmap, srcX, srcY, srcWidth, srcHeight, destWidth, destHeight); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
933 if (pixbuf !is null) { |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
934 OS.gdk_pixbuf_render_to_drawable(pixbuf, data.drawable, handle, 0, 0, destX, destY, destWidth, destHeight, OS.GDK_RGB_DITHER_NORMAL, 0, 0); |
18 | 935 OS.g_object_unref(pixbuf); |
936 } | |
937 } | |
938 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
939 void drawImageAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, bool simple, int imgWidth, int imgHeight) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
940 if (srcImage.alpha is 0) return; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
941 if (srcImage.alpha is 255) { |
18 | 942 drawImage(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight); |
943 return; | |
944 } | |
945 if (device.useXRender) { | |
946 drawImageXRender(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, srcImage.mask, OS.PictStandardA8); | |
947 return; | |
948 } | |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
949 auto pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, true, 8, srcWidth, srcHeight); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
950 if (pixbuf is null) return; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
951 auto colormap = OS.gdk_colormap_get_system(); |
18 | 952 OS.gdk_pixbuf_get_from_drawable(pixbuf, srcImage.pixmap, colormap, srcX, srcY, 0, 0, srcWidth, srcHeight); |
953 int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
954 auto pixels = OS.gdk_pixbuf_get_pixels(pixbuf); |
18 | 955 byte[] line = new byte[stride]; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
956 byte alpha = cast(byte)srcImage.alpha; |
18 | 957 byte[] alphaData = srcImage.alphaData; |
958 for (int y=0; y<srcHeight; y++) { | |
959 int alphaIndex = (y + srcY) * imgWidth + srcX; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
960 memmove(line.ptr, pixels + (y * stride), stride); |
18 | 961 for (int x=3; x<stride; x+=4) { |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
962 line[x] = alphaData is null ? alpha : alphaData[alphaIndex++]; |
18 | 963 } |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
964 memmove(pixels + (y * stride), line.ptr, stride); |
18 | 965 } |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
966 if (srcWidth !is destWidth || srcHeight !is destHeight) { |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
967 auto scaledPixbuf = OS.gdk_pixbuf_scale_simple(pixbuf, destWidth, destHeight, OS.GDK_INTERP_BILINEAR); |
18 | 968 OS.g_object_unref(pixbuf); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
969 if (scaledPixbuf is null) return; |
18 | 970 pixbuf = scaledPixbuf; |
971 } | |
972 /* | |
973 * Feature in GTK. gdk_draw_pixbuf was introduced in GTK+ 2.2.0 and | |
974 * supports clipping. | |
975 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
976 if (OS.GTK_VERSION >= OS.buildVERSION (2, 2, 0)) { |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
977 OS.gdk_draw_pixbuf(data.drawable, handle, pixbuf, 0, 0, destX, destY, destWidth, destHeight, OS.GDK_RGB_DITHER_NORMAL, 0, 0); |
18 | 978 } else { |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
979 OS.gdk_pixbuf_render_to_drawable_alpha(pixbuf, data.drawable, 0, 0, destX, destY, destWidth, destHeight, OS.GDK_PIXBUF_ALPHA_BILEVEL, 128, OS.GDK_RGB_DITHER_NORMAL, 0, 0); |
18 | 980 } |
981 OS.g_object_unref(pixbuf); | |
982 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
983 void drawImageMask(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, bool simple, int imgWidth, int imgHeight) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
984 auto drawable = data.drawable; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
985 auto colorPixmap = srcImage.pixmap; |
18 | 986 /* Generate the mask if necessary. */ |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
987 if (srcImage.transparentPixel !is -1) srcImage.createMask(); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
988 auto maskPixmap = srcImage.mask; |
18 | 989 |
990 if (device.useXRender) { | |
991 drawImageXRender(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, maskPixmap, OS.PictStandardA1); | |
992 } else { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
993 if (srcWidth !is destWidth || srcHeight !is destHeight) { |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
994 auto pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, true, 8, srcWidth, srcHeight); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
995 if (pixbuf !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
996 auto colormap = OS.gdk_colormap_get_system(); |
18 | 997 OS.gdk_pixbuf_get_from_drawable(pixbuf, colorPixmap, colormap, srcX, srcY, 0, 0, srcWidth, srcHeight); |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
998 auto maskPixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, srcWidth, srcHeight); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
999 if (maskPixbuf !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1000 OS.gdk_pixbuf_get_from_drawable(maskPixbuf, maskPixmap, null, srcX, srcY, 0, 0, srcWidth, srcHeight); |
18 | 1001 int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1002 auto pixels = OS.gdk_pixbuf_get_pixels(pixbuf); |
18 | 1003 byte[] line = new byte[stride]; |
1004 int maskStride = OS.gdk_pixbuf_get_rowstride(maskPixbuf); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1005 auto maskPixels = OS.gdk_pixbuf_get_pixels(maskPixbuf); |
18 | 1006 byte[] maskLine = new byte[maskStride]; |
1007 for (int y=0; y<srcHeight; y++) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1008 auto offset = pixels + (y * stride); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1009 memmove(line.ptr, offset, stride); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1010 auto maskOffset = maskPixels + (y * maskStride); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1011 memmove(maskLine.ptr, maskOffset, maskStride); |
18 | 1012 for (int x=0; x<srcWidth; x++) { |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1013 if (maskLine[x * 3] is 0) { |
18 | 1014 line[x*4+3] = 0; |
1015 } | |
1016 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1017 memmove(offset, line.ptr, stride); |
18 | 1018 } |
1019 OS.g_object_unref(maskPixbuf); | |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
1020 auto scaledPixbuf = OS.gdk_pixbuf_scale_simple(pixbuf, destWidth, destHeight, OS.GDK_INTERP_BILINEAR); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1021 if (scaledPixbuf !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1022 GdkPixmap * colorBuffer; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1023 GdkBitmap * maskBuffer; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1024 OS.gdk_pixbuf_render_pixmap_and_mask(scaledPixbuf, &colorBuffer, &maskBuffer, 128); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1025 colorPixmap = cast(GdkDrawable *)colorBuffer; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1026 maskPixmap = cast(GdkDrawable *)maskBuffer; |
18 | 1027 OS.g_object_unref(scaledPixbuf); |
1028 } | |
1029 } | |
1030 OS.g_object_unref(pixbuf); | |
1031 } | |
1032 srcX = 0; | |
1033 srcY = 0; | |
1034 srcWidth = destWidth; | |
1035 srcHeight = destHeight; | |
1036 } | |
1037 | |
1038 /* Merge clipping with mask if necessary */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1039 if (data.clipRgn !is null) { |
18 | 1040 int newWidth = srcX + srcWidth; |
1041 int newHeight = srcY + srcHeight; | |
1042 int bytesPerLine = (newWidth + 7) / 8; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1043 char[] maskData = new char[bytesPerLine * newHeight]; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1044 auto mask = cast(GdkDrawable *) OS.gdk_bitmap_create_from_data(null, maskData.ptr, newWidth, newHeight); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1045 if (mask !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1046 auto gc = OS.gdk_gc_new(mask); |
18 | 1047 OS.gdk_region_offset(data.clipRgn, -destX + srcX, -destY + srcY); |
1048 OS.gdk_gc_set_clip_region(gc, data.clipRgn); | |
1049 OS.gdk_region_offset(data.clipRgn, destX - srcX, destY - srcY); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1050 GdkColor* color = new GdkColor(); |
18 | 1051 color.pixel = 1; |
1052 OS.gdk_gc_set_foreground(gc, color); | |
1053 OS.gdk_draw_rectangle(mask, gc, 1, 0, 0, newWidth, newHeight); | |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
1054 OS.gdk_gc_set_function(gc, OS.GDK_AND); |
18 | 1055 OS.gdk_draw_drawable(mask, gc, maskPixmap, 0, 0, 0, 0, newWidth, newHeight); |
1056 OS.g_object_unref(gc); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1057 if (maskPixmap !is null && srcImage.mask !is maskPixmap) OS.g_object_unref(maskPixmap); |
18 | 1058 maskPixmap = mask; |
1059 } | |
1060 } | |
1061 | |
1062 /* Blit cliping the mask */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1063 GdkGCValues* values = new GdkGCValues(); |
18 | 1064 OS.gdk_gc_get_values(handle, values); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1065 OS.gdk_gc_set_clip_mask(handle, cast(GdkBitmap *)maskPixmap); |
18 | 1066 OS.gdk_gc_set_clip_origin(handle, destX - srcX, destY - srcY); |
1067 OS.gdk_draw_drawable(drawable, handle, colorPixmap, srcX, srcY, destX, destY, srcWidth, srcHeight); | |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
1068 OS.gdk_gc_set_values(handle, values, OS.GDK_GC_CLIP_MASK | OS.GDK_GC_CLIP_X_ORIGIN | OS.GDK_GC_CLIP_Y_ORIGIN); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1069 if (data.clipRgn !is null) OS.gdk_gc_set_clip_region(handle, data.clipRgn); |
18 | 1070 } |
1071 | |
1072 /* Destroy scaled pixmaps */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1073 if (colorPixmap !is null && srcImage.pixmap !is colorPixmap) OS.g_object_unref(colorPixmap); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1074 if (maskPixmap !is null && srcImage.mask !is maskPixmap) OS.g_object_unref(maskPixmap); |
18 | 1075 /* Destroy the image mask if the there is a GC created on the image */ |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1076 if (srcImage.transparentPixel !is -1 && srcImage.memGC !is null) srcImage.destroyMask(); |
18 | 1077 } |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1078 void drawImageXRender(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, bool simple, int imgWidth, int imgHeight, GdkDrawable* maskPixmap, int maskType) { |
18 | 1079 int translateX = 0, translateY = 0; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1080 auto drawable = data.drawable; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1081 if (data.image is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1082 int x, y; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1083 GdkDrawable* real_drawable; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1084 OS.gdk_window_get_internal_paint_info(cast(GdkWindow*)drawable, &real_drawable, &x, &y); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1085 drawable = real_drawable; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1086 translateX = -x; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1087 translateY = -y; |
18 | 1088 } |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1089 auto xDisplay = OS.GDK_DISPLAY(); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1090 int maskPict = 0; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1091 if (maskPixmap !is null) { |
18 | 1092 int attribCount = 0; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1093 XRenderPictureAttributes* attrib; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1094 if (srcImage.alpha !is -1) { |
18 | 1095 attribCount = 1; |
1096 attrib = new XRenderPictureAttributes(); | |
1097 attrib.repeat = true; | |
1098 } | |
28 | 1099 maskPict = OS.XRenderCreatePicture(cast(void*)xDisplay, OS.gdk_x11_drawable_get_xid(maskPixmap), OS.XRenderFindStandardFormat(cast(void*)xDisplay, maskType), attribCount, attrib); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1100 if (maskPict is 0) SWT.error(SWT.ERROR_NO_HANDLES); |
18 | 1101 } |
28 | 1102 auto format = OS.XRenderFindVisualFormat(cast(void*)xDisplay, OS.gdk_x11_visual_get_xvisual(OS.gdk_visual_get_system())); |
1103 auto destPict = OS.XRenderCreatePicture(cast(void*)xDisplay, OS.gdk_x11_drawable_get_xid(drawable), format, 0, null); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1104 if (destPict is 0) SWT.error(SWT.ERROR_NO_HANDLES); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1105 int srcPict = OS.XRenderCreatePicture(xDisplay, OS.gdk_x11_drawable_get_xid(srcImage.pixmap), format, 0, null); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1106 if (srcPict is 0) SWT.error(SWT.ERROR_NO_HANDLES); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1107 if (srcWidth !is destWidth || srcHeight !is destHeight) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1108 int[] transform = [cast(int)((cast(float)srcWidth / destWidth) * 65536), 0, 0, 0, cast(int)((cast(float)srcHeight / destHeight) * 65536), 0, 0, 0, 65536]; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1109 OS.XRenderSetPictureTransform(xDisplay, srcPict, cast(XTransform*)transform.ptr); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1110 if (maskPict !is 0) OS.XRenderSetPictureTransform(xDisplay, maskPict, cast(XTransform*)transform.ptr); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1111 srcX *= destWidth / cast(float)srcWidth; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1112 srcY *= destHeight / cast(float)srcHeight; |
18 | 1113 } |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1114 auto clipping = data.clipRgn; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1115 if (data.damageRgn !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1116 if (clipping is null) { |
18 | 1117 clipping = data.damageRgn; |
1118 } else { | |
1119 clipping = OS.gdk_region_new(); | |
1120 OS.gdk_region_union(clipping, data.clipRgn); | |
1121 OS.gdk_region_intersect(clipping, data.damageRgn); | |
1122 } | |
1123 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1124 if (clipping !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1125 int nRects; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1126 GdkRectangle* rects; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1127 OS.gdk_region_get_rectangles(clipping, &rects, &nRects); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1128 GdkRectangle* rect = new GdkRectangle(); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1129 short[] xRects = new short[nRects * 4]; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1130 for (int i=0, j=0; i<nRects; i++, j+=4) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1131 *rect = rects[i]; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1132 xRects[j] = cast(short)rect.x; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1133 xRects[j+1] = cast(short)rect.y; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1134 xRects[j+2] = cast(short)rect.width; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1135 xRects[j+3] = cast(short)rect.height; |
18 | 1136 } |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1137 OS.XRenderSetPictureClipRectangles(xDisplay, destPict, translateX, translateY,cast(XRectangle*) xRects.ptr, nRects); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1138 if (clipping !is data.clipRgn && clipping !is data.damageRgn) { |
18 | 1139 OS.gdk_region_destroy(clipping); |
1140 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1141 if (rects !is null) OS.g_free(rects); |
18 | 1142 } |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1143 OS.XRenderComposite(xDisplay, maskPict !is 0 ? OS.PictOpOver : OS.PictOpSrc, srcPict, maskPict, destPict, srcX, srcY, srcX, srcY, destX + translateX, destY + translateY, destWidth, destHeight); |
18 | 1144 OS.XRenderFreePicture(xDisplay, destPict); |
1145 OS.XRenderFreePicture(xDisplay, srcPict); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1146 if (maskPict !is 0) OS.XRenderFreePicture(xDisplay, maskPict); |
18 | 1147 } |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1148 |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1149 GdkPixbuf* scale(GdkDrawable* src, int srcX, int srcY, int srcWidth, int srcHeight, int destWidth, int destHeight) { |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
1150 auto pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, srcWidth, srcHeight); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1151 if (pixbuf is null) return null; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1152 auto colormap = OS.gdk_colormap_get_system(); |
18 | 1153 OS.gdk_pixbuf_get_from_drawable(pixbuf, src, colormap, srcX, srcY, 0, 0, srcWidth, srcHeight); |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
1154 auto scaledPixbuf = OS.gdk_pixbuf_scale_simple(pixbuf, destWidth, destHeight, OS.GDK_INTERP_BILINEAR); |
18 | 1155 OS.g_object_unref(pixbuf); |
1156 return scaledPixbuf; | |
1157 } | |
1158 | |
1159 /** | |
1160 * Draws a line, using the foreground color, between the points | |
1161 * (<code>x1</code>, <code>y1</code>) and (<code>x2</code>, <code>y2</code>). | |
1162 * | |
1163 * @param x1 the first point's x coordinate | |
1164 * @param y1 the first point's y coordinate | |
1165 * @param x2 the second point's x coordinate | |
1166 * @param y2 the second point's y coordinate | |
1167 * | |
1168 * @exception SWTException <ul> | |
1169 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1170 * </ul> | |
1171 */ | |
1172 public void drawLine(int x1, int y1, int x2, int y2) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1173 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 1174 checkGC(DRAW); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1175 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1176 if (cairo !is null) { |
18 | 1177 double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset; |
1178 Cairo.cairo_move_to(cairo, x1 + xOffset, y1 + yOffset); | |
1179 Cairo.cairo_line_to(cairo, x2 + xOffset, y2 + yOffset); | |
1180 Cairo.cairo_stroke(cairo); | |
1181 return; | |
1182 } | |
1183 OS.gdk_draw_line (data.drawable, handle, x1, y1, x2, y2); | |
1184 } | |
1185 | |
1186 /** | |
1187 * Draws the outline of an oval, using the foreground color, | |
1188 * within the specified rectangular area. | |
1189 * <p> | |
1190 * The result is a circle or ellipse that fits within the | |
1191 * rectangle specified by the <code>x</code>, <code>y</code>, | |
1192 * <code>width</code>, and <code>height</code> arguments. | |
1193 * </p><p> | |
1194 * The oval covers an area that is <code>width + 1</code> | |
1195 * pixels wide and <code>height + 1</code> pixels tall. | |
1196 * </p> | |
1197 * | |
1198 * @param x the x coordinate of the upper left corner of the oval to be drawn | |
1199 * @param y the y coordinate of the upper left corner of the oval to be drawn | |
1200 * @param width the width of the oval to be drawn | |
1201 * @param height the height of the oval to be drawn | |
1202 * | |
1203 * @exception SWTException <ul> | |
1204 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1205 * </ul> | |
1206 */ | |
1207 public void drawOval(int x, int y, int width, int height) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1208 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 1209 checkGC(DRAW); |
1210 if (width < 0) { | |
1211 x = x + width; | |
1212 width = -width; | |
1213 } | |
1214 if (height < 0) { | |
1215 y = y + height; | |
1216 height = -height; | |
1217 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1218 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1219 if (cairo !is null) { |
18 | 1220 double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1221 if (width is height) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1222 Cairo.cairo_arc_negative(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f, width / 2f, 0, -2 * cast(float)Compatibility.PI); |
18 | 1223 } else { |
1224 Cairo.cairo_save(cairo); | |
1225 Cairo.cairo_translate(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f); | |
1226 Cairo.cairo_scale(cairo, width / 2f, height / 2f); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1227 Cairo.cairo_arc_negative(cairo, 0, 0, 1, 0, -2 * cast(float)Compatibility.PI); |
18 | 1228 Cairo.cairo_restore(cairo); |
1229 } | |
1230 Cairo.cairo_stroke(cairo); | |
1231 return; | |
1232 } | |
1233 OS.gdk_draw_arc(data.drawable, handle, 0, x, y, width, height, 0, 23040); | |
1234 } | |
1235 | |
1236 /** | |
1237 * Draws the path described by the parameter. | |
1238 * <p> | |
1239 * This operation requires the operating system's advanced | |
1240 * graphics subsystem which may not be available on some | |
1241 * platforms. | |
1242 * </p> | |
1243 * | |
1244 * @param path the path to draw | |
1245 * | |
1246 * @exception IllegalArgumentException <ul> | |
1247 * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li> | |
1248 * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li> | |
1249 * </ul> | |
1250 * @exception SWTException <ul> | |
1251 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1252 * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> | |
1253 * </ul> | |
1254 * | |
1255 * @see Path | |
1256 * | |
1257 * @since 3.1 | |
1258 */ | |
1259 public void drawPath(Path path) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1260 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1261 if (path is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1262 if (path.handle is null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
18 | 1263 initCairo(); |
1264 checkGC(DRAW); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1265 auto cairo = data.cairo; |
18 | 1266 Cairo.cairo_save(cairo); |
1267 double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset; | |
1268 Cairo.cairo_translate(cairo, xOffset, yOffset); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1269 auto copy = Cairo.cairo_copy_path(path.handle); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1270 if (copy is null) SWT.error(SWT.ERROR_NO_HANDLES); |
18 | 1271 Cairo.cairo_append_path(cairo, copy); |
1272 Cairo.cairo_path_destroy(copy); | |
1273 Cairo.cairo_stroke(cairo); | |
1274 Cairo.cairo_restore(cairo); | |
1275 } | |
1276 | |
1277 /** | |
1278 * Draws a pixel, using the foreground color, at the specified | |
1279 * point (<code>x</code>, <code>y</code>). | |
1280 * <p> | |
1281 * Note that the receiver's line attributes do not affect this | |
1282 * operation. | |
1283 * </p> | |
1284 * | |
1285 * @param x the point's x coordinate | |
1286 * @param y the point's y coordinate | |
1287 * | |
1288 * @exception SWTException <ul> | |
1289 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1290 * </ul> | |
1291 * | |
1292 * @since 3.0 | |
1293 */ | |
1294 public void drawPoint (int x, int y) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1295 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 1296 checkGC(DRAW); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1297 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1298 if (cairo !is null) { |
18 | 1299 Cairo.cairo_rectangle(cairo, x, y, 1, 1); |
1300 Cairo.cairo_fill(cairo); | |
1301 return; | |
1302 } | |
1303 OS.gdk_draw_point(data.drawable, handle, x, y); | |
1304 } | |
1305 | |
1306 /** | |
1307 * Draws the closed polygon which is defined by the specified array | |
1308 * of integer coordinates, using the receiver's foreground color. The array | |
1309 * contains alternating x and y values which are considered to represent | |
1310 * points which are the vertices of the polygon. Lines are drawn between | |
1311 * each consecutive pair, and between the first pair and last pair in the | |
1312 * array. | |
1313 * | |
1314 * @param pointArray an array of alternating x and y values which are the vertices of the polygon | |
1315 * | |
1316 * @exception IllegalArgumentException <ul> | |
1317 * <li>ERROR_NULL_ARGUMENT if pointArray is null</li> | |
1318 * </ul> | |
1319 * @exception SWTException <ul> | |
1320 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1321 * </ul> | |
1322 */ | |
1323 public void drawPolygon(int[] pointArray) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1324 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1325 if (pointArray is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
18 | 1326 checkGC(DRAW); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1327 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1328 if (cairo !is null) { |
18 | 1329 drawPolyline(cairo, pointArray, true); |
1330 Cairo.cairo_stroke(cairo); | |
1331 return; | |
1332 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1333 OS.gdk_draw_polygon(data.drawable, handle, 0, cast(GdkPoint*)pointArray.ptr, pointArray.length / 2); |
18 | 1334 } |
1335 | |
1336 /** | |
1337 * Draws the polyline which is defined by the specified array | |
1338 * of integer coordinates, using the receiver's foreground color. The array | |
1339 * contains alternating x and y values which are considered to represent | |
1340 * points which are the corners of the polyline. Lines are drawn between | |
1341 * each consecutive pair, but not between the first pair and last pair in | |
1342 * the array. | |
1343 * | |
1344 * @param pointArray an array of alternating x and y values which are the corners of the polyline | |
1345 * | |
1346 * @exception IllegalArgumentException <ul> | |
1347 * <li>ERROR_NULL_ARGUMENT - if the point array is null</li> | |
1348 * </ul> | |
1349 * @exception SWTException <ul> | |
1350 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1351 * </ul> | |
1352 */ | |
1353 public void drawPolyline(int[] pointArray) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1354 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1355 if (pointArray is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
18 | 1356 checkGC(DRAW); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1357 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1358 if (cairo !is null) { |
18 | 1359 drawPolyline(cairo, pointArray, false); |
1360 Cairo.cairo_stroke(cairo); | |
1361 return; | |
1362 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1363 OS.gdk_draw_lines(data.drawable, handle, cast(GdkPoint*)pointArray.ptr, pointArray.length / 2); |
18 | 1364 } |
1365 | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1366 void drawPolyline(cairo_t* cairo, int[] pointArray, bool close) { |
18 | 1367 int count = pointArray.length / 2; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1368 if (count is 0) return; |
18 | 1369 double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset; |
1370 Cairo.cairo_move_to(cairo, pointArray[0] + xOffset, pointArray[1] + yOffset); | |
1371 for (int i = 1, j=2; i < count; i++, j += 2) { | |
1372 Cairo.cairo_line_to(cairo, pointArray[j] + xOffset, pointArray[j + 1] + yOffset); | |
1373 } | |
1374 if (close) Cairo.cairo_close_path(cairo); | |
1375 } | |
1376 | |
1377 /** | |
1378 * Draws the outline of the rectangle specified by the arguments, | |
1379 * using the receiver's foreground color. The left and right edges | |
1380 * of the rectangle are at <code>x</code> and <code>x + width</code>. | |
1381 * The top and bottom edges are at <code>y</code> and <code>y + height</code>. | |
1382 * | |
1383 * @param x the x coordinate of the rectangle to be drawn | |
1384 * @param y the y coordinate of the rectangle to be drawn | |
1385 * @param width the width of the rectangle to be drawn | |
1386 * @param height the height of the rectangle to be drawn | |
1387 * | |
1388 * @exception SWTException <ul> | |
1389 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1390 * </ul> | |
1391 */ | |
1392 public void drawRectangle(int x, int y, int width, int height) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1393 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 1394 checkGC(DRAW); |
1395 if (width < 0) { | |
1396 x = x + width; | |
1397 width = -width; | |
1398 } | |
1399 if (height < 0) { | |
1400 y = y + height; | |
1401 height = -height; | |
1402 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1403 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1404 if (cairo !is null) { |
18 | 1405 double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset; |
1406 Cairo.cairo_rectangle(cairo, x + xOffset, y + yOffset, width, height); | |
1407 Cairo.cairo_stroke(cairo); | |
1408 return; | |
1409 } | |
1410 OS.gdk_draw_rectangle(data.drawable, handle, 0, x, y, width, height); | |
1411 } | |
1412 | |
1413 /** | |
1414 * Draws the outline of the specified rectangle, using the receiver's | |
1415 * foreground color. The left and right edges of the rectangle are at | |
1416 * <code>rect.x</code> and <code>rect.x + rect.width</code>. The top | |
1417 * and bottom edges are at <code>rect.y</code> and | |
1418 * <code>rect.y + rect.height</code>. | |
1419 * | |
1420 * @param rect the rectangle to draw | |
1421 * | |
1422 * @exception IllegalArgumentException <ul> | |
1423 * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li> | |
1424 * </ul> | |
1425 * @exception SWTException <ul> | |
1426 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1427 * </ul> | |
1428 */ | |
1429 public void drawRectangle(Rectangle rect) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1430 if (rect is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
18 | 1431 drawRectangle (rect.x, rect.y, rect.width, rect.height); |
1432 } | |
1433 /** | |
1434 * Draws the outline of the round-cornered rectangle specified by | |
1435 * the arguments, using the receiver's foreground color. The left and | |
1436 * right edges of the rectangle are at <code>x</code> and <code>x + width</code>. | |
1437 * The top and bottom edges are at <code>y</code> and <code>y + height</code>. | |
1438 * The <em>roundness</em> of the corners is specified by the | |
1439 * <code>arcWidth</code> and <code>arcHeight</code> arguments, which | |
1440 * are respectively the width and height of the ellipse used to draw | |
1441 * the corners. | |
1442 * | |
1443 * @param x the x coordinate of the rectangle to be drawn | |
1444 * @param y the y coordinate of the rectangle to be drawn | |
1445 * @param width the width of the rectangle to be drawn | |
1446 * @param height the height of the rectangle to be drawn | |
1447 * @param arcWidth the width of the arc | |
1448 * @param arcHeight the height of the arc | |
1449 * | |
1450 * @exception SWTException <ul> | |
1451 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1452 * </ul> | |
1453 */ | |
1454 public void drawRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1455 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 1456 checkGC(DRAW); |
1457 int nx = x; | |
1458 int ny = y; | |
1459 int nw = width; | |
1460 int nh = height; | |
1461 int naw = arcWidth; | |
1462 int nah = arcHeight; | |
1463 if (nw < 0) { | |
1464 nw = 0 - nw; | |
1465 nx = nx - nw; | |
1466 } | |
1467 if (nh < 0) { | |
1468 nh = 0 - nh; | |
1469 ny = ny -nh; | |
1470 } | |
1471 if (naw < 0) naw = 0 - naw; | |
1472 if (nah < 0) nah = 0 - nah; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1473 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1474 if (cairo !is null) { |
18 | 1475 float naw2 = naw / 2f; |
1476 float nah2 = nah / 2f; | |
1477 float fw = nw / naw2; | |
1478 float fh = nh / nah2; | |
1479 Cairo.cairo_save(cairo); | |
1480 double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset; | |
1481 Cairo.cairo_translate(cairo, nx + xOffset, ny + yOffset); | |
1482 Cairo.cairo_scale(cairo, naw2, nah2); | |
1483 Cairo.cairo_move_to(cairo, fw - 1, 0); | |
1484 Cairo.cairo_arc(cairo, fw - 1, 1, 1, Compatibility.PI + Compatibility.PI/2.0, Compatibility.PI*2.0); | |
1485 Cairo.cairo_arc(cairo, fw - 1, fh - 1, 1, 0, Compatibility.PI/2.0); | |
1486 Cairo.cairo_arc(cairo, 1, fh - 1, 1, Compatibility.PI/2, Compatibility.PI); | |
1487 Cairo.cairo_arc(cairo, 1, 1, 1, Compatibility.PI, 270.0*Compatibility.PI/180.0); | |
1488 Cairo.cairo_close_path(cairo); | |
1489 Cairo.cairo_restore(cairo); | |
1490 Cairo.cairo_stroke(cairo); | |
1491 return; | |
1492 } | |
1493 int naw2 = naw / 2; | |
1494 int nah2 = nah / 2; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1495 auto drawable = data.drawable; |
18 | 1496 if (nw > naw) { |
1497 if (nh > nah) { | |
1498 OS.gdk_draw_arc(drawable, handle, 0, nx, ny, naw, nah, 5760, 5760); | |
1499 OS.gdk_draw_line(drawable, handle, nx + naw2, ny, nx + nw - naw2, ny); | |
1500 OS.gdk_draw_arc(drawable, handle, 0, nx + nw - naw, ny, naw, nah, 0, 5760); | |
1501 OS.gdk_draw_line(drawable, handle, nx + nw, ny + nah2, nx + nw, ny + nh - nah2); | |
1502 OS.gdk_draw_arc(drawable, handle, 0, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760); | |
1503 OS.gdk_draw_line(drawable,handle, nx + naw2, ny + nh, nx + nw - naw2, ny + nh); | |
1504 OS.gdk_draw_arc(drawable, handle, 0, nx, ny + nh - nah, naw, nah, 11520, 5760); | |
1505 OS.gdk_draw_line(drawable, handle, nx, ny + nah2, nx, ny + nh - nah2); | |
1506 } else { | |
1507 OS.gdk_draw_arc(drawable, handle, 0, nx, ny, naw, nh, 5760, 11520); | |
1508 OS.gdk_draw_line(drawable, handle, nx + naw2, ny, nx + nw - naw2, ny); | |
1509 OS.gdk_draw_arc(drawable, handle, 0, nx + nw - naw, ny, naw, nh, 17280, 11520); | |
1510 OS.gdk_draw_line(drawable,handle, nx + naw2, ny + nh, nx + nw - naw2, ny + nh); | |
1511 } | |
1512 } else { | |
1513 if (nh > nah) { | |
1514 OS.gdk_draw_arc(drawable, handle, 0, nx, ny, nw, nah, 0, 11520); | |
1515 OS.gdk_draw_line(drawable, handle, nx + nw, ny + nah2, nx + nw, ny + nh - nah2); | |
1516 OS.gdk_draw_arc(drawable, handle, 0, nx, ny + nh - nah, nw, nah, 11520, 11520); | |
1517 OS.gdk_draw_line(drawable,handle, nx, ny + nah2, nx, ny + nh - nah2); | |
1518 } else { | |
1519 OS.gdk_draw_arc(drawable, handle, 0, nx, ny, nw, nh, 0, 23040); | |
1520 } | |
1521 } | |
1522 } | |
1523 | |
1524 /** | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1525 * Draws the given str, using the receiver's current font and |
18 | 1526 * foreground color. No tab expansion or carriage return processing |
1527 * will be performed. The background of the rectangular area where | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1528 * the str is being drawn will be filled with the receiver's |
18 | 1529 * background color. |
1530 * | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1531 * @param str the str to be drawn |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1532 * @param x the x coordinate of the top left corner of the rectangular area where the str is to be drawn |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1533 * @param y the y coordinate of the top left corner of the rectangular area where the str is to be drawn |
18 | 1534 * |
1535 * @exception IllegalArgumentException <ul> | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1536 * <li>ERROR_NULL_ARGUMENT - if the str is null</li> |
18 | 1537 * </ul> |
1538 * @exception SWTException <ul> | |
1539 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1540 * </ul> | |
1541 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1542 public void drawString (char[] str, int x, int y) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1543 drawString(str, x, y, false); |
18 | 1544 } |
1545 /** | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1546 * Draws the given str, using the receiver's current font and |
18 | 1547 * foreground color. No tab expansion or carriage return processing |
1548 * will be performed. If <code>isTransparent</code> is <code>true</code>, | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1549 * then the background of the rectangular area where the str is being |
18 | 1550 * drawn will not be modified, otherwise it will be filled with the |
1551 * receiver's background color. | |
1552 * | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1553 * @param str the str to be drawn |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1554 * @param x the x coordinate of the top left corner of the rectangular area where the str is to be drawn |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1555 * @param y the y coordinate of the top left corner of the rectangular area where the str is to be drawn |
18 | 1556 * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque |
1557 * | |
1558 * @exception IllegalArgumentException <ul> | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1559 * <li>ERROR_NULL_ARGUMENT - if the str is null</li> |
18 | 1560 * </ul> |
1561 * @exception SWTException <ul> | |
1562 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1563 * </ul> | |
1564 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1565 public void drawString(char[] str, int x, int y, bool isTransparent) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1566 drawText(str, x, y, isTransparent ? SWT.DRAW_TRANSPARENT : 0); |
18 | 1567 } |
1568 | |
1569 /** | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1570 * Draws the given str, using the receiver's current font and |
18 | 1571 * foreground color. Tab expansion and carriage return processing |
1572 * are performed. The background of the rectangular area where | |
1573 * the text is being drawn will be filled with the receiver's | |
1574 * background color. | |
1575 * | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1576 * @param str the str to be drawn |
18 | 1577 * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn |
1578 * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn | |
1579 * | |
1580 * @exception IllegalArgumentException <ul> | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1581 * <li>ERROR_NULL_ARGUMENT - if the str is null</li> |
18 | 1582 * </ul> |
1583 * @exception SWTException <ul> | |
1584 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1585 * </ul> | |
1586 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1587 public void drawText(char[] str, int x, int y) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1588 drawText(str, x, y, SWT.DRAW_DELIMITER | SWT.DRAW_TAB); |
18 | 1589 } |
1590 | |
1591 /** | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1592 * Draws the given str, using the receiver's current font and |
18 | 1593 * foreground color. Tab expansion and carriage return processing |
1594 * are performed. If <code>isTransparent</code> is <code>true</code>, | |
1595 * then the background of the rectangular area where the text is being | |
1596 * drawn will not be modified, otherwise it will be filled with the | |
1597 * receiver's background color. | |
1598 * | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1599 * @param str the str to be drawn |
18 | 1600 * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn |
1601 * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn | |
1602 * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque | |
1603 * | |
1604 * @exception IllegalArgumentException <ul> | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1605 * <li>ERROR_NULL_ARGUMENT - if the str is null</li> |
18 | 1606 * </ul> |
1607 * @exception SWTException <ul> | |
1608 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1609 * </ul> | |
1610 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1611 public void drawText(char[] str, int x, int y, bool isTransparent) { |
18 | 1612 int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB; |
1613 if (isTransparent) flags |= SWT.DRAW_TRANSPARENT; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1614 drawText(str, x, y, flags); |
18 | 1615 } |
1616 | |
1617 /** | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1618 * Draws the given str, using the receiver's current font and |
18 | 1619 * foreground color. Tab expansion, line delimiter and mnemonic |
1620 * processing are performed according to the specified flags. If | |
1621 * <code>flags</code> includes <code>DRAW_TRANSPARENT</code>, | |
1622 * then the background of the rectangular area where the text is being | |
1623 * drawn will not be modified, otherwise it will be filled with the | |
1624 * receiver's background color. | |
1625 * <p> | |
1626 * The parameter <code>flags</code> may be a combination of: | |
1627 * <dl> | |
1628 * <dt><b>DRAW_DELIMITER</b></dt> | |
1629 * <dd>draw multiple lines</dd> | |
1630 * <dt><b>DRAW_TAB</b></dt> | |
1631 * <dd>expand tabs</dd> | |
1632 * <dt><b>DRAW_MNEMONIC</b></dt> | |
1633 * <dd>underline the mnemonic character</dd> | |
1634 * <dt><b>DRAW_TRANSPARENT</b></dt> | |
1635 * <dd>transparent background</dd> | |
1636 * </dl> | |
1637 * </p> | |
1638 * | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1639 * @param str the str to be drawn |
18 | 1640 * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn |
1641 * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn | |
1642 * @param flags the flags specifying how to process the text | |
1643 * | |
1644 * @exception IllegalArgumentException <ul> | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1645 * <li>ERROR_NULL_ARGUMENT - if the str is null</li> |
18 | 1646 * </ul> |
1647 * @exception SWTException <ul> | |
1648 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1649 * </ul> | |
1650 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1651 public void drawText (char[] str, int x, int y, int flags) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1652 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1653 if (str is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1654 if (str.length is 0) return; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1655 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1656 if (cairo !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1657 if (OS.GTK_VERSION < OS.buildVERSION(2, 8, 0)) { |
18 | 1658 //TODO - honor flags |
1659 checkGC(FOREGROUND | FONT); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1660 cairo_font_extents_t* extents = new cairo_font_extents_t(); |
18 | 1661 Cairo.cairo_font_extents(cairo, extents); |
1662 double baseline = y + extents.ascent; | |
1663 Cairo.cairo_move_to(cairo, x, baseline); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1664 char[] buffer = str.dup; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1665 Cairo.cairo_show_text(cairo, buffer.ptr); |
18 | 1666 Cairo.cairo_new_path(cairo); |
1667 return; | |
1668 } | |
1669 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1670 setString(str, flags); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1671 if (cairo !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1672 if ((flags & SWT.DRAW_TRANSPARENT) is 0) { |
18 | 1673 checkGC(BACKGROUND); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1674 int width, height; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1675 OS.pango_layout_get_size(data.layout, &width, &height); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1676 Cairo.cairo_rectangle(cairo, x, y, OS.PANGO_PIXELS(width), OS.PANGO_PIXELS(height)); |
18 | 1677 Cairo.cairo_fill(cairo); |
1678 } | |
1679 checkGC(FOREGROUND | FONT); | |
1680 Cairo.cairo_move_to(cairo, x, y); | |
1681 OS.pango_cairo_show_layout(cairo, data.layout); | |
1682 return; | |
1683 } | |
1684 checkGC(FOREGROUND | FONT | BACKGROUND_BG); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1685 GdkColor* background = null; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1686 if ((flags & SWT.DRAW_TRANSPARENT) is 0) background = data.background; |
18 | 1687 if (!data.xorMode) { |
1688 OS.gdk_draw_layout_with_colors(data.drawable, handle, x, y, data.layout, null, background); | |
1689 } else { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1690 auto layout = data.layout; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1691 int w, h; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1692 OS.pango_layout_get_size(layout, &w, &h); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1693 int width = OS.PANGO_PIXELS(w); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1694 int height = OS.PANGO_PIXELS(h); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1695 auto pixmap = OS.gdk_pixmap_new(cast(GdkDrawable*)OS.GDK_ROOT_PARENT(), width, height, -1); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1696 if (pixmap is null) SWT.error(SWT.ERROR_NO_HANDLES); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1697 auto gdkGC = OS.gdk_gc_new(cast(GdkDrawable*)pixmap); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1698 if (gdkGC is null) SWT.error(SWT.ERROR_NO_HANDLES); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1699 GdkColor* black = new GdkColor(); |
18 | 1700 OS.gdk_gc_set_foreground(gdkGC, black); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1701 OS.gdk_draw_rectangle(cast(GdkDrawable*)pixmap, gdkGC, 1, 0, 0, width, height); |
18 | 1702 OS.gdk_gc_set_foreground(gdkGC, data.foreground); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1703 OS.gdk_draw_layout_with_colors(cast(GdkDrawable*)pixmap, gdkGC, 0, 0, layout, null, background); |
18 | 1704 OS.g_object_unref(gdkGC); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1705 OS.gdk_draw_drawable(data.drawable, handle, cast(GdkDrawable*)pixmap, 0, 0, x, y, width, height); |
18 | 1706 OS.g_object_unref(pixmap); |
1707 } | |
1708 } | |
1709 | |
1710 /** | |
1711 * Compares the argument to the receiver, and returns true | |
1712 * if they represent the <em>same</em> object using a class | |
1713 * specific comparison. | |
1714 * | |
1715 * @param object the object to compare with this object | |
1716 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise | |
1717 * | |
1718 * @see #hashCode | |
1719 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1720 public override int opEquals(Object object) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1721 if (object is this) return true; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1722 if ( auto gc = cast(GC)object){ |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1723 return handle is gc.handle; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1724 } |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1725 return false; |
18 | 1726 } |
1727 | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1728 |
18 | 1729 /** |
1730 * Fills the interior of a circular or elliptical arc within | |
1731 * the specified rectangular area, with the receiver's background | |
1732 * color. | |
1733 * <p> | |
1734 * The resulting arc begins at <code>startAngle</code> and extends | |
1735 * for <code>arcAngle</code> degrees, using the current color. | |
1736 * Angles are interpreted such that 0 degrees is at the 3 o'clock | |
1737 * position. A positive value indicates a counter-clockwise rotation | |
1738 * while a negative value indicates a clockwise rotation. | |
1739 * </p><p> | |
1740 * The center of the arc is the center of the rectangle whose origin | |
1741 * is (<code>x</code>, <code>y</code>) and whose size is specified by the | |
1742 * <code>width</code> and <code>height</code> arguments. | |
1743 * </p><p> | |
1744 * The resulting arc covers an area <code>width + 1</code> pixels wide | |
1745 * by <code>height + 1</code> pixels tall. | |
1746 * </p> | |
1747 * | |
1748 * @param x the x coordinate of the upper-left corner of the arc to be filled | |
1749 * @param y the y coordinate of the upper-left corner of the arc to be filled | |
1750 * @param width the width of the arc to be filled | |
1751 * @param height the height of the arc to be filled | |
1752 * @param startAngle the beginning angle | |
1753 * @param arcAngle the angular extent of the arc, relative to the start angle | |
1754 * | |
1755 * @exception SWTException <ul> | |
1756 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1757 * </ul> | |
1758 * | |
1759 * @see #drawArc | |
1760 */ | |
1761 public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1762 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 1763 checkGC(FILL); |
1764 if (width < 0) { | |
1765 x = x + width; | |
1766 width = -width; | |
1767 } | |
1768 if (height < 0) { | |
1769 y = y + height; | |
1770 height = -height; | |
1771 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1772 if (width is 0 || height is 0 || arcAngle is 0) return; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1773 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1774 if (cairo !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1775 if (width is height) { |
18 | 1776 if (arcAngle >= 0) { |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1777 Cairo.cairo_arc_negative(cairo, x + width / 2f, y + height / 2f, width / 2f, -startAngle * cast(float)Compatibility.PI / 180, -(startAngle + arcAngle) * cast(float)Compatibility.PI / 180); |
18 | 1778 } else { |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1779 Cairo.cairo_arc(cairo, x + width / 2f, y + height / 2f, width / 2f, -startAngle * cast(float)Compatibility.PI / 180, -(startAngle + arcAngle) * cast(float)Compatibility.PI / 180); |
18 | 1780 } |
1781 Cairo.cairo_line_to(cairo, x + width / 2f, y + height / 2f); | |
1782 } else { | |
1783 Cairo.cairo_save(cairo); | |
1784 Cairo.cairo_translate(cairo, x + width / 2f, y + height / 2f); | |
1785 Cairo.cairo_scale(cairo, width / 2f, height / 2f); | |
1786 if (arcAngle >= 0) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1787 Cairo.cairo_arc_negative(cairo, 0, 0, 1, -startAngle * cast(float)Compatibility.PI / 180, -(startAngle + arcAngle) * cast(float)Compatibility.PI / 180); |
18 | 1788 } else { |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1789 Cairo.cairo_arc(cairo, 0, 0, 1, -startAngle * cast(float)Compatibility.PI / 180, -(startAngle + arcAngle) * cast(float)Compatibility.PI / 180); |
18 | 1790 } |
1791 Cairo.cairo_line_to(cairo, 0, 0); | |
1792 Cairo.cairo_restore(cairo); | |
1793 } | |
1794 Cairo.cairo_fill(cairo); | |
1795 return; | |
1796 } | |
1797 OS.gdk_draw_arc(data.drawable, handle, 1, x, y, width, height, startAngle * 64, arcAngle * 64); | |
1798 } | |
1799 | |
1800 /** | |
1801 * Fills the interior of the specified rectangle with a gradient | |
1802 * sweeping from left to right or top to bottom progressing | |
1803 * from the receiver's foreground color to its background color. | |
1804 * | |
1805 * @param x the x coordinate of the rectangle to be filled | |
1806 * @param y the y coordinate of the rectangle to be filled | |
1807 * @param width the width of the rectangle to be filled, may be negative | |
1808 * (inverts direction of gradient if horizontal) | |
1809 * @param height the height of the rectangle to be filled, may be negative | |
1810 * (inverts direction of gradient if vertical) | |
1811 * @param vertical if true sweeps from top to bottom, else | |
1812 * sweeps from left to right | |
1813 * | |
1814 * @exception SWTException <ul> | |
1815 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1816 * </ul> | |
1817 * | |
1818 * @see #drawRectangle(int, int, int, int) | |
1819 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1820 public void fillGradientRectangle(int x, int y, int width, int height, bool vertical) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1821 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1822 if ((width is 0) || (height is 0)) return; |
18 | 1823 |
1824 /* Rewrite this to use GdkPixbuf */ | |
1825 | |
1826 RGB backgroundRGB, foregroundRGB; | |
1827 backgroundRGB = getBackground().getRGB(); | |
1828 foregroundRGB = getForeground().getRGB(); | |
1829 | |
1830 RGB fromRGB, toRGB; | |
1831 fromRGB = foregroundRGB; | |
1832 toRGB = backgroundRGB; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1833 bool swapColors = false; |
18 | 1834 if (width < 0) { |
1835 x += width; width = -width; | |
1836 if (! vertical) swapColors = true; | |
1837 } | |
1838 if (height < 0) { | |
1839 y += height; height = -height; | |
1840 if (vertical) swapColors = true; | |
1841 } | |
1842 if (swapColors) { | |
1843 fromRGB = backgroundRGB; | |
1844 toRGB = foregroundRGB; | |
1845 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1846 if (fromRGB ==/*eq*/ toRGB ) { |
18 | 1847 fillRectangle(x, y, width, height); |
1848 return; | |
1849 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1850 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1851 if (cairo !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1852 cairo_pattern_t* pattern; |
18 | 1853 if (vertical) { |
1854 pattern = Cairo.cairo_pattern_create_linear (0.0, 0.0, 0.0, 1.0); | |
1855 } else { | |
1856 pattern = Cairo.cairo_pattern_create_linear (0.0, 0.0, 1.0, 0.0); | |
1857 } | |
1858 Cairo.cairo_pattern_add_color_stop_rgba (pattern, 0, fromRGB.red / 255f, fromRGB.green / 255f, fromRGB.blue / 255f, data.alpha / 255f); | |
1859 Cairo.cairo_pattern_add_color_stop_rgba (pattern, 1, toRGB.red / 255f, toRGB.green / 255f, toRGB.blue / 255f, data.alpha / 255f); | |
1860 Cairo.cairo_save(cairo); | |
1861 Cairo.cairo_translate(cairo, x, y); | |
1862 Cairo.cairo_scale(cairo, width, height); | |
1863 Cairo.cairo_rectangle(cairo, 0, 0, 1, 1); | |
1864 Cairo.cairo_set_source(cairo, pattern); | |
1865 Cairo.cairo_fill(cairo); | |
1866 Cairo.cairo_restore(cairo); | |
1867 Cairo.cairo_pattern_destroy(pattern); | |
1868 return; | |
1869 } | |
1870 ImageData.fillGradientRectangle(this, data.device, | |
1871 x, y, width, height, vertical, fromRGB, toRGB, | |
1872 8, 8, 8); | |
1873 } | |
1874 | |
1875 /** | |
1876 * Fills the interior of an oval, within the specified | |
1877 * rectangular area, with the receiver's background | |
1878 * color. | |
1879 * | |
1880 * @param x the x coordinate of the upper left corner of the oval to be filled | |
1881 * @param y the y coordinate of the upper left corner of the oval to be filled | |
1882 * @param width the width of the oval to be filled | |
1883 * @param height the height of the oval to be filled | |
1884 * | |
1885 * @exception SWTException <ul> | |
1886 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1887 * </ul> | |
1888 * | |
1889 * @see #drawOval | |
1890 */ | |
1891 public void fillOval(int x, int y, int width, int height) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1892 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 1893 checkGC(FILL); |
1894 if (width < 0) { | |
1895 x = x + width; | |
1896 width = -width; | |
1897 } | |
1898 if (height < 0) { | |
1899 y = y + height; | |
1900 height = -height; | |
1901 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1902 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1903 if (cairo !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1904 if (width is height) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1905 Cairo.cairo_arc_negative(cairo, x + width / 2f, y + height / 2f, width / 2f, 0, 2 * cast(float)Compatibility.PI); |
18 | 1906 } else { |
1907 Cairo.cairo_save(cairo); | |
1908 Cairo.cairo_translate(cairo, x + width / 2f, y + height / 2f); | |
1909 Cairo.cairo_scale(cairo, width / 2f, height / 2f); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1910 Cairo.cairo_arc_negative(cairo, 0, 0, 1, 0, 2 * cast(float)Compatibility.PI); |
18 | 1911 Cairo.cairo_restore(cairo); |
1912 } | |
1913 Cairo.cairo_fill(cairo); | |
1914 return; | |
1915 } | |
1916 OS.gdk_draw_arc(data.drawable, handle, 1, x, y, width, height, 0, 23040); | |
1917 } | |
1918 | |
1919 /** | |
1920 * Fills the path described by the parameter. | |
1921 * <p> | |
1922 * This operation requires the operating system's advanced | |
1923 * graphics subsystem which may not be available on some | |
1924 * platforms. | |
1925 * </p> | |
1926 * | |
1927 * @param path the path to fill | |
1928 * | |
1929 * @exception IllegalArgumentException <ul> | |
1930 * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li> | |
1931 * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li> | |
1932 * </ul> | |
1933 * @exception SWTException <ul> | |
1934 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1935 * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> | |
1936 * </ul> | |
1937 * | |
1938 * @see Path | |
1939 * | |
1940 * @since 3.1 | |
1941 */ | |
1942 public void fillPath (Path path) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1943 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1944 if (path is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1945 if (path.handle is null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
18 | 1946 initCairo(); |
1947 checkGC(FILL); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1948 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1949 auto copy = Cairo.cairo_copy_path(path.handle); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1950 if (copy is null) SWT.error(SWT.ERROR_NO_HANDLES); |
18 | 1951 Cairo.cairo_append_path(cairo, copy); |
1952 Cairo.cairo_path_destroy(copy); | |
1953 Cairo.cairo_fill(cairo); | |
1954 } | |
1955 | |
1956 /** | |
1957 * Fills the interior of the closed polygon which is defined by the | |
1958 * specified array of integer coordinates, using the receiver's | |
1959 * background color. The array contains alternating x and y values | |
1960 * which are considered to represent points which are the vertices of | |
1961 * the polygon. Lines are drawn between each consecutive pair, and | |
1962 * between the first pair and last pair in the array. | |
1963 * | |
1964 * @param pointArray an array of alternating x and y values which are the vertices of the polygon | |
1965 * | |
1966 * @exception IllegalArgumentException <ul> | |
1967 * <li>ERROR_NULL_ARGUMENT if pointArray is null</li> | |
1968 * </ul> | |
1969 * @exception SWTException <ul> | |
1970 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1971 * </ul> | |
1972 * | |
1973 * @see #drawPolygon | |
1974 */ | |
1975 public void fillPolygon(int[] pointArray) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1976 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1977 if (pointArray is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
18 | 1978 checkGC(FILL); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1979 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1980 if (cairo !is null) { |
18 | 1981 drawPolyline(cairo, pointArray, true); |
1982 Cairo.cairo_fill(cairo); | |
1983 return; | |
1984 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
1985 OS.gdk_draw_polygon(data.drawable, handle, 1, cast(GdkPoint*)pointArray.ptr, pointArray.length / 2); |
18 | 1986 } |
1987 | |
1988 /** | |
1989 * Fills the interior of the rectangle specified by the arguments, | |
1990 * using the receiver's background color. | |
1991 * | |
1992 * @param x the x coordinate of the rectangle to be filled | |
1993 * @param y the y coordinate of the rectangle to be filled | |
1994 * @param width the width of the rectangle to be filled | |
1995 * @param height the height of the rectangle to be filled | |
1996 * | |
1997 * @exception SWTException <ul> | |
1998 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
1999 * </ul> | |
2000 * | |
2001 * @see #drawRectangle(int, int, int, int) | |
2002 */ | |
2003 public void fillRectangle(int x, int y, int width, int height) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2004 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 2005 checkGC(FILL); |
2006 if (width < 0) { | |
2007 x = x + width; | |
2008 width = -width; | |
2009 } | |
2010 if (height < 0) { | |
2011 y = y + height; | |
2012 height = -height; | |
2013 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2014 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2015 if (cairo !is null) { |
18 | 2016 Cairo.cairo_rectangle(cairo, x, y, width, height); |
2017 Cairo.cairo_fill(cairo); | |
2018 return; | |
2019 } | |
2020 OS.gdk_draw_rectangle(data.drawable, handle, 1, x, y, width, height); | |
2021 } | |
2022 | |
2023 /** | |
2024 * Fills the interior of the specified rectangle, using the receiver's | |
2025 * background color. | |
2026 * | |
2027 * @param rect the rectangle to be filled | |
2028 * | |
2029 * @exception IllegalArgumentException <ul> | |
2030 * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li> | |
2031 * </ul> | |
2032 * @exception SWTException <ul> | |
2033 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2034 * </ul> | |
2035 * | |
2036 * @see #drawRectangle(int, int, int, int) | |
2037 */ | |
2038 public void fillRectangle(Rectangle rect) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2039 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2040 if (rect is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
18 | 2041 fillRectangle(rect.x, rect.y, rect.width, rect.height); |
2042 } | |
2043 | |
2044 /** | |
2045 * Fills the interior of the round-cornered rectangle specified by | |
2046 * the arguments, using the receiver's background color. | |
2047 * | |
2048 * @param x the x coordinate of the rectangle to be filled | |
2049 * @param y the y coordinate of the rectangle to be filled | |
2050 * @param width the width of the rectangle to be filled | |
2051 * @param height the height of the rectangle to be filled | |
2052 * @param arcWidth the width of the arc | |
2053 * @param arcHeight the height of the arc | |
2054 * | |
2055 * @exception SWTException <ul> | |
2056 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2057 * </ul> | |
2058 * | |
2059 * @see #drawRoundRectangle | |
2060 */ | |
2061 public void fillRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2062 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 2063 checkGC(FILL); |
2064 int nx = x; | |
2065 int ny = y; | |
2066 int nw = width; | |
2067 int nh = height; | |
2068 int naw = arcWidth; | |
2069 int nah = arcHeight; | |
2070 if (nw < 0) { | |
2071 nw = 0 - nw; | |
2072 nx = nx - nw; | |
2073 } | |
2074 if (nh < 0) { | |
2075 nh = 0 - nh; | |
2076 ny = ny -nh; | |
2077 } | |
2078 if (naw < 0) naw = 0 - naw; | |
2079 if (nah < 0) nah = 0 - nah; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2080 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2081 if (cairo !is null) { |
18 | 2082 float naw2 = naw / 2f; |
2083 float nah2 = nah / 2f; | |
2084 float fw = nw / naw2; | |
2085 float fh = nh / nah2; | |
2086 Cairo.cairo_save(cairo); | |
2087 Cairo.cairo_translate(cairo, nx, ny); | |
2088 Cairo.cairo_scale(cairo, naw2, nah2); | |
2089 Cairo.cairo_move_to(cairo, fw - 1, 0); | |
2090 Cairo.cairo_arc(cairo, fw - 1, 1, 1, Compatibility.PI + Compatibility.PI/2.0, Compatibility.PI*2.0); | |
2091 Cairo.cairo_arc(cairo, fw - 1, fh - 1, 1, 0, Compatibility.PI/2.0); | |
2092 Cairo.cairo_arc(cairo, 1, fh - 1, 1, Compatibility.PI/2, Compatibility.PI); | |
2093 Cairo.cairo_arc(cairo, 1, 1, 1, Compatibility.PI, 270.0*Compatibility.PI/180.0); | |
2094 Cairo.cairo_close_path(cairo); | |
2095 Cairo.cairo_restore(cairo); | |
2096 Cairo.cairo_fill(cairo); | |
2097 return; | |
2098 } | |
2099 int naw2 = naw / 2; | |
2100 int nah2 = nah / 2; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2101 auto drawable = data.drawable; |
18 | 2102 if (nw > naw) { |
2103 if (nh > nah) { | |
2104 OS.gdk_draw_arc(drawable, handle, 1, nx, ny, naw, nah, 5760, 5760); | |
2105 OS.gdk_draw_rectangle(drawable, handle, 1, nx + naw2, ny, nw - naw2 * 2, nh); | |
2106 OS.gdk_draw_arc(drawable, handle, 1, nx + nw - naw, ny, naw, nah, 0, 5760); | |
2107 OS.gdk_draw_rectangle(drawable, handle, 1, nx, ny + nah2, naw2, nh - nah2 * 2); | |
2108 OS.gdk_draw_arc(drawable, handle, 1, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760); | |
2109 OS.gdk_draw_rectangle(drawable, handle, 1, nx + nw - naw2, ny + nah2, naw2, nh - nah2 * 2); | |
2110 OS.gdk_draw_arc(drawable, handle, 1, nx, ny + nh - nah, naw, nah, 11520, 5760); | |
2111 } else { | |
2112 OS.gdk_draw_arc(drawable, handle, 1, nx, ny, naw, nh, 5760, 11520); | |
2113 OS.gdk_draw_rectangle(drawable, handle, 1, nx + naw2, ny, nw - naw2 * 2, nh); | |
2114 OS.gdk_draw_arc(drawable, handle, 1, nx + nw - naw, ny, naw, nh, 17280, 11520); | |
2115 } | |
2116 } else { | |
2117 if (nh > nah) { | |
2118 OS.gdk_draw_arc(drawable, handle, 1, nx, ny, nw, nah, 0, 11520); | |
2119 OS.gdk_draw_rectangle(drawable, handle, 1, nx, ny + nah2, nw, nh - nah2 * 2); | |
2120 OS.gdk_draw_arc(drawable, handle, 1, nx, ny + nh - nah, nw, nah, 11520, 11520); | |
2121 } else { | |
2122 OS.gdk_draw_arc(drawable, handle, 1, nx, ny, nw, nh, 0, 23040); | |
2123 } | |
2124 } | |
2125 } | |
2126 | |
2127 int fixMnemonic (char [] buffer) { | |
2128 int i=0, j=0; | |
2129 int mnemonic=-1; | |
2130 while (i < buffer.length) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2131 if ((buffer [j++] = buffer [i++]) is '&') { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2132 if (i is buffer.length) {continue;} |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2133 if (buffer [i] is '&') {i++; continue;} |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2134 if (mnemonic is -1) mnemonic = j; |
18 | 2135 j--; |
2136 } | |
2137 } | |
2138 while (j < buffer.length) buffer [j++] = 0; | |
2139 return mnemonic; | |
2140 } | |
2141 | |
2142 /** | |
2143 * Returns the <em>advance width</em> of the specified character in | |
2144 * the font which is currently selected into the receiver. | |
2145 * <p> | |
2146 * The advance width is defined as the horizontal distance the cursor | |
2147 * should move after printing the character in the selected font. | |
2148 * </p> | |
2149 * | |
2150 * @param ch the character to measure | |
2151 * @return the distance in the x direction to move past the character before painting the next | |
2152 * | |
2153 * @exception SWTException <ul> | |
2154 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2155 * </ul> | |
2156 */ | |
2157 public int getAdvanceWidth(char ch) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2158 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 2159 //BOGUS |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2160 return stringExtent([ch]).x; |
18 | 2161 } |
2162 | |
2163 /** | |
2164 * Returns <code>true</code> if receiver is using the operating system's | |
2165 * advanced graphics subsystem. Otherwise, <code>false</code> is returned | |
2166 * to indicate that normal graphics are in use. | |
2167 * <p> | |
2168 * Advanced graphics may not be installed for the operating system. In this | |
2169 * case, <code>false</code> is always returned. Some operating system have | |
2170 * only one graphics subsystem. If this subsystem supports advanced graphics, | |
2171 * then <code>true</code> is always returned. If any graphics operation such | |
2172 * as alpha, antialias, patterns, interpolation, paths, clipping or transformation | |
2173 * has caused the receiver to switch from regular to advanced graphics mode, | |
2174 * <code>true</code> is returned. If the receiver has been explicitly switched | |
2175 * to advanced mode and this mode is supported, <code>true</code> is returned. | |
2176 * </p> | |
2177 * | |
2178 * @return the advanced value | |
2179 * | |
2180 * @exception SWTException <ul> | |
2181 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2182 * </ul> | |
2183 * | |
2184 * @see #setAdvanced | |
2185 * | |
2186 * @since 3.1 | |
2187 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2188 public bool getAdvanced() { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2189 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2190 return data.cairo !is null; |
18 | 2191 } |
2192 | |
2193 /** | |
2194 * Returns the receiver's alpha value. | |
2195 * | |
2196 * @return the alpha value | |
2197 * | |
2198 * @exception SWTException <ul> | |
2199 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2200 * </ul> | |
2201 * | |
2202 * @since 3.1 | |
2203 */ | |
2204 public int getAlpha() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2205 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 2206 return data.alpha; |
2207 } | |
2208 | |
2209 /** | |
2210 * Returns the receiver's anti-aliasing setting value, which will be | |
2211 * one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or | |
2212 * <code>SWT.ON</code>. Note that this controls anti-aliasing for all | |
2213 * <em>non-text drawing</em> operations. | |
2214 * | |
2215 * @return the anti-aliasing setting | |
2216 * | |
2217 * @exception SWTException <ul> | |
2218 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2219 * </ul> | |
2220 * | |
2221 * @see #getTextAntialias | |
2222 * | |
2223 * @since 3.1 | |
2224 */ | |
2225 public int getAntialias() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2226 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2227 if (data.cairo is null) return SWT.DEFAULT; |
18 | 2228 int antialias = Cairo.cairo_get_antialias(data.cairo); |
2229 switch (antialias) { | |
2230 case Cairo.CAIRO_ANTIALIAS_DEFAULT: return SWT.DEFAULT; | |
2231 case Cairo.CAIRO_ANTIALIAS_NONE: return SWT.OFF; | |
2232 case Cairo.CAIRO_ANTIALIAS_GRAY: | |
2233 case Cairo.CAIRO_ANTIALIAS_SUBPIXEL: return SWT.ON; | |
2234 } | |
2235 return SWT.DEFAULT; | |
2236 } | |
2237 | |
2238 /** | |
2239 * Returns the background color. | |
2240 * | |
2241 * @return the receiver's background color | |
2242 * | |
2243 * @exception SWTException <ul> | |
2244 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2245 * </ul> | |
2246 */ | |
2247 public Color getBackground() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2248 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 2249 return Color.gtk_new(data.device, data.background); |
2250 } | |
2251 | |
2252 /** | |
2253 * Returns the background pattern. The default value is | |
2254 * <code>null</code>. | |
2255 * | |
2256 * @return the receiver's background pattern | |
2257 * | |
2258 * @exception SWTException <ul> | |
2259 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2260 * </ul> | |
2261 * | |
2262 * @see Pattern | |
2263 * | |
2264 * @since 3.1 | |
2265 */ | |
2266 public Pattern getBackgroundPattern() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2267 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 2268 return data.backgroundPattern; |
2269 } | |
2270 | |
2271 /** | |
2272 * Returns the width of the specified character in the font | |
2273 * selected into the receiver. | |
2274 * <p> | |
2275 * The width is defined as the space taken up by the actual | |
2276 * character, not including the leading and tailing whitespace | |
2277 * or overhang. | |
2278 * </p> | |
2279 * | |
2280 * @param ch the character to measure | |
2281 * @return the width of the character | |
2282 * | |
2283 * @exception SWTException <ul> | |
2284 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2285 * </ul> | |
2286 */ | |
2287 public int getCharWidth(char ch) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2288 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 2289 //BOGUS |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2290 return stringExtent([ch]).x; |
18 | 2291 } |
2292 | |
2293 /** | |
2294 * Returns the bounding rectangle of the receiver's clipping | |
2295 * region. If no clipping region is set, the return value | |
2296 * will be a rectangle which covers the entire bounds of the | |
2297 * object the receiver is drawing on. | |
2298 * | |
2299 * @return the bounding rectangle of the clipping region | |
2300 * | |
2301 * @exception SWTException <ul> | |
2302 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2303 * </ul> | |
2304 */ | |
2305 public Rectangle getClipping() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2306 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 2307 /* Calculate visible bounds in device space */ |
2308 int x = 0, y = 0, width = 0, height = 0; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2309 int w, h; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2310 OS.gdk_drawable_get_size(data.drawable, &w, &h); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2311 width = w; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2312 height = h; |
18 | 2313 /* Intersect visible bounds with clipping in device space and then convert then to user space */ |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2314 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2315 auto clipRgn = data.clipRgn; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2316 auto damageRgn = data.damageRgn; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2317 if (clipRgn !is null || damageRgn !is null || cairo !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2318 auto rgn = OS.gdk_region_new(); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2319 GdkRectangle* rect = new GdkRectangle(); |
18 | 2320 rect.width = width; |
2321 rect.height = height; | |
2322 OS.gdk_region_union_with_rect(rgn, rect); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2323 if (damageRgn !is null) { |
18 | 2324 OS.gdk_region_intersect (rgn, damageRgn); |
2325 } | |
2326 /* Intersect visible bounds with clipping */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2327 if (clipRgn !is null) { |
18 | 2328 /* Convert clipping to device space if needed */ |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2329 if (data.clippingTransform !is null) { |
18 | 2330 clipRgn = convertRgn(clipRgn, data.clippingTransform); |
2331 OS.gdk_region_intersect(rgn, clipRgn); | |
2332 OS.gdk_region_destroy(clipRgn); | |
2333 } else { | |
2334 OS.gdk_region_intersect(rgn, clipRgn); | |
2335 } | |
2336 } | |
2337 /* Convert to user space */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2338 if (cairo !is null) { |
18 | 2339 double[] matrix = new double[6]; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2340 Cairo.cairo_get_matrix(cairo, cast(cairo_matrix_t*)matrix.ptr); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2341 Cairo.cairo_matrix_invert(cast(cairo_matrix_t*)matrix.ptr); |
18 | 2342 clipRgn = convertRgn(rgn, matrix); |
2343 OS.gdk_region_destroy(rgn); | |
2344 rgn = clipRgn; | |
2345 } | |
2346 OS.gdk_region_get_clipbox(rgn, rect); | |
2347 OS.gdk_region_destroy(rgn); | |
2348 x = rect.x; | |
2349 y = rect.y; | |
2350 width = rect.width; | |
2351 height = rect.height; | |
2352 } | |
2353 return new Rectangle(x, y, width, height); | |
2354 } | |
2355 | |
2356 /** | |
2357 * Sets the region managed by the argument to the current | |
2358 * clipping region of the receiver. | |
2359 * | |
2360 * @param region the region to fill with the clipping region | |
2361 * | |
2362 * @exception IllegalArgumentException <ul> | |
2363 * <li>ERROR_NULL_ARGUMENT - if the region is null</li> | |
2364 * <li>ERROR_INVALID_ARGUMENT - if the region is disposed</li> | |
2365 * </ul> | |
2366 * @exception SWTException <ul> | |
2367 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2368 * </ul> | |
2369 */ | |
2370 public void getClipping(Region region) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2371 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2372 if (region is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
18 | 2373 if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2374 auto clipping = region.handle; |
18 | 2375 OS.gdk_region_subtract(clipping, clipping); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2376 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2377 auto clipRgn = data.clipRgn; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2378 if (clipRgn is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2379 int width,height; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2380 OS.gdk_drawable_get_size(data.drawable, &width, &height); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2381 GdkRectangle* rect = new GdkRectangle(); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2382 rect.width = width; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2383 rect.height = height; |
18 | 2384 OS.gdk_region_union_with_rect(clipping, rect); |
2385 } else { | |
2386 /* Convert clipping to device space if needed */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2387 if (data.clippingTransform !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2388 auto rgn = convertRgn(clipRgn, data.clippingTransform); |
18 | 2389 OS.gdk_region_union(clipping, rgn); |
2390 OS.gdk_region_destroy(rgn); | |
2391 } else { | |
2392 OS.gdk_region_union(clipping, clipRgn); | |
2393 } | |
2394 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2395 if (data.damageRgn !is null) { |
18 | 2396 OS.gdk_region_intersect(clipping, data.damageRgn); |
2397 } | |
2398 /* Convert to user space */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2399 if (cairo !is null) { |
18 | 2400 double[] matrix = new double[6]; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2401 Cairo.cairo_get_matrix(cairo, cast(cairo_matrix_t*)matrix.ptr); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2402 Cairo.cairo_matrix_invert(cast(cairo_matrix_t*)matrix.ptr); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2403 auto rgn = convertRgn(clipping, matrix); |
18 | 2404 OS.gdk_region_subtract(clipping, clipping); |
2405 OS.gdk_region_union(clipping, rgn); | |
2406 OS.gdk_region_destroy(rgn); | |
2407 } | |
2408 } | |
2409 | |
2410 /** | |
2411 * Returns the receiver's fill rule, which will be one of | |
2412 * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>. | |
2413 * | |
2414 * @return the receiver's fill rule | |
2415 * | |
2416 * @exception SWTException <ul> | |
2417 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2418 * </ul> | |
2419 * | |
2420 * @since 3.1 | |
2421 */ | |
2422 public int getFillRule() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2423 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2424 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2425 if (cairo is null) return SWT.FILL_EVEN_ODD; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2426 return Cairo.cairo_get_fill_rule(cairo) is Cairo.CAIRO_FILL_RULE_WINDING ? SWT.FILL_WINDING : SWT.FILL_EVEN_ODD; |
18 | 2427 } |
2428 | |
2429 /** | |
2430 * Returns the font currently being used by the receiver | |
2431 * to draw and measure text. | |
2432 * | |
2433 * @return the receiver's font | |
2434 * | |
2435 * @exception SWTException <ul> | |
2436 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2437 * </ul> | |
2438 */ | |
2439 public Font getFont() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2440 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 2441 return Font.gtk_new(data.device, data.font); |
2442 } | |
2443 | |
2444 /** | |
2445 * Returns a FontMetrics which contains information | |
2446 * about the font currently being used by the receiver | |
2447 * to draw and measure text. | |
2448 * | |
2449 * @return font metrics for the receiver's font | |
2450 * | |
2451 * @exception SWTException <ul> | |
2452 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2453 * </ul> | |
2454 */ | |
2455 public FontMetrics getFontMetrics() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2456 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2457 if (data.context is null) createLayout(); |
18 | 2458 checkGC(FONT); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2459 auto context = data.context; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2460 auto lang = OS.pango_context_get_language(context); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2461 auto metrics = OS.pango_context_get_metrics(context, data.font, lang); |
18 | 2462 FontMetrics fm = new FontMetrics(); |
2463 fm.ascent = OS.PANGO_PIXELS(OS.pango_font_metrics_get_ascent(metrics)); | |
2464 fm.descent = OS.PANGO_PIXELS(OS.pango_font_metrics_get_descent(metrics)); | |
2465 fm.averageCharWidth = OS.PANGO_PIXELS(OS.pango_font_metrics_get_approximate_char_width(metrics)); | |
2466 fm.height = fm.ascent + fm.descent; | |
2467 OS.pango_font_metrics_unref(metrics); | |
2468 return fm; | |
2469 } | |
2470 | |
2471 /** | |
2472 * Returns the receiver's foreground color. | |
2473 * | |
2474 * @return the color used for drawing foreground things | |
2475 * | |
2476 * @exception SWTException <ul> | |
2477 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2478 * </ul> | |
2479 */ | |
2480 public Color getForeground() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2481 if (handle is null) SWT.error(SWT.ERROR_WIDGET_DISPOSED); |
18 | 2482 return Color.gtk_new(data.device, data.foreground); |
2483 } | |
2484 | |
2485 /** | |
2486 * Returns the foreground pattern. The default value is | |
2487 * <code>null</code>. | |
2488 * | |
2489 * @return the receiver's foreground pattern | |
2490 * | |
2491 * @exception SWTException <ul> | |
2492 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2493 * </ul> | |
2494 * | |
2495 * @see Pattern | |
2496 * | |
2497 * @since 3.1 | |
2498 */ | |
2499 public Pattern getForegroundPattern() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2500 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 2501 return data.foregroundPattern; |
2502 } | |
2503 | |
2504 /** | |
2505 * Returns the GCData. | |
2506 * <p> | |
2507 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public | |
2508 * API for <code>GC</code>. It is marked public only so that it | |
2509 * can be shared within the packages provided by SWT. It is not | |
2510 * available on all platforms, and should never be called from | |
2511 * application code. | |
2512 * </p> | |
2513 * | |
2514 * @return the receiver's GCData | |
2515 * | |
2516 * @exception SWTException <ul> | |
2517 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2518 * </ul> | |
2519 * | |
2520 * @see GCData | |
2521 * | |
2522 * @since 3.2 | |
2523 */ | |
2524 public GCData getGCData() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2525 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 2526 return data; |
2527 } | |
2528 | |
2529 /** | |
2530 * Returns the receiver's interpolation setting, which will be one of | |
2531 * <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>, | |
2532 * <code>SWT.LOW</code> or <code>SWT.HIGH</code>. | |
2533 * | |
2534 * @return the receiver's interpolation setting | |
2535 * | |
2536 * @exception SWTException <ul> | |
2537 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2538 * </ul> | |
2539 * | |
2540 * @since 3.1 | |
2541 */ | |
2542 public int getInterpolation() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2543 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 2544 return data.interpolation; |
2545 } | |
2546 | |
2547 /** | |
2548 * Returns the receiver's line attributes. | |
2549 * | |
2550 * @return the line attributes used for drawing lines | |
2551 * | |
2552 * @exception SWTException <ul> | |
2553 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2554 * </ul> | |
2555 * | |
2556 * @since 3.3 | |
2557 */ | |
2558 public LineAttributes getLineAttributes() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2559 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 2560 float[] dashes = null; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2561 if (data.lineDashes !is null) { |
25
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
24
diff
changeset
|
2562 dashes = new float[data.lineDashes.length]; |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
24
diff
changeset
|
2563 System.arraycopy(data.lineDashes, 0, dashes, 0, dashes.length); |
18 | 2564 } |
2565 return new LineAttributes(data.lineWidth, data.lineCap, data.lineJoin, data.lineStyle, dashes, data.lineDashesOffset, data.lineMiterLimit); | |
2566 } | |
2567 | |
2568 /** | |
2569 * Returns the receiver's line cap style, which will be one | |
2570 * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>, | |
2571 * or <code>SWT.CAP_SQUARE</code>. | |
2572 * | |
2573 * @return the cap style used for drawing lines | |
2574 * | |
2575 * @exception SWTException <ul> | |
2576 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2577 * </ul> | |
2578 * | |
2579 * @since 3.1 | |
2580 */ | |
2581 public int getLineCap() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2582 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 2583 return data.lineCap; |
2584 } | |
2585 | |
2586 /** | |
2587 * Returns the receiver's line dash style. The default value is | |
2588 * <code>null</code>. | |
2589 * | |
2590 * @return the line dash style used for drawing lines | |
2591 * | |
2592 * @exception SWTException <ul> | |
2593 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2594 * </ul> | |
2595 * | |
2596 * @since 3.1 | |
2597 */ | |
2598 public int[] getLineDash() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2599 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2600 if (data.lineDashes is null) return null; |
18 | 2601 int[] lineDashes = new int[data.lineDashes.length]; |
2602 for (int i = 0; i < lineDashes.length; i++) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2603 lineDashes[i] = cast(int)data.lineDashes[i]; |
18 | 2604 } |
2605 return lineDashes; | |
2606 } | |
2607 | |
2608 /** | |
2609 * Returns the receiver's line join style, which will be one | |
2610 * of the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>, | |
2611 * or <code>SWT.JOIN_BEVEL</code>. | |
2612 * | |
2613 * @return the join style used for drawing lines | |
2614 * | |
2615 * @exception SWTException <ul> | |
2616 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2617 * </ul> | |
2618 * | |
2619 * @since 3.1 | |
2620 */ | |
2621 public int getLineJoin() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2622 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 2623 return data.lineJoin; |
2624 } | |
2625 | |
2626 /** | |
2627 * Returns the receiver's line style, which will be one | |
2628 * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>, | |
2629 * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or | |
2630 * <code>SWT.LINE_DASHDOTDOT</code>. | |
2631 * | |
2632 * @return the style used for drawing lines | |
2633 * | |
2634 * @exception SWTException <ul> | |
2635 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2636 * </ul> | |
2637 */ | |
2638 public int getLineStyle() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2639 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 2640 return data.lineStyle; |
2641 } | |
2642 | |
2643 /** | |
2644 * Returns the width that will be used when drawing lines | |
2645 * for all of the figure drawing operations (that is, | |
2646 * <code>drawLine</code>, <code>drawRectangle</code>, | |
2647 * <code>drawPolyline</code>, and so forth. | |
2648 * | |
2649 * @return the receiver's line width | |
2650 * | |
2651 * @exception SWTException <ul> | |
2652 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2653 * </ul> | |
2654 */ | |
2655 public int getLineWidth() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2656 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2657 return cast(int)data.lineWidth; |
18 | 2658 } |
2659 | |
2660 /** | |
2661 * Returns the receiver's style information. | |
2662 * <p> | |
2663 * Note that the value which is returned by this method <em>may | |
2664 * not match</em> the value which was provided to the constructor | |
2665 * when the receiver was created. This can occur when the underlying | |
2666 * operating system does not support a particular combination of | |
2667 * requested styles. | |
2668 * </p> | |
2669 * | |
2670 * @return the style bits | |
2671 * | |
2672 * @exception SWTException <ul> | |
2673 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2674 * </ul> | |
2675 * | |
2676 * @since 2.1.2 | |
2677 */ | |
2678 public int getStyle () { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2679 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 2680 return data.style; |
2681 } | |
2682 | |
2683 /** | |
2684 * Returns the receiver's text drawing anti-aliasing setting value, | |
2685 * which will be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or | |
2686 * <code>SWT.ON</code>. Note that this controls anti-aliasing | |
2687 * <em>only</em> for text drawing operations. | |
2688 * | |
2689 * @return the anti-aliasing setting | |
2690 * | |
2691 * @exception SWTException <ul> | |
2692 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2693 * </ul> | |
2694 * | |
2695 * @see #getAntialias | |
2696 * | |
2697 * @since 3.1 | |
2698 */ | |
2699 public int getTextAntialias() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2700 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2701 if (data.cairo is null) return SWT.DEFAULT; |
18 | 2702 int antialias = Cairo.CAIRO_ANTIALIAS_DEFAULT; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2703 if (OS.GTK_VERSION < OS.buildVERSION(2, 8, 0)) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2704 auto options = Cairo.cairo_font_options_create(); |
18 | 2705 Cairo.cairo_get_font_options(data.cairo, options); |
2706 antialias = Cairo.cairo_font_options_get_antialias(options); | |
2707 Cairo.cairo_font_options_destroy(options); | |
2708 } else { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2709 if (data.context !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2710 auto options = OS.pango_cairo_context_get_font_options(data.context); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2711 if (options !is null) antialias = Cairo.cairo_font_options_get_antialias(options); |
18 | 2712 } |
2713 } | |
2714 switch (antialias) { | |
2715 case Cairo.CAIRO_ANTIALIAS_DEFAULT: return SWT.DEFAULT; | |
2716 case Cairo.CAIRO_ANTIALIAS_NONE: return SWT.OFF; | |
2717 case Cairo.CAIRO_ANTIALIAS_GRAY: | |
2718 case Cairo.CAIRO_ANTIALIAS_SUBPIXEL: return SWT.ON; | |
2719 } | |
2720 return SWT.DEFAULT; | |
2721 } | |
2722 | |
2723 /** | |
2724 * Sets the parameter to the transform that is currently being | |
2725 * used by the receiver. | |
2726 * | |
2727 * @param transform the destination to copy the transform into | |
2728 * | |
2729 * @exception IllegalArgumentException <ul> | |
2730 * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li> | |
2731 * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li> | |
2732 * </ul> | |
2733 * @exception SWTException <ul> | |
2734 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2735 * </ul> | |
2736 * | |
2737 * @see Transform | |
2738 * | |
2739 * @since 3.1 | |
2740 */ | |
2741 public void getTransform(Transform transform) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2742 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2743 if (transform is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
18 | 2744 if (transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2745 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2746 if (cairo !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2747 Cairo.cairo_get_matrix(cairo, cast(cairo_matrix_t*)transform.handle.ptr); |
18 | 2748 } else { |
2749 transform.setElements(1, 0, 0, 1, 0, 0); | |
2750 } | |
2751 } | |
2752 | |
2753 /** | |
2754 * Returns <code>true</code> if this GC is drawing in the mode | |
2755 * where the resulting color in the destination is the | |
2756 * <em>exclusive or</em> of the color values in the source | |
2757 * and the destination, and <code>false</code> if it is | |
2758 * drawing in the mode where the destination color is being | |
2759 * replaced with the source color value. | |
2760 * | |
2761 * @return <code>true</code> true if the receiver is in XOR mode, and false otherwise | |
2762 * | |
2763 * @exception SWTException <ul> | |
2764 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2765 * </ul> | |
2766 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2767 public bool getXORMode() { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2768 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 2769 return data.xorMode; |
2770 } | |
2771 | |
2772 /** | |
2773 * Returns an integer hash code for the receiver. Any two | |
2774 * objects that return <code>true</code> when passed to | |
2775 * <code>equals</code> must return the same value for this | |
2776 * method. | |
2777 * | |
2778 * @return the receiver's hash | |
2779 * | |
2780 * @exception SWTException <ul> | |
2781 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2782 * </ul> | |
2783 * | |
2784 * @see #equals | |
2785 */ | |
2786 public int hashCode() { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2787 return cast(int)/*64*/handle; |
18 | 2788 } |
2789 | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2790 void init(Drawable drawable, GCData data, GdkGC* gdkGC) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2791 if (data.foreground !is null) data.state &= ~FOREGROUND; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2792 if (data.background !is null) data.state &= ~(BACKGROUND | BACKGROUND_BG); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2793 if (data.font !is null) data.state &= ~FONT; |
18 | 2794 |
2795 Image image = data.image; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2796 if (image !is null) { |
18 | 2797 image.memGC = this; |
2798 /* | |
2799 * The transparent pixel mask might change when drawing on | |
2800 * the image. Destroy it so that it is regenerated when | |
2801 * necessary. | |
2802 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2803 if (image.transparentPixel !is -1) image.destroyMask(); |
18 | 2804 } |
2805 this.drawable = drawable; | |
2806 this.data = data; | |
2807 handle = gdkGC; | |
2808 } | |
2809 | |
2810 void initCairo() { | |
2811 data.device.checkCairo(); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2812 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2813 if (cairo !is null) return; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2814 auto xDisplay = OS.GDK_DISPLAY(); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2815 auto xVisual = OS.gdk_x11_visual_get_xvisual(OS.gdk_visual_get_system()); |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
2816 uint xDrawable; |
18 | 2817 int translateX = 0, translateY = 0; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2818 auto drawable = data.drawable; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2819 if (data.image !is null) { |
18 | 2820 xDrawable = OS.GDK_PIXMAP_XID(drawable); |
2821 } else { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2822 int x, y; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2823 GdkDrawable* real_drawable; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2824 OS.gdk_window_get_internal_paint_info(cast(GdkWindow*)drawable, &real_drawable, &x, &y); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2825 xDrawable = OS.gdk_x11_drawable_get_xid(real_drawable); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2826 translateX = -x; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2827 translateY = -y; |
18 | 2828 } |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2829 int w, h; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2830 OS.gdk_drawable_get_size(drawable, &w, &h); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2831 int width = w, height = h; |
28 | 2832 auto surface = Cairo.cairo_xlib_surface_create(cast(void*)xDisplay, xDrawable, xVisual, width, height); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2833 if (surface is null) SWT.error(SWT.ERROR_NO_HANDLES); |
18 | 2834 Cairo.cairo_surface_set_device_offset(surface, translateX, translateY); |
2835 data.cairo = cairo = Cairo.cairo_create(surface); | |
2836 Cairo.cairo_surface_destroy(surface); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2837 if (cairo is null) SWT.error(SWT.ERROR_NO_HANDLES); |
18 | 2838 data.disposeCairo = true; |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
2839 Cairo.cairo_set_fill_rule(cairo, Cairo.CAIRO_FILL_RULE_EVEN_ODD); |
18 | 2840 data.state &= ~(BACKGROUND | FOREGROUND | FONT | LINE_WIDTH | LINE_CAP | LINE_JOIN | LINE_STYLE | DRAW_OFFSET); |
2841 setCairoClip(cairo, data.clipRgn); | |
2842 } | |
2843 | |
2844 /** | |
2845 * Returns <code>true</code> if the receiver has a clipping | |
2846 * region set into it, and <code>false</code> otherwise. | |
2847 * If this method returns false, the receiver will draw on all | |
2848 * available space in the destination. If it returns true, | |
2849 * it will draw only in the area that is covered by the region | |
2850 * that can be accessed with <code>getClipping(region)</code>. | |
2851 * | |
2852 * @return <code>true</code> if the GC has a clipping region, and <code>false</code> otherwise | |
2853 * | |
2854 * @exception SWTException <ul> | |
2855 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2856 * </ul> | |
2857 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2858 public bool isClipped() { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2859 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2860 return data.clipRgn !is null; |
18 | 2861 } |
2862 | |
2863 /** | |
2864 * Returns <code>true</code> if the GC has been disposed, | |
2865 * and <code>false</code> otherwise. | |
2866 * <p> | |
2867 * This method gets the dispose state for the GC. | |
2868 * When a GC has been disposed, it is an error to | |
2869 * invoke any other method using the GC. | |
2870 * | |
2871 * @return <code>true</code> when the GC is disposed and <code>false</code> otherwise | |
2872 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2873 public bool isDisposed() { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2874 return handle is null; |
18 | 2875 } |
2876 | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2877 bool isIdentity(double[] matrix) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2878 if (matrix is null) return true; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2879 return matrix[0] is 1 && matrix[1] is 0 && matrix[2] is 0 && matrix[3] is 1 && matrix[4] is 0 && matrix[5] is 0; |
18 | 2880 } |
2881 | |
2882 /** | |
2883 * Sets the receiver to always use the operating system's advanced graphics | |
2884 * subsystem for all graphics operations if the argument is <code>true</code>. | |
2885 * If the argument is <code>false</code>, the advanced graphics subsystem is | |
2886 * no longer used, advanced graphics state is cleared and the normal graphics | |
2887 * subsystem is used from now on. | |
2888 * <p> | |
2889 * Normally, the advanced graphics subsystem is invoked automatically when | |
2890 * any one of the alpha, antialias, patterns, interpolation, paths, clipping | |
2891 * or transformation operations in the receiver is requested. When the receiver | |
2892 * is switched into advanced mode, the advanced graphics subsystem performs both | |
2893 * advanced and normal graphics operations. Because the two subsystems are | |
2894 * different, their output may differ. Switching to advanced graphics before | |
2895 * any graphics operations are performed ensures that the output is consistent. | |
2896 * </p><p> | |
2897 * Advanced graphics may not be installed for the operating system. In this | |
2898 * case, this operation does nothing. Some operating system have only one | |
2899 * graphics subsystem, so switching from normal to advanced graphics does | |
2900 * nothing. However, switching from advanced to normal graphics will always | |
2901 * clear the advanced graphics state, even for operating systems that have | |
2902 * only one graphics subsystem. | |
2903 * </p> | |
2904 * | |
2905 * @param advanced the new advanced graphics state | |
2906 * | |
2907 * @exception SWTException <ul> | |
2908 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2909 * </ul> | |
2910 * | |
2911 * @see #setAlpha | |
2912 * @see #setAntialias | |
2913 * @see #setBackgroundPattern | |
2914 * @see #setClipping(Path) | |
2915 * @see #setForegroundPattern | |
2916 * @see #setLineAttributes | |
2917 * @see #setInterpolation | |
2918 * @see #setTextAntialias | |
2919 * @see #setTransform | |
2920 * @see #getAdvanced | |
2921 * | |
2922 * @since 3.1 | |
2923 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2924 public void setAdvanced(bool advanced) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2925 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2926 if (advanced && data.cairo !is null) return; |
18 | 2927 if (advanced) { |
2928 try { | |
2929 initCairo(); | |
2930 } catch (SWTException e) {} | |
2931 } else { | |
2932 if (!data.disposeCairo) return; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2933 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2934 if (cairo !is null) Cairo.cairo_destroy(cairo); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2935 data.cairo = null; |
18 | 2936 data.interpolation = SWT.DEFAULT; |
2937 data.backgroundPattern = data.foregroundPattern = null; | |
2938 data.state = 0; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2939 setClipping(cast(GdkRegion*)null); |
18 | 2940 } |
2941 } | |
2942 | |
2943 /** | |
2944 * Sets the receiver's alpha value. | |
2945 * <p> | |
2946 * This operation requires the operating system's advanced | |
2947 * graphics subsystem which may not be available on some | |
2948 * platforms. | |
2949 * </p> | |
2950 * @param alpha the alpha value | |
2951 * | |
2952 * @exception SWTException <ul> | |
2953 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2954 * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> | |
2955 * </ul> | |
2956 * | |
2957 * @see #getAdvanced | |
2958 * @see #setAdvanced | |
2959 * | |
2960 * @since 3.1 | |
2961 */ | |
2962 public void setAlpha(int alpha) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2963 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2964 if (data.cairo is null && (alpha & 0xff) is 0xff) return; |
18 | 2965 initCairo(); |
2966 data.alpha = alpha & 0xff; | |
2967 data.state &= ~(BACKGROUND | FOREGROUND | BACKGROUND_BG); | |
2968 } | |
2969 | |
2970 /** | |
2971 * Sets the receiver's anti-aliasing value to the parameter, | |
2972 * which must be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> | |
2973 * or <code>SWT.ON</code>. Note that this controls anti-aliasing for all | |
2974 * <em>non-text drawing</em> operations. | |
2975 * <p> | |
2976 * This operation requires the operating system's advanced | |
2977 * graphics subsystem which may not be available on some | |
2978 * platforms. | |
2979 * </p> | |
2980 * | |
2981 * @param antialias the anti-aliasing setting | |
2982 * | |
2983 * @exception IllegalArgumentException <ul> | |
2984 * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one of <code>SWT.DEFAULT</code>, | |
2985 * <code>SWT.OFF</code> or <code>SWT.ON</code></li> | |
2986 * </ul> | |
2987 * @exception SWTException <ul> | |
2988 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
2989 * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> | |
2990 * </ul> | |
2991 * | |
2992 * @see #getAdvanced | |
2993 * @see #setAdvanced | |
2994 * @see #setTextAntialias | |
2995 * | |
2996 * @since 3.1 | |
2997 */ | |
2998 public void setAntialias(int antialias) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
2999 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3000 if (data.cairo is null && antialias is SWT.DEFAULT) return; |
18 | 3001 int mode = 0; |
3002 switch (antialias) { | |
3003 case SWT.DEFAULT: mode = Cairo.CAIRO_ANTIALIAS_DEFAULT; break; | |
3004 case SWT.OFF: mode = Cairo.CAIRO_ANTIALIAS_NONE; break; | |
3005 case SWT.ON: mode = Cairo.CAIRO_ANTIALIAS_GRAY; | |
3006 break; | |
3007 default: | |
3008 SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
3009 } | |
3010 initCairo(); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3011 auto cairo = data.cairo; |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
3012 Cairo.cairo_set_antialias(cairo, mode); |
18 | 3013 } |
3014 | |
3015 /** | |
3016 * Sets the background color. The background color is used | |
3017 * for fill operations and as the background color when text | |
3018 * is drawn. | |
3019 * | |
3020 * @param color the new background color for the receiver | |
3021 * | |
3022 * @exception IllegalArgumentException <ul> | |
3023 * <li>ERROR_NULL_ARGUMENT - if the color is null</li> | |
3024 * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li> | |
3025 * </ul> | |
3026 * @exception SWTException <ul> | |
3027 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3028 * </ul> | |
3029 */ | |
3030 public void setBackground(Color color) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3031 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3032 if (color is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
18 | 3033 if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
3034 data.background = color.handle; | |
3035 data.backgroundPattern = null; | |
3036 data.state &= ~(BACKGROUND | BACKGROUND_BG); | |
3037 } | |
3038 | |
3039 /** | |
3040 * Sets the background pattern. The default value is <code>null</code>. | |
3041 * <p> | |
3042 * This operation requires the operating system's advanced | |
3043 * graphics subsystem which may not be available on some | |
3044 * platforms. | |
3045 * </p> | |
3046 * | |
3047 * @param pattern the new background pattern | |
3048 * | |
3049 * @exception IllegalArgumentException <ul> | |
3050 * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li> | |
3051 * </ul> | |
3052 * @exception SWTException <ul> | |
3053 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3054 * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> | |
3055 * </ul> | |
3056 * | |
3057 * @see Pattern | |
3058 * @see #getAdvanced | |
3059 * @see #setAdvanced | |
3060 * | |
3061 * @since 3.1 | |
3062 */ | |
3063 public void setBackgroundPattern(Pattern pattern) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3064 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3065 if (pattern !is null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3066 if (data.cairo is null && pattern is null) return; |
18 | 3067 initCairo(); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3068 if (data.backgroundPattern is pattern) return; |
18 | 3069 data.backgroundPattern = pattern; |
3070 data.state &= ~BACKGROUND; | |
3071 } | |
3072 | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3073 static void setCairoFont(cairo_t* cairo, Font font) { |
18 | 3074 setCairoFont(cairo, font.handle); |
3075 } | |
3076 | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3077 static void setCairoFont(cairo_t* cairo, PangoFontDescription* font) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3078 auto family = OS.pango_font_description_get_family(font); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3079 int len = /*OS.*/strlen(family); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3080 char[] buffer = new char[len + 1]; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3081 memmove(buffer.ptr, family, len); |
18 | 3082 //TODO - convert font height from pango to cairo |
3083 double height = OS.PANGO_PIXELS(OS.pango_font_description_get_size(font)) * 96 / 72; | |
3084 int pangoStyle = OS.pango_font_description_get_style(font); | |
3085 int pangoWeight = OS.pango_font_description_get_weight(font); | |
3086 int slant = Cairo.CAIRO_FONT_SLANT_NORMAL; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3087 if (pangoStyle is OS.PANGO_STYLE_ITALIC) slant = Cairo.CAIRO_FONT_SLANT_ITALIC; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3088 if (pangoStyle is OS.PANGO_STYLE_OBLIQUE) slant = Cairo.CAIRO_FONT_SLANT_OBLIQUE; |
18 | 3089 int weight = Cairo.CAIRO_FONT_WEIGHT_NORMAL; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3090 if (pangoWeight is OS.PANGO_WEIGHT_BOLD) weight = Cairo.CAIRO_FONT_WEIGHT_BOLD; |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
3091 Cairo.cairo_select_font_face(cairo, buffer.ptr, slant, weight); |
18 | 3092 Cairo.cairo_set_font_size(cairo, height); |
3093 } | |
3094 | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3095 static void setCairoClip(cairo_t* cairo, GdkRegion* clipRgn) { |
18 | 3096 Cairo.cairo_reset_clip(cairo); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3097 if (clipRgn is null) return; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3098 if (OS.GTK_VERSION >= OS.buildVERSION(2, 8, 0)) { |
18 | 3099 OS.gdk_cairo_region(cairo, clipRgn); |
3100 } else { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3101 int nRects; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3102 GdkRectangle * rects; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3103 OS.gdk_region_get_rectangles(clipRgn, &rects, &nRects); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3104 GdkRectangle* rect = new GdkRectangle(); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3105 for (int i=0; i<nRects; i++) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3106 Cairo.cairo_rectangle(cairo, rects[i].x, rects[i].y, rects[i].width, rects[i].height); |
18 | 3107 } |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3108 if (rects !is null) OS.g_free(rects); |
18 | 3109 } |
3110 Cairo.cairo_clip(cairo); | |
3111 } | |
3112 | |
21 | 3113 static void setCairoPatternColor( cairo_pattern_t* pattern, int offset, Color c, int alpha) { |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3114 GdkColor* color = c.handle; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3115 double aa = (alpha & 0xFF) / cast(double)0xFF; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3116 double red = ((color.red & 0xFFFF) / cast(double)0xFFFF); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3117 double green = ((color.green & 0xFFFF) / cast(double)0xFFFF); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3118 double blue = ((color.blue & 0xFFFF) / cast(double)0xFFFF); |
18 | 3119 Cairo.cairo_pattern_add_color_stop_rgba(pattern, offset, red, green, blue, aa); |
3120 } | |
3121 | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3122 void setClipping(GdkRegion* clipRgn) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3123 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3124 if (clipRgn is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3125 if (data.clipRgn !is null) { |
18 | 3126 OS.gdk_region_destroy(data.clipRgn); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3127 data.clipRgn = null; |
18 | 3128 } |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3129 if (cairo !is null) { |
18 | 3130 data.clippingTransform = null; |
3131 setCairoClip(cairo, clipRgn); | |
3132 } else { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3133 auto clipping = data.damageRgn !is null ? data.damageRgn : null; |
18 | 3134 OS.gdk_gc_set_clip_region(handle, clipping); |
3135 } | |
3136 } else { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3137 if (data.clipRgn is null) data.clipRgn = OS.gdk_region_new(); |
18 | 3138 OS.gdk_region_subtract(data.clipRgn, data.clipRgn); |
3139 OS.gdk_region_union(data.clipRgn, clipRgn); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3140 if (cairo !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3141 if (data.clippingTransform is null) data.clippingTransform = new double[6]; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3142 Cairo.cairo_get_matrix(cairo,cast(cairo_matrix_t *) data.clippingTransform.ptr); |
18 | 3143 setCairoClip(cairo, clipRgn); |
3144 } else { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3145 auto clipping = clipRgn; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3146 if (data.damageRgn !is null) { |
18 | 3147 clipping = OS.gdk_region_new(); |
3148 OS.gdk_region_union(clipping, clipRgn); | |
3149 OS.gdk_region_intersect(clipping, data.damageRgn); | |
3150 } | |
3151 OS.gdk_gc_set_clip_region(handle, clipping); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3152 if (clipping !is clipRgn) OS.gdk_region_destroy(clipping); |
18 | 3153 } |
3154 } | |
3155 } | |
3156 | |
3157 /** | |
3158 * Sets the area of the receiver which can be changed | |
3159 * by drawing operations to the rectangular area specified | |
3160 * by the arguments. | |
3161 * | |
3162 * @param x the x coordinate of the clipping rectangle | |
3163 * @param y the y coordinate of the clipping rectangle | |
3164 * @param width the width of the clipping rectangle | |
3165 * @param height the height of the clipping rectangle | |
3166 * | |
3167 * @exception SWTException <ul> | |
3168 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3169 * </ul> | |
3170 */ | |
3171 public void setClipping(int x, int y, int width, int height) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3172 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 3173 if (width < 0) { |
3174 x = x + width; | |
3175 width = -width; | |
3176 } | |
3177 if (height < 0) { | |
3178 y = y + height; | |
3179 height = -height; | |
3180 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3181 GdkRectangle* rect = new GdkRectangle(); |
18 | 3182 rect.x = x; |
3183 rect.y = y; | |
3184 rect.width = width; | |
3185 rect.height = height; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3186 auto clipRgn = OS.gdk_region_new(); |
18 | 3187 OS.gdk_region_union_with_rect(clipRgn, rect); |
3188 setClipping(clipRgn); | |
3189 OS.gdk_region_destroy(clipRgn); | |
3190 } | |
3191 | |
3192 /** | |
3193 * Sets the area of the receiver which can be changed | |
3194 * by drawing operations to the path specified | |
3195 * by the argument. | |
3196 * <p> | |
3197 * This operation requires the operating system's advanced | |
3198 * graphics subsystem which may not be available on some | |
3199 * platforms. | |
3200 * </p> | |
3201 * | |
3202 * @param path the clipping path. | |
3203 * | |
3204 * @exception IllegalArgumentException <ul> | |
3205 * <li>ERROR_INVALID_ARGUMENT - if the path has been disposed</li> | |
3206 * </ul> | |
3207 * @exception SWTException <ul> | |
3208 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3209 * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> | |
3210 * </ul> | |
3211 * | |
3212 * @see Path | |
3213 * @see #getAdvanced | |
3214 * @see #setAdvanced | |
3215 * | |
3216 * @since 3.1 | |
3217 */ | |
3218 public void setClipping(Path path) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3219 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3220 if (path !is null && path.isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3221 setClipping(cast(GdkRegion*)null); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3222 if (path !is null) { |
18 | 3223 initCairo(); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3224 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3225 auto copy = Cairo.cairo_copy_path(path.handle); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3226 if (copy is null) SWT.error(SWT.ERROR_NO_HANDLES); |
18 | 3227 Cairo.cairo_append_path(cairo, copy); |
3228 Cairo.cairo_path_destroy(copy); | |
3229 Cairo.cairo_clip(cairo); | |
3230 } | |
3231 } | |
3232 | |
3233 /** | |
3234 * Sets the area of the receiver which can be changed | |
3235 * by drawing operations to the rectangular area specified | |
3236 * by the argument. Specifying <code>null</code> for the | |
3237 * rectangle reverts the receiver's clipping area to its | |
3238 * original value. | |
3239 * | |
3240 * @param rect the clipping rectangle or <code>null</code> | |
3241 * | |
3242 * @exception SWTException <ul> | |
3243 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3244 * </ul> | |
3245 */ | |
3246 public void setClipping(Rectangle rect) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3247 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3248 if (rect is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3249 setClipping(cast(GdkRegion*)null); |
18 | 3250 } else { |
3251 setClipping(rect.x, rect.y, rect.width, rect.height); | |
3252 } | |
3253 } | |
3254 /** | |
3255 * Sets the area of the receiver which can be changed | |
3256 * by drawing operations to the region specified | |
3257 * by the argument. Specifying <code>null</code> for the | |
3258 * region reverts the receiver's clipping area to its | |
3259 * original value. | |
3260 * | |
3261 * @param region the clipping region or <code>null</code> | |
3262 * | |
3263 * @exception IllegalArgumentException <ul> | |
3264 * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li> | |
3265 * </ul> | |
3266 * @exception SWTException <ul> | |
3267 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3268 * </ul> | |
3269 */ | |
3270 public void setClipping(Region region) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3271 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3272 if (region !is null && region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3273 setClipping(region !is null ? region.handle : cast(GdkRegion*)null); |
18 | 3274 } |
3275 | |
3276 /** | |
3277 * Sets the font which will be used by the receiver | |
3278 * to draw and measure text to the argument. If the | |
3279 * argument is null, then a default font appropriate | |
3280 * for the platform will be used instead. | |
3281 * | |
3282 * @param font the new font for the receiver, or null to indicate a default font | |
3283 * | |
3284 * @exception IllegalArgumentException <ul> | |
3285 * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li> | |
3286 * </ul> | |
3287 * @exception SWTException <ul> | |
3288 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3289 * </ul> | |
3290 */ | |
3291 public void setFont(Font font) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3292 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3293 if (font is null) font = data.device.systemFont; |
18 | 3294 if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
3295 data.font = font.handle; | |
3296 data.state &= ~FONT; | |
3297 data.stringWidth = data.stringHeight = -1; | |
3298 } | |
3299 | |
3300 /** | |
3301 * Sets the receiver's fill rule to the parameter, which must be one of | |
3302 * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>. | |
3303 * | |
3304 * @param rule the new fill rule | |
3305 * | |
3306 * @exception IllegalArgumentException <ul> | |
3307 * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of <code>SWT.FILL_EVEN_ODD</code> | |
3308 * or <code>SWT.FILL_WINDING</code></li> | |
3309 * </ul> | |
3310 * @exception SWTException <ul> | |
3311 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3312 * </ul> | |
3313 * | |
3314 * @since 3.1 | |
3315 */ | |
3316 public void setFillRule(int rule) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3317 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 3318 int cairo_mode = Cairo.CAIRO_FILL_RULE_EVEN_ODD; |
3319 switch (rule) { | |
3320 case SWT.FILL_WINDING: | |
3321 cairo_mode = Cairo.CAIRO_FILL_RULE_WINDING; break; | |
3322 case SWT.FILL_EVEN_ODD: | |
3323 cairo_mode = Cairo.CAIRO_FILL_RULE_EVEN_ODD; break; | |
3324 default: | |
3325 SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
3326 } | |
3327 //TODO - need fill rule in X, GDK has no API | |
3328 initCairo(); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3329 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3330 if (cairo !is null) { |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
3331 Cairo.cairo_set_fill_rule(cairo, cairo_mode); |
18 | 3332 } |
3333 } | |
3334 | |
3335 /** | |
3336 * Sets the foreground color. The foreground color is used | |
3337 * for drawing operations including when text is drawn. | |
3338 * | |
3339 * @param color the new foreground color for the receiver | |
3340 * | |
3341 * @exception IllegalArgumentException <ul> | |
3342 * <li>ERROR_NULL_ARGUMENT - if the color is null</li> | |
3343 * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li> | |
3344 * </ul> | |
3345 * @exception SWTException <ul> | |
3346 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3347 * </ul> | |
3348 */ | |
3349 public void setForeground(Color color) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3350 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3351 if (color is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
18 | 3352 if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
3353 data.foreground = color.handle; | |
3354 data.foregroundPattern = null; | |
3355 data.state &= ~FOREGROUND; | |
3356 } | |
3357 | |
3358 /** | |
3359 * Sets the foreground pattern. The default value is <code>null</code>. | |
3360 * <p> | |
3361 * This operation requires the operating system's advanced | |
3362 * graphics subsystem which may not be available on some | |
3363 * platforms. | |
3364 * </p> | |
3365 * @param pattern the new foreground pattern | |
3366 * | |
3367 * @exception IllegalArgumentException <ul> | |
3368 * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li> | |
3369 * </ul> | |
3370 * @exception SWTException <ul> | |
3371 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3372 * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> | |
3373 * </ul> | |
3374 * | |
3375 * @see Pattern | |
3376 * @see #getAdvanced | |
3377 * @see #setAdvanced | |
3378 * | |
3379 * @since 3.1 | |
3380 */ | |
3381 public void setForegroundPattern(Pattern pattern) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3382 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3383 if (pattern !is null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3384 if (data.cairo is null && pattern is null) return; |
18 | 3385 initCairo(); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3386 if (data.foregroundPattern is pattern) return; |
18 | 3387 data.foregroundPattern = pattern; |
3388 data.state &= ~FOREGROUND; | |
3389 } | |
3390 | |
3391 /** | |
3392 * Sets the receiver's interpolation setting to the parameter, which | |
3393 * must be one of <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>, | |
3394 * <code>SWT.LOW</code> or <code>SWT.HIGH</code>. | |
3395 * <p> | |
3396 * This operation requires the operating system's advanced | |
3397 * graphics subsystem which may not be available on some | |
3398 * platforms. | |
3399 * </p> | |
3400 * | |
3401 * @param interpolation the new interpolation setting | |
3402 * | |
3403 * @exception IllegalArgumentException <ul> | |
3404 * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of <code>SWT.DEFAULT</code>, | |
3405 * <code>SWT.NONE</code>, <code>SWT.LOW</code> or <code>SWT.HIGH</code> | |
3406 * </ul> | |
3407 * @exception SWTException <ul> | |
3408 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3409 * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> | |
3410 * </ul> | |
3411 * | |
3412 * @see #getAdvanced | |
3413 * @see #setAdvanced | |
3414 * | |
3415 * @since 3.1 | |
3416 */ | |
3417 public void setInterpolation(int interpolation) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3418 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3419 if (data.cairo is null && interpolation is SWT.DEFAULT) return; |
18 | 3420 switch (interpolation) { |
3421 case SWT.DEFAULT: | |
3422 case SWT.NONE: | |
3423 case SWT.LOW: | |
3424 case SWT.HIGH: | |
3425 break; | |
3426 default: | |
3427 SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
3428 } | |
3429 initCairo(); | |
3430 data.interpolation = interpolation; | |
3431 } | |
3432 | |
3433 /** | |
3434 * Sets the receiver's line attributes. | |
3435 * <p> | |
3436 * This operation requires the operating system's advanced | |
3437 * graphics subsystem which may not be available on some | |
3438 * platforms. | |
3439 * </p> | |
3440 * @param attributes the line attributes | |
3441 * | |
3442 * @exception IllegalArgumentException <ul> | |
3443 * <li>ERROR_NULL_ARGUMENT - if the attributes is null</li> | |
3444 * <li>ERROR_INVALID_ARGUMENT - if any of the line attributes is not valid</li> | |
3445 * </ul> | |
3446 * @exception SWTException <ul> | |
3447 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3448 * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> | |
3449 * </ul> | |
3450 * | |
3451 * @see LineAttributes | |
3452 * @see #getAdvanced | |
3453 * @see #setAdvanced | |
3454 * | |
3455 * @since 3.3 | |
3456 */ | |
3457 public void setLineAttributes(LineAttributes attributes) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3458 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3459 if (attributes is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
18 | 3460 int mask = 0; |
3461 float lineWidth = attributes.width; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3462 if (lineWidth !is data.lineWidth) { |
18 | 3463 mask |= LINE_WIDTH | DRAW_OFFSET; |
3464 } | |
3465 int lineStyle = attributes.style; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3466 if (lineStyle !is data.lineStyle) { |
18 | 3467 mask |= LINE_STYLE; |
3468 switch (lineStyle) { | |
3469 case SWT.LINE_SOLID: | |
3470 case SWT.LINE_DASH: | |
3471 case SWT.LINE_DOT: | |
3472 case SWT.LINE_DASHDOT: | |
3473 case SWT.LINE_DASHDOTDOT: | |
3474 break; | |
3475 case SWT.LINE_CUSTOM: | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3476 if (attributes.dash is null) lineStyle = SWT.LINE_SOLID; |
18 | 3477 break; |
3478 default: | |
3479 SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
3480 } | |
3481 } | |
3482 int join = attributes.join; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3483 if (join !is data.lineJoin) { |
18 | 3484 mask |= LINE_JOIN; |
3485 switch (join) { | |
3486 case SWT.CAP_ROUND: | |
3487 case SWT.CAP_FLAT: | |
3488 case SWT.CAP_SQUARE: | |
3489 break; | |
3490 default: | |
3491 SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
3492 } | |
3493 } | |
3494 int cap = attributes.join; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3495 if (cap !is data.lineCap) { |
18 | 3496 mask |= LINE_CAP; |
3497 switch (cap) { | |
3498 case SWT.JOIN_MITER: | |
3499 case SWT.JOIN_ROUND: | |
3500 case SWT.JOIN_BEVEL: | |
3501 break; | |
3502 default: | |
3503 SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
3504 } | |
3505 } | |
3506 float[] dashes = attributes.dash; | |
3507 float[] lineDashes = data.lineDashes; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3508 if (dashes !is null && dashes.length > 0) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3509 bool changed = lineDashes is null || lineDashes.length !is dashes.length; |
18 | 3510 for (int i = 0; i < dashes.length; i++) { |
3511 float dash = dashes[i]; | |
3512 if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3513 if (!changed && lineDashes[i] !is dash) changed = true; |
18 | 3514 } |
3515 if (changed) { | |
25
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
24
diff
changeset
|
3516 float[] newDashes = new float[dashes.length]; |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
24
diff
changeset
|
3517 System.arraycopy(dashes, 0, newDashes, 0, dashes.length); |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
24
diff
changeset
|
3518 dashes = newDashes; |
18 | 3519 mask |= LINE_STYLE; |
3520 } else { | |
3521 dashes = lineDashes; | |
3522 } | |
3523 } else { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3524 if (lineDashes !is null && lineDashes.length > 0) { |
18 | 3525 mask |= LINE_STYLE; |
3526 } else { | |
3527 dashes = lineDashes; | |
3528 } | |
3529 } | |
3530 float dashOffset = attributes.dashOffset; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3531 if (dashOffset !is data.lineDashesOffset) { |
18 | 3532 mask |= LINE_STYLE; |
3533 } | |
3534 float miterLimit = attributes.miterLimit; | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3535 if (miterLimit !is data.lineMiterLimit) { |
18 | 3536 mask |= LINE_MITERLIMIT; |
3537 } | |
3538 initCairo(); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3539 if (mask is 0) return; |
18 | 3540 data.lineWidth = lineWidth; |
3541 data.lineStyle = lineStyle; | |
3542 data.lineCap = cap; | |
3543 data.lineJoin = join; | |
3544 data.lineDashes = dashes; | |
3545 data.lineDashesOffset = dashOffset; | |
3546 data.lineMiterLimit = miterLimit; | |
3547 data.state &= ~mask; | |
3548 } | |
3549 | |
3550 /** | |
3551 * Sets the receiver's line cap style to the argument, which must be one | |
3552 * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>, | |
3553 * or <code>SWT.CAP_SQUARE</code>. | |
3554 * | |
3555 * @param cap the cap style to be used for drawing lines | |
3556 * | |
3557 * @exception IllegalArgumentException <ul> | |
3558 * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li> | |
3559 * </ul> | |
3560 * @exception SWTException <ul> | |
3561 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3562 * </ul> | |
3563 * | |
3564 * @since 3.1 | |
3565 */ | |
3566 public void setLineCap(int cap) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3567 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3568 if (data.lineCap is cap) return; |
18 | 3569 switch (cap) { |
3570 case SWT.CAP_ROUND: | |
3571 case SWT.CAP_FLAT: | |
3572 case SWT.CAP_SQUARE: | |
3573 break; | |
3574 default: | |
3575 SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
3576 } | |
3577 data.lineCap = cap; | |
3578 data.state &= ~LINE_CAP; | |
3579 } | |
3580 | |
3581 /** | |
3582 * Sets the receiver's line dash style to the argument. The default | |
3583 * value is <code>null</code>. If the argument is not <code>null</code>, | |
3584 * the receiver's line style is set to <code>SWT.LINE_CUSTOM</code>, otherwise | |
3585 * it is set to <code>SWT.LINE_SOLID</code>. | |
3586 * | |
3587 * @param dashes the dash style to be used for drawing lines | |
3588 * | |
3589 * @exception IllegalArgumentException <ul> | |
3590 * <li>ERROR_INVALID_ARGUMENT - if any of the values in the array is less than or equal 0</li> | |
3591 * </ul> | |
3592 * @exception SWTException <ul> | |
3593 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3594 * </ul> | |
3595 * | |
3596 * @since 3.1 | |
3597 */ | |
3598 public void setLineDash(int[] dashes) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3599 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
18 | 3600 float[] lineDashes = data.lineDashes; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3601 if (dashes !is null && dashes.length > 0) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3602 bool changed = data.lineStyle !is SWT.LINE_CUSTOM || lineDashes is null || lineDashes.length !is dashes.length; |
18 | 3603 for (int i = 0; i < dashes.length; i++) { |
3604 int dash = dashes[i]; | |
3605 if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3606 if (!changed && lineDashes[i] !is dash) changed = true; |
18 | 3607 } |
3608 if (!changed) return; | |
3609 data.lineDashes = new float[dashes.length]; | |
3610 for (int i = 0; i < dashes.length; i++) { | |
3611 data.lineDashes[i] = dashes[i]; | |
3612 } | |
3613 data.lineStyle = SWT.LINE_CUSTOM; | |
3614 } else { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3615 if (data.lineStyle is SWT.LINE_SOLID && (lineDashes is null || lineDashes.length is 0)) return; |
18 | 3616 data.lineDashes = null; |
3617 data.lineStyle = SWT.LINE_SOLID; | |
3618 } | |
3619 data.state &= ~LINE_STYLE; | |
3620 } | |
3621 | |
3622 /** | |
3623 * Sets the receiver's line join style to the argument, which must be one | |
3624 * of the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>, | |
3625 * or <code>SWT.JOIN_BEVEL</code>. | |
3626 * | |
3627 * @param join the join style to be used for drawing lines | |
3628 * | |
3629 * @exception IllegalArgumentException <ul> | |
3630 * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li> | |
3631 * </ul> | |
3632 * @exception SWTException <ul> | |
3633 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3634 * </ul> | |
3635 * | |
3636 * @since 3.1 | |
3637 */ | |
3638 public void setLineJoin(int join) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3639 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3640 if (data.lineJoin is join) return; |
18 | 3641 switch (join) { |
3642 case SWT.JOIN_MITER: | |
3643 case SWT.JOIN_ROUND: | |
3644 case SWT.JOIN_BEVEL: | |
3645 break; | |
3646 default: | |
3647 SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
3648 } | |
3649 data.lineJoin = join; | |
3650 data.state &= ~LINE_JOIN; | |
3651 } | |
3652 | |
3653 /** | |
3654 * Sets the receiver's line style to the argument, which must be one | |
3655 * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>, | |
3656 * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or | |
3657 * <code>SWT.LINE_DASHDOTDOT</code>. | |
3658 * | |
3659 * @param lineStyle the style to be used for drawing lines | |
3660 * | |
3661 * @exception IllegalArgumentException <ul> | |
3662 * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li> | |
3663 * </ul> | |
3664 * @exception SWTException <ul> | |
3665 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3666 * </ul> | |
3667 */ | |
3668 public void setLineStyle(int lineStyle) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3669 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3670 if (data.lineStyle is lineStyle) return; |
18 | 3671 switch (lineStyle) { |
3672 case SWT.LINE_SOLID: | |
3673 case SWT.LINE_DASH: | |
3674 case SWT.LINE_DOT: | |
3675 case SWT.LINE_DASHDOT: | |
3676 case SWT.LINE_DASHDOTDOT: | |
3677 break; | |
3678 case SWT.LINE_CUSTOM: | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3679 if (data.lineDashes is null) lineStyle = SWT.LINE_SOLID; |
18 | 3680 break; |
3681 default: | |
3682 SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
3683 } | |
3684 data.lineStyle = lineStyle; | |
3685 data.state &= ~LINE_STYLE; | |
3686 } | |
3687 | |
3688 /** | |
3689 * Sets the width that will be used when drawing lines | |
3690 * for all of the figure drawing operations (that is, | |
3691 * <code>drawLine</code>, <code>drawRectangle</code>, | |
3692 * <code>drawPolyline</code>, and so forth. | |
3693 * <p> | |
3694 * Note that line width of zero is used as a hint to | |
3695 * indicate that the fastest possible line drawing | |
3696 * algorithms should be used. This means that the | |
3697 * output may be different from line width one. | |
3698 * </p> | |
3699 * | |
3700 * @param lineWidth the width of a line | |
3701 * | |
3702 * @exception SWTException <ul> | |
3703 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3704 * </ul> | |
3705 */ | |
3706 public void setLineWidth(int lineWidth) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3707 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3708 if (data.lineWidth is lineWidth) return; |
18 | 3709 data.lineWidth = lineWidth; |
3710 data.state &= ~(LINE_WIDTH | DRAW_OFFSET); | |
3711 } | |
3712 | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3713 void setString(char[] str, int flags) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3714 if (data.layout is null) createLayout(); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3715 if (str is data.str && (flags & ~SWT.DRAW_TRANSPARENT) is (data.drawFlags & ~SWT.DRAW_TRANSPARENT)) { |
18 | 3716 return; |
3717 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3718 char[] buffer; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3719 int mnemonic, len = str.length ; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3720 auto layout = data.layout; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3721 char[] text = str.dup; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3722 if ((flags & SWT.DRAW_MNEMONIC) !is 0 && (mnemonic = fixMnemonic(text)) !is -1) { |
18 | 3723 char[] text1 = new char[mnemonic - 1]; |
25
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
24
diff
changeset
|
3724 System.arraycopy(text, 0, text1, 0, text1.length); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3725 char[] buffer1 = text1.dup; |
18 | 3726 char[] text2 = new char[text.length - mnemonic]; |
25
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
24
diff
changeset
|
3727 System.arraycopy(text, mnemonic - 1, text2, 0, text2.length); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3728 char[] buffer2 = text2.dup; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3729 buffer = new char[buffer1.length + buffer2.length]; |
25
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
24
diff
changeset
|
3730 System.arraycopy(buffer1, 0, buffer, 0, buffer1.length); |
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
24
diff
changeset
|
3731 System.arraycopy(buffer2, 0, buffer, buffer1.length, buffer2.length); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3732 auto attr_list = OS.pango_attr_list_new(); |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
3733 auto attr = OS.pango_attr_underline_new(OS.PANGO_UNDERLINE_LOW); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3734 attr.start_index = buffer1.length; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3735 attr.end_index = buffer1.length + 1; |
18 | 3736 OS.pango_attr_list_insert(attr_list, attr); |
3737 OS.pango_layout_set_attributes(layout, attr_list); | |
3738 OS.pango_attr_list_unref(attr_list); | |
3739 } else { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3740 buffer = text.dup; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3741 OS.pango_layout_set_attributes(layout, null); |
18 | 3742 } |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3743 OS.pango_layout_set_text(layout, buffer.ptr, buffer.length); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3744 OS.pango_layout_set_single_paragraph_mode(layout, (flags & SWT.DRAW_DELIMITER) is 0); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3745 OS.pango_layout_set_tabs(layout, (flags & SWT.DRAW_TAB) !is 0 ? null : data.device.emptyTab); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3746 data.str = str; |
18 | 3747 data.stringWidth = data.stringHeight = -1; |
3748 data.drawFlags = flags; | |
3749 } | |
3750 | |
3751 /** | |
3752 * Sets the receiver's text anti-aliasing value to the parameter, | |
3753 * which must be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> | |
3754 * or <code>SWT.ON</code>. Note that this controls anti-aliasing only | |
3755 * for all <em>text drawing</em> operations. | |
3756 * <p> | |
3757 * This operation requires the operating system's advanced | |
3758 * graphics subsystem which may not be available on some | |
3759 * platforms. | |
3760 * </p> | |
3761 * | |
3762 * @param antialias the anti-aliasing setting | |
3763 * | |
3764 * @exception IllegalArgumentException <ul> | |
3765 * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one of <code>SWT.DEFAULT</code>, | |
3766 * <code>SWT.OFF</code> or <code>SWT.ON</code></li> | |
3767 * </ul> | |
3768 * @exception SWTException <ul> | |
3769 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3770 * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> | |
3771 * </ul> | |
3772 * | |
3773 * @see #getAdvanced | |
3774 * @see #setAdvanced | |
3775 * @see #setAntialias | |
3776 * | |
3777 * @since 3.1 | |
3778 */ | |
3779 public void setTextAntialias(int antialias) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3780 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3781 if (data.cairo is null && antialias is SWT.DEFAULT) return; |
18 | 3782 int mode = 0; |
3783 switch (antialias) { | |
3784 case SWT.DEFAULT: mode = Cairo.CAIRO_ANTIALIAS_DEFAULT; break; | |
3785 case SWT.OFF: mode = Cairo.CAIRO_ANTIALIAS_NONE; break; | |
3786 case SWT.ON: mode = Cairo.CAIRO_ANTIALIAS_GRAY; | |
3787 break; | |
3788 default: | |
3789 SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
3790 } | |
3791 initCairo(); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3792 auto options = Cairo.cairo_font_options_create(); |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
3793 Cairo.cairo_font_options_set_antialias(options, mode); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3794 if (OS.GTK_VERSION < OS.buildVERSION(2, 8, 0)) { |
18 | 3795 Cairo.cairo_set_font_options(data.cairo, options); |
3796 } else { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3797 if (data.context is null) createLayout(); |
18 | 3798 OS.pango_cairo_context_set_font_options(data.context, options); |
3799 } | |
3800 Cairo.cairo_font_options_destroy(options); | |
3801 } | |
3802 | |
3803 /** | |
3804 * Sets the transform that is currently being used by the receiver. If | |
3805 * the argument is <code>null</code>, the current transform is set to | |
3806 * the identity transform. | |
3807 * <p> | |
3808 * This operation requires the operating system's advanced | |
3809 * graphics subsystem which may not be available on some | |
3810 * platforms. | |
3811 * </p> | |
3812 * | |
3813 * @param transform the transform to set | |
3814 * | |
3815 * @exception IllegalArgumentException <ul> | |
3816 * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li> | |
3817 * </ul> | |
3818 * @exception SWTException <ul> | |
3819 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3820 * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> | |
3821 * </ul> | |
3822 * | |
3823 * @see Transform | |
3824 * @see #getAdvanced | |
3825 * @see #setAdvanced | |
3826 * | |
3827 * @since 3.1 | |
3828 */ | |
3829 public void setTransform(Transform transform) { | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3830 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3831 if (transform !is null && transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3832 if (data.cairo is null && transform is null) return; |
18 | 3833 initCairo(); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3834 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3835 if (transform !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3836 Cairo.cairo_set_matrix(cairo,cast(cairo_matrix_t*) transform.handle.ptr); |
18 | 3837 } else { |
3838 Cairo.cairo_identity_matrix(cairo); | |
3839 } | |
3840 data.state &= ~DRAW_OFFSET; | |
3841 } | |
3842 | |
3843 /** | |
3844 * If the argument is <code>true</code>, puts the receiver | |
3845 * in a drawing mode where the resulting color in the destination | |
3846 * is the <em>exclusive or</em> of the color values in the source | |
3847 * and the destination, and if the argument is <code>false</code>, | |
3848 * puts the receiver in a drawing mode where the destination color | |
3849 * is replaced with the source color value. | |
3850 * <p> | |
3851 * Note that this mode in fundamentally unsupportable on certain | |
3852 * platforms, notably Carbon (Mac OS X). Clients that want their | |
3853 * code to run on all platforms need to avoid this method. | |
3854 * </p> | |
3855 * | |
3856 * @param xor if <code>true</code>, then <em>xor</em> mode is used, otherwise <em>source copy</em> mode is used | |
3857 * | |
3858 * @exception SWTException <ul> | |
3859 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3860 * </ul> | |
3861 * | |
3862 * @deprecated this functionality is not supported on some platforms | |
3863 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3864 public void setXORMode(bool xor) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3865 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
33
27324bbbac70
changed to regenerated BCD bindings
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
3866 OS.gdk_gc_set_function(handle, xor ? OS.GDK_XOR : OS.GDK_COPY); |
18 | 3867 data.xorMode = xor; |
3868 } | |
3869 | |
3870 /** | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3871 * Returns the extent of the given str. No tab |
18 | 3872 * expansion or carriage return processing will be performed. |
3873 * <p> | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3874 * The <em>extent</em> of a str is the width and height of |
18 | 3875 * the rectangular area it would cover if drawn in a particular |
3876 * font (in this case, the current font in the receiver). | |
3877 * </p> | |
3878 * | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3879 * @param str the str to measure |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3880 * @return a point containing the extent of the str |
18 | 3881 * |
3882 * @exception IllegalArgumentException <ul> | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3883 * <li>ERROR_NULL_ARGUMENT - if the str is null</li> |
18 | 3884 * </ul> |
3885 * @exception SWTException <ul> | |
3886 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3887 * </ul> | |
3888 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3889 public Point stringExtent(char[] str) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3890 return textExtent(str, 0); |
18 | 3891 } |
3892 | |
3893 /** | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3894 * Returns the extent of the given str. Tab expansion and |
18 | 3895 * carriage return processing are performed. |
3896 * <p> | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3897 * The <em>extent</em> of a str is the width and height of |
18 | 3898 * the rectangular area it would cover if drawn in a particular |
3899 * font (in this case, the current font in the receiver). | |
3900 * </p> | |
3901 * | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3902 * @param str the str to measure |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3903 * @return a point containing the extent of the str |
18 | 3904 * |
3905 * @exception IllegalArgumentException <ul> | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3906 * <li>ERROR_NULL_ARGUMENT - if the str is null</li> |
18 | 3907 * </ul> |
3908 * @exception SWTException <ul> | |
3909 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3910 * </ul> | |
3911 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3912 public Point textExtent(char[] str) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3913 return textExtent(str, SWT.DRAW_DELIMITER | SWT.DRAW_TAB); |
18 | 3914 } |
3915 | |
3916 /** | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3917 * Returns the extent of the given str. Tab expansion, line |
18 | 3918 * delimiter and mnemonic processing are performed according to |
3919 * the specified flags, which can be a combination of: | |
3920 * <dl> | |
3921 * <dt><b>DRAW_DELIMITER</b></dt> | |
3922 * <dd>draw multiple lines</dd> | |
3923 * <dt><b>DRAW_TAB</b></dt> | |
3924 * <dd>expand tabs</dd> | |
3925 * <dt><b>DRAW_MNEMONIC</b></dt> | |
3926 * <dd>underline the mnemonic character</dd> | |
3927 * <dt><b>DRAW_TRANSPARENT</b></dt> | |
3928 * <dd>transparent background</dd> | |
3929 * </dl> | |
3930 * <p> | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3931 * The <em>extent</em> of a str is the width and height of |
18 | 3932 * the rectangular area it would cover if drawn in a particular |
3933 * font (in this case, the current font in the receiver). | |
3934 * </p> | |
3935 * | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3936 * @param str the str to measure |
18 | 3937 * @param flags the flags specifying how to process the text |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3938 * @return a point containing the extent of the str |
18 | 3939 * |
3940 * @exception IllegalArgumentException <ul> | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3941 * <li>ERROR_NULL_ARGUMENT - if the str is null</li> |
18 | 3942 * </ul> |
3943 * @exception SWTException <ul> | |
3944 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
3945 * </ul> | |
3946 */ | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3947 public Point textExtent(char[] str, int flags) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3948 if (handle is null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3949 if (str is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3950 auto cairo = data.cairo; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3951 if (cairo !is null) { |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3952 if (OS.GTK_VERSION < OS.buildVERSION(2, 8, 0)) { |
18 | 3953 //TODO - honor flags |
3954 checkGC(FONT); | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3955 char[] buffer = str.dup; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3956 cairo_font_extents_t* font_extents = new cairo_font_extents_t(); |
18 | 3957 Cairo.cairo_font_extents(cairo, font_extents); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3958 cairo_text_extents_t* extents = new cairo_text_extents_t(); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3959 Cairo.cairo_text_extents(cairo, buffer.ptr, extents); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3960 return new Point(cast(int)extents.width, cast(int)font_extents.height); |
18 | 3961 } |
3962 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3963 setString(str, flags); |
18 | 3964 checkGC(FONT); |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3965 if (data.stringWidth !is -1) return new Point(data.stringWidth, data.stringHeight); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3966 int width, height; |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3967 OS.pango_layout_get_size(data.layout, &width, &height); |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3968 return new Point(data.stringWidth = OS.PANGO_PIXELS(width), data.stringHeight = OS.PANGO_PIXELS(height)); |
18 | 3969 } |
3970 | |
3971 /** | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3972 * Returns a str containing a concise, human-readable |
18 | 3973 * description of the receiver. |
3974 * | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3975 * @return a str representation of the receiver |
18 | 3976 */ |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3977 public char[] toString () { |
18 | 3978 if (isDisposed()) return "GC {*DISPOSED*}"; |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3979 return Format( "GC {{{}}", handle ); |
18 | 3980 } |
3981 | |
3982 } | |
24
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3983 |
bc06000c0816
TextLayout and GC, graphics complete
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
3984 |