summaryrefslogtreecommitdiffstats
path: root/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/FigureDrawContext.java
blob: eda60d25b8b9129deddd4f78a7c4066346d4b5d4 (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
package org.eclipse.swt.examples.paint;

/*

 * (c) Copyright IBM Corp. 2000, 2001.

 * All Rights Reserved

 */

import org.eclipse.swt.graphics.*;

public class FigureDrawContext {
	/*

	 * <p>

	 * The GC must be set up as follows

	 * (it will be returned to this state upon completion of drawing operations)

	 * <ul>

	 *   <li>setXORMode(false)

	 * </ul>

	 * </p>

	 */
	public GC gc = null;
	public int xOffset = 0, yOffset = 0; // substract to get GC coords

	public int xScale = 1, yScale = 1;
	
	public Rectangle toClientRectangle(int x1, int y1, int x2, int y2) {
		return new Rectangle(
			Math.min(x1, x2) * xScale - xOffset,
			Math.min(y1, y2) * yScale - yOffset,
			(Math.abs(x2 - x1) + 1) * xScale,
			(Math.abs(y2 - y1) + 1) * yScale);
	}
	public Point toClientPoint(int x, int y) {
		return new Point(x * xScale - xOffset, y * yScale - yOffset);
	}
}