diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/documentwidget.c | 39 | ||||
-rw-r--r-- | src/ui/util.c | 28 | ||||
-rw-r--r-- | src/ui/util.h | 1 |
3 files changed, 56 insertions, 12 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index d338cf04..5d85e275 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -515,6 +515,7 @@ static void invalidateWideRunsWithNonzeroOffset_DocumentWidget_(iDocumentWidget | |||
515 | 515 | ||
516 | static void animate_DocumentWidget_(void *ticker) { | 516 | static void animate_DocumentWidget_(void *ticker) { |
517 | iDocumentWidget *d = ticker; | 517 | iDocumentWidget *d = ticker; |
518 | refresh_Widget(d); | ||
518 | if (!isFinished_Anim(&d->sideOpacity) || !isFinished_Anim(&d->altTextOpacity)) { | 519 | if (!isFinished_Anim(&d->sideOpacity) || !isFinished_Anim(&d->altTextOpacity)) { |
519 | addTicker_App(animate_DocumentWidget_, d); | 520 | addTicker_App(animate_DocumentWidget_, d); |
520 | } | 521 | } |
@@ -557,15 +558,19 @@ static void updateHover_DocumentWidget_(iDocumentWidget *d, iInt2 mouse) { | |||
557 | } | 558 | } |
558 | } | 559 | } |
559 | } | 560 | } |
560 | if (!d->hoverPre && targetValue_Anim(&d->altTextOpacity) > 0.5f) { | 561 | if (!d->hoverPre) { |
561 | setValue_Anim(&d->altTextOpacity, 0.0f, 300); | 562 | setValueSpeed_Anim(&d->altTextOpacity, 0.0f, 2); |
562 | animate_DocumentWidget_(d); | 563 | if (!isFinished_Anim(&d->altTextOpacity)) { |
563 | refresh_Widget(w); | 564 | animate_DocumentWidget_(d); |
565 | } | ||
564 | } | 566 | } |
565 | else if (d->hoverPre && targetValue_Anim(&d->altTextOpacity) < 0.5f && | 567 | else if (d->hoverPre && |
568 | preHasAltText_GmDocument(d->doc, d->hoverPre->preId) && | ||
566 | ~d->flags & noHoverWhileScrolling_DocumentWidgetFlag) { | 569 | ~d->flags & noHoverWhileScrolling_DocumentWidgetFlag) { |
567 | setValue_Anim(&d->altTextOpacity, 1.0f, 0); | 570 | setValueSpeed_Anim(&d->altTextOpacity, 1.0f, 2); |
568 | refresh_Widget(w); | 571 | if (!isFinished_Anim(&d->altTextOpacity)) { |
572 | animate_DocumentWidget_(d); | ||
573 | } | ||
569 | } | 574 | } |
570 | if (isHover_Widget(w) && !contains_Widget(constAs_Widget(d->scroll), mouse)) { | 575 | if (isHover_Widget(w) && !contains_Widget(constAs_Widget(d->scroll), mouse)) { |
571 | setCursor_Window(get_Window(), | 576 | setCursor_Window(get_Window(), |
@@ -886,6 +891,7 @@ static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode | |||
886 | updateTheme_DocumentWidget_(d); | 891 | updateTheme_DocumentWidget_(d); |
887 | init_Anim(&d->scrollY, 0); | 892 | init_Anim(&d->scrollY, 0); |
888 | init_Anim(&d->sideOpacity, 0); | 893 | init_Anim(&d->sideOpacity, 0); |
894 | init_Anim(&d->altTextOpacity, 0); | ||
889 | resetWideRuns_DocumentWidget_(d); | 895 | resetWideRuns_DocumentWidget_(d); |
890 | d->state = ready_RequestState; | 896 | d->state = ready_RequestState; |
891 | } | 897 | } |
@@ -1090,6 +1096,7 @@ static iBool updateFromHistory_DocumentWidget_(iDocumentWidget *d) { | |||
1090 | set_Block(&d->sourceContent, &resp->body); | 1096 | set_Block(&d->sourceContent, &resp->body); |
1091 | updateDocument_DocumentWidget_(d, resp, iTrue); | 1097 | updateDocument_DocumentWidget_(d, resp, iTrue); |
1092 | init_Anim(&d->scrollY, d->initNormScrollY * size_GmDocument(d->doc).y); | 1098 | init_Anim(&d->scrollY, d->initNormScrollY * size_GmDocument(d->doc).y); |
1099 | init_Anim(&d->altTextOpacity, 0); | ||
1093 | d->state = ready_RequestState; | 1100 | d->state = ready_RequestState; |
1094 | updateSideOpacity_DocumentWidget_(d, iFalse); | 1101 | updateSideOpacity_DocumentWidget_(d, iFalse); |
1095 | updateSideIconBuf_DocumentWidget_(d); | 1102 | updateSideIconBuf_DocumentWidget_(d); |
@@ -1261,6 +1268,7 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) { | |||
1261 | d->state = receivedPartialResponse_RequestState; | 1268 | d->state = receivedPartialResponse_RequestState; |
1262 | updateTrust_DocumentWidget_(d, resp); | 1269 | updateTrust_DocumentWidget_(d, resp); |
1263 | init_Anim(&d->sideOpacity, 0); | 1270 | init_Anim(&d->sideOpacity, 0); |
1271 | init_Anim(&d->altTextOpacity, 0); | ||
1264 | format_String(&d->sourceHeader, "%d %s", statusCode, get_GmError(statusCode)->title); | 1272 | format_String(&d->sourceHeader, "%d %s", statusCode, get_GmError(statusCode)->title); |
1265 | d->sourceStatus = statusCode; | 1273 | d->sourceStatus = statusCode; |
1266 | switch (category_GmStatusCode(statusCode)) { | 1274 | switch (category_GmStatusCode(statusCode)) { |
@@ -1652,6 +1660,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
1652 | updateFetchProgress_DocumentWidget_(d); | 1660 | updateFetchProgress_DocumentWidget_(d); |
1653 | } | 1661 | } |
1654 | init_Anim(&d->sideOpacity, 0); | 1662 | init_Anim(&d->sideOpacity, 0); |
1663 | init_Anim(&d->altTextOpacity, 0); | ||
1655 | updateSideOpacity_DocumentWidget_(d, iFalse); | 1664 | updateSideOpacity_DocumentWidget_(d, iFalse); |
1656 | updateWindowTitle_DocumentWidget_(d); | 1665 | updateWindowTitle_DocumentWidget_(d); |
1657 | allocVisBuffer_DocumentWidget_(d); | 1666 | allocVisBuffer_DocumentWidget_(d); |
@@ -2687,6 +2696,10 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
2687 | return iTrue; | 2696 | return iTrue; |
2688 | } | 2697 | } |
2689 | /* Begin selecting a range of text. */ | 2698 | /* Begin selecting a range of text. */ |
2699 | if (~d->flags & selecting_DocumentWidgetFlag && d->hoverPre && | ||
2700 | preIsFolded_GmDocument(d->doc, d->hoverPre->preId)) { | ||
2701 | return iTrue; | ||
2702 | } | ||
2690 | if (~d->flags & selecting_DocumentWidgetFlag) { | 2703 | if (~d->flags & selecting_DocumentWidgetFlag) { |
2691 | beginMarkingSelection_DocumentWidget_(d, d->click.startPos); | 2704 | beginMarkingSelection_DocumentWidget_(d, d->click.startPos); |
2692 | } | 2705 | } |
@@ -2884,10 +2897,12 @@ static void fillRange_DrawContext_(iDrawContext *d, const iGmRun *run, enum iCol | |||
2884 | if (w > width_Rect(run->visBounds) - x) { | 2897 | if (w > width_Rect(run->visBounds) - x) { |
2885 | w = width_Rect(run->visBounds) - x; | 2898 | w = width_Rect(run->visBounds) - x; |
2886 | } | 2899 | } |
2887 | const iInt2 visPos = | 2900 | if (~run->flags & decoration_GmRunFlag) { |
2888 | add_I2(run->bounds.pos, addY_I2(d->viewPos, -value_Anim(&d->widget->scrollY))); | 2901 | const iInt2 visPos = |
2889 | fillRect_Paint(&d->paint, (iRect){ addX_I2(visPos, x), | 2902 | add_I2(run->bounds.pos, addY_I2(d->viewPos, -value_Anim(&d->widget->scrollY))); |
2890 | init_I2(w, height_Rect(run->bounds)) }, color); | 2903 | fillRect_Paint(&d->paint, (iRect){ addX_I2(visPos, x), |
2904 | init_I2(w, height_Rect(run->bounds)) }, color); | ||
2905 | } | ||
2891 | } | 2906 | } |
2892 | /* Link URLs are not part of the visible document, so they are ignored above. Handle | 2907 | /* Link URLs are not part of the visible document, so they are ignored above. Handle |
2893 | these ranges as a special case. */ | 2908 | these ranges as a special case. */ |
@@ -3473,7 +3488,7 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) { | |||
3473 | } | 3488 | } |
3474 | draw_Widget(w); | 3489 | draw_Widget(w); |
3475 | /* Alt text. */ | 3490 | /* Alt text. */ |
3476 | const float altTextOpacity = value_Anim(&d->altTextOpacity); | 3491 | const float altTextOpacity = value_Anim(&d->altTextOpacity) * 3 - 2; |
3477 | if (d->hoverAltPre && altTextOpacity > 0) { | 3492 | if (d->hoverAltPre && altTextOpacity > 0) { |
3478 | const iGmPreMeta *meta = preMeta_GmDocument(d->doc, d->hoverAltPre->preId); | 3493 | const iGmPreMeta *meta = preMeta_GmDocument(d->doc, d->hoverAltPre->preId); |
3479 | if (meta->flags & topLeft_GmPreMetaFlag && ~meta->flags & decoration_GmRunFlag && | 3494 | if (meta->flags & topLeft_GmPreMetaFlag && ~meta->flags & decoration_GmRunFlag && |
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 | ||
65 | static void removePlus_(iString *str) { | ||
66 | if (endsWith_String(str, "+")) { | ||
67 | removeEnd_String(str, 1); | ||
68 | appendCStr_String(str, " "); | ||
69 | } | ||
70 | } | ||
71 | |||
65 | void toString_Sym(int key, int kmods, iString *str) { | 72 | void 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 | ||
311 | void 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 | |||
296 | void setValueEased_Anim(iAnim *d, float to, uint32_t span) { | 324 | void 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. */ |
diff --git a/src/ui/util.h b/src/ui/util.h index 2be38384..c6320e29 100644 --- a/src/ui/util.h +++ b/src/ui/util.h | |||
@@ -112,6 +112,7 @@ struct Impl_Anim { | |||
112 | 112 | ||
113 | void init_Anim (iAnim *, float value); | 113 | void init_Anim (iAnim *, float value); |
114 | void setValue_Anim (iAnim *, float to, uint32_t span); | 114 | void setValue_Anim (iAnim *, float to, uint32_t span); |
115 | void setValueSpeed_Anim (iAnim *, float to, float unitsPerSecond); | ||
115 | void setValueEased_Anim (iAnim *, float to, uint32_t span); | 116 | void setValueEased_Anim (iAnim *, float to, uint32_t span); |
116 | void setFlags_Anim (iAnim *, int flags, iBool set); | 117 | void setFlags_Anim (iAnim *, int flags, iBool set); |
117 | void stop_Anim (iAnim *); | 118 | void stop_Anim (iAnim *); |