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.

124 lines
3.9KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
  4. * Copyright (C) 2019-2021 Jean Pierre Cimalando <jp-dev@inbox.ru>
  5. *
  6. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  7. * or without fee is hereby granted, provided that the above copyright notice and this
  8. * permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  11. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  12. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  14. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  15. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include "DistrhoUI.hpp"
  18. #include "Artwork.hpp"
  19. #include "DemoWidgetBanner.hpp"
  20. #include "DemoWidgetClickable.hpp"
  21. START_NAMESPACE_DISTRHO
  22. /**
  23. We need a few classes from DGL.
  24. */
  25. using DGL_NAMESPACE::CairoGraphicsContext;
  26. using DGL_NAMESPACE::CairoImage;
  27. using DGL_NAMESPACE::CairoImageButton;
  28. using DGL_NAMESPACE::CairoImageKnob;
  29. class CairoExampleUI : public UI
  30. {
  31. public:
  32. CairoExampleUI()
  33. : UI(200, 200)
  34. {
  35. fWidgetClickable = new DemoWidgetClickable(this);
  36. fWidgetClickable->setSize(50, 50);
  37. fWidgetClickable->setAbsolutePos(100, 100);
  38. fWidgetBanner = new DemoWidgetBanner(this);
  39. fWidgetBanner->setSize(180, 80);
  40. fWidgetBanner->setAbsolutePos(10, 10);
  41. CairoImage knobSkin;
  42. knobSkin.loadFromPNG(Artwork::knobData, Artwork::knobDataSize);
  43. fKnob = new CairoImageKnob(this, knobSkin);
  44. fKnob->setSize(80, 80);
  45. fKnob->setAbsolutePos(10, 100);
  46. CairoImage buttonOn, buttonOff;
  47. buttonOn.loadFromPNG(Artwork::buttonOnData, Artwork::buttonOnDataSize);
  48. buttonOff.loadFromPNG(Artwork::buttonOffData, Artwork::buttonOffDataSize);
  49. fButton = new CairoImageButton(this, buttonOff, buttonOn);
  50. fButton->setSize(60, 35);
  51. fButton->setAbsolutePos(100, 160);
  52. #if 0
  53. // we can use this if/when our resources are scalable, for now they are PNGs
  54. const double scaleFactor = getScaleFactor();
  55. if (scaleFactor != 1.0)
  56. setSize(200 * scaleFactor, 200 * scaleFactor);
  57. #else
  58. // without scalable resources, let DPF handle the scaling internally
  59. setGeometryConstraints(200, 200, true, true);
  60. #endif
  61. }
  62. protected:
  63. void onCairoDisplay(const CairoGraphicsContext& context)
  64. {
  65. cairo_t* const cr = context.handle;
  66. cairo_set_source_rgb(cr, 1.0, 0.8, 0.5);
  67. cairo_paint(cr);
  68. }
  69. #if 0
  70. // we can use this if/when our resources are scalable, for now they are PNGs
  71. void onResize(const ResizeEvent& ev) override
  72. {
  73. UI::onResize(ev);
  74. const double scaleFactor = getScaleFactor();
  75. fWidgetClickable->setSize(50*scaleFactor, 50*scaleFactor);
  76. fWidgetClickable->setAbsolutePos(100*scaleFactor, 100*scaleFactor);
  77. fWidgetBanner->setSize(180*scaleFactor, 80*scaleFactor);
  78. fWidgetBanner->setAbsolutePos(10*scaleFactor, 10*scaleFactor);
  79. fKnob->setSize(80*scaleFactor, 80*scaleFactor);
  80. fKnob->setAbsolutePos(10*scaleFactor, 100*scaleFactor);
  81. fButton->setSize(60*scaleFactor, 35*scaleFactor);
  82. fButton->setAbsolutePos(100*scaleFactor, 160*scaleFactor);
  83. }
  84. #endif
  85. void parameterChanged(uint32_t index, float value) override
  86. {
  87. // unused
  88. (void)index;
  89. (void)value;
  90. }
  91. private:
  92. ScopedPointer<DemoWidgetClickable> fWidgetClickable;
  93. ScopedPointer<DemoWidgetBanner> fWidgetBanner;
  94. ScopedPointer<CairoImageKnob> fKnob;
  95. ScopedPointer<CairoImageButton> fButton;
  96. };
  97. UI* createUI()
  98. {
  99. return new CairoExampleUI;
  100. }
  101. END_NAMESPACE_DISTRHO