From 985117958ce082ae92078355f4b039f2a0963c7d Mon Sep 17 00:00:00 2001 From: Andy Adshead Date: Tue, 29 Jan 2019 00:58:36 +0000 Subject: [PATCH] Simple zooming support with arrow keys --- Ryujinx.Profiler/UI/ProfileWindow.cs | 52 ++++++++++++++++++++--- Ryujinx.Profiler/UI/ProfileWindowGraph.cs | 16 ++++--- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/Ryujinx.Profiler/UI/ProfileWindow.cs b/Ryujinx.Profiler/UI/ProfileWindow.cs index c43acd55f3..01f6ec9444 100644 --- a/Ryujinx.Profiler/UI/ProfileWindow.cs +++ b/Ryujinx.Profiler/UI/ProfileWindow.cs @@ -77,6 +77,8 @@ namespace Ryujinx.Profiler.UI private bool _prevBackspaceDown = false; private double _backspaceDownTime = 0; + private Key _graphControlKey = Key.F35; + // Event management private double _updateTimer; private double _processEventTimer; @@ -262,6 +264,26 @@ namespace Ryujinx.Profiler.UI if (_processEventTimer > 0.05) { ProcessEvents(); + + switch (_graphControlKey) + { + case Key.Left: + _graphPosition += (float)(GraphMoveSpeed * e.Time); + break; + + case Key.Right: + _graphPosition = MathF.Max(_graphPosition - (float)(GraphMoveSpeed * e.Time), 0); + break; + + case Key.Up: + _graphZoom = MathF.Min(_graphZoom + (float)(GraphZoomSpeed * e.Time), 100.0f); + break; + + case Key.Down: + _graphZoom = MathF.Max(_graphZoom - (float)(GraphZoomSpeed * e.Time), 1f); + break; + } + _processEventTimer = 0; } } @@ -574,20 +596,36 @@ namespace Ryujinx.Profiler.UI protected override void OnKeyDown(KeyboardKeyEventArgs e) { - if (e.Key == Key.BackSpace) + switch (e.Key) { - _profileUpdated = _backspaceDown = true; - return; - } + case Key.BackSpace: + _profileUpdated = _backspaceDown = true; + return; + + case Key.Left: + case Key.Right: + case Key.Up: + case Key.Down: + _graphControlKey = e.Key; + return; + } base.OnKeyUp(e); } protected override void OnKeyUp(KeyboardKeyEventArgs e) { - if (e.Key == Key.BackSpace) + switch (e.Key) { - _backspaceDown = false; - return; + case Key.BackSpace: + _backspaceDown = false; + return; + + case Key.Left: + case Key.Right: + case Key.Up: + case Key.Down: + _graphControlKey = Key.F35; + return; } base.OnKeyUp(e); } diff --git a/Ryujinx.Profiler/UI/ProfileWindowGraph.cs b/Ryujinx.Profiler/UI/ProfileWindowGraph.cs index 6f28478836..03fd60c86b 100644 --- a/Ryujinx.Profiler/UI/ProfileWindowGraph.cs +++ b/Ryujinx.Profiler/UI/ProfileWindowGraph.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using OpenTK; using OpenTK.Graphics.OpenGL; @@ -8,6 +6,12 @@ namespace Ryujinx.Profiler.UI { public partial class ProfileWindow { + private const float GraphMoveSpeed = 100; + private const float GraphZoomSpeed = 5; + + private float _graphZoom = 1; + private float _graphPosition = 0; + private void DrawGraph(float xOffset, float yOffset, float width) { if (_sortedProfileData.Count != 0) @@ -17,7 +21,7 @@ namespace Ryujinx.Profiler.UI int verticalIndex = 0; float barHeight = (LineHeight - LinePadding); - long timeWidth = Profile.HistoryLength; + long timeWidth = (long)(Profile.HistoryLength / _graphZoom); GL.Enable(EnableCap.ScissorTest); GL.Begin(PrimitiveType.Triangles); @@ -26,8 +30,8 @@ namespace Ryujinx.Profiler.UI GL.Color3(Color.Green); foreach (Timestamp timestamp in entry.Value.GetAllTimestamps()) { - left = (int)(xOffset + width - (((float)_captureTime - timestamp.BeginTime) / timeWidth) * width); - right = (int)(xOffset + width - (((float)_captureTime - timestamp.EndTime) / timeWidth) * width); + left = (int)(xOffset + width + _graphPosition - (((float)_captureTime - timestamp.BeginTime) / timeWidth) * width); + right = (int)(xOffset + width + _graphPosition - (((float)_captureTime - timestamp.EndTime) / timeWidth) * width); bottom = GetLineY(yOffset, LineHeight, LinePadding, true, verticalIndex); top = bottom + barHeight; @@ -52,7 +56,7 @@ namespace Ryujinx.Profiler.UI long entryBegin = entry.Value.BeginTime; if (entryBegin != -1) { - left = (int)(xOffset + width - (((float)_captureTime - entryBegin) / timeWidth) * width); + left = (int)(xOffset + width + _graphPosition - (((float)_captureTime - entryBegin) / timeWidth) * width); bottom = GetLineY(yOffset, LineHeight, LinePadding, true, verticalIndex); top = bottom + barHeight; right = (int)(xOffset + width);