annotate snippets/cursor/Snippet92.d @ 119:9a1be6ff19a2

More snippets, thanks to Tom D.
author Frank Benoit <benoit@tionex.de>
date Sun, 20 Jul 2008 15:26:06 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
119
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
1 /*******************************************************************************
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
5 * which accompanies this distribution, and is available at
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
7 *
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
8 * Contributors:
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
9 * IBM Corporation - initial API and implementation
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
10 * D Port:
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
11 * Thomas Demmer <t_demmer AT web DOT de>
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
12 *******************************************************************************/
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
13 module cursor.Snippet92;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
14
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
15 /*
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
16 * Cursor example snippet: create a cursor from a source and a mask
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
17 *
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
18 * For a list of all SWT example snippets see
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
19 * http://www.eclipse.org/swt/snippets/
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
20 */
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
21 import dwt.DWT;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
22 import dwt.events.PaintEvent;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
23 import dwt.events.PaintListener;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
24 import dwt.graphics.Color;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
25 import dwt.graphics.Cursor;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
26 import dwt.graphics.GC;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
27 import dwt.graphics.Image;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
28 import dwt.graphics.ImageData;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
29 import dwt.graphics.PaletteData;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
30 import dwt.widgets.Display;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
31 import dwt.widgets.Shell;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
32
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
33 import dwt.dwthelper.utils;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
34
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
35
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
36 void main (String [] args) {
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
37 Display display = new Display();
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
38 Color white = display.getSystemColor (DWT.COLOR_WHITE);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
39 Color black = display.getSystemColor (DWT.COLOR_BLACK);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
40
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
41 //Create a source ImageData of depth 1 (monochrome)
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
42 PaletteData palette = new PaletteData ([white.getRGB(), black.getRGB()]);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
43 ImageData sourceData = new ImageData (20, 20, 1, palette);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
44 for (int i = 0; i < 10; i ++) {
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
45 for (int j = 0; j < 20; j++) {
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
46 sourceData.setPixel(i, j, 1);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
47 }
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
48 }
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
49
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
50 //Create a mask ImageData of depth 1 (monochrome)
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
51 palette = new PaletteData ([white.getRGB(), black.getRGB()]);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
52 ImageData maskData = new ImageData (20, 20, 1, palette);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
53 for (int i = 0; i < 20; i ++) {
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
54 for (int j = 0; j < 10; j++) {
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
55 maskData.setPixel(i, j, 1);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
56 }
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
57 }
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
58 //Create cursor
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
59 Cursor cursor = new Cursor(display, sourceData, maskData, 10, 10);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
60
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
61 Shell shell = new Shell(display);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
62 Image source = new Image (display,sourceData);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
63 Image mask = new Image (display, maskData);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
64 //Draw source and mask just to show what they look like
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
65 shell.addPaintListener(new class() PaintListener{
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
66 void paintControl(PaintEvent e) {
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
67 GC gc = e.gc;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
68 gc.drawString("source: ", 10, 10);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
69 gc.drawImage(source, 0, 0, 20, 20, 60, 10, 20, 20);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
70 gc.drawString("mask: ",10, 40);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
71 gc.drawImage(mask, 0, 0, 20, 20, 60, 40, 20, 20);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
72 }
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
73 });
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
74 shell.setSize(150, 150);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
75 shell.open();
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
76 shell.setCursor(cursor);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
77
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
78 while (!shell.isDisposed()) {
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
79 if (!display.readAndDispatch())
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
80 display.sleep();
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
81 }
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
82 cursor.dispose();
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
83 source.dispose();
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
84 mask.dispose();
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
85 display.dispose();
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
86 }
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
87