1 #!/usr/bin/env dub
2 /+
3 dub.sdl:
4     name "snippet10"
5     dependency "dwt" path="../../../../../../"
6     libs \
7       "atk-1.0" \
8       "cairo" \
9       "dl" \
10       "fontconfig" \
11       "gdk-x11-2.0" \
12       "gdk_pixbuf-2.0" \
13       "glib-2.0" \
14       "gmodule-2.0" \
15       "gnomeui-2" \
16       "gnomevfs-2" \
17       "gobject-2.0" \
18       "gthread-2.0" \
19       "gtk-x11-2.0" \
20       "pango-1.0" \
21       "pangocairo-1.0" \
22       "X11" \
23       "Xcomposite" \
24       "Xcursor" \
25       "Xdamage" \
26       "Xext" \
27       "Xfixes" \
28       "Xi" \
29       "Xinerama" \
30       "Xrandr" \
31       "Xrender" \
32       "Xtst" \
33       platform="linux"
34 +/
35 
36 /*******************************************************************************
37  * Copyright (c) 2000, 2005 IBM Corporation and others.
38  * All rights reserved. This program and the accompanying materials
39  * are made available under the terms of the Eclipse Public License v1.0
40  * which accompanies this distribution, and is available at
41  * http://www.eclipse.org/legal/epl-v10.html
42  *
43  * Contributors:
44  *     IBM Corporation - initial API and implementation
45  * Port to the D programming language:
46  *     Bill Baxter <bill@billbaxter.com>
47  *******************************************************************************/
48 module org.eclipse.swt.snippets.Snippet10;
49 
50 /* 
51  * Draw using transformations, paths and alpha blending
52  *
53  * For a list of all SWT example snippets see
54  * http://www.eclipse.org/swt/snippets/
55  * 
56  * @since 3.1
57  */
58 import org.eclipse.swt.SWT;
59 import org.eclipse.swt.graphics.GC;
60 import org.eclipse.swt.graphics.Path;
61 import org.eclipse.swt.graphics.Transform;
62 import org.eclipse.swt.graphics.Font;
63 import org.eclipse.swt.graphics.FontData;
64 import org.eclipse.swt.graphics.Image;
65 import org.eclipse.swt.graphics.Rectangle;
66 import org.eclipse.swt.widgets.Display;
67 import org.eclipse.swt.widgets.Shell;
68 import org.eclipse.swt.widgets.Listener;
69 import org.eclipse.swt.widgets.Event;
70 
71 void main() {
72     Display display = new Display();
73     Shell shell = new Shell(display);
74     shell.setText("Advanced Graphics");
75     FontData fd = shell.getFont().getFontData()[0];
76     Font font = new Font(display, fd.getName(), 60., SWT.BOLD | SWT.ITALIC);
77     Image image = new Image(display, 640, 480);
78     Rectangle rect = image.getBounds();
79     GC gc = new GC(image);
80     gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
81     gc.fillOval(rect.x, rect.y, rect.width, rect.height);
82     gc.dispose();
83     shell.addListener(SWT.Paint, new class Listener {
84             public void handleEvent(Event event) {
85                 GC gc = event.gc;               
86                 Transform tr = new Transform(display);
87                 tr.translate(50, 120);
88                 tr.rotate(-30);
89                 gc.drawImage(image, 0, 0, rect.width, rect.height, 0, 0, rect.width / 2, rect.height / 2);
90                 gc.setAlpha(100);
91                 gc.setTransform(tr);
92                 Path path = new Path(display);
93                 path.addString("SWT", 0, 0, font);
94                 gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
95                 gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
96                 gc.fillPath(path);
97                 gc.drawPath(path);
98                 tr.dispose();
99                 path.dispose();
100             }           
101         });
102     shell.setSize(shell.computeSize(rect.width / 2, rect.height / 2));
103     shell.open();
104     while (!shell.isDisposed()) {
105         if (!display.readAndDispatch())
106             display.sleep();
107     }
108     image.dispose();
109     font.dispose();
110     display.dispose();
111 }
112