Exemple #1
0
        internal static void AdjustDimensions(Panel_Graph instance, Rect rect, int entries)
        {
            if (Input.GetMouseButtonDown(0) && Mouse.IsOver(rect) && !instance.settings.dragging)
            {
                instance.settings.dragging   = true;
                instance.settings.dragAnchor = Event.current.mousePosition;
            }

            if (instance.settings.dragging)
            {
                var mousePos = Event.current.mousePosition;

                var deltaX = mousePos.x - instance.settings.dragAnchor.x;

                if (Mathf.Abs(deltaX) > 1)
                {
                    instance.settings.offsets.x += deltaX;
                    instance.settings.offsets.x  = Mathf.Clamp(instance.settings.offsets.x, 0, Analyzer.GetCurrentLogCount - entries - 1);

                    instance.settings.dragAnchor.x = mousePos.x;
                }
            }

            if (Input.GetMouseButtonUp(0))
            {
                instance.settings.dragging = false;
            }
        }
Exemple #2
0
        internal static void DrawEntries(Rect rect, Panel_Graph instance, int entries, float aliasing)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            var xIncrement = rect.width / (entries - 1.0f);

            var timeCutoff  = 0.0f;
            var callsCutoff = 0.0f;

            if (aliasing != 0)
            {
                timeCutoff  = instance.calls.max / rect.height / aliasing;
                callsCutoff = instance.times.max / rect.height / aliasing;
            }

            int i = 1, timesIndex = 0, callsIndex = 0;

            visibleMin = instance.times.entries[timesIndex];
            for (; i < entries; i++)
            {
                if (instance.calls.visible)
                {
                    if (Mathf.Abs(instance.calls.entries[callsIndex] - instance.calls.entries[i]) > callsCutoff || i == entries - 1) // We need to draw a line, enough of a difference
                    {
                        DrawLine(instance.calls, callsIndex, i, rect.height, xIncrement, Settings.callsColour);

                        callsIndex = i;
                    }
                }

                if (!instance.times.visible)
                {
                    continue;
                }

                if (Mathf.Abs(instance.times.entries[timesIndex] - instance.times.entries[i]) > timeCutoff || i == entries - 1)
                {
                    var point = DrawLine(instance.times, timesIndex, i, rect.height, xIncrement, Settings.timeColour);

                    if (instance.times.entries[i] < visibleMin)
                    {
                        visibleMin = instance.times.entries[timesIndex];
                    }

                    var cheese = new Rect(point.x - (xIncrement * 0.5f), 0, xIncrement, rect.height);
                    if (Mouse.IsOver(cheese))
                    {
                        SimpleCurveDrawer.DrawPoint(point);
                        hoverValStr = $"{instance.times.entries[timesIndex]}ms {instance.calls.entries[timesIndex]} calls";
                    }

                    timesIndex = i;
                }
            }
        }
 public BottomRowPanel(ProfileInfoMode row, float xStart, float width)
 {
     type        = row;
     this.width  = width;
     this.xStart = xStart;
     dragging    = false;
     if (row == ProfileInfoMode.Graph)
     {
         graph = new Panel_Graph();
     }
 }
Exemple #4
0
 public BottomRowPanel(RowName row, float xStart, float width)
 {
     type        = row;
     this.width  = width;
     this.xStart = xStart;
     dragging    = false;
     if (row == RowName.Graph)
     {
         graph = new Panel_Graph();
     }
 }
Exemple #5
0
        public static void DrawGraph(Panel_Graph instance, Rect rect, int entries)
        {
            GUI.BeginGroup(rect);
            rect = rect.AtZero();

            AdjustDimensions(instance, rect, entries);

            if (Event.current.type != EventType.Repaint)
            {
                GUI.EndGroup();
                return;
            }

            DrawBackground(rect, GraphSettings.showGrid, GraphSettings.showAxis);

            var primaryEntry = instance.times.visible ? instance.times : instance.calls;

            if (GraphSettings.showMax)
            {
                DrawMaxLine(rect, primaryEntry.absMax, primaryEntry.max, instance.times.visible ? "ms" : "calls");
            }

            if (GraphSettings.showAxis)
            {
                DrawAxis(rect, entries, (int)instance.settings.offsets.x, primaryEntry.max, instance.times.visible ? "ms" : "calls");

                rect.x      += 25;
                rect.width  -= 25;
                rect.height -= Text.LineHeight;

                Text.Font = GameFont.Small;

                GUI.BeginGroup(rect);
                rect = rect.AtZero();
            }

            var calls = instance.calls;
            var times = instance.times;

            DrawEntries(rect, calls, times, entries, GraphSettings.lineAliasing);

            if (GraphSettings.showAxis)
            {
                GUI.EndGroup();
            }

            GUI.EndGroup();
        }
Exemple #6
0
        private static void DrawButton(Panel_Graph instance, Rect rect, string str, int idx)
        {
            var iconRect = rect.LeftPartPixels(20f);

            iconRect.height = 10;
            iconRect.x     += 5;
            iconRect.width -= 10;
            iconRect.y     += (rect.height / 2.0f) - 5f;
            rect.AdjustHorizonallyBy(20f);

            DisplayColorPicker(iconRect, idx);

            if (idx == 0 && !instance.times.visible)
            {
                GUI.color = Color.grey;
            }
            else if (idx == 1 && !instance.calls.visible)
            {
                GUI.color = Color.grey;
            }

            Widgets.Label(rect, str);

            GUI.color = Color.white;

            if (idx == 2)
            {
                return;
            }

            if (Widgets.ButtonInvisible(rect))
            {
                if (idx == 0)
                {
                    instance.times.visible = !instance.times.visible;
                }
                else
                {
                    instance.calls.visible = !instance.calls.visible;
                }
            }

            Widgets.DrawHighlightIfMouseover(rect);
        }
Exemple #7
0
        private static void DrawSettings(Panel_Graph instance, ref Rect position)
        {
            // [ - Calls ] [ - Times ] [ Lines ] [ Entries ------ ] [ - Bg Col ]

            var width         = position.width;
            var currentHeight = 32;
            var currentSlice  = position.TopPartPixels(currentHeight);

            position.AdjustVerticallyBy(currentHeight);

            Text.Anchor = TextAnchor.MiddleCenter;

            // [ - Times ]
            var str          = " Times ";
            var contentWidth = 20 + str.GetWidthCached();
            var rect         = currentSlice.LeftPartPixels(contentWidth);

            currentSlice.AdjustHorizonallyBy(contentWidth);

            DrawButton(instance, rect, " Times ", 0);

            // [ - Calls ]
            str          = " Calls ";
            contentWidth = 20 + str.GetWidthCached();
            rect         = currentSlice.LeftPartPixels(contentWidth);
            currentSlice.AdjustHorizonallyBy(contentWidth);

            DrawButton(instance, rect, " Calls ", 1);

            // [ - Background ]
            str          = " Background ";
            contentWidth = 20 + str.GetWidthCached();
            rect         = currentSlice.LeftPartPixels(contentWidth);
            currentSlice.AdjustHorizonallyBy(contentWidth);

            DrawButton(instance, rect, " Background ", 2);

            Text.Anchor = TextAnchor.UpperLeft;

            // [ - Entries ]
            contentWidth = 150;
            if (currentSlice.width < contentWidth)
            {
                currentSlice = position.TopPartPixels(currentHeight);
                position.AdjustVerticallyBy(currentHeight);
            }

            rect = currentSlice.LeftPartPixels(contentWidth);
            instance.entryCount = (int)Widgets.HorizontalSlider(rect.BottomPartPixels(30f), instance.entryCount, 10, 2000, true, string.Intern($"{instance.entryCount} Entries  "));

            currentSlice.AdjustHorizonallyBy(contentWidth);


            Text.Anchor = TextAnchor.MiddleCenter;

            // [ - Show Axis ]
            str          = " Axis";
            contentWidth = str.GetWidthCached() + 30;
            if (currentSlice.width < contentWidth)
            {
                currentSlice = position.TopPartPixels(currentHeight);
                position.AdjustVerticallyBy(currentHeight);
            }

            rect = currentSlice.LeftPartPixels(contentWidth);
            DubGUI.Checkbox(rect, str, ref GraphSettings.showAxis);
            currentSlice.AdjustHorizonallyBy(contentWidth);

            // [ - Show Grid ]
            str          = " Grid " + 30;
            contentWidth = str.GetWidthCached();
            if (currentSlice.width < contentWidth)
            {
                currentSlice = position.TopPartPixels(currentHeight);
                position.AdjustVerticallyBy(currentHeight);
            }

            rect = currentSlice.LeftPartPixels(contentWidth);
            DubGUI.Checkbox(rect, str, ref GraphSettings.showGrid);
            currentSlice.AdjustHorizonallyBy(contentWidth);

            // [ - Show Max ]
            str          = " Max ";
            contentWidth = str.GetWidthCached() + 30;
            if (currentSlice.width < contentWidth)
            {
                currentSlice = position.TopPartPixels(currentHeight);
                position.AdjustVerticallyBy(currentHeight);
            }

            rect = currentSlice.LeftPartPixels(contentWidth);
            DubGUI.Checkbox(rect, str, ref GraphSettings.showMax);
            currentSlice.AdjustHorizonallyBy(contentWidth);

            // [ - Aliasing ]
            str          = " Aliasing: " + (GraphSettings.lineAliasing == 0 ? "none" : GraphSettings.lineAliasing.ToString()) + " ";
            contentWidth = str.GetWidthCached();
            if (currentSlice.width < contentWidth)
            {
                currentSlice = position.TopPartPixels(currentHeight);
                position.AdjustVerticallyBy(currentHeight);
            }

            rect = currentSlice.LeftPartPixels(contentWidth);
            if (Widgets.ButtonText(rect, str, false))
            {
                GraphSettings.lineAliasing = GraphSettings.lineAliasing switch
                {
                    7.5f => 12.5f,
                    12.5f => 0.0f,
                    0.0f => 5.0f,
                    5.0f => 7.5f,
                    _ => 0.0f
                };
            }

            currentSlice.AdjustHorizonallyBy(contentWidth);

            Text.Anchor = TextAnchor.UpperLeft;
        }
Exemple #8
0
        public static void DrawGraph(Panel_Graph instance, Rect rect, int entries)
        {
            var statline = rect.TopPartPixels(20f);

            rect.AdjustVerticallyBy(20f);
            Widgets.DrawRectFast(statline, Settings.GraphCol);
            Widgets.DrawRectFast(rect, Settings.GraphCol);


            Text.Anchor = TextAnchor.UpperCenter;
            Widgets.Label(statline, hoverValStr);

            var primaryEntry = instance.times.visible ? instance.times : instance.calls;
            var suffix       = instance.times.visible ? "ms" : "calls";
            var maxminStr    = $"Max:{primaryEntry.absMax:0.0000}{suffix}";

            if (Analyzer.CurrentlyPaused || Find.TickManager.Paused)
            {
                maxminStr = $"Max:{primaryEntry.absMax:0.0000}{suffix} Min:{visibleMin:0.0000}{suffix}";
            }
            Text.Anchor = TextAnchor.UpperRight;
            Widgets.Label(statline, maxminStr);
            Text.Anchor = TextAnchor.UpperLeft;

            GUI.BeginGroup(rect);
            rect = rect.AtZero();

            AdjustDimensions(instance, rect, entries);

            if (GraphSettings.showAxis)
            {
                var axis = rect;
                axis.height -= Text.LineHeight;
                DrawAxis(axis, primaryEntry.max, instance.times.visible ? "ms" : "calls");

                rect.x     += 25;
                rect.width -= 25;

                Text.Font   = GameFont.Tiny;
                Text.Anchor = TextAnchor.LowerLeft;
                int xAxisValue = Mathf.CeilToInt(entries + (int)instance.settings.offsets.x);
                Widgets.Label(rect, Mathf.CeilToInt(xAxisValue).ToString());
                Text.Anchor = TextAnchor.LowerCenter;
                xAxisValue  = Mathf.CeilToInt((entries / 2f) + (int)instance.settings.offsets.x);
                Widgets.Label(rect, Mathf.CeilToInt(xAxisValue).ToString());
                Text.Anchor = TextAnchor.LowerRight;
                xAxisValue  = Mathf.CeilToInt((int)instance.settings.offsets.x);
                Widgets.Label(rect, Mathf.CeilToInt(xAxisValue).ToString());
                Text.Anchor = TextAnchor.UpperLeft;

                rect.height -= Text.LineHeight;

                DrawGrid(rect);

                GUI.BeginGroup(rect);
                rect = rect.AtZero();
            }



            if (GraphSettings.showMax)
            {
                DrawMaxLine(rect, primaryEntry.absMax, primaryEntry.max, suffix);
            }

            DrawEntries(rect, instance, entries, GraphSettings.lineAliasing);

            if (GraphSettings.showAxis)
            {
                GUI.EndGroup();
            }

            GUI.EndGroup();
        }
        private static void DrawSettings(Panel_Graph instance, ref Rect position)
        {
            void CheckNewRow(ref Rect box, ref Rect position)
            {
                if (box.xMax > position.xMax)
                {
                    position.AdjustVerticallyBy(box.height);
                    box.y += box.height;
                    box.x = position.x;
                }
            }

            var currentHeight = 32;
            var box = position.TopPartPixels(currentHeight).LeftPartPixels(20f);
            position.AdjustVerticallyBy(currentHeight);

            Text.Anchor = TextAnchor.MiddleCenter;

            if (Widgets.ButtonImageFitted(box, Textures.Menu))
            {
                doSettings = !doSettings;
            }
            box.ShiftX(5);

            if (Widgets.ButtonImageFitted(box, TexButton.SpeedButtonTextures[Analyzer.CurrentlyPaused ? 1 : 0]))
            {
                Analyzer.CurrentlyPaused = !Analyzer.CurrentlyPaused;
                GUIController.CurrentEntry.SetActive(!Analyzer.CurrentlyPaused);
            }
            box.ShiftX(5);

            var str = "Times";
            box.width = 20 + str.GetWidthCached();

            instance.times.visible = ToggleColCombo(box, str, instance.times.visible, Settings.timeColour, () => Settings.timeColour = colourPicker.CurrentCol);

            box.ShiftX(5);

            str = "Calls";
            box.width = 20 + str.GetWidthCached();

            instance.calls.visible = ToggleColCombo(box, str, instance.calls.visible, Settings.callsColour, () => Settings.callsColour = colourPicker.CurrentCol);

            box.ShiftX(5);

            str = "Background";
            box.width = 20 + str.GetWidthCached();

            ToggleColCombo(box, str, true, Settings.GraphCol, () => Settings.GraphCol = colourPicker.CurrentCol);

            box.ShiftX(5);

            void jammydodger(ref Rect p, string s, ref bool r)
            {
                box.width = 20 + s.GetWidthCached();
                CheckNewRow(ref box, ref p);

                r = DrawButton(box, s, r);
                box.ShiftX(5);
            }

            jammydodger(ref position, "Axis", ref GraphSettings.showAxis);
            jammydodger(ref position, "Grid", ref GraphSettings.showGrid);
            jammydodger(ref position, "Max", ref GraphSettings.showMax);

            Text.Anchor = TextAnchor.UpperLeft;

            box.width = 100;
            CheckNewRow(ref box, ref position);

            instance.entryCount = (int)Widgets.HorizontalSlider(box.BottomPartPixels(30f), instance.entryCount, 10, 2000, true, string.Intern($"{instance.entryCount} Entries"));

            box.ShiftX(5);


            Text.Anchor = TextAnchor.MiddleCenter;
            Text.Font = GameFont.Tiny;
            str = $"Aliasing:{(GraphSettings.lineAliasing == 0 ? "none" : GraphSettings.lineAliasing.ToString())}";
            box.width = str.GetWidthCached() + 10;
            CheckNewRow(ref box, ref position);

            if (Widgets.ButtonText(box, str, false))
            {
                GraphSettings.lineAliasing = GraphSettings.lineAliasing switch
                {
                    7.5f => 12.5f,
                    12.5f => 0.0f,
                    0.0f => 5.0f,
                    5.0f => 7.5f,
                    _ => 0.0f
                };
            }

            box.ShiftX(5);

            DubGUI.ResetFont();
        }
Exemple #10
0
        private static void DrawSettings(Panel_Graph instance, ref Rect position)
        {
            void CheckNewRow(ref Rect box, ref Rect position)
            {
                if (box.xMax > position.xMax)
                {
                    position.AdjustVerticallyBy(box.height);
                    box.y += box.height;
                    box.x  = position.x;
                }
            }

            var currentHeight = 32;
            var box           = position.TopPartPixels(currentHeight).LeftPartPixels(20f);

            position.AdjustVerticallyBy(currentHeight);

            Text.Anchor = TextAnchor.MiddleCenter;

            if (Widgets.ButtonImageFitted(box, Textures.Gear))
            {
                doSettings = !doSettings;
            }
            box.ShiftX(5);

            if (Widgets.ButtonImageFitted(box, TexButton.SpeedButtonTextures[Analyzer.CurrentlyPaused ? 1 : 0]))
            {
                Analyzer.CurrentlyPaused = !Analyzer.CurrentlyPaused;
                GUIController.CurrentEntry.SetActive(!Analyzer.CurrentlyPaused);
            }
            box.ShiftX(5);

            var str = "Times";

            box.width = 20 + str.GetWidthCached();

            instance.times.visible = ToggleColCombo(box, str, instance.times.visible, Settings.timeColour, () => Settings.timeColour = colourPicker.CurrentCol);

            box.ShiftX(5);

            str       = "Calls";
            box.width = 20 + str.GetWidthCached();

            instance.calls.visible = ToggleColCombo(box, str, instance.calls.visible, Settings.callsColour, () => Settings.callsColour = colourPicker.CurrentCol);

            box.ShiftX(5);

            str       = "Background";
            box.width = 20 + str.GetWidthCached();

            ToggleColCombo(box, str, true, Settings.GraphCol, () => Settings.GraphCol = colourPicker.CurrentCol);

            box.ShiftX(5);

            void jammydodger(ref Rect p, string s, ref bool r, string h)
            {
                box.width = 20 + s.GetWidthCached();
                CheckNewRow(ref box, ref p);

                r = DrawButton(box, s, r);
                if (h != null && Mouse.IsOver(box))
                {
                    TooltipHandler.TipRegion(box, h);
                }
                box.ShiftX(5);
            }

            jammydodger(ref position, "Axis", ref GraphSettings.showAxis, null);
            jammydodger(ref position, "Grid", ref GraphSettings.showGrid, "Grid will only show when the axis is also active");
            jammydodger(ref position, "Max", ref GraphSettings.showMax, null);

            Text.Anchor = TextAnchor.UpperLeft;

            box.width = 100;
            CheckNewRow(ref box, ref position);

            instance.entryCount = (int)Widgets.HorizontalSlider(box.BottomPartPixels(30f), instance.entryCount, 10, 2000, true, string.Intern($"{instance.entryCount} Entries"));
        }