Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet10.d @ 44:ed96ea2a2764
First swt win snippets are buiding with d2+phobos
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 25 Mar 2009 18:31:01 +0100 |
parents | 4e5843b771cc |
children | 536e43f63c81 |
rev | line source |
---|---|
28 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2005 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.Snippet10; | |
14 | |
15 /* | |
16 * Draw using transformations, paths and alpha blending | |
17 * | |
18 * For a list of all SWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 * | |
21 * @since 3.1 | |
22 */ | |
23 import org.eclipse.swt.SWT; | |
24 import org.eclipse.swt.graphics.GC; | |
25 import org.eclipse.swt.graphics.Path; | |
26 import org.eclipse.swt.graphics.Transform; | |
27 import org.eclipse.swt.graphics.Font; | |
28 import org.eclipse.swt.graphics.FontData; | |
29 import org.eclipse.swt.graphics.Image; | |
30 import org.eclipse.swt.graphics.Rectangle; | |
31 import org.eclipse.swt.widgets.Display; | |
32 import org.eclipse.swt.widgets.Shell; | |
33 import org.eclipse.swt.widgets.Listener; | |
34 import org.eclipse.swt.widgets.Event; | |
35 | |
36 void main() { | |
37 Display display = new Display(); | |
38 Shell shell = new Shell(display); | |
39 shell.setText("Advanced Graphics"); | |
40 FontData fd = shell.getFont().getFontData()[0]; | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
41 Font font = new Font(display, fd.getName(), 60., SWT.BOLD | SWT.ITALIC); |
28 | 42 Image image = new Image(display, 640, 480); |
43 Rectangle rect = image.getBounds(); | |
44 GC gc = new GC(image); | |
45 gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); | |
46 gc.fillOval(rect.x, rect.y, rect.width, rect.height); | |
47 gc.dispose(); | |
48 shell.addListener(SWT.Paint, new class() Listener { | |
49 public void handleEvent(Event event) { | |
50 GC gc = event.gc; | |
51 Transform tr = new Transform(display); | |
52 tr.translate(50, 120); | |
53 tr.rotate(-30); | |
54 gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2); | |
55 gc.setAlpha(100); | |
56 gc.setTransform(tr); | |
57 Path path = new Path(display); | |
58 path.addString("SWT", 0, 0, font); | |
59 gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); | |
60 gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); | |
61 gc.fillPath(path); | |
62 gc.drawPath(path); | |
63 tr.dispose(); | |
64 path.dispose(); | |
65 } | |
66 }); | |
67 shell.setSize(shell.computeSize(rect.width / 2, rect.height / 2)); | |
68 shell.open(); | |
69 while (!shell.isDisposed()) { | |
70 if (!display.readAndDispatch()) | |
71 display.sleep(); | |
72 } | |
73 image.dispose(); | |
74 font.dispose(); | |
75 display.dispose(); | |
76 } | |
77 |