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/documentwidget.c | 39 +++++++++++++++++++++++++++------------ src/ui/util.c | 28 ++++++++++++++++++++++++++++ src/ui/util.h | 1 + 3 files changed, 56 insertions(+), 12 deletions(-) (limited to 'src/ui') 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 static void animate_DocumentWidget_(void *ticker) { iDocumentWidget *d = ticker; + refresh_Widget(d); if (!isFinished_Anim(&d->sideOpacity) || !isFinished_Anim(&d->altTextOpacity)) { addTicker_App(animate_DocumentWidget_, d); } @@ -557,15 +558,19 @@ static void updateHover_DocumentWidget_(iDocumentWidget *d, iInt2 mouse) { } } } - if (!d->hoverPre && targetValue_Anim(&d->altTextOpacity) > 0.5f) { - setValue_Anim(&d->altTextOpacity, 0.0f, 300); - animate_DocumentWidget_(d); - refresh_Widget(w); + if (!d->hoverPre) { + setValueSpeed_Anim(&d->altTextOpacity, 0.0f, 2); + if (!isFinished_Anim(&d->altTextOpacity)) { + animate_DocumentWidget_(d); + } } - else if (d->hoverPre && targetValue_Anim(&d->altTextOpacity) < 0.5f && + else if (d->hoverPre && + preHasAltText_GmDocument(d->doc, d->hoverPre->preId) && ~d->flags & noHoverWhileScrolling_DocumentWidgetFlag) { - setValue_Anim(&d->altTextOpacity, 1.0f, 0); - refresh_Widget(w); + setValueSpeed_Anim(&d->altTextOpacity, 1.0f, 2); + if (!isFinished_Anim(&d->altTextOpacity)) { + animate_DocumentWidget_(d); + } } if (isHover_Widget(w) && !contains_Widget(constAs_Widget(d->scroll), mouse)) { setCursor_Window(get_Window(), @@ -886,6 +891,7 @@ static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode updateTheme_DocumentWidget_(d); init_Anim(&d->scrollY, 0); init_Anim(&d->sideOpacity, 0); + init_Anim(&d->altTextOpacity, 0); resetWideRuns_DocumentWidget_(d); d->state = ready_RequestState; } @@ -1090,6 +1096,7 @@ static iBool updateFromHistory_DocumentWidget_(iDocumentWidget *d) { set_Block(&d->sourceContent, &resp->body); updateDocument_DocumentWidget_(d, resp, iTrue); init_Anim(&d->scrollY, d->initNormScrollY * size_GmDocument(d->doc).y); + init_Anim(&d->altTextOpacity, 0); d->state = ready_RequestState; updateSideOpacity_DocumentWidget_(d, iFalse); updateSideIconBuf_DocumentWidget_(d); @@ -1261,6 +1268,7 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) { d->state = receivedPartialResponse_RequestState; updateTrust_DocumentWidget_(d, resp); init_Anim(&d->sideOpacity, 0); + init_Anim(&d->altTextOpacity, 0); format_String(&d->sourceHeader, "%d %s", statusCode, get_GmError(statusCode)->title); d->sourceStatus = statusCode; switch (category_GmStatusCode(statusCode)) { @@ -1652,6 +1660,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) updateFetchProgress_DocumentWidget_(d); } init_Anim(&d->sideOpacity, 0); + init_Anim(&d->altTextOpacity, 0); updateSideOpacity_DocumentWidget_(d, iFalse); updateWindowTitle_DocumentWidget_(d); allocVisBuffer_DocumentWidget_(d); @@ -2687,6 +2696,10 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e return iTrue; } /* Begin selecting a range of text. */ + if (~d->flags & selecting_DocumentWidgetFlag && d->hoverPre && + preIsFolded_GmDocument(d->doc, d->hoverPre->preId)) { + return iTrue; + } if (~d->flags & selecting_DocumentWidgetFlag) { beginMarkingSelection_DocumentWidget_(d, d->click.startPos); } @@ -2884,10 +2897,12 @@ static void fillRange_DrawContext_(iDrawContext *d, const iGmRun *run, enum iCol if (w > width_Rect(run->visBounds) - x) { w = width_Rect(run->visBounds) - x; } - const iInt2 visPos = - add_I2(run->bounds.pos, addY_I2(d->viewPos, -value_Anim(&d->widget->scrollY))); - fillRect_Paint(&d->paint, (iRect){ addX_I2(visPos, x), - init_I2(w, height_Rect(run->bounds)) }, color); + if (~run->flags & decoration_GmRunFlag) { + const iInt2 visPos = + add_I2(run->bounds.pos, addY_I2(d->viewPos, -value_Anim(&d->widget->scrollY))); + fillRect_Paint(&d->paint, (iRect){ addX_I2(visPos, x), + init_I2(w, height_Rect(run->bounds)) }, color); + } } /* Link URLs are not part of the visible document, so they are ignored above. Handle these ranges as a special case. */ @@ -3473,7 +3488,7 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) { } draw_Widget(w); /* Alt text. */ - const float altTextOpacity = value_Anim(&d->altTextOpacity); + const float altTextOpacity = value_Anim(&d->altTextOpacity) * 3 - 2; if (d->hoverAltPre && altTextOpacity > 0) { const iGmPreMeta *meta = preMeta_GmDocument(d->doc, d->hoverAltPre->preId); 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) { 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. */ 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 { void init_Anim (iAnim *, float value); void setValue_Anim (iAnim *, float to, uint32_t span); +void setValueSpeed_Anim (iAnim *, float to, float unitsPerSecond); void setValueEased_Anim (iAnim *, float to, uint32_t span); void setFlags_Anim (iAnim *, int flags, iBool set); void stop_Anim (iAnim *); -- cgit v1.2.3