PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Scenes/UserInterfaces/Controls/Image.cs

#
C# | 260 lines | 173 code | 32 blank | 55 comment | 0 complexity | 0ca5473f8671286072bf7ec94da695f3 MD5 | raw file
Possible License(s): Apache-2.0
  1. using Delta.Engine;
  2. using Delta.Rendering.Basics.Materials;
  3. using Delta.Rendering.Enums;
  4. using Delta.Utilities;
  5. using Delta.Utilities.Datatypes;
  6. using NUnit.Framework;
  7. namespace Delta.Scenes.UserInterfaces.Controls
  8. {
  9. /// <summary>
  10. /// This class represents a control for displaying images via materials on
  11. /// the screen.
  12. /// </summary>
  13. public class Image : BaseControl
  14. {
  15. #region Protected
  16. #region FallbackDesign (Protected)
  17. /// <summary>
  18. /// Defines the theme which will be used if no "Theme" was set explicitely.
  19. /// </summary>
  20. protected override ControlDesign FallbackDesign
  21. {
  22. get
  23. {
  24. return Theme.Current.ImageDesign;
  25. }
  26. }
  27. #endregion
  28. #endregion
  29. /// <summary>
  30. /// Tests for Image controls
  31. /// </summary>
  32. [Category("Visual")]
  33. internal class ImageTests
  34. {
  35. #region AddChild (Static)
  36. /// <summary>
  37. /// Add child. Note: Too slow for a dynamic unit test.
  38. /// </summary>
  39. [Test]
  40. public static void AddChild()
  41. {
  42. Image parentOne = new Image();
  43. Image parentTwo = new Image();
  44. Image child = new Image();
  45. Assert.Null(parentOne.Parent);
  46. Assert.Equal(0, parentOne.Children.Count);
  47. Assert.Null(parentTwo.Parent);
  48. Assert.Equal(0, parentTwo.Children.Count);
  49. Assert.Null(child.Parent);
  50. Assert.Equal(0, child.Children.Count);
  51. parentOne.Add(child);
  52. Assert.Equal(parentOne, child.Parent);
  53. Assert.Equal(1, parentOne.Children.Count);
  54. Assert.Null(parentTwo.Parent);
  55. Assert.Equal(0, parentTwo.Children.Count);
  56. Assert.NotNull(child.Parent);
  57. Assert.Equal(0, child.Children.Count);
  58. parentTwo.Add(child);
  59. Assert.Null(parentOne.Parent);
  60. Assert.Equal(0, parentOne.Children.Count);
  61. Assert.Equal(parentTwo, child.Parent);
  62. Assert.Equal(1, parentTwo.Children.Count);
  63. Assert.NotNull(child.Parent);
  64. Assert.Equal(0, child.Children.Count);
  65. }
  66. #endregion
  67. #region DisplayImage (Static)
  68. /// <summary>
  69. /// Display image
  70. /// </summary>
  71. [Test]
  72. public static void DisplayImage()
  73. {
  74. Image testImage = new Image
  75. {
  76. //ControlArea = new Rectangle(0.4f, 0.4f, 0.2f, 0.2f));
  77. //ControlArea = new Rectangle(0.4f, 0.4f, 0.4f, 0.4f));
  78. //ControlArea = new Rectangle(0.0f, 0.0f, 0.5f, 0.5f));
  79. LocalArea = new Rectangle(0.25f, 0.25f, 0.5f, 0.5f),
  80. CustomDesign = new ControlDesign
  81. {
  82. //Background = UserTheme.GetUIMaterial(Color.Green),
  83. Background = BaseTheme.GetUIMaterial("Deltaenginelogo"),
  84. },
  85. };
  86. Screen testScene = new Screen();
  87. testScene.Add(testImage);
  88. // Open now the scene to "activate" for the test
  89. testScene.Open();
  90. // We just call here the "StartTest()" to display the image, but we
  91. // don't need to call the "Image.Draw()" explicitely, because this
  92. // already handled automatically by the UI manager
  93. Application.Start();
  94. }
  95. #endregion
  96. #region Hovering (Static)
  97. /// <summary>
  98. /// Hovering
  99. /// </summary>
  100. [Test]
  101. public static void Hovering()
  102. {
  103. // The used UI scene for the unit test
  104. Screen testScene = new Screen();
  105. Image testImage = new Image
  106. {
  107. LocalArea = Rectangle.FromCenter(0.5f, 0.5f, 0.5f, 0.3f),
  108. CustomDesign = new ControlDesign
  109. {
  110. Background = BaseTheme.GetUIMaterial("DeltaEngineLogo"),
  111. Hover = BaseTheme.GetUIMaterial("DeltaEngineLogo", Color.Red),
  112. },
  113. };
  114. testScene.Add(testImage);
  115. //Label debugLabel = new Label
  116. //{
  117. // LocalArea = new Rectangle(0.1f, 0.15f, 0.6f, 0.1f),
  118. //};
  119. //testScene.Add(debugLabel);
  120. // Open now the scene to "activate" for the test
  121. testScene.Open();
  122. Application.Start();
  123. }
  124. #endregion
  125. #region DisplayImageRotated (Static)
  126. /// <summary>
  127. /// Display image rotated
  128. /// </summary>
  129. [Test]
  130. public static void DisplayImageRotated()
  131. {
  132. Image testImage = new Image
  133. {
  134. Size = new Size(0.5f, 0.3f),
  135. Rotation = 45,
  136. CustomDesign = new ControlDesign
  137. {
  138. Background = new Material2DColored("DeltaEngineLogo")
  139. {
  140. DrawLayer = RenderLayer.UI,
  141. },
  142. Hover = new Material2DColored("DeltaEngineLogo")
  143. {
  144. DrawLayer = RenderLayer.UI,
  145. BlendColor = Color.Red,
  146. },
  147. },
  148. };
  149. Screen testScene = new Screen();
  150. testScene.Add(testImage);
  151. // Open now the scene to "activate" for the test
  152. testScene.Open();
  153. Application.Start();
  154. }
  155. #endregion
  156. #region MouseDrag (Static)
  157. /// <summary>
  158. /// Mouse drag. Testing with depth values
  159. /// </summary>
  160. [Test]
  161. public static void MouseDrag()
  162. {
  163. // The used UI scene for the unit test
  164. Screen testScene = new Screen();
  165. Image parentLeft = new Image
  166. {
  167. LocalArea = new Rectangle(0.1f, 0.1f, 0.2f, 0.2f),
  168. };
  169. testScene.Add(parentLeft);
  170. Image parentRight = new Image
  171. {
  172. LocalArea = new Rectangle(0.7f, 0.7f, 0.2f, 0.2f),
  173. };
  174. testScene.Add(parentRight);
  175. Image child = new Image
  176. {
  177. LocalArea = new Rectangle(0.5f, 0.5f, 0.1f, 0.1f),
  178. };
  179. testScene.Add(child);
  180. // if the child is getting "picked up", its depth must decrease to
  181. // the bottom, so that it lies over everything else.
  182. //child.Dragging += OnImageDragging;
  183. // Open now the scene to "activate" for the test
  184. testScene.Open();
  185. Application.Start();
  186. }
  187. #endregion
  188. #region MouseDragComplexDepths (Static)
  189. /// <summary>
  190. /// Mouse drag. Testing with complex, nested depth values
  191. /// </summary>
  192. [Test]
  193. public static void MouseDragComplexDepths()
  194. {
  195. // The used UI scene for the unit test
  196. Screen testScene = new Screen();
  197. Image parentLeft = new Image
  198. {
  199. LocalArea = new Rectangle(0.3f, 0.3f, 0.5f, 0.5f),
  200. };
  201. testScene.Add(parentLeft);
  202. Image parentRight = new Image
  203. {
  204. LocalArea = new Rectangle(0.7f, 0.7f, 0.2f, 0.2f),
  205. };
  206. testScene.Add(parentRight);
  207. Image child = new Image
  208. {
  209. LocalArea = new Rectangle(0.5f, 0.5f, 0.1f, 0.1f),
  210. };
  211. testScene.Add(child);
  212. Image child2 = new Image
  213. {
  214. LocalArea = new Rectangle(0.1f, 0.1f, 0.02f, 0.02f),
  215. };
  216. // the small, draggable rectangle is again child of the bigger draggable
  217. child.Add(child2);
  218. // Add the new drag events
  219. //child.Dragging += OnImageDragging;
  220. //child2.Dragging += OnImageDragging;
  221. // Open now the scene to "activate" for the test
  222. testScene.Open();
  223. Application.Start();
  224. }
  225. #endregion
  226. }
  227. }
  228. }