DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
4.9KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef DGL_GEOMETRY_HPP_INCLUDED
  17. #define DGL_GEOMETRY_HPP_INCLUDED
  18. #include "Base.hpp"
  19. START_NAMESPACE_DGL
  20. // -----------------------------------------------------------------------
  21. template<typename> class Rectangle;
  22. // -----------------------------------------------------------------------
  23. template<typename T>
  24. class Point
  25. {
  26. public:
  27. Point() noexcept;
  28. Point(const T& x, const T& y) noexcept;
  29. Point(const Point<T>& pos) noexcept;
  30. const T& getX() const noexcept;
  31. const T& getY() const noexcept;
  32. void setX(const T& x) noexcept;
  33. void setY(const T& y) noexcept;
  34. void setPos(const T& x, const T& y) noexcept;
  35. void setPos(const Point<T>& pos) noexcept;
  36. void moveBy(const T& x, const T& y) noexcept;
  37. void moveBy(const Point<T>& pos) noexcept;
  38. Point<T>& operator=(const Point<T>& pos) noexcept;
  39. Point<T>& operator+=(const Point<T>& pos) noexcept;
  40. Point<T>& operator-=(const Point<T>& pos) noexcept;
  41. bool operator==(const Point<T>& pos) const noexcept;
  42. bool operator!=(const Point<T>& pos) const noexcept;
  43. private:
  44. T fX, fY;
  45. template<typename> friend class Rectangle;
  46. };
  47. // -----------------------------------------------------------------------
  48. template<typename T>
  49. class Size
  50. {
  51. public:
  52. Size() noexcept;
  53. Size(const T& width, const T& height) noexcept;
  54. Size(const Size<T>& size) noexcept;
  55. const T& getWidth() const noexcept;
  56. const T& getHeight() const noexcept;
  57. void setWidth(const T& width) noexcept;
  58. void setHeight(const T& height) noexcept;
  59. void setSize(const T& width, const T& height) noexcept;
  60. void setSize(const Size<T>& size) noexcept;
  61. void growBy(const T& multiplier) noexcept;
  62. void shrinkBy(const T& divider) noexcept;
  63. Size<T>& operator=(const Size<T>& size) noexcept;
  64. Size<T>& operator+=(const Size<T>& size) noexcept;
  65. Size<T>& operator-=(const Size<T>& size) noexcept;
  66. Size<T>& operator*=(const T& m) noexcept;
  67. Size<T>& operator/=(const T& d) noexcept;
  68. bool operator==(const Size<T>& size) const noexcept;
  69. bool operator!=(const Size<T>& size) const noexcept;
  70. private:
  71. T fWidth, fHeight;
  72. template<typename> friend class Rectangle;
  73. };
  74. // -----------------------------------------------------------------------
  75. template<typename T>
  76. class Rectangle
  77. {
  78. public:
  79. Rectangle() noexcept;
  80. Rectangle(const T& x, const T& y, const T& width, const T& height) noexcept;
  81. Rectangle(const T& x, const T& y, const Size<T>& size) noexcept;
  82. Rectangle(const Point<T>& pos, const T& width, const T& height) noexcept;
  83. Rectangle(const Point<T>& pos, const Size<T>& size) noexcept;
  84. Rectangle(const Rectangle<T>& rect) noexcept;
  85. const T& getX() const noexcept;
  86. const T& getY() const noexcept;
  87. const T& getWidth() const noexcept;
  88. const T& getHeight() const noexcept;
  89. const Point<T>& getPos() const noexcept;
  90. const Size<T>& getSize() const noexcept;
  91. void setX(const T& x) noexcept;
  92. void setY(const T& y) noexcept;
  93. void setPos(const T& x, const T& y) noexcept;
  94. void setPos(const Point<T>& pos) noexcept;
  95. void moveBy(const T& x, const T& y) noexcept;
  96. void moveBy(const Point<T>& pos) noexcept;
  97. void setWidth(const T& width) noexcept;
  98. void setHeight(const T& height) noexcept;
  99. void setSize(const T& width, const T& height) noexcept;
  100. void setSize(const Size<T>& size) noexcept;
  101. void growBy(const T& multiplier) noexcept;
  102. void shrinkBy(const T& divider) noexcept;
  103. bool contains(const T& x, const T& y) const noexcept;
  104. bool contains(const Point<T>& pos) const noexcept;
  105. bool containsX(const T& x) const noexcept;
  106. bool containsY(const T& y) const noexcept;
  107. void draw();
  108. Rectangle<T>& operator=(const Rectangle<T>& rect) noexcept;
  109. Rectangle<T>& operator*=(const T& m) noexcept;
  110. Rectangle<T>& operator/=(const T& d) noexcept;
  111. bool operator==(const Rectangle<T>& size) const noexcept;
  112. bool operator!=(const Rectangle<T>& size) const noexcept;
  113. private:
  114. Point<T> fPos;
  115. Size<T> fSize;
  116. };
  117. // -----------------------------------------------------------------------
  118. END_NAMESPACE_DGL
  119. #endif // DGL_GEOMETRY_HPP_INCLUDED