TouchHoldTriggerTests ClassDelta Engine Documentation
Inheritance Hierarchy

System Object
  DeltaEngine.Platforms TestWithMocksOrVisually
    DeltaEngine.Input.Tests TouchHoldTriggerTests

Namespace: DeltaEngine.Input.Tests
Assembly: DeltaEngine.Input.Tests (in DeltaEngine.Input.Tests.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public class TouchHoldTriggerTests : TestWithMocksOrVisually

The TouchHoldTriggerTests type exposes the following members.

Constructors

  NameDescription
Public methodTouchHoldTriggerTests
Initializes a new instance of the TouchHoldTriggerTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodCreate
Public methodCreateFromAttributes
Public methodHoldOnRectangle
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
Public methodIsHovering
Public methodPessingInTheSamePositionWillMakeTriggerHover
Protected methodRegisterMock T  (Inherited from TestWithMocksOrVisually.)
Protected methodResolve T  (Inherited from TestWithMocksOrVisually.)
Protected methodRunAfterFirstFrame (Inherited from TestWithMocksOrVisually.)
Public methodRunTestAndDisposeResolverWhenDone (Inherited from TestWithMocksOrVisually.)
Public methodSetUp
Top
Properties

  NameDescription
Protected propertyIsMockResolver (Inherited from TestWithMocksOrVisually.)
Top
Examples

[Test]
public void HoldOnRectangle()
{
    var drawArea = new Rectangle(0.25f, 0.25f, 0.5f, 0.25f);
    new FilledRect(drawArea, Color.Blue);
    var trigger = new TouchHoldTrigger(drawArea);
    var counter = 0;
    var text = new FontText(Font.Default, "", drawArea.Move(new Vector2D(0.0f, 0.25f)));
    new Command(() => text.Text = "TouchHold Triggered " + ++counter + " times.").Add(trigger);
}
[Test, CloseAfterFirstFrame]
public void Create()
{
    var trigger = new TouchHoldTrigger(Rectangle.One, 0.5f);
    Assert.AreEqual(Rectangle.One, trigger.HoldArea);
    Assert.AreEqual(0.5f, trigger.HoldTime);
}
    [Test, CloseAfterFirstFrame]
    public void CreateFromAttributes()
    {
        var trigger = new TouchHoldTrigger(new Dictionary<string, string>
            {
                { "HoldArea", "0.1, 0.2, 0.3, 0.4" },
                { "HoldTime", "10.4" }
            });
        Assert.AreEqual(new Rectangle(0.1f, 0.2f, 0.3f, 0.4f), trigger.HoldArea);
        Assert.AreEqual(10.4f, trigger.HoldTime);
    }

    [Test, CloseAfterFirstFrame]
    public void IsHovering()
    {
        var trigger = new TouchHoldTrigger(Rectangle.One, 0.5f);
        Assert.IsFalse(trigger.IsHovering());
        trigger.Elapsed = 1f;
        Assert.IsFalse(trigger.IsHovering());
    }

    [Test, CloseAfterFirstFrame]
    public void PessingInTheSamePositionWillMakeTriggerHover()
    {
        var trigger = new TouchHoldTrigger(Rectangle.One, 0.0001f);
        new Command(() => { }).Add(trigger);
        SetTouchState(State.Pressing, Vector2D.Half);
        SetTouchState(State.Pressed, Vector2D.Half);
        SetTouchState(State.Releasing, Vector2D.Half);
        Assert.IsTrue(trigger.IsHovering());
    }

    private void SetTouchState(State state, Vector2D position)
    {
        if (touch == null)
            return; //ncrunch: no coverage
        touch.SetTouchState(0, state, position);
        AdvanceTimeAndUpdateEntities();
    }
}
[Test, CloseAfterFirstFrame]
public void IsHovering()
{
    var trigger = new TouchHoldTrigger(Rectangle.One, 0.5f);
    Assert.IsFalse(trigger.IsHovering());
    trigger.Elapsed = 1f;
    Assert.IsFalse(trigger.IsHovering());
}
[Test, CloseAfterFirstFrame]
public void PessingInTheSamePositionWillMakeTriggerHover()
{
    var trigger = new TouchHoldTrigger(Rectangle.One, 0.0001f);
    new Command(() => { }).Add(trigger);
    SetTouchState(State.Pressing, Vector2D.Half);
    SetTouchState(State.Pressed, Vector2D.Half);
    SetTouchState(State.Releasing, Vector2D.Half);
    Assert.IsTrue(trigger.IsHovering());
}
See Also