summaryrefslogtreecommitdiff
path: root/src/ui/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/util.c')
-rw-r--r--src/ui/util.c28
1 files changed, 28 insertions, 0 deletions
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) {
62 return ""; 62 return "";
63} 63}
64 64
65static void removePlus_(iString *str) {
66 if (endsWith_String(str, "+")) {
67 removeEnd_String(str, 1);
68 appendCStr_String(str, " ");
69 }
70}
71
65void toString_Sym(int key, int kmods, iString *str) { 72void toString_Sym(int key, int kmods, iString *str) {
66#if defined (iPlatformApple) 73#if defined (iPlatformApple)
67 if (kmods & KMOD_CTRL) { 74 if (kmods & KMOD_CTRL) {
@@ -100,27 +107,35 @@ void toString_Sym(int key, int kmods, iString *str) {
100 appendCStr_String(str, "Esc"); 107 appendCStr_String(str, "Esc");
101 } 108 }
102 else if (key == SDLK_LEFT) { 109 else if (key == SDLK_LEFT) {
110 removePlus_(str);
103 appendChar_String(str, 0x2190); 111 appendChar_String(str, 0x2190);
104 } 112 }
105 else if (key == SDLK_RIGHT) { 113 else if (key == SDLK_RIGHT) {
114 removePlus_(str);
106 appendChar_String(str, 0x2192); 115 appendChar_String(str, 0x2192);
107 } 116 }
108 else if (key == SDLK_UP) { 117 else if (key == SDLK_UP) {
118 removePlus_(str);
109 appendChar_String(str, 0x2191); 119 appendChar_String(str, 0x2191);
110 } 120 }
111 else if (key == SDLK_DOWN) { 121 else if (key == SDLK_DOWN) {
122 removePlus_(str);
112 appendChar_String(str, 0x2193); 123 appendChar_String(str, 0x2193);
113 } 124 }
114 else if (key < 128 && (isalnum(key) || ispunct(key))) { 125 else if (key < 128 && (isalnum(key) || ispunct(key))) {
126 if (ispunct(key)) removePlus_(str);
115 appendChar_String(str, upper_Char(key)); 127 appendChar_String(str, upper_Char(key));
116 } 128 }
117 else if (key == SDLK_BACKSPACE) { 129 else if (key == SDLK_BACKSPACE) {
130 removePlus_(str);
118 appendChar_String(str, 0x232b); /* Erase to the Left */ 131 appendChar_String(str, 0x232b); /* Erase to the Left */
119 } 132 }
120 else if (key == SDLK_DELETE) { 133 else if (key == SDLK_DELETE) {
134 removePlus_(str);
121 appendChar_String(str, 0x2326); /* Erase to the Right */ 135 appendChar_String(str, 0x2326); /* Erase to the Right */
122 } 136 }
123 else if (key == SDLK_RETURN) { 137 else if (key == SDLK_RETURN) {
138 removePlus_(str);
124 appendChar_String(str, 0x21a9); /* Leftwards arrow with a hook */ 139 appendChar_String(str, 0x21a9); /* Leftwards arrow with a hook */
125 } 140 }
126 else { 141 else {
@@ -293,6 +308,19 @@ void setValue_Anim(iAnim *d, float to, uint32_t span) {
293 } 308 }
294} 309}
295 310
311void setValueSpeed_Anim(iAnim *d, float to, float unitsPerSecond) {
312 if (iAbs(d->to - to) > 0.0001f) {
313 const uint32_t now = SDL_GetTicks();
314 const float from = valueAt_Anim_(d, now);
315 const float delta = to - from;
316 const uint32_t span = (fabsf(delta) / unitsPerSecond) * 1000;
317 d->from = from;
318 d->to = to;
319 d->when = now;
320 d->due = d->when + span;
321 }
322}
323
296void setValueEased_Anim(iAnim *d, float to, uint32_t span) { 324void setValueEased_Anim(iAnim *d, float to, uint32_t span) {
297 if (fabsf(to - d->to) <= 0.00001f) { 325 if (fabsf(to - d->to) <= 0.00001f) {
298 d->to = to; /* Pretty much unchanged. */ 326 d->to = to; /* Pretty much unchanged. */