example.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #include "oxygine-framework.h"
  2. #include "test.h"
  3. #include "TestPerf.h"
  4. #include "TestTweens.h"
  5. #include "TestDrag.h"
  6. #include "TestManageRes.h"
  7. #include "TestRender2Texture.h"
  8. #include "TestText.h"
  9. #include "TestTextureFormat.h"
  10. #include "TestTexel2Pixel.h"
  11. #include "TestSliding.h"
  12. #include "TestProgressBar.h"
  13. #include "TestBox9Sprite.h"
  14. #include "TestClipRect.h"
  15. #include "TestUserShader.h"
  16. #include "TestUserShader2.h"
  17. #include "TestMask.h"
  18. #include "TestPolygon.h"
  19. #include "TestInputText.h"
  20. #include "TestHttp.h"
  21. #include "core/STDFileSystem.h"
  22. #ifdef __S3E__
  23. #include "s3eKeyboard.h"
  24. #endif
  25. using namespace oxygine;
  26. spActor _tests;
  27. //it is our resources
  28. //in real project you would have more than one Resources declarations. It is important on mobile devices with limited memory and you would load/unload them
  29. Resources resources;
  30. Resources resourcesUI;
  31. //extern spStage stage2;
  32. class TestActor: public Test
  33. {
  34. public:
  35. TestActor()
  36. {
  37. _x = 90;//getStage()->getWidth()/2.0f;
  38. _y = 80;
  39. addButton("tweens", "Tweens");
  40. addButton("text", "Text");
  41. addButton("progress_bar", "Progress Bar");
  42. addButton("drag", "Drag and Drop");
  43. addButton("drag2", "Drag and Drop2");
  44. addButton("perf", "Performance");
  45. addButton("manage_res", "Manage Resources");
  46. addButton("texture_format", "Textures Format");
  47. addButton("r2t", "Render to Texture");
  48. addButton("t2p", "Texel to Pixel");
  49. addButton("sliding", "Sliding Actor");
  50. addButton("box9sprite", "Box9 Sprite");
  51. addButton("cliprect", "ClipRect Actor");
  52. addButton("usershader", "User Shader");
  53. addButton("usershader2", "User Shader2");
  54. addButton("mask", "Mask");
  55. addButton("polygon", "Polygon");
  56. addButton("inputtext", "Input Text");
  57. addButton("openbrowser", "Open Browser");
  58. addButton("http", "Http requests");
  59. }
  60. void showTest(spActor actor)
  61. {
  62. setVisible(false);
  63. //spStage stage = stage2;
  64. getStage()->addChild(actor);
  65. }
  66. void clicked(string id)
  67. {
  68. if (id == "perf")
  69. {
  70. showTest(new PerfTest);
  71. }
  72. if (id == "tweens")
  73. {
  74. showTest(new TweensTest);
  75. }
  76. if (id == "drag")
  77. {
  78. showTest(new DragTest);
  79. }
  80. if (id == "drag2")
  81. {
  82. showTest(new Drag2Test);
  83. }
  84. if (id == "manage_res")
  85. {
  86. showTest(new ManageResTest);
  87. }
  88. if (id == "r2t")
  89. {
  90. showTest(new TestRender2Texture);
  91. }
  92. if (id == "text")
  93. {
  94. showTest(new TestText);
  95. }
  96. if (id == "progress_bar")
  97. {
  98. showTest(new TestProgressBar);
  99. }
  100. if (id == "texture_format")
  101. {
  102. showTest(new TestTextureFormat);
  103. }
  104. if (id == "sliding")
  105. {
  106. showTest(new TestSliding);
  107. }
  108. if (id == "t2p")
  109. {
  110. showTest(new TestTexel2Pixel);
  111. }
  112. if (id == "box9sprite")
  113. {
  114. showTest(new TestBox9Sprite);
  115. }
  116. if (id == "cliprect")
  117. {
  118. showTest(new TestClipRect);
  119. }
  120. if (id == "usershader")
  121. {
  122. showTest(new TestUserShader);
  123. }
  124. if (id == "usershader2")
  125. {
  126. showTest(new TestUserShader2);
  127. }
  128. if (id == "mask")
  129. {
  130. showTest(new TestMask);
  131. }
  132. if (id == "polygon")
  133. {
  134. showTest(new TestPolygon);
  135. }
  136. if (id == "inputtext")
  137. {
  138. showTest(new TestInputText);
  139. }
  140. if (id == "openbrowser")
  141. {
  142. core::execute("http://oxygine.org/");
  143. setVisible(true);
  144. }
  145. if (id == "http")
  146. {
  147. showTest(new TestHttp);
  148. }
  149. }
  150. };
  151. void example_preinit()
  152. {
  153. /**
  154. There are 2 modes of loading and blending/rendering sprites: normal and premultiplied alpha.
  155. You should set it before loading any assets.
  156. Premultiplied mode is more advanced and faster than normal. In this mode RGB pixels of textures premultiplying to alpha when textures are loading and using blend_premultiply_alpha as default Sprites blend option.
  157. Default value is premultiplied = true
  158. http://blog.rarepebble.com/111/premultiplied-alpha-in-opengl/
  159. I set it to false to simplify shaders for UserShaderDemo
  160. */
  161. Renderer::setPremultipliedAlphaRender(false);
  162. }
  163. file::STDFileSystem extfs(true);
  164. void example_init()
  165. {
  166. //mount additional file system with inner path "ext"
  167. //it would be used for searching path in data/ext
  168. extfs.setPath(file::fs().getFullPath("ext").c_str());
  169. file::mount(&extfs);
  170. //load xml file with resources definition
  171. resources.loadXML("xmls/res.xml");
  172. resourcesUI.loadXML("demo/res_ui.xml");
  173. resourcesUI.loadXML("demo/fonts.xml");
  174. spSprite sp = initActor(new Sprite,
  175. arg_resAnim = resourcesUI.getResAnim("logo2"),
  176. arg_input = false,
  177. arg_attachTo = getStage(),
  178. arg_priority = 10,
  179. arg_alpha = 128
  180. );
  181. sp->setX(getStage()->getWidth() - sp->getWidth());
  182. sp->setY(getStage()->getHeight() - sp->getHeight());
  183. _tests = new TestActor;
  184. getStage()->addChild(_tests);
  185. //initialize http requests
  186. HttpRequestTask::init();
  187. }
  188. void example_update()
  189. {
  190. }
  191. void example_destroy()
  192. {
  193. _tests->detach();
  194. _tests = 0;
  195. resources.free();
  196. resourcesUI.free();
  197. HttpRequestTask::release();
  198. }