geometry.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #if defined(Hiro_Geometry)
  2. Geometry::Geometry() {
  3. setGeometry(0, 0, 0, 0);
  4. }
  5. Geometry::Geometry(Position position, Size size) {
  6. setGeometry(position, size);
  7. }
  8. Geometry::Geometry(float x, float y, float width, float height) {
  9. setGeometry(x, y, width, height);
  10. }
  11. Geometry::operator bool() const {
  12. return state.x || state.y || state.width || state.height;
  13. }
  14. auto Geometry::operator==(const Geometry& source) const -> bool {
  15. return x() == source.x() && y() == source.y() && width() == source.width() && height() == source.height();
  16. }
  17. auto Geometry::operator!=(const Geometry& source) const -> bool {
  18. return !operator==(source);
  19. }
  20. auto Geometry::height() const -> float {
  21. return state.height;
  22. }
  23. auto Geometry::position() const -> Position {
  24. return {state.x, state.y};
  25. }
  26. auto Geometry::reset() -> type& {
  27. return setGeometry(0, 0, 0, 0);
  28. }
  29. auto Geometry::setHeight(float height) -> type& {
  30. state.height = height;
  31. return *this;
  32. }
  33. auto Geometry::setGeometry(Geometry geometry) -> type& {
  34. return setGeometry(geometry.x(), geometry.y(), geometry.width(), geometry.height());
  35. }
  36. auto Geometry::setGeometry(Position position, Size size) -> type& {
  37. setGeometry(position.x(), position.y(), size.width(), size.height());
  38. return *this;
  39. }
  40. auto Geometry::setGeometry(float x, float y, float width, float height) -> type& {
  41. state.x = x;
  42. state.y = y;
  43. state.width = width;
  44. state.height = height;
  45. return *this;
  46. }
  47. auto Geometry::setPosition(Position position) -> type& {
  48. return setPosition(position.x(), position.y());
  49. }
  50. auto Geometry::setPosition(float x, float y) -> type& {
  51. state.x = x;
  52. state.y = y;
  53. return *this;
  54. }
  55. auto Geometry::setSize(Size size) -> type& {
  56. return setSize(size.width(), size.height());
  57. }
  58. auto Geometry::setSize(float width, float height) -> type& {
  59. state.width = width;
  60. state.height = height;
  61. return *this;
  62. }
  63. auto Geometry::setWidth(float width) -> type& {
  64. state.width = width;
  65. return *this;
  66. }
  67. auto Geometry::setX(float x) -> type& {
  68. state.x = x;
  69. return *this;
  70. }
  71. auto Geometry::setY(float y) -> type& {
  72. state.y = y;
  73. return *this;
  74. }
  75. auto Geometry::size() const -> Size {
  76. return {state.width, state.height};
  77. }
  78. auto Geometry::width() const -> float {
  79. return state.width;
  80. }
  81. auto Geometry::x() const -> float {
  82. return state.x;
  83. }
  84. auto Geometry::y() const -> float {
  85. return state.y;
  86. }
  87. #endif