From fb38f92c3a5c29c568575df87f0c29e777ebd969 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Mon, 29 Mar 2021 11:05:09 +0300 Subject: Improving alt text animation; cleaned up key shortcut labels Remove extra Plus signs from key shortcuts. --- src/ui/util.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/ui/util.c') diff --git a/src/ui/util.c b/src/ui/util.c index 08a04105..2996bfd5 100644 --- a/src/ui/util.c +++ b/src/ui/util.c @@ -62,6 +62,13 @@ const char *command_UserEvent(const SDL_Event *d) { return ""; } +static void removePlus_(iString *str) { + if (endsWith_String(str, "+")) { + removeEnd_String(str, 1); + appendCStr_String(str, " "); + } +} + void toString_Sym(int key, int kmods, iString *str) { #if defined (iPlatformApple) if (kmods & KMOD_CTRL) { @@ -100,27 +107,35 @@ void toString_Sym(int key, int kmods, iString *str) { appendCStr_String(str, "Esc"); } else if (key == SDLK_LEFT) { + removePlus_(str); appendChar_String(str, 0x2190); } else if (key == SDLK_RIGHT) { + removePlus_(str); appendChar_String(str, 0x2192); } else if (key == SDLK_UP) { + removePlus_(str); appendChar_String(str, 0x2191); } else if (key == SDLK_DOWN) { + removePlus_(str); appendChar_String(str, 0x2193); } else if (key < 128 && (isalnum(key) || ispunct(key))) { + if (ispunct(key)) removePlus_(str); appendChar_String(str, upper_Char(key)); } else if (key == SDLK_BACKSPACE) { + removePlus_(str); appendChar_String(str, 0x232b); /* Erase to the Left */ } else if (key == SDLK_DELETE) { + removePlus_(str); appendChar_String(str, 0x2326); /* Erase to the Right */ } else if (key == SDLK_RETURN) { + removePlus_(str); appendChar_String(str, 0x21a9); /* Leftwards arrow with a hook */ } else { @@ -293,6 +308,19 @@ void setValue_Anim(iAnim *d, float to, uint32_t span) { } } +void setValueSpeed_Anim(iAnim *d, float to, float unitsPerSecond) { + if (iAbs(d->to - to) > 0.0001f) { + const uint32_t now = SDL_GetTicks(); + const float from = valueAt_Anim_(d, now); + const float delta = to - from; + const uint32_t span = (fabsf(delta) / unitsPerSecond) * 1000; + d->from = from; + d->to = to; + d->when = now; + d->due = d->when + span; + } +} + void setValueEased_Anim(iAnim *d, float to, uint32_t span) { if (fabsf(to - d->to) <= 0.00001f) { d->to = to; /* Pretty much unchanged. */ -- cgit v1.2.3