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.

136 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. }
  66. private:
  67. NanoRectangle rect1, rect2, rect3;
  68. };
  69. // --------------------------------------------------------------------------------------------------------------------
  70. class NanoExampleWindow : public Window
  71. {
  72. public:
  73. explicit NanoExampleWindow(Application& app)
  74. : Window(app),
  75. container(*this)
  76. {
  77. const uint targetWidth = 1000;
  78. const uint targetHeight = 600;
  79. setSize(targetWidth, targetHeight);
  80. // container.setSize(width, height);
  81. setTitle("NanoVG SubWidgets test");
  82. }
  83. /*
  84. protected:
  85. void onReshape(uint width, uint height) override
  86. {
  87. container.setSize(width, height);
  88. Window::onReshape(width, height);
  89. }
  90. */
  91. private:
  92. NanoRectanglesContainer container;
  93. };
  94. // --------------------------------------------------------------------------------------------------------------------
  95. END_NAMESPACE_DGL
  96. int main()
  97. {
  98. USE_NAMESPACE_DGL;
  99. Application app;
  100. NanoExampleWindow win(app);
  101. win.show();
  102. app.exec();
  103. return 0;
  104. }
  105. // --------------------------------------------------------------------------------------------------------------------