summaryrefslogtreecommitdiffstats
path: root/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ImageFlipTab.java
blob: ff9579b7aa49710934efb36420a1d8495bee628a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.swt.examples.graphics;

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;

/**
 * This tab demonstrates how an image can be flipped in various fashions. 
 */
public class ImageFlipTab extends GraphicsTab {

public ImageFlipTab(GraphicsExample example) {
	super(example);
}

public String getCategory() {
	return GraphicsExample.getResourceString("Image"); //$NON-NLS-1$
}

public String getText() {
	return GraphicsExample.getResourceString("Flip"); //$NON-NLS-1$
}

public String getDescription() {
	return GraphicsExample.getResourceString("FlipDescription"); //$NON-NLS-1$
}

public void paint(GC gc, int width, int height) {
	if (!example.checkAdvancedGraphics()) return;
	Device device = gc.getDevice();
	
	Image image = GraphicsExample.loadImage(device, GraphicsExample.class, "houses.png");
	Rectangle bounds = image.getBounds();
	
	// top
	Transform transform = new Transform(device);
	transform.translate((width-bounds.width)/2, (height-bounds.height)/2);
	transform.scale(1, -1);
	gc.setTransform(transform);
		
	// draw the original image
	gc.drawImage(image, 0, 0);
	
	transform.dispose();
	
	// bottom
	transform = new Transform(device);
	transform.translate((width-bounds.width)/2, 2*bounds.height + (height-bounds.height)/2);
	transform.scale(1, -1);
	gc.setTransform(transform);
	
	// draw the original image
	gc.drawImage(image, 0, 0);
	
	transform.dispose();
	
	// left
	transform = new Transform(device);
	transform.translate((width-bounds.width)/2, (height-bounds.height)/2);
	transform.scale(-1, 1);
	gc.setTransform(transform);
	
	// draw the original image
	gc.drawImage(image, 0, 0);
	
	transform.dispose();
	
	// right
	transform = new Transform(device);
	transform.translate(2*bounds.width + (width-bounds.width)/2, (height-bounds.height)/2);
	transform.scale(-1, 1);
	gc.setTransform(transform);
	
	// draw the original image
	gc.drawImage(image, 0, 0);
	
	transform.dispose();
	
	gc.setTransform(null);
	gc.drawImage(image, (width-bounds.width)/2, (height-bounds.height)/2);
	image.dispose();
}

/**
 * Returns the name of a valid font for the host platform.
 */
static String getPlatformFont() {
	if(SWT.getPlatform() == "win32") {
		return "Arial";	
	} else if (SWT.getPlatform() == "motif") {
		return "Helvetica";		
	} else if (SWT.getPlatform() == "gtk") {
		return "Baekmuk Batang";		
	} else if (SWT.getPlatform() == "carbon") {
		return "Arial";
	} else { // photon, etc ...
		return "Verdana";
	}
}
}