public static void DrawClip(Rect fullRect, ClipViewInfo info, Color color) { using (new Utility.HandlesColorScope(color)) { var left = info.ContentMin; var right = info.ContentMax; float top = fullRect.y; var bottom = fullRect.yMax; var leftTop = new Vector3(left, top); var leftBottom = new Vector3(left, bottom); var rightTop = new Vector3(right, top); var rightBottom = new Vector3(right, bottom); Utility.FillTriangle(leftBottom, leftTop, rightTop, color); Utility.FillTriangle(leftBottom, rightTop, rightBottom, color); if (info.Min < info.ContentMin) { var leftBottom2 = new Vector3(info.Min, bottom); Utility.FillTriangle(leftBottom2, leftTop, leftBottom, color); } if (info.Max > info.ContentMax) { var rightBottom2 = new Vector3(info.Max, bottom); Utility.FillTriangle(rightBottom, rightTop, rightBottom2, color); } } }
public void Draw(Rect viewRect, ClipViewInfo info, Navigator navigator, float totalFrame, float currentFrame, IReadOnlyList <Blackboard> blackboards) { if (Asset == null) { return; } if (SerializedObject == null) { return; } m_BlackboardList = blackboards; var beginFrame = BeginFrame; var endFrame = EndFrame; var fullRect = new Rect(info.Min, viewRect.y + 2f, info.Max - info.Min, viewRect.height - 4f); if (endFrame <= navigator.MinFrame || beginFrame >= navigator.MaxFrame) { return; } var edgeRect = Utility.CalculateEdgeRects(fullRect, 8f); EditorGUIUtility.AddCursorRect(edgeRect.left, MouseCursor.SplitResizeLeftRight); EditorGUIUtility.AddCursorRect(edgeRect.right, MouseCursor.SplitResizeLeftRight); var contentRect = new Rect(info.ContentMin + 2f, fullRect.y + 2f, info.ContentMax - info.ContentMin - 4f, fullRect.height - 4f); ClipViewUtility.DrawClip(fullRect, info, BackgroundColor); SerializedObject.Update(); DrawContents(contentRect, SerializedObject); SerializedObject.ApplyModifiedProperties(); var dragCtrlId = GUIUtility.GetControlID(FocusType.Passive); var e = Event.current; switch (e.type) { case EventType.MouseDown: { if (edgeRect.left.Contains(e.mousePosition)) { m_DragType = DragType.Min; GUIUtility.hotControl = dragCtrlId; e.Use(); break; } if (edgeRect.right.Contains(e.mousePosition)) { m_DragType = DragType.Max; GUIUtility.hotControl = dragCtrlId; e.Use(); break; } if (contentRect.Contains(e.mousePosition) && e.button == 1) { ShowContextMenu(); e.Use(); break; } if (contentRect.Contains(e.mousePosition)) { Selection.objects = new Object[] { Asset }; m_DragType = DragType.Range; GUIUtility.hotControl = dragCtrlId; e.Use(); } } break; case EventType.MouseDrag: if (dragCtrlId == GUIUtility.hotControl) { switch (m_DragType) { case DragType.Min: { var next = Utility.Remap(e.mousePosition.x, viewRect.xMin, viewRect.xMax, navigator.MinFrame, navigator.MaxFrame); BeginFrame = ClipViewUtility.Adjust(next, viewRect, navigator); BeginFrame = Mathf.Min(BeginFrame, EndFrame); BeginFrame = Mathf.Max(BeginFrame, info.StopMin); } break; case DragType.Max: { var next = Utility.Remap(e.mousePosition.x, viewRect.xMin, viewRect.xMax, navigator.MinFrame, navigator.MaxFrame); EndFrame = ClipViewUtility.Adjust(next, viewRect, navigator); EndFrame = Mathf.Max(BeginFrame, EndFrame); EndFrame = Mathf.Min(EndFrame, info.StopMax); } break; case DragType.Range: { var delta = Utility.Remap(e.delta.x, 0f, viewRect.width, 0f, navigator.Range); if (0f > delta) { if (0f > BeginFrame + delta) { delta = -BeginFrame; } } else { if (totalFrame < EndFrame + delta) { delta = totalFrame - EndFrame; } } BeginFrame += delta; EndFrame += delta; BeginFrame = Mathf.Max(BeginFrame, info.StopMin); EndFrame = Mathf.Min(EndFrame, info.StopMax); if (info.HasPrev) { EndFrame = Mathf.Max(EndFrame, info.StopMax2); } if (info.HasNext) { BeginFrame = Mathf.Min(BeginFrame, info.StopMin2); } } break; } e.Use(); } break; case EventType.MouseUp: case EventType.Ignore: if (dragCtrlId == GUIUtility.hotControl) { BeginFrame = ClipViewUtility.Adjust(BeginFrame, viewRect, navigator); EndFrame = ClipViewUtility.Adjust(EndFrame, viewRect, navigator); m_DragType = DragType.None; GUIUtility.hotControl = 0; e.Use(); } break; } }