Mercurial > projects > dwt-samples
annotate snippets/gc/Snippet66.d @ 179:89de7ff0752c default tip
Add JFace snippet Snippet054NativeControlsInViewers, thanks to WasserDragoon
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 29 Apr 2009 11:01:41 +0200 |
parents | 1f0a7a472680 |
children |
rev | line source |
---|---|
78 | 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 *******************************************************************************/ | |
120
1f0a7a472680
fix rm snippets from module statements.
Frank Benoit <benoit@tionex.de>
parents:
78
diff
changeset
|
13 module gc.Snippet66; |
78 | 14 |
15 /* | |
16 * GC example snippet: implement a simple scribble program | |
17 * | |
18 * For a list of all SWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 */ | |
21 import dwt.DWT; | |
22 import dwt.graphics.GC; | |
23 import dwt.widgets.Display; | |
24 import dwt.widgets.Shell; | |
25 import dwt.widgets.Listener; | |
26 import dwt.widgets.Event; | |
27 | |
28 void main () { | |
29 Display display = new Display (); | |
30 final Shell shell = new Shell (display); | |
31 Listener listener = new class() Listener { | |
32 int lastX = 0, lastY = 0; | |
33 public void handleEvent (Event event) { | |
34 switch (event.type) { | |
35 case DWT.MouseMove: | |
36 if ((event.stateMask & DWT.BUTTON1) == 0) break; | |
37 GC gc = new GC (shell); | |
38 gc.drawLine (lastX, lastY, event.x, event.y); | |
39 gc.dispose (); | |
40 //FALL THROUGH | |
41 case DWT.MouseDown: | |
42 lastX = event.x; | |
43 lastY = event.y; | |
44 break; | |
45 } | |
46 } | |
47 }; | |
48 shell.addListener (DWT.MouseDown, listener); | |
49 shell.addListener (DWT.MouseMove, listener); | |
50 shell.open (); | |
51 while (!shell.isDisposed ()) { | |
52 if (!display.readAndDispatch ()) display.sleep (); | |
53 } | |
54 display.dispose (); | |
55 } | |
56 |