public void DeselectEvents(FrameRange range) { for (int i = 0; i != _eventEditors.Count; ++i) { if (range.Overlaps(_eventEditors[i]._evt.FrameRange)) { SequenceEditor.Deselect(_eventEditors[i]); } else if (_eventEditors[i]._evt.Start > range.End) { break; } } }
protected virtual void RenderEvent(FrameRange viewRange, FrameRange validKeyframeRange) { int leftHandleId = EditorGUIUtility.GetControlID(FocusType.Passive); int evtHandleId = EditorGUIUtility.GetControlID(FocusType.Passive); int rightHandleId = EditorGUIUtility.GetControlID(FocusType.Passive); bool leftHandleVisible = viewRange.Contains(_evt.Start); bool rightHandleVisible = viewRange.Contains(_evt.End); Rect leftHandleRect = _eventRect; leftHandleRect.width = 4; Rect rightHandleRect = _eventRect; rightHandleRect.xMin = rightHandleRect.xMax - 4; if (leftHandleVisible && IsSelected()) { EditorGUIUtility.AddCursorRect(leftHandleRect, MouseCursor.ResizeHorizontal, leftHandleId); } if (rightHandleVisible && IsSelected()) { EditorGUIUtility.AddCursorRect(rightHandleRect, MouseCursor.ResizeHorizontal, rightHandleId); } switch (Event.current.type) { case EventType.Repaint: if (!viewRange.Overlaps(_evt.FrameRange)) { break; } GUISkin skin = FUtility.GetFluxSkin(); GUIStyle eventStyle = skin.GetStyle("Event"); GUI.color = GetColor(); eventStyle.Draw(_eventRect, _isSelected, _isSelected, false, false); GUI.color = Color.white; break; case EventType.MouseDown: if (EditorGUIUtility.hotControl == 0 && IsSelected() && !Event.current.control && !Event.current.shift) { Vector2 mousePos = Event.current.mousePosition; if (rightHandleVisible && rightHandleRect.Contains(mousePos)) { EditorGUIUtility.hotControl = rightHandleId; // keyframeOnSelect = evt.Start; Event.current.Use(); } else if (leftHandleVisible && leftHandleRect.Contains(mousePos)) { EditorGUIUtility.hotControl = leftHandleId; // keyframeOnSelect = evt.End; Event.current.Use(); } else if (_eventRect.Contains(mousePos)) { EditorGUIUtility.hotControl = evtHandleId; _mouseOffsetFrames = SequenceEditor.GetFrameForX(mousePos.x) - _evt.Start; if (IsSelected()) { if (Event.current.control) { SequenceEditor.Deselect(this); } } else { if (Event.current.shift) { SequenceEditor.Select(this); } else if (!Event.current.control) { SequenceEditor.SelectExclusive(this); } } Event.current.Use(); } } break; case EventType.MouseUp: if (EditorGUIUtility.hotControl != 0) { if (EditorGUIUtility.hotControl == evtHandleId || EditorGUIUtility.hotControl == leftHandleId || EditorGUIUtility.hotControl == rightHandleId) { EditorGUIUtility.hotControl = 0; Event.current.Use(); SequenceEditor.Repaint(); } } break; case EventType.MouseDrag: if (EditorGUIUtility.hotControl != 0) { if (EditorGUIUtility.hotControl == evtHandleId) { int t = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - _mouseOffsetFrames; int delta = t - _evt.Start; SequenceEditor.MoveEvents(delta); Event.current.Use(); } else if (EditorGUIUtility.hotControl == leftHandleId || EditorGUIUtility.hotControl == rightHandleId) { int leftLimit = 0; int rightLimit = 0; bool draggingStart = EditorGUIUtility.hotControl == leftHandleId; if (draggingStart) { leftLimit = validKeyframeRange.Start; rightLimit = _evt.End - 1; } else { leftLimit = _evt.Start + 1; rightLimit = validKeyframeRange.End; } int t = SequenceEditor.GetFrameForX(Event.current.mousePosition.x); t = Mathf.Clamp(t, leftLimit, rightLimit); int delta = t - (draggingStart ? _evt.Start : _evt.End); if (draggingStart) { int newLength = _evt.Length - delta; if (newLength < _evt.GetMinLength()) { delta += newLength - _evt.GetMinLength(); } if (newLength > _evt.GetMaxLength()) { delta += newLength - _evt.GetMaxLength(); } } else { int newLength = _evt.Length + delta; if (newLength < _evt.GetMinLength()) { delta -= newLength - _evt.GetMinLength(); } if (newLength > _evt.GetMaxLength()) { delta -= newLength - _evt.GetMaxLength(); } } if (delta != 0) { if (draggingStart) { SequenceEditor.ResizeEventsLeft(delta); } else { SequenceEditor.ResizeEventsRight(delta); } } Event.current.Use(); } } break; } }
protected virtual void RenderEvent(FrameRange viewRange, FrameRange validKeyframeRange) { bool leftHandleVisible = viewRange.Contains(Evt.Start); bool rightHandleVisible = viewRange.Contains(Evt.End); Rect leftHandleRect = _eventRect; leftHandleRect.width = 4; Rect rightHandleRect = _eventRect; rightHandleRect.xMin = rightHandleRect.xMax - 4; if (leftHandleVisible && IsSelected) { EditorGUIUtility.AddCursorRect(leftHandleRect, MouseCursor.ResizeHorizontal, _leftHandleGuiId); } if (rightHandleVisible && IsSelected) { EditorGUIUtility.AddCursorRect(rightHandleRect, MouseCursor.ResizeHorizontal, _rightHandleGuiId); } switch (Event.current.type) { case EventType.Repaint: if (!viewRange.Overlaps(Evt.FrameRange)) { break; } GUIStyle evtStyle = GetEventStyle(); GUI.backgroundColor = GetColor(); evtStyle.Draw(_eventRect, _isSelected, _isSelected, false, false); string text = Evt.Text; if (text != null) { var style = GetTextStyle(); //style.alignment = TextAnchor.MiddleCenter; GUI.Label(_eventRect, text, style); } /* * var leftRect = _eventRect; * leftRect.xMax = leftRect.xMin + 16; * GUI.Label(leftRect, Evt.Start.ToString(), GetTextStyle()); * var rightRect = _eventRect; * rightRect.xMin = rightRect.xMax - 16; * GUI.Label(rightRect, Evt.End.ToString(), GetTextStyle()); */ break; case EventType.MouseDown: if (EditorGUIUtility.hotControl == 0 && IsSelected && !Event.current.control && !Event.current.shift) { Vector2 mousePos = Event.current.mousePosition; if (Event.current.button == 0) // left click? { if (rightHandleVisible && rightHandleRect.Contains(mousePos)) { EditorGUIUtility.hotControl = _rightHandleGuiId; // keyframeOnSelect = evt.Start; Event.current.Use(); } else if (leftHandleVisible && leftHandleRect.Contains(mousePos)) { EditorGUIUtility.hotControl = _leftHandleGuiId; // keyframeOnSelect = evt.End; Event.current.Use(); } else if (_eventRect.Contains(mousePos)) { EditorGUIUtility.hotControl = GuiId; _mouseOffsetFrames = SequenceEditor.GetFrameForX(mousePos.x) - Evt.Start; if (IsSelected) { if (Event.current.control) { SequenceEditor.Deselect(this); } } else { if (Event.current.shift) { SequenceEditor.Select(this); } else if (!Event.current.control) { SequenceEditor.SelectExclusive(this); } } Event.current.Use(); } } else if (Event.current.button == 1 && _eventRect.Contains(Event.current.mousePosition)) // right click? { CreateEventContextMenu().ShowAsContext(); Event.current.Use(); } } break; case EventType.MouseUp: if (EditorGUIUtility.hotControl != 0) { if (EditorGUIUtility.hotControl == GuiId || EditorGUIUtility.hotControl == _leftHandleGuiId || EditorGUIUtility.hotControl == _rightHandleGuiId) { EditorGUIUtility.hotControl = 0; Event.current.Use(); SequenceEditor.Repaint(); FinishMovingEventEditors(); } } break; case EventType.MouseDrag: if (EditorGUIUtility.hotControl != 0) { if (EditorGUIUtility.hotControl == GuiId) { int t = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - _mouseOffsetFrames; int delta = t - Evt.Start; SequenceEditor.MoveEvents(delta); Event.current.Use(); } else if (EditorGUIUtility.hotControl == _leftHandleGuiId || EditorGUIUtility.hotControl == _rightHandleGuiId) { int leftLimit = 0; int rightLimit = 0; bool draggingStart = EditorGUIUtility.hotControl == _leftHandleGuiId; if (draggingStart) { leftLimit = validKeyframeRange.Start; rightLimit = Evt.End - 1; } else { leftLimit = Evt.Start + 1; rightLimit = validKeyframeRange.End; } int t = SequenceEditor.GetFrameForX(Event.current.mousePosition.x); t = Mathf.Clamp(t, leftLimit, rightLimit); int delta = t - (draggingStart ? Evt.Start : Evt.End); if (draggingStart) { int newLength = Evt.Length - delta; if (newLength < Evt.GetMinLength()) { delta += newLength - Evt.GetMinLength(); } if (newLength > Evt.GetMaxLength()) { delta += newLength - Evt.GetMaxLength(); } } else { int newLength = Evt.Length + delta; if (newLength < Evt.GetMinLength()) { delta -= newLength - Evt.GetMinLength(); } if (newLength > Evt.GetMaxLength()) { delta -= newLength - Evt.GetMaxLength(); } } if (delta != 0) { if (draggingStart) { SequenceEditor.ResizeEventsLeft(delta); } else { SequenceEditor.ResizeEventsRight(delta); } } Event.current.Use(); } } break; case EventType.Ignore: if (EditorGUIUtility.hotControl == GuiId || EditorGUIUtility.hotControl == _leftHandleGuiId || EditorGUIUtility.hotControl == _rightHandleGuiId) { EditorGUIUtility.hotControl = 0; SequenceEditor.Repaint(); FinishMovingEventEditors(); } break; } }
private void SingleFrameRender(FrameRange viewRange, FrameRange validKeyframeRange) { Rect rect = _eventRect; rect.width = 15; rect.x = SequenceEditor.PixelsPerFrame * Evt.Start; FrameRange range = Evt.FrameRange; range.Start = SequenceEditor.GetFrameForX(rect.x); range.End = range.Start + 1 + _mouseOffsetFrames + SequenceEditor.GetFrameForX(rect.width); Evt.FrameRange = range; switch (Event.current.type) { case EventType.Repaint: { if (!viewRange.Overlaps(Evt.FrameRange)) { break; } _mouseOffsetFrames = 0; GUIStyle evtStyle = _singleFrameStyle; GUI.backgroundColor = Color.white; Rect renderRect = rect; renderRect.x -= 2.5f; evtStyle.Draw(renderRect, _isSelected, _isSelected, false, false); string text = Evt.Text; if (text != null) { GUIStyle style = GetTextStyle(); Vector2 size = style.CalcSize(new GUIContent(text)); rect.size = size; GUI.Label(rect, text, GetTextStyle()); } break; } case EventType.MouseDown: if (EditorGUIUtility.hotControl == 0 && IsSelected && !Event.current.control && !Event.current.shift) { Vector2 mousePos = Event.current.mousePosition; if (Event.current.button == 0) { if (rect.Contains(mousePos)) { EditorGUIUtility.hotControl = GuiId; _mouseOffsetFrames = SequenceEditor.GetFrameForX(mousePos.x) - Evt.Start; if (IsSelected) { if (Event.current.control) { SequenceEditor.Deselect(this); } } else { if (Event.current.shift) { SequenceEditor.Select(this); } else if (!Event.current.control) { SequenceEditor.SelectExclusive(this); } } Event.current.Use(); } } else if (Event.current.button == 1 && rect.Contains(Event.current.mousePosition)) // right click? { CreateEventContextMenu().ShowAsContext(); Event.current.Use(); } } break; case EventType.MouseUp: if (EditorGUIUtility.hotControl == GuiId) { EditorGUIUtility.hotControl = 0; Event.current.Use(); SequenceEditor.Repaint(); FinishMovingEventEditors(); } break; case EventType.MouseDrag: if (EditorGUIUtility.hotControl == GuiId) { int t = SequenceEditor.GetFrameForX(Event.current.mousePosition.x) - _mouseOffsetFrames; int delta = t - Evt.Start; if (t < viewRange.Start) { t = viewRange.Start; } else if (t > viewRange.End - 1) { t = viewRange.End - 1; } Evt.SingleFrame = t + 1; SequenceEditor.MoveEvents(delta); Event.current.Use(); } break; case EventType.Ignore: if (EditorGUIUtility.hotControl == GuiId) { EditorGUIUtility.hotControl = 0; SequenceEditor.Repaint(); FinishMovingEventEditors(); } break; } }