Mercurial > projects > dwt-addons
comparison dwtx/draw2d/Ellipse.d @ 98:95307ad235d9
Added Draw2d code, still work in progress
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 03 Aug 2008 00:52:14 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
96:b492ba44e44d | 98:95307ad235d9 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2005 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 * Port to the D programming language: | |
12 * Frank Benoit <benoit@tionex.de> | |
13 *******************************************************************************/ | |
14 module dwtx.draw2d.Ellipse; | |
15 | |
16 import dwt.dwthelper.utils; | |
17 | |
18 import dwtx.draw2d.geometry.Rectangle; | |
19 import dwtx.draw2d.Shape; | |
20 import dwtx.draw2d.Graphics; | |
21 | |
22 /** | |
23 * An figure that draws an ellipse filling its bounds. | |
24 */ | |
25 public class Ellipse | |
26 : Shape | |
27 { | |
28 | |
29 /** | |
30 * Constructs a new Ellipse with the default values of a Shape. | |
31 * @since 2.0 | |
32 */ | |
33 public this() { } | |
34 | |
35 /** | |
36 * Returns <code>true</code> if the given point (x,y) is contained within this ellipse. | |
37 * @param x the x coordinate | |
38 * @param y the y coordinate | |
39 * @return <code>true</code>if the given point is contained | |
40 */ | |
41 public bool containsPoint(int x, int y) { | |
42 if (!super.containsPoint(x, y)) | |
43 return false; | |
44 Rectangle r = getBounds(); | |
45 long ux = x - r.x - r.width / 2; | |
46 long uy = y - r.y - r.height / 2; | |
47 return ((ux * ux) << 10) / (r.width * r.width) | |
48 + ((uy * uy) << 10) / (r.height * r.height) <= 256; | |
49 } | |
50 | |
51 /** | |
52 * Fills the ellipse. | |
53 * @see dwtx.draw2d.Shape#fillShape(dwtx.draw2d.Graphics) | |
54 */ | |
55 protected void fillShape(Graphics graphics) { | |
56 graphics.fillOval(getBounds()); | |
57 } | |
58 | |
59 /** | |
60 * Outlines the ellipse. | |
61 * @see dwtx.draw2d.Shape#outlineShape(dwtx.draw2d.Graphics) | |
62 */ | |
63 protected void outlineShape(Graphics graphics) { | |
64 Rectangle r = Rectangle.SINGLETON; | |
65 r.setBounds(getBounds()); | |
66 r.width--; | |
67 r.height--; | |
68 r.shrink((lineWidth - 1) / 2, (lineWidth - 1) / 2); | |
69 graphics.drawOval(r); | |
70 } | |
71 | |
72 } |