Mercurial > projects > dwt-addons
comparison dwtx/draw2d/PolylineDecoration.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 | 2d6540440fe6 |
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 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.draw2d.PolylineDecoration; | |
14 | |
15 import dwt.dwthelper.utils; | |
16 | |
17 import dwtx.draw2d.geometry.Point; | |
18 import dwtx.draw2d.geometry.PointList; | |
19 import dwtx.draw2d.geometry.Transform; | |
20 import dwtx.draw2d.Polyline; | |
21 import dwtx.draw2d.RotatableDecoration; | |
22 import dwtx.draw2d.ColorConstants; | |
23 | |
24 /** | |
25 * A decorative Figure intended to be placed on a {@link Polyline}. It has the default | |
26 * shape of right-pointing triangle. | |
27 */ | |
28 public class PolylineDecoration | |
29 : Polyline | |
30 , RotatableDecoration | |
31 { | |
32 | |
33 /** A triangle template_ */ | |
34 public static const PointList TRIANGLE_TIP; | |
35 | |
36 static this() { | |
37 TRIANGLE_TIP = new PointList(); | |
38 TRIANGLE_TIP.addPoint(-1, 1); | |
39 TRIANGLE_TIP.addPoint(0, 0); | |
40 TRIANGLE_TIP.addPoint(-1, -1); | |
41 } | |
42 | |
43 private Point location; | |
44 private PointList template_; | |
45 private Transform transform; | |
46 | |
47 /** | |
48 * Constructs a PolylineDecoration. Defaults the PolylineDecoration to fill its region | |
49 * with black. | |
50 * | |
51 * @since 2.0 | |
52 */ | |
53 public this() { | |
54 location = new Point(); | |
55 template_ = TRIANGLE_TIP; | |
56 transform = new Transform(); | |
57 setBackgroundColor(ColorConstants.black); | |
58 setScale(7, 3); | |
59 } | |
60 | |
61 /** | |
62 * @see Polyline#getPoints() | |
63 */ | |
64 public PointList getPoints() { | |
65 if (points is null) { | |
66 points = new PointList(); | |
67 for (int i = 0; i < template_.size(); i++) | |
68 points.addPoint(transform.getTransformed(template_.getPoint(i))); | |
69 } | |
70 return points; | |
71 } | |
72 | |
73 /** | |
74 * @see IFigure#setLocation(Point) | |
75 */ | |
76 public void setLocation(Point p) { | |
77 points = null; | |
78 bounds = null; | |
79 location.setLocation(p); | |
80 transform.setTranslation(p.x, p.y); | |
81 } | |
82 | |
83 /** | |
84 * Sets the PolylineDecoration's point template_. This template_ is an outline of the | |
85 * PolylineDecoration's region. (The default value is TRIANGLE_TIP which is a triangle | |
86 * whose tip is pointing to the right). | |
87 * | |
88 * @param pl the template_ | |
89 * @since 2.0 | |
90 */ | |
91 public void setTemplate(PointList pl) { | |
92 erase(); | |
93 template_ = pl; | |
94 points = null; | |
95 bounds = null; | |
96 repaint(); | |
97 } | |
98 | |
99 /** | |
100 * Sets the amount of scaling to be done along X and Y axes on the PolylineDecoration's | |
101 * template_. | |
102 * | |
103 * @param x the x scale | |
104 * @param y the y scale | |
105 * @since 2.0 | |
106 */ | |
107 public void setScale(double x, double y) { | |
108 points = null; | |
109 bounds = null; | |
110 transform.setScale(x, y); | |
111 } | |
112 | |
113 /** | |
114 * @see RotatableDecoration#setReferencePoint(Point) | |
115 */ | |
116 public void setReferencePoint(Point ref_) { | |
117 Point pt = Point.SINGLETON; | |
118 pt.setLocation(ref_); | |
119 pt.negate().translate(location); | |
120 setRotation(Math.atan2(pt.y, pt.x)); | |
121 } | |
122 | |
123 /** | |
124 * Sets the angle by which rotation is to be done on the PolylineDecoration. | |
125 * | |
126 * @param angle the angle of rotation | |
127 * @since 2.0 | |
128 */ | |
129 public void setRotation(double angle) { | |
130 points = null; | |
131 bounds = null; | |
132 transform.setRotation(angle); | |
133 } | |
134 | |
135 } |