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