UnitGraphPoint.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package holeg.ui.view.inspector;
  2. import holeg.utility.math.vector.Vec2f;
  3. import holeg.utility.math.vector.Vec2i;
  4. /**
  5. * A class for saving all points of a Object with a editable state. e.g HolonElement, HolonSwitch
  6. *
  7. * @author Tom Troppmann
  8. */
  9. public class UnitGraphPoint {
  10. /**
  11. * Relative position in the UnitGraphCanvas
  12. */
  13. public double x, y;
  14. /**
  15. * To determine if this point has changed to only write back points that are changed.
  16. */
  17. public boolean changed;
  18. /**
  19. * The displayed Position of the UnitGraphPoint
  20. */
  21. public Vec2i displayedPosition;
  22. /**
  23. * Default Constructor
  24. */
  25. public UnitGraphPoint(double x, double y, boolean changed) {
  26. this.x = x;
  27. this.y = y;
  28. this.changed = changed;
  29. }
  30. /**
  31. * Constructor with a Point2D.Double
  32. */
  33. public UnitGraphPoint(Vec2f pos, boolean changed) {
  34. this.x = pos.getX();
  35. this.y = pos.getY();
  36. this.changed = changed;
  37. }
  38. /**
  39. * Constructor with a Point2D.Double when changed not specified is false;
  40. */
  41. public UnitGraphPoint(Vec2f pos) {
  42. this.x = pos.getX();
  43. this.y = pos.getY();
  44. this.changed = false;
  45. }
  46. public void calcDisplayedPosition(int border, int widthWithBorder, int heightWithBorder) {
  47. //Relativ to Border
  48. //1-p.y because its on the Top
  49. displayedPosition = new Vec2i((int) (x * widthWithBorder) + border,
  50. (int) ((1 - y) * heightWithBorder) + border);
  51. }
  52. public Vec2f getPoint() {
  53. return new Vec2f((float) x, (float) y);
  54. }
  55. @Override
  56. public String toString() {
  57. return "[" + x + ":" + y + "]";
  58. }
  59. }