Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet215.d @ 112:9f4c18c268b2
Update to compile and execute with dmd 2.052.
author | kntroh |
---|---|
date | Wed, 16 Mar 2011 21:53:53 +0900 |
parents | 4e5843b771cc |
children | 536e43f63c81 |
rev | line source |
---|---|
28 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2004 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 * Bill Baxter <bill@billbaxter.com> | |
12 *******************************************************************************/ | |
13 module org.eclipse.swt.snippets.Snippet215; | |
14 | |
15 /* | |
16 * GC example snippet: take a screen shot with a GC | |
17 * | |
18 * For a list of all SWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 */ | |
21 import org.eclipse.swt.SWT; | |
22 import org.eclipse.swt.graphics.GC; | |
23 import org.eclipse.swt.graphics.Image; | |
24 import org.eclipse.swt.widgets.Display; | |
25 import org.eclipse.swt.widgets.Shell; | |
26 import org.eclipse.swt.widgets.Listener; | |
27 import org.eclipse.swt.widgets.Event; | |
28 import org.eclipse.swt.widgets.Button; | |
29 import org.eclipse.swt.widgets.Canvas; | |
30 import org.eclipse.swt.custom.ScrolledComposite; | |
31 import org.eclipse.swt.layout.FillLayout; | |
32 import org.eclipse.swt.events.PaintListener; | |
33 | |
34 Image image; | |
35 | |
36 void main() { | |
112 | 37 Display display = new Display(); |
38 Shell shell = new Shell(display); | |
28 | 39 shell.setLayout(new FillLayout()); |
40 Button button = new Button(shell, SWT.PUSH); | |
41 button.setText("Capture"); | |
42 button.addListener(SWT.Selection, new class() Listener { | |
43 public void handleEvent(Event event) { | |
44 | |
45 /* Take the screen shot */ | |
46 GC gc = new GC(display); | |
47 image = new Image(display, display.getBounds()); | |
48 gc.copyArea(image, 0, 0); | |
49 gc.dispose(); | |
50 | |
51 Shell popup = new Shell(shell, SWT.SHELL_TRIM); | |
52 popup.setLayout(new FillLayout()); | |
53 popup.setText("Image"); | |
54 popup.setBounds(50, 50, 200, 200); | |
55 popup.addListener(SWT.Close, new class() Listener { | |
56 public void handleEvent(Event e) { | |
57 image.dispose(); | |
58 } | |
59 }); | |
60 | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
61 ScrolledComposite sc = new ScrolledComposite (popup, SWT.V_SCROLL | SWT.H_SCROLL); |
28 | 62 Canvas canvas = new Canvas(sc, SWT.NONE); |
63 sc.setContent(canvas); | |
64 canvas.setBounds(display.getBounds ()); | |
65 canvas.addPaintListener(new class() PaintListener { | |
66 public void paintControl(PaintEvent e) { | |
67 e.gc.drawImage(image, 0, 0); | |
68 } | |
69 }); | |
70 popup.open(); | |
71 } | |
72 }); | |
73 shell.pack(); | |
74 shell.open(); | |
75 while (!shell.isDisposed()) { | |
76 if (!display.readAndDispatch()) display.sleep(); | |
77 } | |
78 display.dispose(); | |
79 } | |
80 |