public override void HandleInputStateChange(InputStateChangeEvent inputStateChange)
        {
            switch (inputStateChange)
            {
            case MousePositionChangeEvent mousePositionChange:
                var mouse = mousePositionChange.State.Mouse;

                // confine cursor
                if (Host.Window != null)
                {
                    RectangleF?cursorConfineRect = null;
                    var        clientSize        = Host.Window.ClientSize;
                    var        windowRect        = new RectangleF(0, 0, clientSize.Width, clientSize.Height);

                    if (Host.Window.CursorState.HasFlagFast(CursorState.Confined))
                    {
                        cursorConfineRect = Host.Window.CursorConfineRect ?? windowRect;
                    }
                    else if (mouseOutsideAllDisplays(mouse.Position))
                    {
                        // Implicitly confine the cursor to prevent a feedback loop of MouseHandler warping the cursor to an invalid position
                        // and the OS immediately warping it back inside a display.

                        // Window.CursorConfineRect is not used here as that should only be used when confining is explicitly enabled.
                        cursorConfineRect = windowRect;
                    }

                    if (cursorConfineRect.HasValue)
                    {
                        mouse.Position = Vector2.Clamp(mouse.Position, cursorConfineRect.Value.Location, cursorConfineRect.Value.Location + cursorConfineRect.Value.Size - Vector2.One);
                    }
                }

                break;

            case ButtonStateChangeEvent <MouseButton> buttonChange:
                if (buttonChange.Kind == ButtonStateChangeKind.Pressed && Host.Window?.CursorInWindow.Value == false)
                {
                    return;
                }

                break;

            case MouseScrollChangeEvent _:
                if (Host.Window?.CursorInWindow.Value == false)
                {
                    return;
                }

                break;
            }

            base.HandleInputStateChange(inputStateChange);
        }
예제 #2
0
 /// <summary>
 /// Select all masks in a given rectangle selection area.
 /// </summary>
 /// <param name="rect">The rectangle to perform a selection on in screen-space coordinates.</param>
 public void Select(RectangleF rect)
 {
     foreach (var mask in aliveMasks.ToList())
     {
         if (mask.IsPresent && rect.Contains(mask.SelectionPoint))
         {
             mask.Select();
         }
         else
         {
             mask.Deselect();
         }
     }
 }
예제 #3
0
파일: Interpolation.cs 프로젝트: Acivev/osu
        public static RectangleF ValueAt(double time, RectangleF val1, RectangleF val2, double startTime, double endTime, Easing easing = Easing.None)
        {
            float current  = (float)(time - startTime);
            float duration = (float)(endTime - startTime);

            if (duration == 0 || current == 0)
            {
                return(val1);
            }

            float t = (float)ApplyEasing(easing, current / duration);

            return(new RectangleF(
                       val1.X + t * (val2.X - val1.X),
                       val1.Y + t * (val2.Y - val1.Y),
                       val1.Width + t * (val2.Width - val1.Width),
                       val1.Height + t * (val2.X - val1.Height)));
        }
예제 #4
0
        /// <summary>
        /// Populates <see cref="Vertices"/> and <see cref="Normals"/>.
        /// </summary>
        protected virtual void UpdateVertices()
        {
            Vertices.Clear();
            Normals.Clear();

            float cornerRadius = CornerRadius;

            // Sides
            RectangleF rect = DrawRectangle;

            Vector2[] corners           = { rect.TopLeft, rect.TopRight, rect.BottomRight, rect.BottomLeft };
            const int amount_side_steps = 2;

            for (int i = 0; i < 4; ++i)
            {
                Vector2 a      = corners[i];
                Vector2 b      = corners[(i + 1) % 4];
                Vector2 diff   = b - a;
                float   length = diff.Length;
                Vector2 dir    = diff / length;

                float usableLength = Math.Max(length - 2 * cornerRadius, 0);

                Vector2 normal = (b - a).PerpendicularRight.Normalized();
                for (int j = 0; j < amount_side_steps; ++j)
                {
                    Vertices.Add(a + dir * (cornerRadius + j * usableLength / (amount_side_steps - 1)));
                    Normals.Add(normal);
                }
            }

            const int amount_corner_steps = 10;

            if (cornerRadius > 0)
            {
                // Rounded corners
                Vector2[] offsets =
                {
                    new Vector2(cornerRadius,  cornerRadius),
                    new Vector2(-cornerRadius, cornerRadius),
                    new Vector2(-cornerRadius, -cornerRadius),
                    new Vector2(cornerRadius,  -cornerRadius),
                };

                for (int i = 0; i < 4; ++i)
                {
                    Vector2 a = corners[i];

                    float startTheta = (i - 1) * (float)Math.PI / 2;

                    for (int j = 0; j < amount_corner_steps; ++j)
                    {
                        float theta = startTheta + j * (float)Math.PI / (2 * (amount_corner_steps - 1));

                        Vector2 normal = new Vector2((float)Math.Sin(theta), (float)Math.Cos(theta));
                        Vertices.Add(a + offsets[i] + normal * cornerRadius);
                        Normals.Add(normal);
                    }
                }
            }

            // To simulation space
            Matrix3 mat     = DrawInfo.Matrix * ScreenToSimulationSpace;
            Matrix3 normMat = mat.Inverted();

            normMat.Transpose();

            // Remove translation
            normMat.M31 = normMat.M32 = normMat.M13 = normMat.M23 = 0;
            Vector2 translation = Vector2Extensions.Transform(Vector2.Zero, normMat);

            for (int i = 0; i < Vertices.Count; ++i)
            {
                Vertices[i] = Vector2Extensions.Transform(Vertices[i], mat);
                Normals[i]  = (Vector2Extensions.Transform(Normals[i], normMat) - translation).Normalized();
            }
        }