From fdb83f143e6e7bb1e4382b7e3bbe2130e15a9861 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 24 Sep 2017 22:25:45 +1000 Subject: [PATCH] Fix launcher input widget caret still blinking when inserting text or moving cursor, fixes #376 --- Launcher2/Gui/Screens/InputScreen.cs | 32 +++++++++++++++----------- Launcher2/Gui/Screens/ServersScreen.cs | 4 ++-- src/Client/DisplayDevice.h | 9 -------- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/Launcher2/Gui/Screens/InputScreen.cs b/Launcher2/Gui/Screens/InputScreen.cs index bb2aa9889..79bb6ef50 100644 --- a/Launcher2/Gui/Screens/InputScreen.cs +++ b/Launcher2/Gui/Screens/InputScreen.cs @@ -17,16 +17,22 @@ namespace Launcher.Gui.Screens { game.Window.Mouse.WheelChanged += MouseWheelChanged; game.Window.KeyPress += KeyPress; game.Window.Keyboard.KeyRepeat = true; + last = DateTime.UtcNow; } - DateTime widgetOpenTime; - bool lastCaretFlash = false; + DateTime last; + bool lastCaretShow = false; Rectangle lastRec; + double elapsed; + public override void Tick() { - double elapsed = (DateTime.UtcNow - widgetOpenTime).TotalSeconds; + DateTime now = DateTime.UtcNow; + elapsed += (now - last).TotalSeconds; + last = now; + bool caretShow = (elapsed % 1) < 0.5; - if (caretShow == lastCaretFlash || curInput == null) - return; + if (caretShow == lastCaretShow || curInput == null) return; + lastCaretShow = caretShow; using (drawer) { drawer.SetBitmap(game.Framebuffer); @@ -41,8 +47,7 @@ namespace Launcher.Gui.Screens { if (lastRec == r) game.DirtyArea = r; lastRec = r; game.Dirty = true; - } - lastCaretFlash = caretShow; + } } protected override void KeyDown(object sender, KeyboardKeyEventArgs e) { @@ -69,11 +74,9 @@ namespace Launcher.Gui.Screens { } else if (e.Key == Key.C && ControlDown) { curInput.Chars.CopyToClipboard(); } else if (e.Key == Key.V && ControlDown) { - if (curInput.Chars.CopyFromClipboard()) - RedrawLastInput(); + if (curInput.Chars.CopyFromClipboard()) RedrawLastInput(); } else if (e.Key == Key.Escape) { - if (curInput.Chars.Clear()) - RedrawLastInput(); + if (curInput.Chars.Clear()) RedrawLastInput(); } else if (e.Key == Key.Left) { curInput.AdvanceCaretPos(false); RedrawLastInput(); @@ -98,8 +101,10 @@ namespace Launcher.Gui.Screens { } protected virtual void RedrawLastInput() { - if (curInput.RealWidth > curInput.ButtonWidth) + if (curInput.RealWidth > curInput.ButtonWidth) { game.ResetArea(curInput.X, curInput.Y, curInput.RealWidth, curInput.Height); + } + elapsed = 0; lastCaretShow = false; using (drawer) { drawer.SetBitmap(game.Framebuffer); @@ -136,8 +141,7 @@ namespace Launcher.Gui.Screens { } input.Active = true; - widgetOpenTime = DateTime.UtcNow; - lastCaretFlash = false; + elapsed = 0; lastCaretShow = false; input.SetCaretToCursor(mouseX, mouseY, drawer); input.Redraw(drawer); } diff --git a/Launcher2/Gui/Screens/ServersScreen.cs b/Launcher2/Gui/Screens/ServersScreen.cs index fc1a5546d..5766a39ce 100644 --- a/Launcher2/Gui/Screens/ServersScreen.cs +++ b/Launcher2/Gui/Screens/ServersScreen.cs @@ -73,8 +73,8 @@ namespace Launcher.Gui.Screens { protected override void RedrawLastInput() { base.RedrawLastInput(); - if (curInput != widgets[view.hashIndex]) - return; + if (curInput != widgets[view.hashIndex]) return; + TableWidget table = (TableWidget)widgets[view.tableIndex]; table.SetSelected(widgets[view.hashIndex].Text); MarkPendingRedraw(); diff --git a/src/Client/DisplayDevice.h b/src/Client/DisplayDevice.h index 85eab0b8a..0479202d2 100644 --- a/src/Client/DisplayDevice.h +++ b/src/Client/DisplayDevice.h @@ -16,13 +16,10 @@ typedef struct DisplayResolution_ { /* The width of this display in pixels. */ Int32 Width; - /* The height of this display in pixels. */ Int32 Height; - /* The number of bits per pixel of this display. Typical values include 8, 16, 24 and 32. */ Int32 BitsPerPixel; - /* The vertical refresh rate of this display. */ Real32 RefreshRate; } DisplayResolution; @@ -33,24 +30,18 @@ DisplayResolution DisplayResolution_Make(Int32 width, Int32 height, Int32 bitsPe /* Defines a display device on the underlying system.*/ typedef struct DisplayDevice_ { - /* The current resolution of the display device.*/ DisplayResolution CurResolution; - /* The bounds of the display device.*/ Rectangle2D Bounds; - /* Metadata unique to this display device instance. */ void* Metadata; } DisplayDevice; /* Constructs a new display device instance. */ DisplayDevice DisplayDevice_Make(DisplayResolution* curResolution); - /* Updates the bounds of the display device to the given bounds. */ void DisplayDevice_SetBounds(DisplayDevice* device, Rectangle2D* bounds); - /* The primary / default / main display device. */ DisplayDevice DisplayDevice_Default; - #endif \ No newline at end of file