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.

215 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 App::IdleCallback,
  30. Widget
  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. }
  55. private:
  56. void idleCallback() override
  57. {
  58. if (fImg1rev)
  59. {
  60. fImg1x -= 2;
  61. if (fImg1x <= -50)
  62. {
  63. fImg1rev = false;
  64. setNewTopImg(1);
  65. }
  66. }
  67. else
  68. {
  69. fImg1x += 2;
  70. if (fImg1x >= kImg1max+50)
  71. {
  72. fImg1rev = true;
  73. setNewTopImg(1);
  74. }
  75. }
  76. if (fImg2rev)
  77. {
  78. fImg2x -= 1;
  79. if (fImg2x <= -50)
  80. {
  81. fImg2rev = false;
  82. setNewTopImg(2);
  83. }
  84. }
  85. else
  86. {
  87. fImg2x += 4;
  88. if (fImg2x >= kImg2max+50)
  89. {
  90. fImg2rev = true;
  91. setNewTopImg(2);
  92. }
  93. }
  94. if (fImg3rev)
  95. {
  96. fImg3y -= 3;
  97. if (fImg3y <= -50)
  98. {
  99. fImg3rev = false;
  100. setNewTopImg(3);
  101. }
  102. }
  103. else
  104. {
  105. fImg3y += 3;
  106. if (fImg3y >= kImg3max+50)
  107. {
  108. fImg3rev = true;
  109. setNewTopImg(3);
  110. }
  111. }
  112. repaint();
  113. }
  114. void setNewTopImg(const int imgId)
  115. {
  116. if (fImgTop1st == imgId)
  117. return;
  118. if (fImgTop2nd == imgId)
  119. {
  120. fImgTop2nd = fImgTop1st;
  121. fImgTop1st = imgId;
  122. return;
  123. }
  124. fImgTop3rd = fImgTop2nd;
  125. fImgTop2nd = fImgTop1st;
  126. fImgTop1st = imgId;
  127. }
  128. void onDisplay() override
  129. {
  130. switch (fImgTop3rd)
  131. {
  132. case 1:
  133. fImg1.draw(fImg1x, kImg1y);
  134. break;
  135. case 2:
  136. fImg2.draw(fImg2x, kImg2y);
  137. break;
  138. case 3:
  139. fImg3.draw(kImg3x, fImg3y);
  140. break;
  141. };
  142. switch (fImgTop2nd)
  143. {
  144. case 1:
  145. fImg1.draw(fImg1x, kImg1y);
  146. break;
  147. case 2:
  148. fImg2.draw(fImg2x, kImg2y);
  149. break;
  150. case 3:
  151. fImg3.draw(kImg3x, fImg3y);
  152. break;
  153. };
  154. switch (fImgTop1st)
  155. {
  156. case 1:
  157. fImg1.draw(fImg1x, kImg1y);
  158. break;
  159. case 2:
  160. fImg2.draw(fImg2x, kImg2y);
  161. break;
  162. case 3:
  163. fImg3.draw(kImg3x, fImg3y);
  164. break;
  165. };
  166. }
  167. int fImgTop1st, fImgTop2nd, fImgTop3rd;
  168. int fImg1x, fImg2x, fImg3y;
  169. bool fImg1rev, fImg2rev, fImg3rev;
  170. Image fImg1, fImg2, fImg3;
  171. };
  172. // ------------------------------------------------------
  173. // main entry point
  174. int main()
  175. {
  176. App app;
  177. Window win(app);
  178. ExampleImagesWidget images(win);
  179. app.addIdleCallback(&images);
  180. win.setResizable(false);
  181. win.setSize(500, 400);
  182. win.setTitle("Images");
  183. win.show();
  184. app.exec();
  185. return 0;
  186. }
  187. // ------------------------------------------------------