Changeset 1102 for trunk/src/org/expeditee/items/Circle.java
- Timestamp:
- 05/10/18 16:04:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/Circle.java
r919 r1102 19 19 package org.expeditee.items; 20 20 21 import java.awt.Color;22 import java.awt.Graphics2D;23 import java.awt.Polygon;24 import java.awt.Rectangle;25 import java.awt.geom.Point2D;26 21 import java.util.Collection; 27 22 import java.util.LinkedList; 23 24 import org.expeditee.core.Colour; 25 import org.expeditee.core.Dimension; 26 import org.expeditee.core.Fill; 27 import org.expeditee.core.Point; 28 import org.expeditee.core.Stroke; 29 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 30 import org.expeditee.core.bounds.CombinationBoxBounds; 31 import org.expeditee.core.bounds.EllipticalBounds; 32 import org.expeditee.core.bounds.PolygonBounds; 33 import org.expeditee.gio.EcosystemManager; 28 34 29 35 /** … … 42 48 * @param _source 43 49 */ 44 public Circle(Text source) { 50 public Circle(Text source) 51 { 45 52 super(source); 46 53 // Collection<Item> connected = source.getAllConnected(); … … 50 57 _center.addEnclosure(this); 51 58 _line.setHidden(true); 52 updatePolygon();59 invalidateBounds(); 53 60 } 54 61 … … 87 94 88 95 @Override 89 public Polygon getEnclosedShape() {96 public PolygonBounds getEnclosedShape() { 90 97 // assert(_poly != null); 91 98 // Ensure that vector items will gradient fill are painted OK!! 92 if (_poly == null) { 93 updatePolygon(); 94 } 95 return _poly; 99 return ((EllipticalBounds) updateBounds()).getPolygon(16); 96 100 } 97 101 … … 138 142 newCircle._line.setVisible(_line.isVisible()); 139 143 newCircle._source.setVisible(_source.isVisible()); 140 newCircle. updatePolygon();144 newCircle.invalidateBounds(); 141 145 return newCircle; 142 146 } … … 152 156 153 157 @Override 154 public boolean contains( int x, int y) {158 public boolean contains(Point p) { 155 159 double radius = getRadius(); 156 160 157 double distance = Math.sqrt(Math.pow(Math.abs(_center.getX() - x), 2)158 + Math.pow(Math.abs(_center.getY() - y), 2));161 double distance = Math.sqrt(Math.pow(Math.abs(_center.getX() - p.x), 2) 162 + Math.pow(Math.abs(_center.getY() - p.y), 2)); 159 163 160 164 return Math.abs(distance - radius) < getGravity() * 2; … … 167 171 */ 168 172 @Override 169 public void paint( Graphics2D g) {173 public void paint() { 170 174 int radius = (int) Math.round(getRadius()); 171 int diameter = radius * 2; 172 Color fillColor = getFillColor(); 173 if (fillColor != null) { 174 setFillPaint(g); 175 g.fillOval(_center.getX() - radius, _center.getY() - radius, 176 diameter, diameter); 175 Point centre = new Point(_center.getX(), _center.getY()); 176 Dimension diameters = new Dimension(radius * 2, radius * 2); 177 Fill fill = new Fill(getFillColor()); 178 Colour lineColour = null; 179 Stroke lineStroke = null; 180 if (isHighlighted()) { 181 lineColour = getHighlightColor(); 182 lineStroke = HIGHLIGHT_STROKE; 183 } else if (getThickness() > 0 || getFillColor() == null) { 184 lineColour = getPaintColor(); 185 lineStroke = _line.getStroke(); 177 186 } 178 if (getThickness() > 0 || fillColor == null) { 179 Color lineColor = getPaintColor(); 180 g.setColor(lineColor); 181 g.setStroke(_line.getStroke()); 182 g.drawOval(_center.getX() - radius, _center.getY() - radius, 183 diameter, diameter); 187 188 EcosystemManager.getGraphicsManager().drawOval(centre, diameters, 0.0f, fill, lineColour, lineStroke); 189 190 if (isHighlighted()) { 191 _center.paint(); 184 192 } 185 // Arc version, same result but allows for portions of the circle to be 186 // drawn 187 // g.drawArc(end.getX() - (distance / 2), end.getY() - (distance / 2), 188 // distance, distance, 0, 360); 189 190 if (isHighlighted()) { 191 // Flag the background color of the circle so that the item will be 192 // drawn with alternate color if the background is the same as 193 // the highlight} 194 _center.paint(g); 195 Color highlightColor = getHighlightColor(); 196 g.setColor(highlightColor); 197 g.setStroke(HIGHLIGHT_STROKE); 198 g.drawOval(_center.getX() - radius, _center.getY() - radius, 199 diameter, diameter); 200 } 201 } 202 203 @Override 204 public void setHighlightMode(HighlightMode mode, Color color) { 205 _center.setHighlightMode(mode, color); 206 super.setHighlightMode(mode, color); 207 } 208 209 @Override 210 public int setHighlightColor(Color c) { 193 } 194 195 @Override 196 public void setHighlightModeAndColour(HighlightMode mode, Colour color) { 197 _center.setHighlightModeAndColour(mode, color); 198 super.setHighlightModeAndColour(mode, color); 199 } 200 201 @Override 202 public void setHighlightColor(Colour c) { 211 203 _center.setHighlightColor(c); 212 returnsuper.setHighlightColor(c);213 } 214 215 @Override 216 public void setFillColor(Colo r c) {204 /*return*/ super.setHighlightColor(c); 205 } 206 207 @Override 208 public void setFillColor(Colour c) { 217 209 super.setFillColor(c); 218 210 _center.setColor(c); … … 221 213 222 214 @Override 223 public void setGradientColor(Colo r c) {215 public void setGradientColor(Colour c) { 224 216 super.setGradientColor(c); 225 217 invalidateCommonTrait(ItemAppearence.GradientColor); … … 255 247 */ 256 248 @Override 257 public void updatePolygon() { 258 double radius = getRadius(); 259 // Approximation of circle for mouse interaction 260 int points = 20; 261 262 double radians = 0.0; 263 int xPoints[] = new int[points]; 264 int yPoints[] = new int[xPoints.length]; 265 266 for (int i = 0; i < xPoints.length; i++) { 267 xPoints[i] = (int) Math.round(radius * Math.cos(radians)); 268 yPoints[i] = (int) Math.round(radius * Math.sin(radians)); 269 radians += (2.0 * Math.PI) / xPoints.length; 270 } 271 272 _poly = new Polygon(xPoints, yPoints, xPoints.length); 273 _poly.translate(_center.getX(), _center.getY()); 274 return; 249 public EllipticalBounds updateBounds() 250 { 251 return new EllipticalBounds(_center.getPosition(), (int) (getRadius() * 2)); 275 252 } 276 253 … … 280 257 } 281 258 282 /** 283 * Resizes the circle from the center. 284 */ 285 @Override 286 public void setSize(float size) { 259 /** Resizes the circle from the center. */ 260 @Override 261 public void setSize(float size) 262 { 287 263 double ratio = size / getRadius(); 288 264 … … 290 266 _source.translate(_center.getPosition(), ratio); 291 267 292 updatePolygon();268 invalidateBounds(); 293 269 } 294 270 … … 303 279 } 304 280 305 @Override 306 public void translate(Point2D origin, double ratio) { 307 updatePolygon(); 281 // TODO: Why is this commented out? cts16 282 @Override 283 public void translate(Point origin, double ratio) 284 { 285 invalidateBounds(); 308 286 // _center.translate(origin, ratio); 309 287 // super.translate(origin, ratio); … … 311 289 312 290 @Override 313 public Rectangle[]getDrawingArea() {291 public AxisAlignedBoxBounds getDrawingArea() { 314 292 315 293 float thickness = getThickness(); … … 318 296 int size = (int) ((2 * radius) + 3.0 + thickness); 319 297 320 return new Rectangle[] { new Rectangle((int) (_center.getX() - radius298 return new AxisAlignedBoxBounds((int) (_center.getX() - radius 321 299 - 0.5 - (thickness / 2.0)), (int) (_center.getY() - radius 322 - 0.5 - (thickness / 2.0)), size, size) };300 - 0.5 - (thickness / 2.0)), size, size); 323 301 } 324 302
Note:
See TracChangeset
for help on using the changeset viewer.