TimelineWindow_TimeArea.cs
3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using UnityEngine;
namespace UnityEditor.Timeline
{
partial class TimelineWindow
{
[NonSerialized] TimelineTimeArea m_TimeArea;
public TimeArea timeArea { get { return m_TimeArea; } }
internal static class Styles
{
public static string DurationModeText = L10n.Tr("Duration Mode/{0}");
}
float m_LastFrameRate;
bool m_TimeAreaDirty = true;
void InitializeTimeArea()
{
if (m_TimeArea == null)
{
m_TimeArea = new TimelineTimeArea(state, false)
{
hRangeLocked = false,
vRangeLocked = true,
margin = 10,
scaleWithWindow = true,
hSlider = true,
vSlider = false,
hBaseRangeMin = 0.0f,
hBaseRangeMax = WindowState.kMaxShownTime,
hRangeMin = 0.0f,
hScaleMax = WindowConstants.maxTimeAreaScaling,
rect = state.timeAreaRect
};
m_TimeAreaDirty = true;
InitTimeAreaFrameRate();
SyncTimeAreaShownRange();
}
}
void TimelineGUI()
{
if (!currentMode.ShouldShowTimeArea(state))
return;
Rect rect = state.timeAreaRect;
m_TimeArea.rect = new Rect(rect.x, rect.y, rect.width, clientArea.height - rect.y);
if (m_LastFrameRate != state.referenceSequence.frameRate)
InitTimeAreaFrameRate();
SyncTimeAreaShownRange();
m_TimeArea.BeginViewGUI();
m_TimeArea.TimeRuler(rect, state.referenceSequence.frameRate, true, false, 1.0f, state.timeInFrames ? TimeArea.TimeFormat.Frame : TimeArea.TimeFormat.TimeFrame);
m_TimeArea.EndViewGUI();
}
void InitTimeAreaFrameRate()
{
m_LastFrameRate = state.referenceSequence.frameRate;
m_TimeArea.hTicks.SetTickModulosForFrameRate(m_LastFrameRate);
}
void SyncTimeAreaShownRange()
{
var range = state.timeAreaShownRange;
if (!Mathf.Approximately(range.x, m_TimeArea.shownArea.x) || !Mathf.Approximately(range.y, m_TimeArea.shownArea.xMax))
{
// set view data onto the time area
if (m_TimeAreaDirty)
{
m_TimeArea.SetShownHRange(range.x, range.y);
m_TimeAreaDirty = false;
}
else
{
// set time area data onto the view data
state.TimeAreaChanged();
}
}
m_TimeArea.hBaseRangeMax = (float)state.editSequence.duration;
}
class TimelineTimeArea : TimeArea
{
readonly WindowState m_State;
public TimelineTimeArea(WindowState state, bool minimalGUI) : base(minimalGUI)
{
m_State = state;
}
public override string FormatTickTime(float time, float frameRate, TimeFormat timeFormat)
{
time = m_State.timeReferenceMode == TimeReferenceMode.Global ?
(float)m_State.editSequence.ToGlobalTime(time) : time;
return FormatTime(time, frameRate, timeFormat);
}
}
}
}