Collection of DPF-based plugins for packaging
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.

158 lines
4.0KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2019 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. #include "../Geometry.hpp"
  17. #include "../OpenGL.hpp"
  18. START_NAMESPACE_DGL
  19. // -----------------------------------------------------------------------
  20. // Line
  21. template<typename T>
  22. void Line<T>::draw()
  23. {
  24. DISTRHO_SAFE_ASSERT_RETURN(fPosStart != fPosEnd,);
  25. glBegin(GL_LINES);
  26. {
  27. glVertex2d(fPosStart.fX, fPosStart.fY);
  28. glVertex2d(fPosEnd.fX, fPosEnd.fY);
  29. }
  30. glEnd();
  31. }
  32. // -----------------------------------------------------------------------
  33. // Circle
  34. template<typename T>
  35. void Circle<T>::_draw(const bool outline)
  36. {
  37. DISTRHO_SAFE_ASSERT_RETURN(fNumSegments >= 3 && fSize > 0.0f,);
  38. double t, x = fSize, y = 0.0;
  39. glBegin(outline ? GL_LINE_LOOP : GL_POLYGON);
  40. for (uint i=0; i<fNumSegments; ++i)
  41. {
  42. glVertex2d(x + fPos.fX, y + fPos.fY);
  43. t = x;
  44. x = fCos * x - fSin * y;
  45. y = fSin * t + fCos * y;
  46. }
  47. glEnd();
  48. }
  49. // -----------------------------------------------------------------------
  50. // Triangle
  51. template<typename T>
  52. void Triangle<T>::_draw(const bool outline)
  53. {
  54. DISTRHO_SAFE_ASSERT_RETURN(fPos1 != fPos2 && fPos1 != fPos3,);
  55. glBegin(outline ? GL_LINE_LOOP : GL_TRIANGLES);
  56. {
  57. glVertex2d(fPos1.fX, fPos1.fY);
  58. glVertex2d(fPos2.fX, fPos2.fY);
  59. glVertex2d(fPos3.fX, fPos3.fY);
  60. }
  61. glEnd();
  62. }
  63. // -----------------------------------------------------------------------
  64. // Rectangle
  65. template<typename T>
  66. void Rectangle<T>::_draw(const bool outline)
  67. {
  68. DISTRHO_SAFE_ASSERT_RETURN(fSize.isValid(),);
  69. glBegin(outline ? GL_LINE_LOOP : GL_QUADS);
  70. {
  71. glTexCoord2f(0.0f, 0.0f);
  72. glVertex2d(fPos.fX, fPos.fY);
  73. glTexCoord2f(1.0f, 0.0f);
  74. glVertex2d(fPos.fX+fSize.fWidth, fPos.fY);
  75. glTexCoord2f(1.0f, 1.0f);
  76. glVertex2d(fPos.fX+fSize.fWidth, fPos.fY+fSize.fHeight);
  77. glTexCoord2f(0.0f, 1.0f);
  78. glVertex2d(fPos.fX, fPos.fY+fSize.fHeight);
  79. }
  80. glEnd();
  81. }
  82. // -----------------------------------------------------------------------
  83. // Possible template data types
  84. template class Point<double>;
  85. template class Point<float>;
  86. template class Point<int>;
  87. template class Point<uint>;
  88. template class Point<short>;
  89. template class Point<ushort>;
  90. template class Size<double>;
  91. template class Size<float>;
  92. template class Size<int>;
  93. template class Size<uint>;
  94. template class Size<short>;
  95. template class Size<ushort>;
  96. template class Line<double>;
  97. template class Line<float>;
  98. template class Line<int>;
  99. template class Line<uint>;
  100. template class Line<short>;
  101. template class Line<ushort>;
  102. template class Circle<double>;
  103. template class Circle<float>;
  104. template class Circle<int>;
  105. template class Circle<uint>;
  106. template class Circle<short>;
  107. template class Circle<ushort>;
  108. template class Triangle<double>;
  109. template class Triangle<float>;
  110. template class Triangle<int>;
  111. template class Triangle<uint>;
  112. template class Triangle<short>;
  113. template class Triangle<ushort>;
  114. template class Rectangle<double>;
  115. template class Rectangle<float>;
  116. template class Rectangle<int>;
  117. template class Rectangle<uint>;
  118. template class Rectangle<short>;
  119. template class Rectangle<ushort>;
  120. // -----------------------------------------------------------------------
  121. END_NAMESPACE_DGL