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.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 org.eclipse.swt.SWT;
|
|
22 import org.eclipse.swt.graphics.GC;
|
|
23 import org.eclipse.swt.widgets.Display;
|
|
24 import org.eclipse.swt.widgets.Shell;
|
|
25 import org.eclipse.swt.widgets.Listener;
|
|
26 import org.eclipse.swt.widgets.Event;
|
|
27
|
|
28 void main () {
|
|
29 Display display = new Display ();
|
112
|
30 Shell shell = new Shell (display);
|
28
|
31 Listener listener = new class() Listener {
|
|
32 int lastX = 0, lastY = 0;
|
|
33 public void handleEvent (Event event) {
|
|
34 switch (event.type) {
|
|
35 case SWT.MouseMove:
|
|
36 if ((event.stateMask & SWT.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 SWT.MouseDown:
|
|
42 lastX = event.x;
|
|
43 lastY = event.y;
|
|
44 break;
|
|
45 }
|
|
46 }
|
|
47 };
|
|
48 shell.addListener (SWT.MouseDown, listener);
|
|
49 shell.addListener (SWT.MouseMove, listener);
|
|
50 shell.open ();
|
|
51 while (!shell.isDisposed ()) {
|
|
52 if (!display.readAndDispatch ()) display.sleep ();
|
|
53 }
|
|
54 display.dispose ();
|
|
55 }
|
|
56
|