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