summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/MacRect.java
blob: 5a0b3d063139c4a62aa0f032ec8f13bedcabf9d2 (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
/*
 * Copyright (c) 2002 IBM Corp.  All rights reserved.
 * This file is made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 *
 * Andre Weinand, OTI - Initial version
 */
package org.eclipse.swt.internal.carbon;

import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Point;

public class MacRect {

	// 0: top
	// 1: left
	// 2: bottom
	// 3: right
	private short[] fData= new short[4];
	
	public MacRect() {
	}
	
	public MacRect(int x, int y, int w, int h) {
		fData[0]= (short) y;
		fData[1]= (short) x;
		fData[2]= (short) (y+h);
		fData[3]= (short) (x+w);
	}
	
	public MacRect(Rectangle r) {
		fData[0]= (short) (r.y);
		fData[1]= (short) (r.x);
		fData[2]= (short) (r.y+r.height);
		fData[3]= (short) (r.x+r.width);
	}
	
	public void set(int x, int y, int w, int h) {
		fData[0]= (short) y;
		fData[1]= (short) x;
		fData[2]= (short) (y+h);
		fData[3]= (short) (x+w);
	}
	
	public short[] getData() {
		return fData;
	}
	
	public Rectangle toRectangle() {
		return new Rectangle(fData[1], fData[0], fData[3]-fData[1], fData[2]-fData[0]);
	}
	
	public Point getSize() {
		return new Point(fData[3]-fData[1], fData[2]-fData[0]);
	}
	
	public Point getLocation() {
		return new Point(fData[1], fData[0]);
	}
	
	public void setLocation(int x, int y) {
		int w= fData[3]-fData[1];
		int h= fData[2]-fData[0];
		fData[0]= (short)(y);
		fData[1]= (short)(x);
		fData[2]= (short)(y+h);
		fData[3]= (short)(x+w);
	}
	
	public void setSize(int width, int height) {
		fData[2]= (short)(fData[0]+ height);
		fData[3]= (short)(fData[1]+ width);
	}
	
	public int getX() {
		return fData[1];
	}
	
	public int getY() {
		return fData[0];
	}

	public int getWidth() {
		return fData[3]-fData[1];
	}
	
	public int getHeight() {
		return fData[2]-fData[0];
	}

	public boolean isEmpty() {
		return (fData[0] >= fData[2]) || (fData[1] >= fData[3]);
	}
	
	public boolean contains(Point p) {
		return p.x >= fData[1] && p.x < fData[3] && p.y >= fData[0] && p.y < fData[2];
	}
	
	public void inset(int left, int top, int right, int bottom) {
		fData[0]+= top;
		fData[1]+= left;
		fData[2]-= bottom;
		fData[3]-= right;
	}
}