DPF OpenGL examples
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.

328 lines
8.2KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2015 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 "NanoVG.hpp"
  19. #include "Widget.hpp"
  20. #include "StandaloneWindow.hpp"
  21. #include "extra/ScopedPointer.hpp"
  22. #include "src/nanovg/nanovg.h"
  23. #include "src/oui-blendish/blendish.h"
  24. // ------------------------------------------------------
  25. // use namespace
  26. USE_NAMESPACE_DISTRHO;
  27. USE_NAMESPACE_DGL;
  28. // ------------------------------------------------------
  29. // Test
  30. class BlendishCommon : public NanoWidget
  31. {
  32. public:
  33. enum State {
  34. kStateDefault = 0, // not interacting
  35. kStateHover = 1, // the mouse is hovering over the control
  36. kStateActive = 2 // the widget is activated (pressed) or in an active state (toggled)
  37. };
  38. BlendishCommon(NanoWidget* groupWidget)
  39. : NanoWidget(groupWidget),
  40. fState(kStateDefault)
  41. {
  42. setSize(250, BND_WIDGET_HEIGHT);
  43. }
  44. State getCurrentState() const noexcept
  45. {
  46. return fState;
  47. }
  48. protected:
  49. bool onMouse(const MouseEvent& e)
  50. {
  51. if (! e.press)
  52. return false;
  53. if (! contains(e.pos))
  54. return false;
  55. if (fState == kStateActive)
  56. fState = kStateHover;
  57. else
  58. fState = kStateActive;
  59. repaint();
  60. return true;
  61. }
  62. bool onMotion(const MotionEvent& e)
  63. {
  64. if (! contains(e.pos))
  65. {
  66. if (fState == kStateHover)
  67. {
  68. fState = kStateDefault;
  69. repaint();
  70. return true;
  71. }
  72. return false;
  73. }
  74. if (fState == kStateDefault)
  75. {
  76. fState = kStateHover;
  77. repaint();
  78. }
  79. return true;
  80. }
  81. private:
  82. State fState;
  83. };
  84. // ------------------------------------------------------
  85. // Test
  86. class BlendishLabel : public BlendishCommon
  87. {
  88. public:
  89. BlendishLabel(NanoWidget* groupWidget)
  90. : BlendishCommon(groupWidget) {}
  91. protected:
  92. void onNanoDisplay() override
  93. {
  94. bndLabel(getContext(),
  95. getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight(),
  96. BND_ICON_HELP,
  97. "this is a label [help]");
  98. }
  99. };
  100. class BlendishToolButton : public BlendishCommon
  101. {
  102. public:
  103. BlendishToolButton(NanoWidget* groupWidget)
  104. : BlendishCommon(groupWidget) {}
  105. protected:
  106. void onNanoDisplay() override
  107. {
  108. bndToolButton(getContext(),
  109. getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight(),
  110. 0, static_cast<BNDwidgetState>(getCurrentState()), BND_ICON_SOUND,
  111. "this is a tool-button [sound]");
  112. }
  113. };
  114. class BlendishPushButton: public BlendishCommon
  115. {
  116. public:
  117. BlendishPushButton(NanoWidget* groupWidget)
  118. : BlendishCommon(groupWidget) {}
  119. protected:
  120. void onNanoDisplay() override
  121. {
  122. bndRadioButton(getContext(),
  123. getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight(),
  124. 0, static_cast<BNDwidgetState>(getCurrentState()), BND_ICON_NEW,
  125. "this is a push-button [file->new]");
  126. }
  127. };
  128. // text field here
  129. class BlendishCheckbox : public BlendishCommon
  130. {
  131. public:
  132. BlendishCheckbox(NanoWidget* groupWidget)
  133. : BlendishCommon(groupWidget) {}
  134. protected:
  135. void onNanoDisplay() override
  136. {
  137. bndOptionButton(getContext(),
  138. getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight(),
  139. static_cast<BNDwidgetState>(getCurrentState()),
  140. "this is a checkbox");
  141. }
  142. };
  143. class BlendishComboBox : public BlendishCommon
  144. {
  145. public:
  146. BlendishComboBox(NanoWidget* groupWidget)
  147. : BlendishCommon(groupWidget) {}
  148. protected:
  149. void onNanoDisplay() override
  150. {
  151. bndChoiceButton(getContext(),
  152. getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight(),
  153. 0, static_cast<BNDwidgetState>(getCurrentState()), BND_ICON_NEW,
  154. "this is a combobox");
  155. // bndMenuBackground
  156. // bndMenuLabel
  157. // bndMenuItem
  158. }
  159. };
  160. class BlendishColorButton : public BlendishCommon
  161. {
  162. public:
  163. BlendishColorButton(NanoWidget* groupWidget)
  164. : BlendishCommon(groupWidget) {}
  165. protected:
  166. void onNanoDisplay() override
  167. {
  168. bndColorButton(getContext(),
  169. getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight(),
  170. BND_DEFAULT,
  171. Color::fromHTML("#132487"));
  172. }
  173. };
  174. // bndNumberField
  175. class BlendishSlider : public BlendishCommon
  176. {
  177. public:
  178. BlendishSlider(NanoWidget* groupWidget)
  179. : BlendishCommon(groupWidget) {}
  180. protected:
  181. void onNanoDisplay() override
  182. {
  183. bndSlider(getContext(),
  184. getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight(),
  185. 0, static_cast<BNDwidgetState>(getCurrentState()),
  186. 0.25f, "this is a slider", "and value");
  187. }
  188. };
  189. class BlendishScrollBar : public BlendishCommon
  190. {
  191. public:
  192. BlendishScrollBar(NanoWidget* groupWidget, bool horizontal)
  193. : BlendishCommon(groupWidget)
  194. {
  195. if (horizontal)
  196. setSize(250, BND_SCROLLBAR_HEIGHT);
  197. else
  198. setSize(BND_SCROLLBAR_WIDTH, 200);
  199. }
  200. protected:
  201. void onNanoDisplay() override
  202. {
  203. bndScrollBar(getContext(),
  204. getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight(),
  205. static_cast<BNDwidgetState>(getCurrentState()),
  206. 0.25f, 0.5f);
  207. }
  208. };
  209. // bndTooltipBackground
  210. // bndNodePort
  211. // bndNodeWire
  212. // bndColoredNodeWire
  213. // bndNodeBackground
  214. // bndSplitterWidgets
  215. // bndJoinAreaOverlay
  216. // ------------------------------------------------------
  217. // Test
  218. class TestWidget : public NanoWidget
  219. {
  220. public:
  221. TestWidget(Window& parent)
  222. : NanoWidget(parent, NanoVG::CREATE_ANTIALIAS|NanoVG::CREATE_STENCIL_STROKES),
  223. w0(this),
  224. w1(this),
  225. w2(this),
  226. w3(this),
  227. w4(this),
  228. w5(this),
  229. w6(this),
  230. w7(this, true),
  231. w7b(this, false)
  232. {
  233. NVGcontext* const context(getContext());
  234. bndSetFont(nvgCreateFont(context, "system", "./blendish_res/DejaVuSans.ttf"));
  235. bndSetIconImage(nvgCreateImage(context, "./blendish_res/blender_icons16.png", 0));
  236. w0.setAbsolutePos(10, 10+25*0);
  237. w1.setAbsolutePos(10, 10+25*1);
  238. w2.setAbsolutePos(10, 10+25*2);
  239. w3.setAbsolutePos(10, 10+25*3);
  240. w4.setAbsolutePos(10, 10+25*4);
  241. w5.setAbsolutePos(10, 10+25*5);
  242. w6.setAbsolutePos(10, 10+25*6);
  243. w7.setAbsolutePos(10, 10+25*7);
  244. //w8.setAbsolutePos(10, 10+25*8);
  245. //w9.setAbsolutePos(10, 10+25*9);
  246. w7b.setAbsolutePos(470, 10);
  247. }
  248. protected:
  249. void onNanoDisplay() override
  250. {
  251. glClearColor(0.3f, 0.3f, 0.32f, 1.0f);
  252. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
  253. }
  254. private:
  255. BlendishLabel w0;
  256. BlendishToolButton w1;
  257. BlendishPushButton w2;
  258. BlendishCheckbox w3;
  259. BlendishComboBox w4;
  260. BlendishColorButton w5;
  261. BlendishSlider w6;
  262. BlendishScrollBar w7;
  263. BlendishScrollBar w7b;
  264. };
  265. // ------------------------------------------------------
  266. // main entry point
  267. int main()
  268. {
  269. StandaloneWindow win;
  270. TestWidget w(win);
  271. win.setSize(500, 500);
  272. win.setTitle("Blendish");
  273. win.exec();
  274. return 0;
  275. }
  276. // ------------------------------------------------------