example.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 "TestAlphaHitTest.h"
  22. #include "TestCounter.h"
  23. #include "TestTweenText.h"
  24. #include "TestTweenShine.h"
  25. #include "TestTouches.h"
  26. #include "TestColorFont.h"
  27. #include "TestSignedDistanceFont.h"
  28. #include "TestTweenPostProcessing.h"
  29. #include "TestEdges.h"
  30. #include "TestCamera.h"
  31. #include "TestTiled.h"
  32. #include "TestOpenGL.h"
  33. #ifdef __S3E__
  34. #include "s3eKeyboard.h"
  35. #endif
  36. using namespace oxygine;
  37. //This contains our resources
  38. //In a real project you would have more than one Resources declaration.
  39. //It is important on mobile devices with limited memory and you would load/unload them
  40. Resources resources;
  41. //#define MULTIWINDOW 1
  42. #if MULTIWINDOW
  43. spStage stage2;
  44. #endif
  45. class TestActor: public Test
  46. {
  47. public:
  48. TestActor()
  49. {
  50. _x = 90;//getStage()->getWidth()/2.0f;
  51. _y = 80;
  52. addButton("tweens", "Tweens");
  53. addButton("text", "Text");
  54. addButton("progress_bar", "Progress Bar");
  55. addButton("drag", "Drag and Drop with Test Intersections");
  56. addButton("drag2", "Drag and Drop2");
  57. addButton("hittest", "Alpha Hit Test");
  58. addButton("perf", "Performance");
  59. addButton("manage_res", "Manage Resources");
  60. addButton("texture_format", "Textures Format");
  61. addButton("r2t", "Render to Texture");
  62. addButton("t2p", "Texel to Pixel");
  63. addButton("edges", "Edges");
  64. addButton("touches", "Touches");
  65. addButton("sliding", "Sliding Actor");
  66. addButton("box9sprite", "Box9 Sprite");
  67. addButton("cliprect", "ClipRect Actor");
  68. addButton("usershader", "Extended UberShader");
  69. addButton("usershader2", "Custom shaders and render");
  70. addButton("opengl", "OpenGL usage");
  71. addButton("multicolorfont", "Outer Font Color");
  72. addButton("sdf", "Signed Distance Font");
  73. addButton("mask", "Mask");
  74. addButton("polygon", "Polygon");
  75. addButton("inputtext", "Input Text");
  76. addButton("openbrowser", "Open Browser");
  77. addButton("http", "Http requests");
  78. addButton("tweenpp", "Post Processing Tweens");
  79. _color = Color::Red;
  80. _txtColor = Color::White;
  81. _y = 5;
  82. _x += 200;
  83. addButton("counter", "Counter");
  84. addButton("tweentext", "Tween Text");
  85. addButton("tweenshine", "Tween Shine");
  86. addButton("mtz", "MultiTouch Camera/Zoom");
  87. addButton("tiled", "Tiled Map Editor");
  88. //clicked("tiled");
  89. }
  90. void showTest(spActor actor)
  91. {
  92. spStage stage = getStage();
  93. #if MULTIWINDOW
  94. stage = stage2;
  95. #else
  96. setVisible(false);
  97. #endif
  98. stage->addChild(actor);
  99. }
  100. void clicked(string id)
  101. {
  102. if (id == "perf") showTest(new PerfTest);
  103. if (id == "tweens") showTest(new TweensTest);
  104. if (id == "drag") showTest(new DragTest);
  105. if (id == "drag2") showTest(new Drag2Test);
  106. if (id == "hittest") showTest(new TestAlphaHitTest);
  107. if (id == "manage_res") showTest(new ManageResTest);
  108. if (id == "r2t") showTest(new TestRender2Texture);
  109. if (id == "text") showTest(new TestText);
  110. if (id == "progress_bar") showTest(new TestProgressBar);
  111. if (id == "texture_format") showTest(new TestTextureFormat);
  112. if (id == "sliding") showTest(new TestSliding);
  113. if (id == "t2p") showTest(new TestTexel2Pixel);
  114. if (id == "touches") showTest(new TestTouches);
  115. if (id == "box9sprite") showTest(new TestBox9Sprite);
  116. if (id == "cliprect") showTest(new TestClipRect);
  117. if (id == "usershader") showTest(new TestUserShader);
  118. if (id == "usershader2") showTest(new TestUserShader2);
  119. if (id == "opengl") showTest(new TestOpenGL);
  120. if (id == "mask") showTest(new TestMask);
  121. if (id == "polygon") showTest(new TestPolygon);
  122. if (id == "inputtext") showTest(new TestInputText);
  123. if (id == "http") showTest(new TestHttp);
  124. if (id == "counter") showTest(new TestCounter);
  125. if (id == "tweentext") showTest(new TestTweenText);
  126. if (id == "tweenshine") showTest(new TestTweenShine);
  127. if (id == "multicolorfont") showTest(new TestColorFont);
  128. if (id == "sdf") showTest(new TestSignedDistanceFont);
  129. if (id == "tweenpp") showTest(new TestTweenPostProcessing);
  130. if (id == "edges") showTest(new TestEdges);
  131. if (id == "mtz") showTest(new TestCamera);
  132. if (id == "tiled") showTest(new TestTiled);
  133. if (id == "openbrowser")
  134. {
  135. core::execute("http://oxygine.org/");
  136. setVisible(true);
  137. }
  138. }
  139. };
  140. void example_preinit()
  141. {
  142. }
  143. void example_init()
  144. {
  145. //Load resources in xml file
  146. resources.loadXML("xmls/res.xml");
  147. Test::init();
  148. Test::instance = new TestActor;
  149. getStage()->addChild(Test::instance);
  150. //Initialize http requests
  151. HttpRequestTask::init();
  152. #if MULTIWINDOW
  153. SDL_Window* window2 = SDL_CreateWindow("Second Oxygine Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, getStage()->getWidth(), getStage()->getHeight(), SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
  154. stage2 = new Stage(false);
  155. stage2->setSize(getStage()->getSize());
  156. stage2->associateWithWindow(window2);
  157. #endif
  158. }
  159. void example_update()
  160. {
  161. #if MULTIWINDOW
  162. stage2->update();
  163. SDL_Window* wnd = stage2->getAssociatedWindow();
  164. if (core::beginRendering(wnd))
  165. {
  166. Color clearColor(32, 32, 32, 255);
  167. Rect viewport(Point(0, 0), core::getDisplaySize());
  168. //render all actors. Actor::render would be called also for all children
  169. stage2->render(clearColor, viewport);
  170. core::swapDisplayBuffers(wnd);
  171. }
  172. #endif
  173. }
  174. void example_destroy()
  175. {
  176. resources.free();
  177. Test::free();
  178. HttpRequestTask::release();
  179. }