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.

134 lines
3.3KB

  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_COLOR_WIDGET_HPP_INCLUDED
  17. #define EXAMPLE_COLOR_WIDGET_HPP_INCLUDED
  18. // ------------------------------------------------------
  19. // DGL Stuff
  20. #include "../../dgl/SubWidget.hpp"
  21. START_NAMESPACE_DGL
  22. // ------------------------------------------------------
  23. // our widget
  24. class ExampleColorWidget : public SubWidget,
  25. public IdleCallback
  26. {
  27. char cur;
  28. bool reverse;
  29. int r, g, b;
  30. Rectangle<uint> bgFull, bgSmall;
  31. public:
  32. ExampleColorWidget(TopLevelWidget* const topWidget)
  33. : SubWidget(topWidget),
  34. cur('r'),
  35. reverse(false),
  36. r(0), g(0), b(0)
  37. {
  38. setSize(300, 300);
  39. // topWidget->getApp().addIdleCallback(this);
  40. }
  41. protected:
  42. void idleCallback() noexcept override
  43. {
  44. switch (cur)
  45. {
  46. case 'r':
  47. if (reverse)
  48. {
  49. if (--r == 0)
  50. cur = 'g';
  51. }
  52. else
  53. {
  54. if (++r == 100)
  55. cur = 'g';
  56. }
  57. break;
  58. case 'g':
  59. if (reverse)
  60. {
  61. if (--g == 0)
  62. cur = 'b';
  63. }
  64. else
  65. {
  66. if (++g == 100)
  67. cur = 'b';
  68. }
  69. break;
  70. case 'b':
  71. if (reverse)
  72. {
  73. if (--b == 0)
  74. {
  75. cur = 'r';
  76. reverse = false;
  77. }
  78. }
  79. else
  80. {
  81. if (++b == 100)
  82. {
  83. cur = 'r';
  84. reverse = true;
  85. }
  86. }
  87. break;
  88. }
  89. repaint();
  90. }
  91. void onDisplay() override
  92. {
  93. // paint bg color (in full size)
  94. glColor3b(r, g, b);
  95. bgFull.draw();
  96. // paint inverted color (in 2/3 size)
  97. glColor3b(100-r, 100-g, 100-b);
  98. bgSmall.draw();
  99. }
  100. void onResize(const ResizeEvent& ev) override
  101. {
  102. const uint width = ev.size.getWidth();
  103. const uint height = ev.size.getHeight();
  104. // full bg
  105. bgFull = Rectangle<uint>(0, 0, width, height);
  106. // small bg, centered 2/3 size
  107. bgSmall = Rectangle<uint>(width/6, height/6, width*2/3, height*2/3);
  108. }
  109. };
  110. // ------------------------------------------------------
  111. END_NAMESPACE_DGL
  112. #endif // EXAMPLE_COLOR_WIDGET_HPP_INCLUDED