1 #!/usr/bin/env dub
2 /+
3 dub.sdl:
4     name "snippet92"
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, 2004 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  * D Port:
46  *     Thomas Demmer <t_demmer AT web DOT de>
47  *******************************************************************************/
48 module org.eclipse.swt.snippets.Snippet92;
49 
50 /*
51  * Cursor example snippet: create a cursor from a source and a mask
52  *
53  * For a list of all SWT example snippets see
54  * http://www.eclipse.org/swt/snippets/
55  */
56 import org.eclipse.swt.SWT;
57 import org.eclipse.swt.events.PaintEvent;
58 import org.eclipse.swt.events.PaintListener;
59 import org.eclipse.swt.graphics.Color;
60 import org.eclipse.swt.graphics.Cursor;
61 import org.eclipse.swt.graphics.GC;
62 import org.eclipse.swt.graphics.Image;
63 import org.eclipse.swt.graphics.ImageData;
64 import org.eclipse.swt.graphics.PaletteData;
65 import org.eclipse.swt.widgets.Display;
66 import org.eclipse.swt.widgets.Shell;
67 
68 import java.lang.all;
69 
70 
71 void main () {
72     Display display = new Display();
73     Color white = display.getSystemColor (SWT.COLOR_WHITE);
74     Color black = display.getSystemColor (SWT.COLOR_BLACK);
75 
76     //Create a source ImageData of depth 1 (monochrome)
77     PaletteData palette = new PaletteData ([white.getRGB(), black.getRGB()]);
78     ImageData sourceData = new ImageData (20, 20, 1, palette);
79     for (int i = 0; i < 10; i ++) {
80         for (int j = 0; j < 20; j++) {
81             sourceData.setPixel(i, j, 1);
82         }
83     }
84 
85     //Create a mask ImageData of depth 1 (monochrome)
86     palette = new PaletteData ([white.getRGB(), black.getRGB()]);
87     ImageData maskData = new ImageData (20, 20, 1, palette);
88     for (int i = 0; i < 20; i ++) {
89         for (int j = 0; j < 10; j++) {
90             maskData.setPixel(i, j, 1);
91         }
92     }
93     //Create cursor
94     Cursor cursor = new Cursor(display, sourceData, maskData, 10, 10);
95 
96     Shell shell = new Shell(display);
97     Image source = new Image (display,sourceData);
98     Image mask = new Image (display, maskData);
99     //Draw source and mask just to show what they look like
100     shell.addPaintListener(new class PaintListener{
101         void paintControl(PaintEvent e) {
102             GC gc = e.gc;
103             gc.drawString("source: ", 10, 10);
104             gc.drawImage(source, 0, 0, 20, 20, 60, 10, 20, 20);
105             gc.drawString("mask: ",10, 40);
106             gc.drawImage(mask, 0, 0, 20, 20, 60, 40, 20, 20);
107         }
108     });
109     shell.setSize(150, 150);
110     shell.open();
111     shell.setCursor(cursor);
112 
113     while (!shell.isDisposed()) {
114         if (!display.readAndDispatch())
115             display.sleep();
116     }
117     cursor.dispose();
118     source.dispose();
119     mask.dispose();
120     display.dispose();
121 }
122