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.

199 lines
5.4KB

  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. #ifndef DGL_OPENGL
  17. #error OpenGL build required for Demo
  18. #endif
  19. #include "tests.hpp"
  20. // #define DPF_TEST_POINT_CPP
  21. #include "dgl/src/pugl.cpp"
  22. // #include "dgl/src/SubWidget.cpp"
  23. #include "dgl/src/Application.cpp"
  24. #include "dgl/src/ApplicationPrivateData.cpp"
  25. #include "dgl/src/Geometry.cpp"
  26. #include "dgl/src/OpenGL.cpp"
  27. #include "dgl/src/SubWidget.cpp"
  28. #include "dgl/src/TopLevelWidget.cpp"
  29. #include "dgl/src/TopLevelWidgetPrivateData.cpp"
  30. #include "dgl/src/Widget.cpp"
  31. #include "dgl/src/WidgetPrivateData.cpp"
  32. #include "dgl/src/Window.cpp"
  33. #include "dgl/src/WindowPrivateData.cpp"
  34. #include "dgl/StandaloneWindow.hpp"
  35. #include "widgets/ExampleColorWidget.hpp"
  36. START_NAMESPACE_DGL
  37. // --------------------------------------------------------------------------------------------------------------------
  38. // ------------------------------------------------------
  39. // Left side tab-like widget
  40. class LeftSideWidget : public SubWidget
  41. {
  42. public:
  43. static const int kPageCount = 5;
  44. class Callback
  45. {
  46. public:
  47. virtual ~Callback() {}
  48. virtual void curPageChanged(int curPage) = 0;
  49. };
  50. LeftSideWidget(Widget* parent, Callback* const cb)
  51. : SubWidget(parent),
  52. callback(cb),
  53. curPage(0),
  54. curHover(-1)
  55. {
  56. // for text
  57. // font = nvg.createFontFromFile("sans", "./nanovg_res/Roboto-Regular.ttf");
  58. // using namespace DemoArtwork;
  59. // img1.loadFromMemory(ico1Data, ico1Width, ico1Height, GL_BGR);
  60. // img2.loadFromMemory(ico2Data, ico2Width, ico2Height, GL_BGR);
  61. // img3.loadFromMemory(ico3Data, ico3Width, ico2Height, GL_BGR);
  62. // img4.loadFromMemory(ico4Data, ico4Width, ico4Height, GL_BGR);
  63. // img5.loadFromMemory(ico5Data, ico5Width, ico5Height, GL_BGR);
  64. }
  65. private:
  66. Callback* const callback;
  67. int curPage, curHover;
  68. // Rectangle<int> bgIcon;
  69. // Line<int> lineSep;
  70. // Image img1, img2, img3, img4, img5;
  71. // for text
  72. // NanoVG nvg;
  73. // NanoVG::FontId font;
  74. };
  75. // ------------------------------------------------------
  76. // Our Demo Window
  77. class DemoWindow : public StandaloneWindow,
  78. public LeftSideWidget::Callback
  79. {
  80. static const int kSidebarWidth = 81;
  81. ExampleColorWidget wColor;
  82. Widget* curWidget;
  83. public:
  84. DemoWindow(Application& app)
  85. : StandaloneWindow(app),
  86. wColor(this),
  87. curWidget(nullptr)
  88. {
  89. wColor.hide();
  90. // wImages.hide();
  91. // wRects.hide();
  92. // wShapes.hide();
  93. // wText.hide();
  94. // //wPerf.hide();
  95. wColor.setAbsoluteX(kSidebarWidth);
  96. // wImages.setAbsoluteX(kSidebarWidth);
  97. // wRects.setAbsoluteX(kSidebarWidth);
  98. // wShapes.setAbsoluteX(kSidebarWidth);
  99. // wText.setAbsoluteX(kSidebarWidth);
  100. // wLeft.setAbsolutePos(2, 2);
  101. // wPerf.setAbsoluteY(5);
  102. setSize(600, 500);
  103. setTitle("DGL Demo");
  104. curPageChanged(0);
  105. }
  106. protected:
  107. void curPageChanged(int curPage) override
  108. {
  109. if (curWidget != nullptr)
  110. {
  111. curWidget->hide();
  112. curWidget = nullptr;
  113. }
  114. switch (curPage)
  115. {
  116. case 0:
  117. curWidget = &wColor;
  118. break;
  119. // case 1:
  120. // curWidget = &wImages;
  121. // break;
  122. // case 2:
  123. // curWidget = &wRects;
  124. // break;
  125. // case 3:
  126. // curWidget = &wShapes;
  127. // break;
  128. // case 4:
  129. // curWidget = &wText;
  130. // break;
  131. }
  132. if (curWidget != nullptr)
  133. curWidget->show();
  134. }
  135. void onReshape(uint width, uint height) override
  136. {
  137. StandaloneWindow::onReshape(width, height);
  138. if (width < kSidebarWidth)
  139. return;
  140. Size<uint> size(width-kSidebarWidth, height);
  141. wColor.setSize(size);
  142. // wImages.setSize(size);
  143. // wRects.setSize(size);
  144. // wShapes.setSize(size);
  145. // wText.setSize(size);
  146. // wLeft.setSize(kSidebarWidth-4, height-4);
  147. // //wRezHandle.setAbsoluteX(width-wRezHandle.getWidth());
  148. // //wRezHandle.setAbsoluteY(height-wRezHandle.getHeight());
  149. //
  150. // wPerf.setAbsoluteX(width-wPerf.getWidth()-5);
  151. }
  152. };
  153. // --------------------------------------------------------------------------------------------------------------------
  154. END_NAMESPACE_DGL
  155. int main()
  156. {
  157. USE_NAMESPACE_DGL;
  158. Application app;
  159. DemoWindow win(app);
  160. win.show();
  161. app.exec();
  162. return 0;
  163. }
  164. // --------------------------------------------------------------------------------------------------------------------