PageRenderTime 54ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/Scenes/Tests/PerformanceTests.cs

#
C# | 179 lines | 150 code | 13 blank | 16 comment | 12 complexity | deb26db32f997ed6ccc748a36188b410 MD5 | raw file
Possible License(s): Apache-2.0
  1. using Delta.ContentSystem;
  2. using Delta.Engine;
  3. using Delta.InputSystem;
  4. using Delta.Rendering.Basics.Materials;
  5. using Delta.Rendering.Enums;
  6. using Delta.Scenes.UserInterfaces;
  7. using Delta.Scenes.UserInterfaces.Controls;
  8. using Delta.Utilities.Datatypes;
  9. using NUnit.Framework;
  10. namespace Delta.Scenes.Tests
  11. {
  12. /// <summary>
  13. /// Performance tests
  14. /// </summary>
  15. internal class PerformanceTests
  16. {
  17. #region TestBackgroundSpeed (LongRunning)
  18. /// <summary>
  19. /// Test background speed, press 1, 2, 3, or 0 to change the background!
  20. /// </summary>
  21. [Test, Category("Visual")]
  22. public static void TestBackgroundSpeed()
  23. {
  24. Screen scene = new Screen();
  25. scene.Open();
  26. Application.Start(delegate
  27. {
  28. if (Input.Keyboard.GetState(InputButton.D1) == InputState.Pressed)
  29. {
  30. scene.Background = new Material2DColored("SimpleMainMenuBackground")
  31. {
  32. DrawLayer = RenderLayer.Background,
  33. };
  34. }
  35. else if (Input.Keyboard.GetState(InputButton.D2) == InputState.Pressed)
  36. {
  37. scene.Background = new Material2DColored("DeltaEngineLogo")
  38. {
  39. DrawLayer = RenderLayer.Background,
  40. };
  41. }
  42. else if (Input.Keyboard.GetState(InputButton.D3) == InputState.Pressed)
  43. {
  44. scene.Background = new Material2DColored(Content.EmptyName)
  45. {
  46. DrawLayer = RenderLayer.Background,
  47. };
  48. }
  49. else if (Input.Keyboard.GetState(InputButton.D0) == InputState.Pressed)
  50. {
  51. scene.Background = null;
  52. }
  53. });
  54. }
  55. #endregion
  56. #region ScreenPerformance (LongRunning)
  57. /// <summary>
  58. /// Screen performance
  59. /// </summary>
  60. [Test, Category("Visual")]
  61. public static void ScreenPerformance()
  62. {
  63. Screen controlsScreen = new Screen("<ControlsScreen>")
  64. {
  65. Background = new Material2DColored("SpaceBackground")
  66. {
  67. DrawLayer = RenderLayer.Background,
  68. },
  69. };
  70. const float xPosOffset = 0.075f;
  71. const float yPosOffset = 0.075f;
  72. for (int index = 0; index < 1; index++)
  73. {
  74. float xPos = 0.15f + index * xPosOffset;
  75. float yPos = 0.275f;
  76. #region Adding an Image control
  77. Image image = new Image
  78. {
  79. Name = "Image control " + index,
  80. LocalArea = Rectangle.FromCenter(xPos, yPos, 0.2f, 0.075f),
  81. CustomDesign = new ControlDesign
  82. {
  83. Background = BaseTheme.GetUIMaterial("DeltaEnginelogo")
  84. },
  85. //Alignment = Alignment.TopLeft,
  86. };
  87. controlsScreen.Add(image);
  88. yPos += yPosOffset;
  89. #endregion
  90. #region Adding a Label control
  91. Label label = new Label
  92. {
  93. Name = "Label control " + index,
  94. LocalArea = Rectangle.FromCenter(xPos, yPos, 0.2f, 0.05f),
  95. Text = "Label text",
  96. //Alignment = Alignment.Top,
  97. };
  98. controlsScreen.Add(label);
  99. yPos += yPosOffset;
  100. #endregion
  101. #region Adding a Button control
  102. Button button = new Button
  103. {
  104. Name = "Button control " + index,
  105. LocalArea = Rectangle.FromCenter(xPos, yPos, 0.2f, 0.05f),
  106. Text = "Button text",
  107. //Alignment = Alignment.TopRight,
  108. };
  109. controlsScreen.Add(button);
  110. yPos += yPosOffset;
  111. #endregion
  112. #region Adding a Slider control
  113. Slider slider = new Slider
  114. {
  115. Name = "Slider control " + index,
  116. LocalArea = Rectangle.FromCenter(xPos, yPos, 0.2f, 0.05f),
  117. Text = "Slider text",
  118. MinValue = 1,
  119. MaxValue = 3,
  120. Value = 1.5f,
  121. //Alignment = Alignment.Left,
  122. };
  123. controlsScreen.Add(slider);
  124. yPos += yPosOffset;
  125. #endregion
  126. #region Adding a Checkbox control
  127. Checkbox checkbox = new Checkbox
  128. {
  129. Name = "Checkbox control " + index,
  130. LocalArea = Rectangle.FromCenter(xPos, yPos, 0.2f, 0.05f),
  131. Text = "Checkbox text",
  132. IsChecked = true,
  133. //Alignment = Alignment.Center,
  134. };
  135. controlsScreen.Add(checkbox);
  136. yPos += yPosOffset;
  137. #endregion
  138. #region Adding a RadioButton control
  139. RadioButton radioButton = new RadioButton
  140. {
  141. Name = "RadioButton control " + index,
  142. LocalArea = Rectangle.FromCenter(xPos, yPos, 0.2f, 0.05f),
  143. Text = "RadioButton text",
  144. IsChecked = true,
  145. //Alignment = Alignment.Right,
  146. };
  147. controlsScreen.Add(radioButton);
  148. yPos += yPosOffset;
  149. #endregion
  150. #region Adding a TextBox control
  151. TextBox textBox = new TextBox
  152. {
  153. Name = "TextBox control " + index,
  154. LocalArea = Rectangle.FromCenter(xPos, yPos, 0.2f, 0.05f),
  155. Text = "TextBox text",
  156. //Alignment = Alignment.Bottom,
  157. };
  158. controlsScreen.Add(textBox);
  159. yPos += yPosOffset;
  160. #endregion
  161. } // for
  162. Application.Start(Scene.Open(controlsScreen));
  163. }
  164. #endregion
  165. }
  166. }