Project

General

Profile

Download (2.11 KB) Statistics
| Branch: | Tag: | Revision:
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Alex Selkov - Fix for Bug# 22701
11
 *******************************************************************************/
12
package org.eclipse.draw2d;
13

    
14
import org.eclipse.draw2d.geometry.Rectangle;
15

    
16
/**
17
 * An figure that draws an ellipse filling its bounds.
18
 */
19
public class Ellipse extends Shape {
20
	/**
21
	 * Constructs a new Ellipse with the default values of a Shape.
22
	 * 
23
	 * @since 2.0
24
	 */
25
	public Ellipse() {
26
	}
27

    
28
	/**
29
	 * Returns <code>true</code> if the given point (x,y) is contained within
30
	 * this ellipse.
31
	 * 
32
	 * @param x
33
	 *            the x coordinate
34
	 * @param y
35
	 *            the y coordinate
36
	 * @return <code>true</code>if the given point is contained
37
	 */
38
	public boolean containsPoint(int x, int y) {
39
		if (!super.containsPoint(x, y)) {
40
			return false;
41
		} else {
42
			Rectangle r = getBounds();
43
			long ux = x - r.x - r.width / 2;
44
			long uy = y - r.y - r.height / 2;
45
			return ((ux * ux) << 10) / (r.width * r.width) + ((uy * uy) << 10)
46
					/ (r.height * r.height) <= 256;
47
		}
48
	}
49

    
50
	/**
51
	 * Fills the ellipse.
52
	 * 
53
	 * @see org.eclipse.draw2d.Shape#fillShape(org.eclipse.draw2d.Graphics)
54
	 */
55
	protected void fillShape(Graphics graphics) {
56
		graphics.fillOval(getBounds());
57
	}
58

    
59
	/**
60
	 * Outlines the ellipse.
61
	 * 
62
	 * @see org.eclipse.draw2d.Shape#outlineShape(org.eclipse.draw2d.Graphics)
63
	 */
64
	protected void outlineShape(Graphics graphics) {
65
		float lineInset = Math.max(1.0f, getLineWidthFloat()) / 2.0f;
66
		int inset1 = (int) Math.floor(lineInset);
67
		int inset2 = (int) Math.ceil(lineInset);
68

    
69
		Rectangle r = Rectangle.SINGLETON.setBounds(getBounds());
70
		r.x += inset1;
71
		r.y += inset1;
72
		r.width -= inset1 + inset2;
73
		r.height -= inset1 + inset2;
74

    
75
		graphics.drawOval(r);
76
	}
77
}
(54-54/171)