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.

171 lines
4.3KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2025 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 "tests.hpp"
  17. #include "dgl.cpp"
  18. #include "dgl/src/Color.cpp"
  19. #include "dgl/src/NanoVG.cpp"
  20. #include "dgl/src/Resources.cpp"
  21. START_NAMESPACE_DGL
  22. // --------------------------------------------------------------------------------------------------------------------
  23. class NanoRectangle : public NanoSubWidget
  24. {
  25. public:
  26. explicit NanoRectangle(Widget* const parent)
  27. : NanoSubWidget(parent),
  28. color() {}
  29. void setColor(const Color c) noexcept
  30. {
  31. color = c;
  32. }
  33. protected:
  34. void onNanoDisplay() override
  35. {
  36. beginPath();
  37. fillColor(color);
  38. rect(0, 0, getWidth(), getHeight());
  39. fill();
  40. closePath();
  41. }
  42. private:
  43. Color color;
  44. };
  45. // --------------------------------------------------------------------------------------------------------------------
  46. class NanoRectanglesContainer : public NanoTopLevelWidget,
  47. public IdleCallback
  48. {
  49. public:
  50. explicit NanoRectanglesContainer(Window& parent)
  51. : NanoTopLevelWidget(parent),
  52. rect1(this),
  53. rect2(this),
  54. rect3(this),
  55. rectToHide(1)
  56. {
  57. rect1.setAbsolutePos(100, 100);
  58. rect1.setSize(25, 25);
  59. rect1.setColor(Color(255, 0, 0));
  60. rect2.setAbsolutePos(200, 200);
  61. rect2.setSize(25, 25);
  62. rect2.setColor(Color(0, 255, 0));
  63. rect3.setAbsolutePos(300, 300);
  64. rect3.setSize(25, 25);
  65. rect3.setColor(Color(0, 0, 255));
  66. idleCallback();
  67. addIdleCallback(this, 500);
  68. }
  69. protected:
  70. void onNanoDisplay() override
  71. {
  72. beginPath();
  73. fillColor(Color(0.5f, 0.5f, 0.5f));
  74. rect(0, 0, getWidth(), getHeight());
  75. fill();
  76. closePath();
  77. }
  78. void idleCallback() override
  79. {
  80. switch (rectToHide)
  81. {
  82. case 1:
  83. rect1.hide();
  84. rect2.show();
  85. rect3.show();
  86. rectToHide = 2;
  87. break;
  88. case 2:
  89. rect1.show();
  90. rect2.hide();
  91. rect3.show();
  92. rectToHide = 3;
  93. break;
  94. case 3:
  95. rect1.show();
  96. rect2.show();
  97. rect3.hide();
  98. rectToHide = 1;
  99. break;
  100. }
  101. }
  102. private:
  103. NanoRectangle rect1, rect2, rect3;
  104. int rectToHide;
  105. };
  106. // --------------------------------------------------------------------------------------------------------------------
  107. class NanoExampleWindow : public Window
  108. {
  109. public:
  110. explicit NanoExampleWindow(Application& app)
  111. : Window(app)
  112. {
  113. {
  114. const ScopedGraphicsContext sgc(*this);
  115. container = new NanoRectanglesContainer(*this);
  116. }
  117. const uint targetWidth = 400;
  118. const uint targetHeight = 400;
  119. const double scaleFactor = getScaleFactor();
  120. setGeometryConstraints(targetWidth, targetHeight, true);
  121. setResizable(true);
  122. setSize(targetWidth * scaleFactor, targetHeight * scaleFactor);
  123. setTitle("NanoVG SubWidgets test");
  124. }
  125. private:
  126. ScopedPointer<NanoRectanglesContainer> container;
  127. };
  128. // --------------------------------------------------------------------------------------------------------------------
  129. END_NAMESPACE_DGL
  130. int main()
  131. {
  132. using DGL_NAMESPACE::Application;
  133. using DGL_NAMESPACE::NanoExampleWindow;
  134. Application app;
  135. NanoExampleWindow win(app);
  136. win.show();
  137. app.exec();
  138. return 0;
  139. }
  140. // --------------------------------------------------------------------------------------------------------------------