public void DrawCurveEditor(Rect rect, WindowState state, Vector2 clipRange, bool loop, bool selected) { var timelineWidth = state.TimeToPixel(Mathf.Max((float)state.editSequence.duration, state.timeAreaShownRange.y)); m_CurveEditor.rect = new Rect(-rect.xMin, 0.0f, timelineWidth, rect.height); UpdateCurveEditorIfNeeded(state); var curveEndTime = m_DataSource.start + m_DataSource.animationClip.length / m_DataSource.timeScale; var curveRange = new Vector2(state.TimeToPixel(m_DataSource.start), state.TimeToPixel(curveEndTime)); m_CurveEditor.leftmargin = curveRange.x; m_CurveEditor.rightmargin = timelineWidth - curveRange.y; m_CurveEditor.topmargin = m_CurveEditor.bottommargin = CalculateTopMargin(rect.height); m_CurveEditor.SetShownHRangeInsideMargins(0.0f, m_DataSource.animationClip.length); //align the curve with the clip. if (m_LastFrameRate != state.referenceSequence.frameRate) { m_CurveEditor.hTicks.SetTickModulosForFrameRate(state.referenceSequence.frameRate); m_LastFrameRate = state.referenceSequence.frameRate; } foreach (var cw in m_CurveEditor.animationCurves) { cw.renderer.SetWrap(WrapMode.Default, loop ? WrapMode.Loop : WrapMode.Default); } using (new GUIGroupScope(rect)) { var localRect = new Rect(0.0f, 0.0f, rect.width, rect.height); var localClipRange = new Vector2(Mathf.Floor(clipRange.x - rect.xMin), Mathf.Ceil(clipRange.y - rect.xMin)); var localCurveRange = new Vector2(Mathf.Floor(curveRange.x - rect.xMin), Mathf.Ceil(curveRange.y - rect.xMin)); EditorGUI.DrawRect(new Rect(localCurveRange.x, 0.0f, 1.0f, rect.height), new Color(1.0f, 1.0f, 1.0f, 0.5f)); DrawCurveEditorBackground(localRect, localClipRange); if (selected) { var selectionRect = new Rect(localClipRange.x, 0.0f, localClipRange.y - localClipRange.x, localRect.height); DrawOutline(selectionRect); } EditorGUI.BeginChangeCheck(); { var evt = Event.current; if (evt.type == EventType.Layout || evt.type == EventType.Repaint || selected) { m_CurveEditor.CurveGUI(); } } if (EditorGUI.EndChangeCheck()) { OnCurvesUpdated(); } DrawOverlay(localRect, localClipRange, DirectorStyles.Instance.customSkin.colorInlineCurveOutOfRangeOverlay); DrawGrid(localRect, localCurveRange); } }
void SetupMarginsAndRect(Rect rect, Vector2 curveRange, WindowState state) { var timelineWidth = state.TimeToPixel(Mathf.Max((float)state.editSequence.duration, state.timeAreaShownRange.y)); m_CurveEditor.rect = new Rect(-rect.xMin, 0.0f, timelineWidth, rect.height); m_CurveEditor.leftmargin = curveRange.x; m_CurveEditor.rightmargin = timelineWidth - curveRange.y; m_CurveEditor.topmargin = m_CurveEditor.bottommargin = CalculateTopMargin(rect.height); }
public void DrawCurveEditor(Rect rect, WindowState state, Vector2 clipRange, bool loop, bool selected) { SetupMarginsAndRect(rect, state); UpdateCurveEditorIfNeeded(state); if (m_ShouldRestoreShownArea) { RestoreShownArea(); } var curveVisibleTimeRange = CalculateCurveVisibleTimeRange(state.timeAreaShownRange, m_DataSource); m_CurveEditor.SetShownHRangeInsideMargins(curveVisibleTimeRange.x, curveVisibleTimeRange.y); //align the curve with the clip. if (m_LastFrameRate != state.referenceSequence.frameRate) { m_CurveEditor.hTicks.SetTickModulosForFrameRate(state.referenceSequence.frameRate); m_LastFrameRate = state.referenceSequence.frameRate; } foreach (var cw in m_CurveEditor.animationCurves) { cw.renderer.SetWrap(WrapMode.Default, loop ? WrapMode.Loop : WrapMode.Default); } using (new GUIGroupScope(rect)) { var localRect = new Rect(0.0f, 0.0f, rect.width, rect.height); var localClipRange = new Vector2(Mathf.Floor(clipRange.x - rect.xMin), Mathf.Ceil(clipRange.y - rect.xMin)); var curveStartPosX = Mathf.Floor(state.TimeToPixel(m_DataSource.start) - rect.xMin); EditorGUI.DrawRect(new Rect(curveStartPosX, 0.0f, 1.0f, rect.height), new Color(1.0f, 1.0f, 1.0f, 0.5f)); DrawCurveEditorBackground(localRect); if (selected) { var selectionRect = new Rect(localClipRange.x, 0.0f, localClipRange.y - localClipRange.x, localRect.height); DrawOutline(selectionRect); } EditorGUI.BeginChangeCheck(); { var evt = Event.current; if (evt.type == EventType.Layout || evt.type == EventType.Repaint || selected) { m_CurveEditor.CurveGUI(); } } if (EditorGUI.EndChangeCheck()) { OnCurvesUpdated(); } DrawOverlay(localRect, localClipRange, DirectorStyles.Instance.customSkin.colorInlineCurveOutOfRangeOverlay); DrawGrid(localRect, curveStartPosX); } }
void SetupMarginsAndRect(Rect rect, WindowState state) { var startX = state.TimeToPixel(m_DataSource.start) - rect.x; var timelineWidth = state.timeAreaRect.width; m_CurveEditor.rect = new Rect(0.0f, 0.0f, timelineWidth, rect.height); m_CurveEditor.leftmargin = Math.Max(startX, 0.0f); m_CurveEditor.rightmargin = 0.0f; m_CurveEditor.topmargin = m_CurveEditor.bottommargin = CalculateTopMargin(rect.height); }
public void DrawCurveEditor(Rect animEditorRect, WindowState state, Vector2 activeRange, bool loop, bool selected) { var curveStart = state.TimeToPixel(m_DataSource.start); var minCurveStart = animEditorRect.xMax - 1.0f; if (curveStart > minCurveStart) // Prevent the curve from drawing inside small rect { animEditorRect.xMax += curveStart - minCurveStart; } UpdateCurveEditorIfNeeded(state); DrawCurveEditorBackground(animEditorRect); float localCurveStart = curveStart - animEditorRect.xMin; // adjust the top margin so smaller rectangle have smaller top / bottom margins. m_CurveEditor.topmargin = m_CurveEditor.bottommargin = CalculateTopMargin(animEditorRect.height); // calculate the margin needed to align the curve with the clip. m_CurveEditor.rightmargin = 0.0f; m_CurveEditor.leftmargin = localCurveStart; m_CurveEditor.rect = new Rect(0.0f, 0.0f, animEditorRect.width, animEditorRect.height); m_CurveEditor.SetShownHRangeInsideMargins(0.0f, (state.PixelToTime(animEditorRect.xMax) - m_DataSource.start) * m_DataSource.timeScale); if (m_LastFrameRate != state.referenceSequence.frameRate) { m_CurveEditor.hTicks.SetTickModulosForFrameRate(state.referenceSequence.frameRate); m_LastFrameRate = state.referenceSequence.frameRate; } foreach (CurveWrapper cw in m_CurveEditor.animationCurves) { cw.renderer.SetWrap(WrapMode.Default, loop ? WrapMode.Loop : WrapMode.Default); } m_CurveEditor.BeginViewGUI(); Color oldColor = GUI.color; GUI.color = Color.white; GUI.BeginGroup(animEditorRect); // Draw a line at 0 Graphics.DrawLine(new Vector2(localCurveStart, 0.0f), new Vector2(localCurveStart, animEditorRect.height), new Color(1.0f, 1.0f, 1.0f, 0.5f)); float rangeStart = activeRange.x - animEditorRect.x; float rangeWidth = activeRange.y - activeRange.x; // draw selection outline underneath the curves. if (selected) { var selectionRect = new Rect(rangeStart, 0.0f, rangeWidth, animEditorRect.height); DrawOutline(selectionRect); } EditorGUI.BeginChangeCheck(); Event evt = Event.current; if ((evt.type == EventType.Layout) || (evt.type == EventType.Repaint) || selected) { m_CurveEditor.CurveGUI(); } m_CurveEditor.EndViewGUI(); if (EditorGUI.EndChangeCheck()) { OnCurvesUpdated(); } // draw overlays on top of curves var overlayColor = DirectorStyles.Instance.customSkin.colorInlineCurveOutOfRangeOverlay; var leftSide = new Rect(localCurveStart, 0.0f, rangeStart - localCurveStart, animEditorRect.height); EditorGUI.DrawRect(leftSide, overlayColor); var rightSide = new Rect(rangeStart + rangeWidth, 0.0f, animEditorRect.width - rangeStart - rangeWidth, animEditorRect.height); EditorGUI.DrawRect(rightSide, overlayColor); GUI.color = oldColor; GUI.EndGroup(); // draw the grid labels last Rect gridRect = animEditorRect; gridRect.width = s_GridLabelWidth; float offset = localCurveStart - s_GridLabelWidth; if (offset > 0.0f) { gridRect.x = animEditorRect.x + offset; } GUI.BeginGroup(gridRect); m_CurveEditor.GridGUI(); GUI.EndGroup(); }