Fix launcher input widget caret still blinking when inserting text or moving cursor, fixes #376

This commit is contained in:
UnknownShadow200 2017-09-24 22:25:45 +10:00
parent 869a8639b8
commit fdb83f143e
3 changed files with 20 additions and 25 deletions

View File

@ -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);
@ -42,7 +48,6 @@ namespace Launcher.Gui.Screens {
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);
}

View File

@ -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();

View File

@ -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