Mercurial > projects > dwt-samples
comparison dwtsnippets/gc/Snippet215.d @ 51:7bb67937cbb4
Fix crash
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 06 Apr 2008 21:15:26 +0200 |
parents | 6b88d308c210 |
children |
comparison
equal
deleted
inserted
replaced
50:6b88d308c210 | 51:7bb67937cbb4 |
---|---|
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * Port to the D programming language: | 10 * Port to the D programming language: |
11 * Bill Baxter <bill@billbaxter.com> | 11 * Bill Baxter <bill@billbaxter.com> |
12 *******************************************************************************/ | 12 *******************************************************************************/ |
13 module dwtsnippets.gc.Snippet215; | 13 module dwtsnippets.gc.Snippet215; |
14 | 14 |
15 /* | 15 /* |
16 * GC example snippet: take a screen shot with a GC | 16 * GC example snippet: take a screen shot with a GC |
17 * | 17 * |
18 * For a list of all SWT example snippets see | 18 * For a list of all SWT example snippets see |
19 * http://www.eclipse.org/swt/snippets/ | 19 * http://www.eclipse.org/swt/snippets/ |
29 import dwt.widgets.Canvas; | 29 import dwt.widgets.Canvas; |
30 import dwt.custom.ScrolledComposite; | 30 import dwt.custom.ScrolledComposite; |
31 import dwt.layout.FillLayout; | 31 import dwt.layout.FillLayout; |
32 import dwt.events.PaintListener; | 32 import dwt.events.PaintListener; |
33 | 33 |
34 Image image; | |
35 | |
34 void main() { | 36 void main() { |
35 final Display display = new Display(); | 37 final Display display = new Display(); |
36 final Shell shell = new Shell(display); | 38 final Shell shell = new Shell(display); |
37 shell.setLayout(new FillLayout()); | 39 shell.setLayout(new FillLayout()); |
38 Button button = new Button(shell, DWT.PUSH); | 40 Button button = new Button(shell, DWT.PUSH); |
39 button.setText("Capture"); | 41 button.setText("Capture"); |
40 button.addListener(DWT.Selection, new class() Listener { | 42 button.addListener(DWT.Selection, new class() Listener { |
41 public void handleEvent(Event event) { | 43 public void handleEvent(Event event) { |
42 | 44 |
43 /* Take the screen shot */ | 45 /* Take the screen shot */ |
44 GC gc = new GC(display); | 46 GC gc = new GC(display); |
45 final Image image = new Image(display, display.getBounds()); | 47 image = new Image(display, display.getBounds()); |
46 gc.copyArea(image, 0, 0); | 48 gc.copyArea(image, 0, 0); |
47 gc.dispose(); | 49 gc.dispose(); |
48 | 50 |
49 Shell popup = new Shell(shell, DWT.SHELL_TRIM); | 51 Shell popup = new Shell(shell, DWT.SHELL_TRIM); |
50 popup.setLayout(new FillLayout()); | 52 popup.setLayout(new FillLayout()); |
51 popup.setText("Image"); | 53 popup.setText("Image"); |
52 popup.setBounds(50, 50, 200, 200); | 54 popup.setBounds(50, 50, 200, 200); |
53 popup.addListener(DWT.Close, new class() Listener { | 55 popup.addListener(DWT.Close, new class() Listener { |
54 public void handleEvent(Event e) { | 56 public void handleEvent(Event e) { |
55 image.dispose(); | 57 image.dispose(); |
56 } | 58 } |
57 }); | 59 }); |
58 | 60 |
59 ScrolledComposite sc = new ScrolledComposite (popup, DWT.V_SCROLL | DWT.H_SCROLL); | 61 ScrolledComposite sc = new ScrolledComposite (popup, DWT.V_SCROLL | DWT.H_SCROLL); |
60 Canvas canvas = new Canvas(sc, DWT.NONE); | 62 Canvas canvas = new Canvas(sc, DWT.NONE); |
61 sc.setContent(canvas); | 63 sc.setContent(canvas); |
62 canvas.setBounds(display.getBounds ()); | 64 canvas.setBounds(display.getBounds ()); |
63 canvas.addPaintListener(new class() PaintListener { | 65 canvas.addPaintListener(new class() PaintListener { |