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.

166 lines
5.3KB

  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. // We need a few classes from DGL.
  23. using DGL_NAMESPACE::CairoGraphicsContext;
  24. using DGL_NAMESPACE::CairoImage;
  25. using DGL_NAMESPACE::CairoImageKnob;
  26. using DGL_NAMESPACE::CairoImageSwitch;
  27. // And from ourselves
  28. using DGL_NAMESPACE::DemoWidgetBanner;
  29. class CairoExampleUI : public UI,
  30. public CairoImageKnob::Callback,
  31. public CairoImageSwitch::Callback,
  32. public DemoWidgetClickable::Callback
  33. {
  34. ScopedPointer<CairoImageKnob> fKnob;
  35. ScopedPointer<CairoImageSwitch> fButton;
  36. ScopedPointer<DemoWidgetBanner> fWidgetBanner;
  37. ScopedPointer<DemoWidgetClickable> fWidgetClickable;
  38. public:
  39. CairoExampleUI()
  40. {
  41. CairoImage knobSkin;
  42. knobSkin.loadFromPNG(Artwork::knobData, Artwork::knobDataSize);
  43. fWidgetBanner = new DemoWidgetBanner(this);
  44. fWidgetBanner->setAbsolutePos(10, 10);
  45. fWidgetBanner->setSize(180, 80);
  46. fWidgetClickable = new DemoWidgetClickable(this);
  47. fWidgetClickable->setAbsolutePos(100, 100);
  48. fWidgetClickable->setSize(50, 50);
  49. fWidgetClickable->setCallback(this);
  50. fWidgetClickable->setId(kParameterTriState);
  51. fKnob = new CairoImageKnob(this, knobSkin);
  52. fKnob->setAbsolutePos(10, 100);
  53. fKnob->setSize(80, 80);
  54. fKnob->setCallback(this);
  55. fKnob->setId(kParameterKnob);
  56. CairoImage buttonOn, buttonOff;
  57. buttonOn.loadFromPNG(Artwork::buttonOnData, Artwork::buttonOnDataSize);
  58. buttonOff.loadFromPNG(Artwork::buttonOffData, Artwork::buttonOffDataSize);
  59. fButton = new CairoImageSwitch(this, buttonOff, buttonOn);
  60. fButton->setAbsolutePos(100, 160);
  61. fButton->setSize(60, 35);
  62. fButton->setCallback(this);
  63. fButton->setId(kParameterButton);
  64. #if 0
  65. // we can use this if/when our resources are scalable, for now they are PNGs
  66. const double scaleFactor = getScaleFactor();
  67. if (scaleFactor != 1.0)
  68. setSize(200 * scaleFactor, 200 * scaleFactor);
  69. #else
  70. // without scalable resources, let DPF handle the scaling internally
  71. setGeometryConstraints(DISTRHO_UI_DEFAULT_WIDTH, DISTRHO_UI_DEFAULT_HEIGHT, true, true);
  72. #endif
  73. }
  74. protected:
  75. void onCairoDisplay(const CairoGraphicsContext& context)
  76. {
  77. cairo_t* const cr = context.handle;
  78. cairo_set_source_rgb(cr, 1.0, 0.8, 0.5);
  79. cairo_paint(cr);
  80. }
  81. #if 0
  82. // we can use this if/when our resources are scalable, for now they are PNGs
  83. void onResize(const ResizeEvent& ev) override
  84. {
  85. UI::onResize(ev);
  86. const double scaleFactor = getScaleFactor();
  87. fWidgetClickable->setSize(50*scaleFactor, 50*scaleFactor);
  88. fWidgetClickable->setAbsolutePos(100*scaleFactor, 100*scaleFactor);
  89. fWidgetBanner->setSize(180*scaleFactor, 80*scaleFactor);
  90. fWidgetBanner->setAbsolutePos(10*scaleFactor, 10*scaleFactor);
  91. fKnob->setSize(80*scaleFactor, 80*scaleFactor);
  92. fKnob->setAbsolutePos(10*scaleFactor, 100*scaleFactor);
  93. fButton->setSize(60*scaleFactor, 35*scaleFactor);
  94. fButton->setAbsolutePos(100*scaleFactor, 160*scaleFactor);
  95. }
  96. #endif
  97. void parameterChanged(const uint32_t index, const float value) override
  98. {
  99. switch (index)
  100. {
  101. case kParameterKnob:
  102. fKnob->setValue(value);
  103. break;
  104. case kParameterTriState:
  105. fWidgetClickable->setColorId(static_cast<int>(value + 0.5f));
  106. break;
  107. case kParameterButton:
  108. fButton->setDown(value > 0.5f);
  109. break;
  110. }
  111. }
  112. void demoWidgetClicked(DemoWidgetClickable*, const uint8_t colorId) override
  113. {
  114. setParameterValue(kParameterTriState, colorId);
  115. }
  116. void imageKnobDragStarted(CairoImageKnob*) override
  117. {
  118. editParameter(kParameterKnob, true);
  119. }
  120. void imageKnobDragFinished(CairoImageKnob*) override
  121. {
  122. editParameter(kParameterKnob, false);
  123. }
  124. void imageKnobValueChanged(CairoImageKnob*, const float value) override
  125. {
  126. setParameterValue(kParameterKnob, value);
  127. }
  128. void imageSwitchClicked(CairoImageSwitch*, bool down) override
  129. {
  130. setParameterValue(kParameterButton, down ? 1.f : 0.f);
  131. }
  132. };
  133. UI* createUI()
  134. {
  135. return new CairoExampleUI;
  136. }
  137. END_NAMESPACE_DISTRHO