Mercurial > projects > dwt-samples
comparison dwtsnippets/gc/Snippet66.d @ 50:6b88d308c210
Ports of several gc Snippets: 10,66,207,215
215 has a crash bug currently.
author | Bill Baxter <bill@billbaxter.com> |
---|---|
date | Mon, 07 Apr 2008 01:21:04 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
49:e1edfebec7fa | 50:6b88d308c210 |
---|---|
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 dwtsnippets.gc.Snippet66; | |
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 |