protected override bool OnFinish(Event evt, WindowState state, Rect rect) { var x = state.PixelToTime(rect.xMin); var y = state.PixelToTime(rect.xMax); state.SetTimeAreaShownRange(x, y); return(true); }
protected override bool MouseWheel(Event evt, WindowState state) { if (Math.Abs(evt.delta.y) < 1e-5) { return(false); } var zoomRect = TimelineWindow.instance.sequenceContentRect; zoomRect.yMax += TimelineWindow.instance.horizontalScrollbarHeight; if (!zoomRect.Contains(evt.mousePosition)) { return(false); } if (!m_WheelUsedLast || Mathf.Abs(m_LastMouseMoveX - evt.mousePosition.x) > 1.0f) { m_LastMouseMoveX = evt.mousePosition.x; m_FocalTime = state.PixelToTime(m_LastMouseMoveX); } var zoomFactor = -evt.delta.y * 0.02f + 1; DoZoom(zoomFactor, state.timeAreaShownRange, m_FocalTime); m_WheelUsedLast = true; return(true); }
protected override bool MouseDown(Event evt, WindowState state) { m_MouseDownPos = evt.mousePosition; m_FocalTime = state.PixelToTime(m_MouseDownPos.x); m_InitialShownRange = state.timeAreaShownRange; return(false); }
protected override bool MouseWheel(Event evt, WindowState state) { if (Math.Abs(evt.delta.y) < 1e-5) { return(false); } if (!m_WheelUsedLast || Mathf.Abs(m_LastMouseMoveX - evt.mousePosition.x) > 1.0f) { m_LastMouseMoveX = evt.mousePosition.x; m_FocalTime = state.PixelToTime(m_LastMouseMoveX); m_InitialShownRange = state.timeAreaShownRange; m_ZoomFactor = 1; } var newZoom = m_ZoomFactor * (-evt.delta.y * 0.02f + 1); newZoom = Mathf.Clamp(newZoom, 1e-7f, 1e7f); var lastRange = state.timeAreaShownRange; DoZoom(newZoom, state, m_InitialShownRange, m_FocalTime); // if we hit a limit, don't change the zoom // this prevents accumulating when zoom doesn't change if (lastRange != state.timeAreaShownRange) { m_ZoomFactor = newZoom; } m_WheelUsedLast = true; return(true); }
public TimelinePoint(WindowState state, Vector2 mousePosition) { m_State = state; m_TreeViewGUI = state.GetWindow().treeView; m_Time = m_State.PixelToTime(mousePosition.x); m_YPos = mousePosition.y; m_YScrollPos = m_TreeViewGUI.scrollPosition.y; }
public SnapEngine(IAttractable attractable, IAttractionHandler attractionHandler, ManipulateEdges manipulateEdges, WindowState state, Vector2 mousePosition, IEnumerable <ISnappable> snappables = null) { m_Attractable = attractable; m_ManipulateEdges = manipulateEdges; m_AttractionHandler = attractionHandler; m_State = state; m_CurrentTimes = m_GrabbedTimes = new TimeBoundaries(m_Attractable.start, m_Attractable.end); m_GrabbedTime = m_State.PixelToTime(mousePosition.x); // Add Time zero as Magnet AddMagnet(0.0, true, state); // Add current Time as Magnet // case1157280 only add current time as magnet if visible if (TimelineWindow.instance.currentMode.ShouldShowTimeCursor(m_State)) { AddMagnet(state.editSequence.time, true, state); } if (state.IsEditingASubTimeline()) { // Add start and end of evaluable range as Magnets // This includes the case where the master timeline has a fixed length var range = state.editSequence.GetEvaluableRange(); AddMagnet(range.start, true, state); AddMagnet(range.end, true, state); } else if (state.masterSequence.asset.durationMode == TimelineAsset.DurationMode.FixedLength) { // Add end sequence Time as Magnet AddMagnet(state.masterSequence.asset.duration, true, state); } if (snappables == null) { snappables = GetVisibleSnappables(m_State); } foreach (var snappable in snappables) { if (!attractable.ShouldSnapTo(snappable)) { continue; } var edges = snappable.SnappableEdgesFor(attractable, manipulateEdges); foreach (var edge in edges) { AddMagnet(edge.time, edge.showSnapHint, state); } } }
public void Snap(Vector2 currentMousePosition, EventModifiers modifiers) { var d = m_State.PixelToTime(currentMousePosition.x) - m_GrabbedTime; m_CurrentTimes = m_GrabbedTimes.Translate(d); bool isLeft = m_ManipulateEdges == ManipulateEdges.Left || m_ManipulateEdges == ManipulateEdges.Both; bool isRight = m_ManipulateEdges == ManipulateEdges.Right || m_ManipulateEdges == ManipulateEdges.Both; bool attracted = false; m_SnapEnabled = modifiers == ManipulatorsUtils.actionModifier ? !m_State.edgeSnaps : m_State.edgeSnaps; if (m_SnapEnabled) { SnapInfo leftActiveMagnet = null; SnapInfo rightActiveMagnet = null; if (isLeft) { leftActiveMagnet = ClosestMagnet(m_CurrentTimes.left); } if (isRight) { rightActiveMagnet = ClosestMagnet(m_CurrentTimes.right); } if (leftActiveMagnet != null || rightActiveMagnet != null) { attracted = true; bool leftAttraction = false; if (rightActiveMagnet == null) { // Attracted by a left magnet only. leftAttraction = true; } else { if (leftActiveMagnet != null) { // Attracted by both magnets, choose the closest one. var leftDistance = Math.Abs(leftActiveMagnet.time - m_CurrentTimes.left); var rightDistance = Math.Abs(rightActiveMagnet.time - m_CurrentTimes.right); leftAttraction = leftDistance <= rightDistance; } // else, Attracted by right magnet only } if (leftAttraction) { m_AttractionHandler.OnAttractedEdge(m_Attractable, m_ManipulateEdges, AttractedEdge.Left, leftActiveMagnet.time); } else { m_AttractionHandler.OnAttractedEdge(m_Attractable, m_ManipulateEdges, AttractedEdge.Right, rightActiveMagnet.time); } } } if (!attracted) { var time = isLeft ? m_CurrentTimes.left : m_CurrentTimes.right; time = m_State.SnapToFrameIfRequired(time); m_AttractionHandler.OnAttractedEdge(m_Attractable, m_ManipulateEdges, AttractedEdge.None, time); } }