Mercurial > projects > dwt-samples
annotate snippets/canvas/Snippet275.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 |
---|---|
90 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 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 * D Port: | |
11 * Bill Baxter <wbaxter> at gmail com | |
12 *******************************************************************************/ | |
120
1f0a7a472680
fix rm snippets from module statements.
Frank Benoit <benoit@tionex.de>
parents:
90
diff
changeset
|
13 module canvas.Snippet275; |
90 | 14 |
15 /* | |
16 * Canvas snippet: update a portion of a Canvas frequently | |
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.graphics.Color; | |
24 import dwt.graphics.Point; | |
25 import dwt.graphics.Image; | |
26 import dwt.widgets.Display; | |
27 import dwt.widgets.Shell; | |
28 import dwt.widgets.Event; | |
29 import dwt.widgets.Listener; | |
30 import dwt.widgets.Canvas; | |
31 | |
32 import dwt.dwthelper.System; | |
33 import dwt.dwthelper.utils; | |
34 import dwt.dwthelper.Runnable; | |
35 | |
36 import tango.util.Convert; | |
37 | |
38 static String value; | |
39 public static void main () { | |
40 final int INTERVAL = 888; | |
41 final Display display = new Display (); | |
42 final Image image = new Image (display, 750, 750); | |
43 GC gc = new GC (image); | |
44 gc.setBackground (display.getSystemColor (DWT.COLOR_RED)); | |
45 gc.fillRectangle (image.getBounds ()); | |
46 gc.dispose (); | |
47 | |
48 Shell shell = new Shell (display); | |
49 shell.setBounds (10, 10, 790, 790); | |
50 final Canvas canvas = new Canvas (shell, DWT.NONE); | |
51 canvas.setBounds (10, 10, 750, 750); | |
52 | |
53 void onPaint (Event event) { | |
54 value = to!(char[])(System.currentTimeMillis ()); | |
55 event.gc.drawImage (image, 0, 0); | |
56 event.gc.drawString (value, 10, 10, true); | |
57 } | |
58 canvas.addListener (DWT.Paint, dgListener(&onPaint)); | |
59 | |
60 display.timerExec (INTERVAL, new class Runnable { | |
61 void run () { | |
62 if (canvas.isDisposed ()) return; | |
63 // canvas.redraw (); // <-- bad, damages more than is needed | |
64 GC gc = new GC (canvas); | |
65 Point extent = gc.stringExtent (value ~ '0'); | |
66 gc.dispose (); | |
67 canvas.redraw (10, 10, extent.x, extent.y, false); | |
68 display.timerExec (INTERVAL, this); | |
69 } | |
70 }); | |
71 shell.open (); | |
72 while (!shell.isDisposed ()){ | |
73 if (!display.readAndDispatch ()) display.sleep (); | |
74 } | |
75 image.dispose (); | |
76 display.dispose (); | |
77 } |