summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-03-18 14:44:19 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-03-18 14:44:19 +0200
commit0b14c8d488c8c2c3f98bd880f30743778ada6827 (patch)
treee0e631ba0c3191d3abd254c15bbb96e1f2acdc46 /src/ui
parent2a3da970abf17115b5d9d0404213c617b80f3f25 (diff)
Translation: More colorful progress animation
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/translation.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/ui/translation.c b/src/ui/translation.c
index 2c7a9f30..1112f9ea 100644
--- a/src/ui/translation.c
+++ b/src/ui/translation.c
@@ -110,20 +110,33 @@ static void draw_TranslationProgressWidget_(const iTranslationProgressWidget *d)
110 init_Paint(&p); 110 init_Paint(&p);
111 const iInt2 mid = mid_Rect(bounds); 111 const iInt2 mid = mid_Rect(bounds);
112 SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_BLEND); 112 SDL_SetRenderDrawBlendMode(renderer_Window(get_Window()), SDL_BLENDMODE_BLEND);
113 const int palette[] = {
114 uiBackgroundSelected_ColorId,
115 red_ColorId,
116 blue_ColorId,
117 green_ColorId,
118 };
113 iConstForEach(Array, i, &d->sprites) { 119 iConstForEach(Array, i, &d->sprites) {
114 const int index = (int) index_ArrayConstIterator(&i); 120 const int index = (int) index_ArrayConstIterator(&i);
115 const float angle = (float) index; 121 const float angle = (float) index;
116 const iSprite *spr = i.value; 122 const iSprite *spr = i.value;
117 const float opacity = iClamp(t - index * 0.5f, 0.0, 1.0f); 123 const float opacity = iClamp(t - index * 0.5f, 0.0, 1.0f);
118 int bg = uiBackgroundSelected_ColorId; 124 const float palPos = index * 0.025f + t / 10;
119 int fg = uiTextSelected_ColorId; 125 const int palCur = (size_t)(palPos) % iElemCount(palette);
126 const int palNext = (palCur + 1) % iElemCount(palette);
127
128 int fg = palCur == 0 ? uiTextSelected_ColorId
129 : isLight_ColorTheme(colorTheme_App()) ? white_ColorId
130 : black_ColorId;
120 iInt2 pos = add_I2(mid, spr->pos); 131 iInt2 pos = add_I2(mid, spr->pos);
121 float t2 = sin(0.2f * t); 132 float t2 = sin(0.2f * t);
122 pos.y += sin(angle + t) * spr->size.y * t2 * t2 * iClamp(t * 0.25f - 0.3f, 0.0f, 1.0f); 133 pos.y += sin(angle + t) * spr->size.y * t2 * t2 * iClamp(t * 0.25f - 0.3f, 0.0f, 1.0f);
123 if (bg >= 0) { 134 p.alpha = opacity * 255;
124 p.alpha = opacity * 255; 135 const iColor back = mix_Color(
125 fillRect_Paint(&p, (iRect){ pos, spr->size }, bg); 136 get_Color(palette[palCur]), get_Color(palette[palNext]), palPos - (int) palPos);
126 } 137 SDL_SetRenderDrawColor(renderer_Window(get_Window()), back.r, back.g, back.b, p.alpha);
138 SDL_RenderFillRect(renderer_Window(get_Window()),
139 &(SDL_Rect){ pos.x, pos.y, spr->size.x, spr->size.y });
127 if (fg >= 0) { 140 if (fg >= 0) {
128 setOpacity_Text(opacity * 2); 141 setOpacity_Text(opacity * 2);
129 drawRange_Text(d->font, addX_I2(pos, spr->xoff), fg, range_String(&spr->text)); 142 drawRange_Text(d->font, addX_I2(pos, spr->xoff), fg, range_String(&spr->text));
@@ -151,6 +164,8 @@ iDefineTypeConstructionArgs(Translation, (iDocumentWidget *doc), doc)
151static const char * translationServiceHost = "xlt.skyjake.fi"; 164static const char * translationServiceHost = "xlt.skyjake.fi";
152static const uint16_t translationServicePort = 443; 165static const uint16_t translationServicePort = 443;
153 166
167/* TODO: Move these quote/unquote methods to the_Foundation. */
168
154static iString *quote_String_(const iString *d) { 169static iString *quote_String_(const iString *d) {
155 iString *quot = new_String(); 170 iString *quot = new_String();
156 iConstForEach(String, i, d) { 171 iConstForEach(String, i, d) {
@@ -442,12 +457,14 @@ iBool handleCommand_Translation(iTranslation *d, const char *cmd) {
442 return iTrue; 457 return iTrue;
443 } 458 }
444 if (equalWidget_Command(cmd, w, "translation.finished")) { 459 if (equalWidget_Command(cmd, w, "translation.finished")) {
460#if 0
445 if (!isFinished_Translation(d)) { 461 if (!isFinished_Translation(d)) {
446 if (processResult_Translation_(d)) { 462 if (processResult_Translation_(d)) {
447 destroy_Widget(d->dlg); 463 destroy_Widget(d->dlg);
448 d->dlg = NULL; 464 d->dlg = NULL;
449 } 465 }
450 } 466 }
467#endif
451 return iTrue; 468 return iTrue;
452 } 469 }
453 if (equalWidget_Command(cmd, d->dlg, "translation.cancel")) { 470 if (equalWidget_Command(cmd, d->dlg, "translation.cancel")) {