78
|
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 snippets.gc.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 dwt.DWT;
|
|
24 import dwt.graphics.GC;
|
|
25 import dwt.graphics.Path;
|
|
26 import dwt.graphics.Transform;
|
|
27 import dwt.graphics.Font;
|
|
28 import dwt.graphics.FontData;
|
|
29 import dwt.graphics.Image;
|
|
30 import dwt.graphics.Rectangle;
|
|
31 import dwt.widgets.Display;
|
|
32 import dwt.widgets.Shell;
|
|
33 import dwt.widgets.Listener;
|
|
34 import dwt.widgets.Event;
|
|
35
|
|
36
|
|
37 void main() {
|
|
38 Display display = new Display();
|
|
39 Shell shell = new Shell(display);
|
|
40 shell.setText("Advanced Graphics");
|
|
41 FontData fd = shell.getFont().getFontData()[0];
|
|
42 Font font = new Font(display, fd.getName(), 60., DWT.BOLD | DWT.ITALIC);
|
|
43 Image image = new Image(display, 640, 480);
|
|
44 Rectangle rect = image.getBounds();
|
|
45 GC gc = new GC(image);
|
|
46 gc.setBackground(display.getSystemColor(DWT.COLOR_RED));
|
|
47 gc.fillOval(rect.x, rect.y, rect.width, rect.height);
|
|
48 gc.dispose();
|
|
49 shell.addListener(DWT.Paint, new class() Listener {
|
|
50 public void handleEvent(Event event) {
|
|
51 GC gc = event.gc;
|
|
52 Transform tr = new Transform(display);
|
|
53 tr.translate(50, 120);
|
|
54 tr.rotate(-30);
|
|
55 gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2);
|
|
56 gc.setAlpha(100);
|
|
57 gc.setTransform(tr);
|
|
58 Path path = new Path(display);
|
|
59 path.addString("DWT", 0, 0, font);
|
|
60 gc.setBackground(display.getSystemColor(DWT.COLOR_GREEN));
|
|
61 gc.setForeground(display.getSystemColor(DWT.COLOR_BLUE));
|
|
62 gc.fillPath(path);
|
|
63 gc.drawPath(path);
|
|
64 tr.dispose();
|
|
65 path.dispose();
|
|
66 }
|
|
67 });
|
|
68 shell.setSize(shell.computeSize(rect.width / 2, rect.height / 2));
|
|
69 shell.open();
|
|
70 while (!shell.isDisposed()) {
|
|
71 if (!display.readAndDispatch())
|
|
72 display.sleep();
|
|
73 }
|
|
74 image.dispose();
|
|
75 font.dispose();
|
|
76 display.dispose();
|
|
77 }
|
|
78
|