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.

132 lines
3.8KB

  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 EXAMPLE_SHAPES_WIDGET_HPP_INCLUDED
  17. #define EXAMPLE_SHAPES_WIDGET_HPP_INCLUDED
  18. // ------------------------------------------------------
  19. // DGL Stuff
  20. #include "../../dgl/Color.hpp"
  21. #include "../../dgl/StandaloneWindow.hpp"
  22. #include "../../dgl/SubWidget.hpp"
  23. START_NAMESPACE_DGL
  24. // ------------------------------------------------------
  25. // our widget
  26. template <class BaseWidget>
  27. class ExampleShapesWidget : public BaseWidget
  28. {
  29. Rectangle<int> bg;
  30. Rectangle<int> rect;
  31. Triangle<int> tri;
  32. Circle<int> cir;
  33. public:
  34. static constexpr const char* const kExampleWidgetName = "Shapes";
  35. // SubWidget
  36. explicit ExampleShapesWidget(Widget* const parent);
  37. // TopLevelWidget
  38. explicit ExampleShapesWidget(Window& windowToMapTo);
  39. // StandaloneWindow
  40. explicit ExampleShapesWidget(Application& app);
  41. protected:
  42. void onDisplay() override
  43. {
  44. const GraphicsContext& context(BaseWidget::getGraphicsContext());
  45. Color(0.302f, 0.337f, 0.361f).setFor(context);;
  46. bg.draw(context);
  47. Color(0.235f, 0.271f, 0.294f).setFor(context);
  48. rect.draw(context);
  49. Color(0.176f, 0.212f, 0.235f).setFor(context);
  50. rect.drawOutline(context, 1);
  51. Color(0.302f*2, 0.337f*2, 0.361f*2).setFor(context);
  52. tri.draw(context);
  53. Color(0.302f/2.0f, 0.337f/2.0f, 0.361f/2.0f).setFor(context);
  54. tri.drawOutline(context, 3);
  55. Color(0.235f, 0.271f, 0.294f).setFor(context);
  56. cir.draw(context);
  57. Color(0.176f/4, 0.212f/4, 0.235f/4).setFor(context);
  58. cir.drawOutline(context, 2);
  59. }
  60. void onResize(const Widget::ResizeEvent& ev) override
  61. {
  62. const int width = ev.size.getWidth();
  63. const int height = ev.size.getHeight();
  64. // background
  65. bg = Rectangle<int>(0, 0, width, height);
  66. // rectangle
  67. rect = Rectangle<int>(20, 10, width-40, height-20);
  68. // center triangle
  69. tri = Triangle<int>(width*0.5, height*0.1, width*0.1, height*0.9, width*0.9, height*0.9);
  70. // circle
  71. cir = Circle<int>(width/2, height*2/3, height/6, 300);
  72. }
  73. };
  74. // SubWidget
  75. template<> inline
  76. ExampleShapesWidget<SubWidget>::ExampleShapesWidget(Widget* const parentWidget)
  77. : SubWidget(parentWidget)
  78. {
  79. setSize(300, 300);
  80. }
  81. // TopLevelWidget
  82. template<> inline
  83. ExampleShapesWidget<TopLevelWidget>::ExampleShapesWidget(Window& windowToMapTo)
  84. : TopLevelWidget(windowToMapTo)
  85. {
  86. setSize(300, 300);
  87. }
  88. // StandaloneWindow
  89. template<> inline
  90. ExampleShapesWidget<StandaloneWindow>::ExampleShapesWidget(Application& app)
  91. : StandaloneWindow(app)
  92. {
  93. setSize(300, 300);
  94. done();
  95. }
  96. typedef ExampleShapesWidget<SubWidget> ExampleShapesSubWidget;
  97. typedef ExampleShapesWidget<TopLevelWidget> ExampleShapesTopLevelWidget;
  98. typedef ExampleShapesWidget<StandaloneWindow> ExampleShapesStandaloneWindow;
  99. // ------------------------------------------------------
  100. END_NAMESPACE_DGL
  101. #endif // EXAMPLE_SHAPES_WIDGET_HPP_INCLUDED