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.

214 lines
5.1KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2014 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. // Pics
  18. #include "images_src/CatPics.cpp"
  19. // ------------------------------------------------------
  20. // DGL Stuff
  21. #include "Image.hpp"
  22. #include "Widget.hpp"
  23. #include "StandaloneWindow.hpp"
  24. // ------------------------------------------------------
  25. // use namespace
  26. using namespace DGL;
  27. // ------------------------------------------------------
  28. // our widget
  29. class ExampleImagesWidget : public Widget,
  30. public IdleCallback
  31. {
  32. public:
  33. static const int kImg1y = 0;
  34. static const int kImg2y = 500/2-CatPics::cat2Height/2;
  35. static const int kImg3x = 400/3-CatPics::cat3Width/3;
  36. static const int kImg1max = 500-CatPics::cat1Width;
  37. static const int kImg2max = 500-CatPics::cat2Width;
  38. static const int kImg3max = 400-CatPics::cat3Height;
  39. ExampleImagesWidget(Window& win)
  40. : Widget(win),
  41. fImgTop1st(1),
  42. fImgTop2nd(2),
  43. fImgTop3rd(3),
  44. fImg1x(0),
  45. fImg2x(kImg2max),
  46. fImg3y(kImg3max),
  47. fImg1rev(false),
  48. fImg2rev(true),
  49. fImg3rev(true),
  50. fImg1(CatPics::cat1Data, CatPics::cat1Width, CatPics::cat1Height, GL_BGR),
  51. fImg2(CatPics::cat2Data, CatPics::cat2Width, CatPics::cat2Height, GL_BGR),
  52. fImg3(CatPics::cat3Data, CatPics::cat3Width, CatPics::cat3Height, GL_BGR)
  53. {
  54. win.addIdleCallback(this);
  55. }
  56. private:
  57. void idleCallback() override
  58. {
  59. if (fImg1rev)
  60. {
  61. fImg1x -= 2;
  62. if (fImg1x <= -50)
  63. {
  64. fImg1rev = false;
  65. setNewTopImg(1);
  66. }
  67. }
  68. else
  69. {
  70. fImg1x += 2;
  71. if (fImg1x >= kImg1max+50)
  72. {
  73. fImg1rev = true;
  74. setNewTopImg(1);
  75. }
  76. }
  77. if (fImg2rev)
  78. {
  79. fImg2x -= 1;
  80. if (fImg2x <= -50)
  81. {
  82. fImg2rev = false;
  83. setNewTopImg(2);
  84. }
  85. }
  86. else
  87. {
  88. fImg2x += 4;
  89. if (fImg2x >= kImg2max+50)
  90. {
  91. fImg2rev = true;
  92. setNewTopImg(2);
  93. }
  94. }
  95. if (fImg3rev)
  96. {
  97. fImg3y -= 3;
  98. if (fImg3y <= -50)
  99. {
  100. fImg3rev = false;
  101. setNewTopImg(3);
  102. }
  103. }
  104. else
  105. {
  106. fImg3y += 3;
  107. if (fImg3y >= kImg3max+50)
  108. {
  109. fImg3rev = true;
  110. setNewTopImg(3);
  111. }
  112. }
  113. repaint();
  114. }
  115. void onDisplay() override
  116. {
  117. switch (fImgTop3rd)
  118. {
  119. case 1:
  120. fImg1.drawAt(fImg1x, kImg1y);
  121. break;
  122. case 2:
  123. fImg2.drawAt(fImg2x, kImg2y);
  124. break;
  125. case 3:
  126. fImg3.drawAt(kImg3x, fImg3y);
  127. break;
  128. };
  129. switch (fImgTop2nd)
  130. {
  131. case 1:
  132. fImg1.drawAt(fImg1x, kImg1y);
  133. break;
  134. case 2:
  135. fImg2.drawAt(fImg2x, kImg2y);
  136. break;
  137. case 3:
  138. fImg3.drawAt(kImg3x, fImg3y);
  139. break;
  140. };
  141. switch (fImgTop1st)
  142. {
  143. case 1:
  144. fImg1.drawAt(fImg1x, kImg1y);
  145. break;
  146. case 2:
  147. fImg2.drawAt(fImg2x, kImg2y);
  148. break;
  149. case 3:
  150. fImg3.drawAt(kImg3x, fImg3y);
  151. break;
  152. };
  153. }
  154. void setNewTopImg(const int imgId)
  155. {
  156. if (fImgTop1st == imgId)
  157. return;
  158. if (fImgTop2nd == imgId)
  159. {
  160. fImgTop2nd = fImgTop1st;
  161. fImgTop1st = imgId;
  162. return;
  163. }
  164. fImgTop3rd = fImgTop2nd;
  165. fImgTop2nd = fImgTop1st;
  166. fImgTop1st = imgId;
  167. }
  168. int fImgTop1st, fImgTop2nd, fImgTop3rd;
  169. int fImg1x, fImg2x, fImg3y;
  170. bool fImg1rev, fImg2rev, fImg3rev;
  171. Image fImg1, fImg2, fImg3;
  172. };
  173. // ------------------------------------------------------
  174. // main entry point
  175. int main()
  176. {
  177. App app;
  178. Window win(app);
  179. ExampleImagesWidget images(win);
  180. win.setResizable(false);
  181. win.setSize(500, 400);
  182. win.setTitle("Images");
  183. win.show();
  184. app.exec();
  185. return 0;
  186. }
  187. // ------------------------------------------------------