예제 #1
0
        /// <summary>
        /// Handles input. Should be called by the owning window whenever a pointer is pressed.
        /// </summary>
        /// <param name="ev">Object containing pointer press event information.</param>
        internal void OnPointerPressed(PointerEvent ev)
        {
            if (ev.IsUsed)
            {
                return;
            }

            Vector2I windowPos = window.ScreenToWindowPos(ev.ScreenPos);

            Rect2I   elementBounds = GUIUtility.CalculateBounds(gui, window.GUI);
            Vector2I pointerPos    = windowPos - new Vector2I(elementBounds.x, elementBounds.y);

            Rect2I   drawingBounds = drawingPanel.Bounds;
            Vector2I drawingPos    = pointerPos - new Vector2I(drawingBounds.x, drawingBounds.y);

            Rect2I   eventBounds = eventsPanel.Bounds;
            Vector2I eventPos    = pointerPos - new Vector2I(eventBounds.x, eventBounds.y);

            if (ev.Button == PointerButton.Left)
            {
                Vector2 curveCoord;
                if (guiCurveDrawing.PixelToCurveSpace(drawingPos, out curveCoord))
                {
                    KeyframeRef keyframeRef;
                    if (!guiCurveDrawing.FindKeyFrame(drawingPos, out keyframeRef))
                    {
                        TangentRef tangentRef;
                        if (guiCurveDrawing.FindTangent(drawingPos, out tangentRef))
                        {
                            isMousePressedOverTangent = true;
                            dragStart      = drawingPos;
                            draggedTangent = tangentRef;
                        }
                        else
                        {
                            ClearSelection();
                        }
                    }
                    else
                    {
                        if (!IsSelected(keyframeRef))
                        {
                            if (!Input.IsButtonHeld(ButtonCode.LeftShift) && !Input.IsButtonHeld(ButtonCode.RightShift))
                            {
                                ClearSelection();
                            }

                            SelectKeyframe(keyframeRef);
                        }

                        isMousePressedOverKey = true;
                        dragStart             = drawingPos;
                    }

                    guiCurveDrawing.Rebuild();
                    UpdateEventsGUI();
                }
                else
                {
                    int frameIdx = guiTimeline.GetFrame(pointerPos);

                    if (frameIdx != -1)
                    {
                        SetMarkedFrame(frameIdx);
                    }
                    else
                    {
                        int eventIdx;
                        if (guiEvents.FindEvent(eventPos, out eventIdx))
                        {
                            if (!Input.IsButtonHeld(ButtonCode.LeftShift) && !Input.IsButtonHeld(ButtonCode.RightShift))
                            {
                                ClearSelection();
                            }

                            events[eventIdx].selected = true;
                            UpdateEventsGUI();
                        }
                        else
                        {
                            ClearSelection();

                            guiCurveDrawing.Rebuild();
                            UpdateEventsGUI();
                        }
                    }

                    OnFrameSelected?.Invoke(frameIdx);
                }

                isPointerHeld = true;
            }
            else if (ev.Button == PointerButton.Right)
            {
                Vector2 curveCoord;
                if (guiCurveDrawing.PixelToCurveSpace(drawingPos, out curveCoord))
                {
                    contextClickPosition = drawingPos;

                    KeyframeRef keyframeRef;
                    if (!guiCurveDrawing.FindKeyFrame(drawingPos, out keyframeRef))
                    {
                        ClearSelection();

                        blankContextMenu.Open(pointerPos, gui);

                        guiCurveDrawing.Rebuild();
                        UpdateEventsGUI();
                    }
                    else
                    {
                        // If clicked outside of current selection, just select the one keyframe
                        if (!IsSelected(keyframeRef))
                        {
                            ClearSelection();
                            SelectKeyframe(keyframeRef);

                            guiCurveDrawing.Rebuild();
                            UpdateEventsGUI();
                        }

                        keyframeContextMenu.Open(pointerPos, gui);
                    }
                }
                else if (guiEvents.GetFrame(eventPos) != -1) // Clicked over events bar
                {
                    contextClickPosition = eventPos;

                    int eventIdx;
                    if (!guiEvents.FindEvent(eventPos, out eventIdx))
                    {
                        ClearSelection();

                        blankEventContextMenu.Open(pointerPos, gui);

                        guiCurveDrawing.Rebuild();
                        UpdateEventsGUI();
                    }
                    else
                    {
                        // If clicked outside of current selection, just select the one event
                        if (!events[eventIdx].selected)
                        {
                            ClearSelection();
                            events[eventIdx].selected = true;

                            guiCurveDrawing.Rebuild();
                            UpdateEventsGUI();
                        }

                        eventContextMenu.Open(pointerPos, gui);
                    }
                }
            }
        }