example.cpp 5.9 KB

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