Esempio n. 1
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;
        }
Esempio n. 2
0
        public void DoTimeRulerGUI(Rect rect, float frameTime)
        {
            if (m_TimeArea == null || Event.current.type != EventType.Repaint)
            {
                return;
            }

            GUI.BeginClip(rect);
            rect.x = rect.y = 0;

            GUI.Box(rect, GUIContent.none, EditorStyles.toolbarButton);

            var baseColor = styles.timelineTick.normal.textColor;

            baseColor.a *= 0.75f;

            PrepareTicks();

            // Tick lines
            if (Event.current.type == EventType.Repaint)
            {
                HandleUtility.ApplyWireMaterial();
                if (Application.platform == RuntimePlatform.WindowsEditor)
                {
                    GL.Begin(GL.QUADS);
                }
                else
                {
                    GL.Begin(GL.LINES);
                }

                for (int l = 0; l < m_HTicks.tickLevels; l++)
                {
                    var strength = m_HTicks.GetStrengthOfLevel(l) * .8f;
                    var ticks    = m_HTicks.GetTicksAtLevel(l, true);
                    for (int i = 0; i < ticks.Length; i++)
                    {
                        // Draw line
                        var time   = ticks[i];
                        var x      = m_TimeArea.TimeToPixel(time, rect);
                        var height = rect.height * Mathf.Min(1, strength) * TimeArea.kTickRulerHeightMax;
                        var color  = new Color(1, 1, 1, strength / TimeArea.kTickRulerFatThreshold) * baseColor;
                        TimeArea.DrawVerticalLineFast(x, rect.height - height + 0.5f, rect.height - 0.5f, color);
                    }
                }

                GL.End();
            }

            // Tick labels
            var labelWidth = k_TickLabelSeparation;
            int labelLevel = m_HTicks.GetLevelWithMinSeparation(labelWidth);

            float[] labelTicks = m_HTicks.GetTicksAtLevel(labelLevel, false);
            for (int i = 0; i < labelTicks.Length; i++)
            {
                var    time     = labelTicks[i];
                float  labelpos = Mathf.Floor(m_TimeArea.TimeToPixel(time, rect));
                string label    = FormatTickLabel(time, labelLevel);
                GUI.Label(new Rect(labelpos + 3, -3, labelWidth, 20), label, styles.timelineTick);
            }

            // Outside current frame coloring
            DrawOutOfRangeOverlay(rect, frameTime);

            // Range selection coloring
            DrawRangeSelectionOverlay(rect);

            GUI.EndClip();
        }