void SetTimeEditMode(TimelineViewMode timelineViewMode)
 {
     if (timelineViewMode == TimelineViewMode.frames)
     {
         m_SecondsField.style.display = DisplayStyle.None;
         m_FrameField.style.display   = DisplayStyle.Flex;
     }
     else
     {
         m_FrameField.style.display   = DisplayStyle.None;
         m_SecondsField.style.display = DisplayStyle.Flex;
     }
 }
        void SyncToViewModeSetting()
        {
            string           viewMode         = EditorPrefs.GetString(Timeline.k_TimelineUnitsPreferenceKey);
            TimelineViewMode timelineViewMode = TimelineViewMode.frames;

            if (!string.IsNullOrEmpty(viewMode))
            {
                if (int.TryParse(viewMode, out int intVal))
                {
                    timelineViewMode = (TimelineViewMode)intVal;
                }
                else
                {
                    timelineViewMode = TimelineViewMode.frames;
                }
            }

            SetTimeEditMode(timelineViewMode);
        }
        public static string GetTimeString(TimelineViewMode mode, float time, int sampleRate)
        {
            string str = string.Empty;

            switch (mode)
            {
            case TimelineViewMode.frames:
                str = TimeToFrameStr(time, sampleRate);
                break;

            case TimelineViewMode.secondsFrames:
                str = TimeToTimeFrameStr(time, sampleRate);
                break;

            case TimelineViewMode.seconds:
                str = TimeToTimeStr(time);
                break;
            }


            return(str);
        }
예제 #4
0
        void DrawRuler(
            Rect position,
            float frameRate,
            TimelineViewMode timeFormat)
        {
            if (float.IsNaN(position.x) || float.IsNaN(position.xMax) || float.IsNaN(worldBound.x) || float.IsNaN(worldBound.xMax))
            {
                return;
            }

            Rect  shownArea = new Rect(m_DrawInfo.layout.startTime, -90f, m_DrawInfo.layout.Duration, .05f);
            Color backupCol = GUI.color;

            GUI.BeginGroup(position);

            Color tempBackgroundColor = GUI.backgroundColor;

            m_TickHandler.SetRanges(m_DrawInfo.layout.startTime, m_DrawInfo.layout.endTime, worldBound.x, worldBound.xMax);
            m_TickHandler.SetTickStrengths(kTickRulerDistMin, kTickRulerDistFull, true);

            int labelLevel = m_TickHandler.GetLevelWithMinSeparation(kTickRulerDistLabel);

            if (Event.current.type == EventType.Repaint)
            {
                var originalColor = GUI.color;
                // Draw tick markers of various sizes
                for (int tickLevel = 0; tickLevel < m_TickHandler.tickLevels; tickLevel++)
                {
                    float strength = m_TickHandler.GetStrengthOfLevel(tickLevel) * .9f;
                    m_TickCache.Clear();
                    m_TickHandler.GetTicksAtLevel(tickLevel, true, m_TickCache);
                    for (int i = 0; i < m_TickCache.Count; i++)
                    {
                        if (m_TickCache[i] < k_RangeMin || m_TickCache[i] > k_RangeMax)
                        {
                            continue;
                        }

                        float frame = Mathf.Round(m_TickCache[i] * frameRate);

                        float height = position.height * Mathf.Min(1, strength) * kTickRulerHeightMax;
                        float x      = FrameToPixel(frame, frameRate, position, shownArea);

                        // Draw line
                        float minY = position.height - height + 0.5f;
                        float maxY = position.height - 0.5f;

                        GUI.color = tickLevel >= labelLevel ? TimelineWidget.k_MajorTickColor : TimelineWidget.k_MinorTickColor;
                        Rect r = new Rect(new Vector2(x - .5f, minY),
                                          new Vector2(1, maxY - minY)
                                          );
                        GUI.DrawTexture(r, EditorGUIUtility.whiteTexture);
                    }
                }

                GUI.color = originalColor;
            }

            // Draw tick labels
            m_TickCache.Clear();
            m_TickHandler.GetTicksAtLevel(labelLevel, false, m_TickCache);
            for (int i = 0; i < m_TickCache.Count; i++)
            {
                if (m_TickCache[i] < k_RangeMin || m_TickCache[i] > k_RangeMax)
                {
                    continue;
                }

                float frame = Mathf.Round(m_TickCache[i] * frameRate);
                // Important to take floor of positions of GUI stuff to get pixel correct alignment of
                // stuff drawn with both GUI and Handles/GL. Otherwise things are off by one pixel half the time.
                float  labelPos  = FrameToPixel(frame, frameRate, position, shownArea);
                string label     = TimelineUtility.GetTimeString(timeFormat, m_TickCache[i], (int)frameRate);
                var    labelSize = GUI.skin.GetStyle("label").CalcSize(new GUIContent(label));
                float  x         = labelPos + 3;
                float  y         = -1;
                float  w         = labelSize.x + 2;
                float  h         = labelSize.y;

                GUI.Label(new Rect(x, y, w, h),
                          label,
                          TimeAreaStyles.timelineTick);
            }

            GUI.EndGroup();

            GUI.backgroundColor = tempBackgroundColor;
            GUI.color           = backupCol;
        }
예제 #5
0
    public static void DrawNotations(
        DrawInfo drawInfo,
        int sampleRate               = 60,
        float tickmarkHeight         = 32f,
        bool above                   = false,
        TimelineViewMode labelFormat = TimelineViewMode.seconds)
    {
        // first figure out what step I should use
        float majorStepSize = 200.0f;

        float width  = drawInfo.layout.drawRect.width;
        float height = drawInfo.layout.drawRect.height;

        float numSteps = Mathf.Ceil(width / majorStepSize);

        float scale     = drawInfo.layout.Duration;
        float scaleStep = scale / numSteps;

        // Get the time step
        float modScale     = scaleStep;
        float modScaleMult = 1.0f;

        while (modScale < 1.0f)
        {
            modScale     *= 10.0f;
            modScaleMult *= 10.0f;
        }
        while (modScale > 10.0f)
        {
            modScale     /= 10.0f;
            modScaleMult /= 10.0f;
        }

        // modify scale to be divisible by 1/2/4/5
        if (modScale > 5.0f)
        {
            modScale = 5.0f;
        }
        else if (modScale > 2.5f)
        {
            modScale = 2.5f;
        }
        else if (modScale > 2.0f)
        {
            modScale = 2.0f;
        }
        else
        {
            modScale = 1.0f;
        }

        modScale /= modScaleMult;

        // with fixed scale need to find our start point
        float startOffset = drawInfo.layout.startTime % modScale;
        float start       = drawInfo.layout.startTime - startOffset;

        float rangeEnd = drawInfo.layout.startTime + scale;

        float textLineHeight = GUI.skin.font.lineHeight;

        float tickmarkHeightSmall  = tickmarkHeight * 0.5f;
        float tickmarkHeightMedium = tickmarkHeight * 0.75f;
        float verticalPosition     = above ? height :  height - textLineHeight;

        // draw
        for (int i = -1;; ++i)
        {
            float point = start + modScale * i;
            if (point > rangeEnd)
            {
                break;
            }

            // draw minor steps
            for (int j = 1; j < 5; ++j)
            {
                float subPoint = point + (modScale / 5) * j;

                float position = drawInfo.GetPixelPosition(subPoint);

                float heightThis = (j == 2 ? tickmarkHeightSmall : tickmarkHeightMedium);

                Rect r = new Rect(position, verticalPosition - heightThis, 1, heightThis);

                GUI.color = k_MinorTickColor;
                GUI.DrawTexture(r, EditorGUIUtility.whiteTexture);
            }

            // draw major step
            {
                float position = drawInfo.GetPixelPosition(point);

                Rect r = new Rect(position, verticalPosition - tickmarkHeight, 1, tickmarkHeight);

                GUI.color = k_MajorTickColor;
                GUI.DrawTexture(r, EditorGUIUtility.whiteTexture);

                string label = string.Empty;
                int    frame = (int)(point * sampleRate);

                switch (labelFormat)
                {
                case TimelineViewMode.frames:
                    label = frame.ToString(CultureInfo.InvariantCulture);
                    break;

                case TimelineViewMode.secondsFrames:
                    label = TimelineUtility.TimeToTimeFrameStr(point, sampleRate);
                    break;

                default:
                    label = string.Format(scale < 0.1f ? "{0:0.000}" : "{0:0.00}", (float)point);
                    break;
                }

                var labelSize   = GUI.skin.GetStyle("label").CalcSize(new GUIContent(label));
                var labelOffset = labelSize.y - textLineHeight;

                float x = position - labelSize.x * 0.5f;
                float y;
                if (above)
                {
                    y = 0;
                }
                else
                {
                    y = verticalPosition - labelOffset * 0.5f; // Centered position below guide line
                }

                var w = labelSize.x + 2;
                var h = labelSize.y;

                GUI.color = k_MajorTickColor;
                GUI.Label(new Rect(x, y, w, h), label);
            }
        }
    }