/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
- using Delta.Engine;
- using Delta.Rendering.Basics.Materials;
- using Delta.Rendering.Enums;
- using Delta.Utilities;
- using Delta.Utilities.Datatypes;
- using NUnit.Framework;
-
- namespace Delta.Scenes.UserInterfaces.Controls
- {
- /// <summary>
- /// This class represents a control for displaying images via materials on
- /// the screen.
- /// </summary>
- public class Image : BaseControl
- {
- #region Protected
-
- #region FallbackDesign (Protected)
- /// <summary>
- /// Defines the theme which will be used if no "Theme" was set explicitely.
- /// </summary>
- protected override ControlDesign FallbackDesign
- {
- get
- {
- return Theme.Current.ImageDesign;
- }
- }
- #endregion
-
- #endregion
-
- /// <summary>
- /// Tests for Image controls
- /// </summary>
- [Category("Visual")]
- internal class ImageTests
- {
- #region AddChild (Static)
- /// <summary>
- /// Add child. Note: Too slow for a dynamic unit test.
- /// </summary>
- [Test]
- public static void AddChild()
- {
- Image parentOne = new Image();
- Image parentTwo = new Image();
- Image child = new Image();
-
- Assert.Null(parentOne.Parent);
- Assert.Equal(0, parentOne.Children.Count);
- Assert.Null(parentTwo.Parent);
- Assert.Equal(0, parentTwo.Children.Count);
- Assert.Null(child.Parent);
- Assert.Equal(0, child.Children.Count);
-
- parentOne.Add(child);
- Assert.Equal(parentOne, child.Parent);
- Assert.Equal(1, parentOne.Children.Count);
- Assert.Null(parentTwo.Parent);
- Assert.Equal(0, parentTwo.Children.Count);
- Assert.NotNull(child.Parent);
- Assert.Equal(0, child.Children.Count);
-
- parentTwo.Add(child);
- Assert.Null(parentOne.Parent);
- Assert.Equal(0, parentOne.Children.Count);
- Assert.Equal(parentTwo, child.Parent);
- Assert.Equal(1, parentTwo.Children.Count);
- Assert.NotNull(child.Parent);
- Assert.Equal(0, child.Children.Count);
- }
- #endregion
-
- #region DisplayImage (Static)
- /// <summary>
- /// Display image
- /// </summary>
- [Test]
- public static void DisplayImage()
- {
- Image testImage = new Image
- {
- //ControlArea = new Rectangle(0.4f, 0.4f, 0.2f, 0.2f));
- //ControlArea = new Rectangle(0.4f, 0.4f, 0.4f, 0.4f));
- //ControlArea = new Rectangle(0.0f, 0.0f, 0.5f, 0.5f));
- LocalArea = new Rectangle(0.25f, 0.25f, 0.5f, 0.5f),
- CustomDesign = new ControlDesign
- {
- //Background = UserTheme.GetUIMaterial(Color.Green),
- Background = BaseTheme.GetUIMaterial("Deltaenginelogo"),
- },
- };
-
- Screen testScene = new Screen();
- testScene.Add(testImage);
-
- // Open now the scene to "activate" for the test
- testScene.Open();
-
- // We just call here the "StartTest()" to display the image, but we
- // don't need to call the "Image.Draw()" explicitely, because this
- // already handled automatically by the UI manager
- Application.Start();
- }
- #endregion
-
- #region Hovering (Static)
- /// <summary>
- /// Hovering
- /// </summary>
- [Test]
- public static void Hovering()
- {
- // The used UI scene for the unit test
- Screen testScene = new Screen();
-
- Image testImage = new Image
- {
- LocalArea = Rectangle.FromCenter(0.5f, 0.5f, 0.5f, 0.3f),
- CustomDesign = new ControlDesign
- {
- Background = BaseTheme.GetUIMaterial("DeltaEngineLogo"),
- Hover = BaseTheme.GetUIMaterial("DeltaEngineLogo", Color.Red),
- },
- };
- testScene.Add(testImage);
-
- //Label debugLabel = new Label
- //{
- // LocalArea = new Rectangle(0.1f, 0.15f, 0.6f, 0.1f),
- //};
- //testScene.Add(debugLabel);
-
- // Open now the scene to "activate" for the test
- testScene.Open();
- Application.Start();
- }
- #endregion
-
- #region DisplayImageRotated (Static)
- /// <summary>
- /// Display image rotated
- /// </summary>
- [Test]
- public static void DisplayImageRotated()
- {
- Image testImage = new Image
- {
- Size = new Size(0.5f, 0.3f),
- Rotation = 45,
- CustomDesign = new ControlDesign
- {
- Background = new Material2DColored("DeltaEngineLogo")
- {
- DrawLayer = RenderLayer.UI,
- },
- Hover = new Material2DColored("DeltaEngineLogo")
- {
- DrawLayer = RenderLayer.UI,
- BlendColor = Color.Red,
- },
- },
- };
-
- Screen testScene = new Screen();
- testScene.Add(testImage);
-
- // Open now the scene to "activate" for the test
- testScene.Open();
- Application.Start();
- }
- #endregion
-
- #region MouseDrag (Static)
- /// <summary>
- /// Mouse drag. Testing with depth values
- /// </summary>
- [Test]
- public static void MouseDrag()
- {
- // The used UI scene for the unit test
- Screen testScene = new Screen();
-
- Image parentLeft = new Image
- {
- LocalArea = new Rectangle(0.1f, 0.1f, 0.2f, 0.2f),
- };
- testScene.Add(parentLeft);
-
- Image parentRight = new Image
- {
- LocalArea = new Rectangle(0.7f, 0.7f, 0.2f, 0.2f),
- };
- testScene.Add(parentRight);
-
- Image child = new Image
- {
- LocalArea = new Rectangle(0.5f, 0.5f, 0.1f, 0.1f),
- };
- testScene.Add(child);
-
- // if the child is getting "picked up", its depth must decrease to
- // the bottom, so that it lies over everything else.
- //child.Dragging += OnImageDragging;
-
- // Open now the scene to "activate" for the test
- testScene.Open();
- Application.Start();
- }
- #endregion
-
- #region MouseDragComplexDepths (Static)
- /// <summary>
- /// Mouse drag. Testing with complex, nested depth values
- /// </summary>
- [Test]
- public static void MouseDragComplexDepths()
- {
- // The used UI scene for the unit test
- Screen testScene = new Screen();
-
- Image parentLeft = new Image
- {
- LocalArea = new Rectangle(0.3f, 0.3f, 0.5f, 0.5f),
- };
- testScene.Add(parentLeft);
-
- Image parentRight = new Image
- {
- LocalArea = new Rectangle(0.7f, 0.7f, 0.2f, 0.2f),
- };
- testScene.Add(parentRight);
-
- Image child = new Image
- {
- LocalArea = new Rectangle(0.5f, 0.5f, 0.1f, 0.1f),
- };
- testScene.Add(child);
-
- Image child2 = new Image
- {
- LocalArea = new Rectangle(0.1f, 0.1f, 0.02f, 0.02f),
- };
- // the small, draggable rectangle is again child of the bigger draggable
- child.Add(child2);
-
- // Add the new drag events
- //child.Dragging += OnImageDragging;
-
- //child2.Dragging += OnImageDragging;
-
- // Open now the scene to "activate" for the test
- testScene.Open();
- Application.Start();
- }
- #endregion
- }
- }
- }