Fires once when the mouse button is pressed and the mouse has not moved for some time.
View code on GitHub
Inheritance Hierarchy
DeltaEngine.Entities Entity
DeltaEngine.Commands Trigger
DeltaEngine.Commands InputTrigger
DeltaEngine.Input MouseHoldTrigger
Namespace: DeltaEngine.Input
Assembly: DeltaEngine.Input (in DeltaEngine.Input.dll) Version: 1.1.1.0 (1.1.1)
Syntax
The MouseHoldTrigger type exposes the following members.
Constructors
Name | Description | |
---|---|---|
MouseHoldTrigger(Dictionary String, String ) | Initializes a new instance of the MouseHoldTrigger class | |
MouseHoldTrigger(Rectangle, Single, MouseButton) | Initializes a new instance of the MouseHoldTrigger class |
Methods
Name | Description | |
---|---|---|
Add T | (Inherited from Entity.) | |
AddTag | (Inherited from Entity.) | |
ClearTags | (Inherited from Entity.) | |
Contains T | (Inherited from Entity.) | |
ContainsBehavior T | (Inherited from Entity.) | |
ContainsTag | (Inherited from Entity.) | |
Deactivate | (Inherited from Entity.) | |
Dispose | (Inherited from Entity.) | |
Get T |
Gets a specific component, derived classes can return faster cached values (e.g. Entity2D)
View code on GitHub (Inherited from Entity.) | |
GetActiveBehaviors | (Inherited from Entity.) | |
GetComponentsForSaving | (Inherited from Entity.) | |
GetOrDefault T | (Inherited from Entity.) | |
GetTags | (Inherited from Entity.) | |
HandleWithMouse | ||
Invoke | (Inherited from Trigger.) | |
IsHovering | ||
Remove T | (Inherited from Entity.) | |
RemoveTag | (Inherited from Entity.) | |
Set | (Inherited from Entity.) | |
SetComponents | (Inherited from Entity.) | |
Start T | (Inherited from Entity.) | |
StartInputDevice | (Overrides InputTrigger StartInputDevice .) | |
Stop T | (Inherited from Entity.) | |
ToString | (Inherited from Entity.) | |
Update | (Inherited from Trigger.) |
Fields
Name | Description | |
---|---|---|
components | (Inherited from Entity.) | |
Invoked | (Inherited from Trigger.) |
Properties
Name | Description | |
---|---|---|
Button | ||
HoldArea | ||
HoldTime | ||
IsActive | (Inherited from Entity.) | |
IsPauseable | (Inherited from Trigger.) | |
Movement | ||
NumberOfComponents | (Inherited from Entity.) | |
UpdatePriority | (Inherited from Entity.) | |
WasInvokedThisTick | (Inherited from Trigger.) |
Remarks
Examples
[Test] public void HoldLeftClickOnRectangle() { var drawArea = new Rectangle(0.25f, 0.25f, 0.5f, 0.25f); new FilledRect(drawArea, Color.Blue); var trigger = new MouseHoldTrigger(drawArea); var counter = 0; var text = new FontText(Font.Default, "", drawArea.Move(new Vector2D(0.0f, 0.25f))); new Command(() => text.Text = "MouseHold Triggered " + ++counter + " times.").Add(trigger); }
[Test, CloseAfterFirstFrame] public void Create() { var trigger = new MouseHoldTrigger(Rectangle.One, 0.5f, MouseButton.Right); Assert.AreEqual(Rectangle.One, trigger.HoldArea); Assert.AreEqual(0.5f, trigger.HoldTime); Assert.AreEqual(MouseButton.Right, trigger.Button); }
[Test, CloseAfterFirstFrame] public void CreateFromAttributes() { var trigger = new MouseHoldTrigger(new Dictionary<string, string> { { "HoldArea", "1 2 3 4" }, { "HoldTime", "5.5" }, { "Button", "Right" } }); Assert.AreEqual(new Rectangle(1, 2, 3, 4), trigger.HoldArea); Assert.AreEqual(5.5f, trigger.HoldTime); Assert.AreEqual(MouseButton.Right, trigger.Button); Assert.Throws<MouseHoldTrigger.CannotCreateMouseHoldTriggerWithoutHoldArea>( () => new MouseHoldTrigger(new Dictionary<string, string>())); } [Test, CloseAfterFirstFrame] public void HoldMouseOutsideHoldArea() { if (mouse == null) return; //ncrunch: no coverage Vector2D mousePosition = -Vector2D.One; new Command(position => { mousePosition = position; }).Add( new MouseHoldTrigger(Rectangle.HalfCentered)); SetMouseState(State.Pressing, Vector2D.Zero); SetMouseState(State.Pressed, Vector2D.Zero); AdvanceTimeAndUpdateEntities(1.05f); Assert.AreEqual(-Vector2D.One, mousePosition); } private void SetMouseState(State state, Vector2D position) { if (mouse == null) return; //ncrunch: no coverage mouse.SetNativePosition(position); mouse.SetButtonState(MouseButton.Left, state); AdvanceTimeAndUpdateEntities(); } [Test, CloseAfterFirstFrame] public void HoldMouseHovering() { var drawArea = new Rectangle(0.25f, 0.25f, 0.5f, 0.25f); var rect = new FilledRect(drawArea, Color.Blue); var trigger = new MouseHoldTrigger(drawArea); trigger.Invoked += () => rect.Color = Color.Red; trigger.Movement = new Vector2D(0.3f, 0.3f); Assert.IsFalse(trigger.IsHovering()); AdvanceTimeAndUpdateEntities(1.05f); Assert.IsFalse(trigger.IsHovering()); } [Test, CloseAfterFirstFrame] public void MoveMouseInsideHoldArea() { if (mouse == null) return; //ncrunch: no coverage Vector2D mousePosition = -Vector2D.One; new Command(position => { mousePosition = position; }).Add( new MouseHoldTrigger(Rectangle.HalfCentered)); SetMouseState(State.Pressing, Vector2D.Half); SetMouseState(State.Pressed, Vector2D.Half); AdvanceTimeAndUpdateEntities(0.5f); SetMouseState(State.Pressed, new Vector2D(0.6f, 0.6f)); AdvanceTimeAndUpdateEntities(0.5f); Assert.AreEqual(Vector2D.Half, mousePosition); } //ncrunch: no coverage start [Test, CloseAfterFirstFrame, Category("Slow")] public void HoldMouseInsideHoldArea() { if (mouse == null) return; //ncrunch: no coverage Vector2D mousePosition = -Vector2D.One; new Command(position => { mousePosition = position; }).Add( new MouseHoldTrigger(Rectangle.HalfCentered)); SetMouseState(State.Pressing, Vector2D.Half); SetMouseState(State.Pressed, Vector2D.Half); AdvanceTimeAndUpdateEntities(1.05f); Assert.AreEqual(Vector2D.Half, mousePosition); } }
See Also