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.

103 lines
3.2KB

  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. DemoWidgetClickable* widgetClickable = new DemoWidgetClickable(this);
  30. fWidgetClickable = widgetClickable;
  31. widgetClickable->setSize(50, 50);
  32. widgetClickable->setAbsolutePos(100, 100);
  33. DemoWidgetBanner* widgetBanner = new DemoWidgetBanner(this);
  34. fWidgetBanner = widgetBanner;
  35. widgetBanner->setSize(180, 80);
  36. widgetBanner->setAbsolutePos(10, 10);
  37. Image knobSkin;
  38. knobSkin.loadFromPng(Artwork::knobData, Artwork::knobDataSize);
  39. ImageKnob* knob = new ImageKnob(this, knobSkin);
  40. fKnob = knob;
  41. knob->setSize(80, 80);
  42. knob->setAbsolutePos(10, 100);
  43. // knob->setRotationAngle(270);
  44. Image buttonOn, buttonOff;
  45. buttonOn.loadFromPng(Artwork::buttonOnData, Artwork::buttonOnDataSize);
  46. buttonOff.loadFromPng(Artwork::buttonOffData, Artwork::buttonOffDataSize);
  47. ImageButton* button = new ImageButton(this, buttonOff, buttonOn);
  48. fButton = button;
  49. button->setSize(60, 35);
  50. button->setAbsolutePos(100, 160);
  51. }
  52. ~CairoExampleUI()
  53. {
  54. }
  55. void onDisplay()
  56. {
  57. cairo_t* cr = getParentWindow().getGraphicsContext().cairo;
  58. cairo_set_source_rgb(cr, 1.0, 0.8, 0.5);
  59. cairo_paint(cr);
  60. ImageKnob* knob = fKnob;
  61. cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.1);
  62. cairo_rectangle(cr, knob->getAbsoluteX(), knob->getAbsoluteY(), knob->getWidth(), knob->getHeight());
  63. cairo_fill(cr);
  64. ImageButton* button = fButton;
  65. cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.1);
  66. cairo_rectangle(cr, button->getAbsoluteX(), button->getAbsoluteY(), button->getWidth(), button->getHeight());
  67. cairo_fill(cr);
  68. }
  69. void parameterChanged(uint32_t index, float value)
  70. {
  71. // unused
  72. (void)index;
  73. (void)value;
  74. }
  75. private:
  76. ScopedPointer<DemoWidgetClickable> fWidgetClickable;
  77. ScopedPointer<DemoWidgetBanner> fWidgetBanner;
  78. ScopedPointer<ImageKnob> fKnob;
  79. ScopedPointer<ImageButton> fButton;
  80. };
  81. UI* createUI()
  82. {
  83. return new CairoExampleUI;
  84. }
  85. END_NAMESPACE_DISTRHO