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.

180 lines
4.0KB

  1. /*
  2. * DISTRHO Plugin Toolkit (DPT)
  3. * Copyright (C) 2012-2013 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. // ------------------------------------------------------
  17. // DGL Stuff
  18. #include "App.hpp"
  19. #include "Window.hpp"
  20. #include "Widget.hpp"
  21. #include <cstdio>
  22. // ------------------------------------------------------
  23. // use namespace
  24. using namespace DGL;
  25. // ------------------------------------------------------
  26. // Single color widget
  27. class ColorWidget : public App::IdleCallback,
  28. Widget
  29. {
  30. public:
  31. ColorWidget(Window& parent)
  32. : Widget(parent),
  33. cur('r'),
  34. reverse(false),
  35. r(0), g(0), b(0)
  36. {
  37. }
  38. private:
  39. void idleCallback() override
  40. {
  41. switch (cur)
  42. {
  43. case 'r':
  44. if (reverse)
  45. {
  46. if (--r == 0)
  47. cur = 'g';
  48. }
  49. else
  50. {
  51. if (++r == 100)
  52. cur = 'g';
  53. }
  54. break;
  55. case 'g':
  56. if (reverse)
  57. {
  58. if (--g == 0)
  59. cur = 'b';
  60. }
  61. else
  62. {
  63. if (++g == 100)
  64. cur = 'b';
  65. }
  66. break;
  67. case 'b':
  68. if (reverse)
  69. {
  70. if (--b == 0)
  71. {
  72. cur = 'r';
  73. reverse = false;
  74. }
  75. }
  76. else
  77. {
  78. if (++b == 100)
  79. {
  80. cur = 'r';
  81. reverse = true;
  82. }
  83. }
  84. break;
  85. }
  86. repaint();
  87. }
  88. void onDisplay() override
  89. {
  90. int x = 0;
  91. int y = 0;
  92. int width = getWidth();
  93. int height = getHeight();
  94. // paint bg color (in full size)
  95. glColor3b(r, g, b);
  96. glBegin(GL_QUADS);
  97. glTexCoord2f(0.0f, 0.0f);
  98. glVertex2i(x, y);
  99. glTexCoord2f(1.0f, 0.0f);
  100. glVertex2i(x+width, y);
  101. glTexCoord2f(1.0f, 1.0f);
  102. glVertex2i(x+width, y+height);
  103. glTexCoord2f(0.0f, 1.0f);
  104. glVertex2i(x, y+height);
  105. glEnd();
  106. // centered 2/3 size
  107. x = width/6;
  108. y = height/6;
  109. width = width*2/3;
  110. height = height*2/3;
  111. // paint inverted color (in 2/3 size)
  112. glColor3b(100-r, 100-g, 100-b);
  113. glBegin(GL_QUADS);
  114. glTexCoord2f(0.0f, 0.0f);
  115. glVertex2i(x, y);
  116. glTexCoord2f(1.0f, 0.0f);
  117. glVertex2i(x+width, y);
  118. glTexCoord2f(1.0f, 1.0f);
  119. glVertex2i(x+width, y+height);
  120. glTexCoord2f(0.0f, 1.0f);
  121. glVertex2i(x, y+height);
  122. glEnd();
  123. }
  124. void onReshape(int width, int height) override
  125. {
  126. // make widget same size as window
  127. setSize(width, height);
  128. Widget::onReshape(width, height);
  129. }
  130. char cur;
  131. bool reverse;
  132. int r, g, b;
  133. };
  134. // ------------------------------------------------------
  135. // main entry point
  136. int main()
  137. {
  138. App app;
  139. Window win(app);
  140. ColorWidget color(win);
  141. app.addIdleCallback(&color);
  142. win.setSize(300, 300);
  143. win.setTitle("Color");
  144. win.show();
  145. app.exec();
  146. return 0;
  147. }
  148. // ------------------------------------------------------