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.

162 lines
3.9KB

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