Mercurial > projects > dwt2
comparison org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet294.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 | 9f4c18c268b2 |
children |
comparison
equal
deleted
inserted
replaced
119:d00e8db0a568 | 120:536e43f63c81 |
---|---|
10 * D Port: | 10 * D Port: |
11 * Thomas Demmer <t_demmer AT web DOT de> | 11 * Thomas Demmer <t_demmer AT web DOT de> |
12 *******************************************************************************/ | 12 *******************************************************************************/ |
13 module org.eclipse.swt.snippets.Snippet294; | 13 module org.eclipse.swt.snippets.Snippet294; |
14 | 14 |
15 /* Port OK */ | 15 /* |
16 * Region on a control: create a non-rectangular button | |
17 * | |
18 * For a list of all SWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 * | |
21 * @since 3.4 | |
22 */ | |
16 import org.eclipse.swt.SWT; | 23 import org.eclipse.swt.SWT; |
17 import org.eclipse.swt.graphics.Image; | 24 import org.eclipse.swt.graphics.Image; |
18 import org.eclipse.swt.graphics.Region; | 25 import org.eclipse.swt.graphics.Region; |
19 import org.eclipse.swt.layout.FillLayout; | 26 import org.eclipse.swt.layout.FillLayout; |
20 import org.eclipse.swt.widgets.Button; | 27 import org.eclipse.swt.widgets.Button; |
28 import tango.util.Convert; | 35 import tango.util.Convert; |
29 } else { // Phobos | 36 } else { // Phobos |
30 import std.conv; | 37 import std.conv; |
31 } | 38 } |
32 | 39 |
33 void main(String[] args){ | 40 int[] circle(int r, int offsetX, int offsetY) { |
34 Snippet294.main(args); | 41 int[] polygon = new int[8 * r + 4]; |
42 // x^2 + y^2 = r^2 | |
43 for (int i = 0; i < 2 * r + 1; i++) { | |
44 int x = i - r; | |
45 int y = cast(int)Math.sqrt(cast(real)(r*r - x*x)); | |
46 polygon[2*i] = offsetX + x; | |
47 polygon[2*i+1] = offsetY + y; | |
48 polygon[8*r - 2*i - 2] = offsetX + x; | |
49 polygon[8*r - 2*i - 1] = offsetY - y; | |
50 } | |
51 return polygon; | |
35 } | 52 } |
36 | 53 |
37 /* | 54 void main() { |
38 * Region on a control: create a non-rectangular button | 55 Display display = new Display(); |
39 * | 56 Shell shell = new Shell(display); |
40 * For a list of all SWT example snippets see | 57 shell.setText("Regions on a Control"); |
41 * http://www.eclipse.org/swt/snippets/ | 58 shell.setLayout(new FillLayout()); |
42 * | 59 shell.setBackground(display.getSystemColor(SWT.COLOR_DARK_RED)); |
43 * @since 3.4 | |
44 */ | |
45 | 60 |
46 public class Snippet294 { | 61 Button b2 = new Button(shell, SWT.PUSH); |
62 b2.setText("Button with Regions"); | |
47 | 63 |
48 static int[] circle(int r, int offsetX, int offsetY) { | 64 // define a region that looks like a circle with two holes in ot |
49 int[] polygon = new int[8 * r + 4]; | 65 Region region = new Region(); |
50 // x^2 + y^2 = r^2 | 66 region.add(circle(67, 87, 77)); |
51 for (int i = 0; i < 2 * r + 1; i++) { | 67 region.subtract(circle(20, 87, 47)); |
52 int x = i - r; | 68 region.subtract(circle(20, 87, 113)); |
53 int y = cast(int)Math.sqrt(cast(real)(r*r - x*x)); | 69 |
54 polygon[2*i] = offsetX + x; | 70 // define the shape of the button using setRegion |
55 polygon[2*i+1] = offsetY + y; | 71 b2.setRegion(region); |
56 polygon[8*r - 2*i - 2] = offsetX + x; | 72 b2.setLocation(100,50); |
57 polygon[8*r - 2*i - 1] = offsetY - y; | 73 |
74 b2.addListener(SWT.Selection, new class Listener { | |
75 public void handleEvent(Event e) { | |
76 shell.close(); | |
58 } | 77 } |
59 return polygon; | 78 }); |
79 | |
80 shell.setSize(200,200); | |
81 shell.open(); | |
82 | |
83 while (!shell.isDisposed()) { | |
84 if (!display.readAndDispatch()) | |
85 display.sleep(); | |
60 } | 86 } |
61 | 87 region.dispose(); |
62 public static void main(String[] args) { | 88 display.dispose(); |
63 Display display = new Display(); | |
64 Shell shell = new Shell(display); | |
65 shell.setText("Regions on a Control"); | |
66 shell.setLayout(new FillLayout()); | |
67 shell.setBackground(display.getSystemColor(SWT.COLOR_DARK_RED)); | |
68 | |
69 Button b2 = new Button(shell, SWT.PUSH); | |
70 b2.setText("Button with Regions"); | |
71 | |
72 // define a region that looks like a circle with two holes in ot | |
73 Region region = new Region(); | |
74 region.add(circle(67, 87, 77)); | |
75 region.subtract(circle(20, 87, 47)); | |
76 region.subtract(circle(20, 87, 113)); | |
77 | |
78 // define the shape of the button using setRegion | |
79 b2.setRegion(region); | |
80 b2.setLocation(100,50); | |
81 | |
82 b2.addListener(SWT.Selection, new class() Listener { | |
83 public void handleEvent(Event e) { | |
84 shell.close(); | |
85 } | |
86 }); | |
87 | |
88 shell.setSize(200,200); | |
89 shell.open(); | |
90 | |
91 while (!shell.isDisposed()) { | |
92 if (!display.readAndDispatch()) | |
93 display.sleep(); | |
94 } | |
95 region.dispose(); | |
96 display.dispose(); | |
97 } | |
98 } | 89 } |