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.

131 lines
3.3KB

  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. {
  45. public:
  46. explicit NanoRectanglesContainer(Window& parent)
  47. : NanoTopLevelWidget(parent),
  48. rect1(this),
  49. rect2(this),
  50. rect3(this)
  51. {
  52. rect1.setAbsolutePos(100, 100);
  53. rect1.setSize(25, 25);
  54. rect1.setColor(Color(255, 0, 0));
  55. rect2.setAbsolutePos(200, 200);
  56. rect2.setSize(25, 25);
  57. rect2.setColor(Color(0, 255, 0));
  58. rect3.setAbsolutePos(300, 300);
  59. rect3.setSize(25, 25);
  60. rect3.setColor(Color(0, 0, 255));
  61. }
  62. protected:
  63. void onNanoDisplay() override
  64. {
  65. beginPath();
  66. fillColor(Color(0.5f, 0.5f, 0.5f));
  67. rect(0, 0, getWidth(), getHeight());
  68. fill();
  69. closePath();
  70. }
  71. private:
  72. NanoRectangle rect1, rect2, rect3;
  73. };
  74. // --------------------------------------------------------------------------------------------------------------------
  75. class NanoExampleWindow : public Window
  76. {
  77. public:
  78. explicit NanoExampleWindow(Application& app)
  79. : Window(app),
  80. container(*this)
  81. {
  82. const uint targetWidth = 400;
  83. const uint targetHeight = 400;
  84. setSize(targetWidth, targetHeight);
  85. setTitle("NanoVG SubWidgets test");
  86. }
  87. private:
  88. NanoRectanglesContainer container;
  89. };
  90. // --------------------------------------------------------------------------------------------------------------------
  91. END_NAMESPACE_DGL
  92. int main()
  93. {
  94. USE_NAMESPACE_DGL;
  95. Application app;
  96. NanoExampleWindow win(app);
  97. win.show();
  98. app.exec();
  99. return 0;
  100. }
  101. // --------------------------------------------------------------------------------------------------------------------