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.

89 lines
2.7KB

  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. : BaseWidget(parent)
  32. {
  33. NanoVG::loadSharedResources();
  34. BaseWidget::setSize(500, 300);
  35. }
  36. // TopLevelWidget
  37. explicit ExampleTextWidget(Window& windowToMapTo)
  38. : BaseWidget(windowToMapTo)
  39. {
  40. NanoVG::loadSharedResources();
  41. BaseWidget::setSize(500, 300);
  42. }
  43. // StandaloneWindow
  44. explicit ExampleTextWidget(Application& app)
  45. : BaseWidget(app)
  46. {
  47. NanoVG::loadSharedResources();
  48. BaseWidget::setSize(500, 300);
  49. }
  50. protected:
  51. void onNanoDisplay() override
  52. {
  53. const int width = BaseWidget::getWidth();
  54. const int height = BaseWidget::getHeight();
  55. NanoVG::fontSize(40.0f);
  56. NanoVG::textAlign(NanoVG::Align(NanoVG::ALIGN_CENTER|NanoVG::ALIGN_MIDDLE));
  57. NanoVG::textLineHeight(20.0f);
  58. NanoVG::beginPath();
  59. NanoVG::fillColor(220,220,220,255);
  60. NanoVG::roundedRect(10, height/4+10, width-20, height/2-20, 3);
  61. NanoVG::fill();
  62. NanoVG::fillColor(0,150,0,220);
  63. NanoVG::textBox(10, height/2, width-20, "Hello World!", nullptr);
  64. }
  65. };
  66. typedef ExampleTextWidget<NanoSubWidget> ExampleTextSubWidget;
  67. typedef ExampleTextWidget<NanoTopLevelWidget> ExampleTextTopLevelWidget;
  68. typedef ExampleTextWidget<NanoStandaloneWindow> ExampleTextStandaloneWindow;
  69. // ------------------------------------------------------
  70. END_NAMESPACE_DGL
  71. #endif // EXAMPLE_TEXT_WIDGET_HPP_INCLUDED