Example #1
0
        public override bool HandleInput(Point2D mousePos, bool mouseDown)
        {
            var button = Character as Button;

            var transform = _curTransform.GeometryRotation;

            transform.Translation = _curTransform.GeometryTranslation;// * scaling;
            ApplyCurrentRecord(ref transform);

            var verts = button.Vertices;
            var mouse = new Point2D(mousePos.X, mousePos.Y);

            foreach (var tri in button.Triangles)
            {
                var v1 = Vector2.Transform(verts[tri.IDX0], transform);
                var v2 = Vector2.Transform(verts[tri.IDX1], transform);
                var v3 = Vector2.Transform(verts[tri.IDX2], transform);

                if (TriangleUtility.IsPointInside(v1, v2, v3, mouse))
                {
                    if (!_isHovered)
                    {
                        logger.Debug("Hit: " + mousePos.X + "-" + mousePos.Y);
                        var idx = button.Actions.FindIndex(ba => ba.Flags.HasFlag(ButtonActionFlags.IdleToOverUp));
                        if (idx != -1)
                        {
                            _actionList.Add(button.Actions[idx].Instructions);
                        }
                        _isHovered = true;
                    }

                    if (_isHovered && mouseDown && !_isDown)
                    {
                        logger.Debug("Down: " + mousePos.X + "-" + mousePos.Y);
                        var idx = button.Actions.FindIndex(ba => ba.Flags.HasFlag(ButtonActionFlags.OverUpToOverDown));
                        if (idx != -1)
                        {
                            _actionList.Add(button.Actions[idx].Instructions);
                        }
                        _isDown = true;
                    }

                    if (_isHovered && !mouseDown && _isDown)
                    {
                        logger.Debug("Up: " + mousePos.X + "-" + mousePos.Y);
                        var idx = button.Actions.FindIndex(ba => ba.Flags.HasFlag(ButtonActionFlags.OverDownToOverUp));
                        if (idx != -1)
                        {
                            _actionList.Add(button.Actions[idx].Instructions);
                        }
                        _isDown = false;
                    }

                    return(true);
                }
            }

            if (_isHovered)
            {
                var idx = button.Actions.FindIndex(ba => ba.Flags.HasFlag(ButtonActionFlags.OverUpToIdle));
                if (idx != -1)
                {
                    _actionList.Add(button.Actions[idx].Instructions);
                }
                _isHovered = false;
                logger.Debug("Unhovered: " + mousePos.X + "-" + mousePos.Y);
            }
            return(false);
        }
Example #2
0
 public void IsPointInsideTest(Vector2 v1, Vector2 v2, Vector2 v3, Point2D point, bool expectedResult)
 {
     Assert.Equal(expectedResult, TriangleUtility.IsPointInside(v1, v2, v3, point));
 }