UnitGraphPoint.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. public class UnitGraphPoint {
  8. /**
  9. * Relative position in the UnitGraphCanvas
  10. */
  11. public double x, y;
  12. /**
  13. * To determine if this point has changed to only write back points that are changed.
  14. */
  15. public boolean changed;
  16. /**
  17. * The displayed Position of the UnitGraphPoint
  18. */
  19. public Vec2i displayedPosition;
  20. /**
  21. * Default Constructor
  22. */
  23. public UnitGraphPoint(double x, double y, boolean changed) {
  24. this.x = x;
  25. this.y = y;
  26. this.changed = changed;
  27. }
  28. /**
  29. * Constructor with a Point2D.Double
  30. */
  31. public UnitGraphPoint(Vec2f pos, boolean changed) {
  32. this.x = pos.getX();
  33. this.y = pos.getY();
  34. this.changed = changed;
  35. }
  36. /**
  37. * Constructor with a Point2D.Double when changed not specified is false;
  38. */
  39. public UnitGraphPoint(Vec2f pos) {
  40. this.x = pos.getX();
  41. this.y = pos.getY();
  42. this.changed = false;
  43. }
  44. /**
  45. * Calculate the corresponding position in pixels [0,width] from the relative position [0.0,1.0].
  46. * @param border the border size
  47. * @param widthWithBorder the width
  48. * @param heightWithBorder the height
  49. */
  50. public void calcDisplayedPosition(int border, int widthWithBorder, int heightWithBorder) {
  51. //Relativ to Border
  52. //1-p.y because its on the Top
  53. displayedPosition = new Vec2i((int) (x * widthWithBorder) + border,
  54. (int) ((1 - y) * heightWithBorder) + border);
  55. }
  56. public Vec2f getPoint() {
  57. return new Vec2f((float) x, (float) y);
  58. }
  59. @Override
  60. public String toString() {
  61. return "[" + x + ":" + y + "]";
  62. }
  63. }