example.cpp 6.1 KB

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