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.

105 lines
3.3KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2019 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. #include "DistrhoUI.hpp"
  17. #include "DemoWidgetBanner.hpp"
  18. #include "DemoWidgetClickable.hpp"
  19. #include "ImageWidgets.hpp"
  20. #include "Window.hpp"
  21. #include "Artwork.hpp"
  22. START_NAMESPACE_DISTRHO
  23. class CairoExampleUI : public UI
  24. {
  25. public:
  26. CairoExampleUI()
  27. : UI(200, 200)
  28. {
  29. const GraphicsContext& gc = getParentWindow().getGraphicsContext();
  30. DemoWidgetClickable* widgetClickable = new DemoWidgetClickable(this);
  31. fWidgetClickable = widgetClickable;
  32. widgetClickable->setSize(50, 50);
  33. widgetClickable->setAbsolutePos(100, 100);
  34. DemoWidgetBanner* widgetBanner = new DemoWidgetBanner(this);
  35. fWidgetBanner = widgetBanner;
  36. widgetBanner->setSize(180, 80);
  37. widgetBanner->setAbsolutePos(10, 10);
  38. Image knobSkin;
  39. knobSkin.loadFromPng(Artwork::knobData, Artwork::knobDataSize, &gc);
  40. ImageKnob* knob = new ImageKnob(this, knobSkin);
  41. fKnob = knob;
  42. knob->setSize(80, 80);
  43. knob->setAbsolutePos(10, 100);
  44. // knob->setRotationAngle(270);
  45. Image buttonOn, buttonOff;
  46. buttonOn.loadFromPng(Artwork::buttonOnData, Artwork::buttonOnDataSize, &gc);
  47. buttonOff.loadFromPng(Artwork::buttonOffData, Artwork::buttonOffDataSize, &gc);
  48. ImageButton* button = new ImageButton(this, buttonOff, buttonOn);
  49. fButton = button;
  50. button->setSize(60, 35);
  51. button->setAbsolutePos(100, 160);
  52. }
  53. ~CairoExampleUI()
  54. {
  55. }
  56. void onDisplay()
  57. {
  58. cairo_t* cr = getParentWindow().getGraphicsContext().cairo;
  59. cairo_set_source_rgb(cr, 1.0, 0.8, 0.5);
  60. cairo_paint(cr);
  61. ImageKnob* knob = fKnob;
  62. cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.1);
  63. cairo_rectangle(cr, knob->getAbsoluteX(), knob->getAbsoluteY(), knob->getWidth(), knob->getHeight());
  64. cairo_fill(cr);
  65. ImageButton* button = fButton;
  66. cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.1);
  67. cairo_rectangle(cr, button->getAbsoluteX(), button->getAbsoluteY(), button->getWidth(), button->getHeight());
  68. cairo_fill(cr);
  69. }
  70. void parameterChanged(uint32_t index, float value)
  71. {
  72. // unused
  73. (void)index;
  74. (void)value;
  75. }
  76. private:
  77. ScopedPointer<DemoWidgetClickable> fWidgetClickable;
  78. ScopedPointer<DemoWidgetBanner> fWidgetBanner;
  79. ScopedPointer<ImageKnob> fKnob;
  80. ScopedPointer<ImageButton> fButton;
  81. };
  82. UI* createUI()
  83. {
  84. return new CairoExampleUI;
  85. }
  86. END_NAMESPACE_DISTRHO