PageRenderTime 224ms CodeModel.GetById 121ms app.highlight 10ms RepoModel.GetById 90ms app.codeStats 0ms

/Scenes/UserInterfaces/Controls/Image.cs

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