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.

102 lines
3.1KB

  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_TEXT_WIDGET_HPP_INCLUDED
  17. #define EXAMPLE_TEXT_WIDGET_HPP_INCLUDED
  18. // ------------------------------------------------------
  19. // DGL Stuff
  20. #include "../../dgl/NanoVG.hpp"
  21. START_NAMESPACE_DGL
  22. // ------------------------------------------------------
  23. // our widget
  24. template <class BaseWidget>
  25. class ExampleTextWidget : public BaseWidget
  26. {
  27. public:
  28. static constexpr const char* kExampleWidgetName = "Text";
  29. // SubWidget
  30. explicit ExampleTextWidget(Widget* const parent);
  31. // TopLevelWidget
  32. explicit ExampleTextWidget(Window& windowToMapTo);
  33. // StandaloneWindow
  34. explicit ExampleTextWidget(Application& app);
  35. protected:
  36. void onNanoDisplay() override
  37. {
  38. const int width = BaseWidget::getWidth();
  39. const int height = BaseWidget::getHeight();
  40. NanoVG::fontSize(40.0f);
  41. NanoVG::textAlign(NanoVG::Align(NanoVG::ALIGN_CENTER|NanoVG::ALIGN_MIDDLE));
  42. NanoVG::textLineHeight(20.0f);
  43. NanoVG::beginPath();
  44. NanoVG::fillColor(220,220,220,255);
  45. NanoVG::roundedRect(10, height/4+10, width-20, height/2-20, 3);
  46. NanoVG::fill();
  47. NanoVG::fillColor(0,150,0,220);
  48. NanoVG::textBox(10, height/2, width-20, "Hello World!", nullptr);
  49. }
  50. };
  51. template<> inline
  52. ExampleTextWidget<NanoSubWidget>::ExampleTextWidget(Widget* const parent)
  53. : NanoSubWidget(parent)
  54. {
  55. loadSharedResources();
  56. setSize(500, 300);
  57. }
  58. template<> inline
  59. ExampleTextWidget<NanoTopLevelWidget>::ExampleTextWidget(Window& windowToMapTo)
  60. : NanoTopLevelWidget(windowToMapTo)
  61. {
  62. loadSharedResources();
  63. setSize(500, 300);
  64. }
  65. template<> inline
  66. ExampleTextWidget<NanoStandaloneWindow>::ExampleTextWidget(Application& app)
  67. : NanoStandaloneWindow(app)
  68. {
  69. loadSharedResources();
  70. setSize(500, 300);
  71. }
  72. template class ExampleTextWidget<NanoSubWidget>;
  73. template class ExampleTextWidget<NanoTopLevelWidget>;
  74. template class ExampleTextWidget<NanoStandaloneWindow>;
  75. typedef ExampleTextWidget<NanoSubWidget> ExampleTextSubWidget;
  76. typedef ExampleTextWidget<NanoTopLevelWidget> ExampleTextTopLevelWidget;
  77. typedef ExampleTextWidget<NanoStandaloneWindow> ExampleTextStandaloneWindow;
  78. // ------------------------------------------------------
  79. END_NAMESPACE_DGL
  80. #endif // EXAMPLE_TEXT_WIDGET_HPP_INCLUDED