diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-12 13:49:38 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-12 13:49:38 +0300 |
commit | 33620846cca5678fbd662ea1a48fad302727dae7 (patch) | |
tree | 322fb4ab2c1dd7dd3eceee0834f3e90d27838de4 /src/ui/text.c | |
parent | 1410bbde7779efe3a20f603523547c8b8f55b6a1 (diff) |
Mobile: Draw optimizations; focus handling
Widgets can now be marked for buffering their contents, which is useful if their contents change seldom but they are drawn often.
For example, the navbar is always visible but doesn't change very often, and during animations menu contents are static but there is a moving animation so everything gets drawn 60 FPS.
Focus handling was also improved so the lookup results can be scrolled while entering text, and one can tap outside an input field to unfocus it.
Diffstat (limited to 'src/ui/text.c')
-rw-r--r-- | src/ui/text.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/ui/text.c b/src/ui/text.c index 231281eb..f7fff4bc 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -25,6 +25,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
25 | #include "metrics.h" | 25 | #include "metrics.h" |
26 | #include "embedded.h" | 26 | #include "embedded.h" |
27 | #include "window.h" | 27 | #include "window.h" |
28 | #include "paint.h" | ||
28 | #include "app.h" | 29 | #include "app.h" |
29 | 30 | ||
30 | #define STB_TRUETYPE_IMPLEMENTATION | 31 | #define STB_TRUETYPE_IMPLEMENTATION |
@@ -1712,6 +1713,8 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { | |||
1712 | } | 1713 | } |
1713 | SDL_Rect src; | 1714 | SDL_Rect src; |
1714 | memcpy(&src, &glyph->rect[hoff], sizeof(SDL_Rect)); | 1715 | memcpy(&src, &glyph->rect[hoff], sizeof(SDL_Rect)); |
1716 | dst.x += origin_Paint.x; | ||
1717 | dst.y += origin_Paint.y; | ||
1715 | if (args->mode & fillBackground_RunMode) { | 1718 | if (args->mode & fillBackground_RunMode) { |
1716 | /* Alpha blending looks much better if the RGB components don't change in | 1719 | /* Alpha blending looks much better if the RGB components don't change in |
1717 | the partially transparent pixels. */ | 1720 | the partially transparent pixels. */ |
@@ -2182,6 +2185,8 @@ void init_TextBuf(iTextBuf *d, iWrapText *wrapText, int font, int color) { | |||
2182 | } | 2185 | } |
2183 | if (d->texture) { | 2186 | if (d->texture) { |
2184 | SDL_Texture *oldTarget = SDL_GetRenderTarget(render); | 2187 | SDL_Texture *oldTarget = SDL_GetRenderTarget(render); |
2188 | const iInt2 oldOrigin = origin_Paint; | ||
2189 | origin_Paint = zero_I2(); | ||
2185 | SDL_SetRenderTarget(render, d->texture); | 2190 | SDL_SetRenderTarget(render, d->texture); |
2186 | SDL_SetRenderDrawBlendMode(render, SDL_BLENDMODE_NONE); | 2191 | SDL_SetRenderDrawBlendMode(render, SDL_BLENDMODE_NONE); |
2187 | SDL_SetRenderDrawColor(render, 255, 255, 255, 0); | 2192 | SDL_SetRenderDrawColor(render, 255, 255, 255, 0); |
@@ -2190,6 +2195,7 @@ void init_TextBuf(iTextBuf *d, iWrapText *wrapText, int font, int color) { | |||
2190 | draw_WrapText(wrapText, font, zero_I2(), color | fillBackground_ColorId); | 2195 | draw_WrapText(wrapText, font, zero_I2(), color | fillBackground_ColorId); |
2191 | SDL_SetTextureBlendMode(text_.cache, SDL_BLENDMODE_BLEND); | 2196 | SDL_SetTextureBlendMode(text_.cache, SDL_BLENDMODE_BLEND); |
2192 | SDL_SetRenderTarget(render, oldTarget); | 2197 | SDL_SetRenderTarget(render, oldTarget); |
2198 | origin_Paint = oldOrigin; | ||
2193 | SDL_SetTextureBlendMode(d->texture, SDL_BLENDMODE_BLEND); | 2199 | SDL_SetTextureBlendMode(d->texture, SDL_BLENDMODE_BLEND); |
2194 | } | 2200 | } |
2195 | } | 2201 | } |
@@ -2203,6 +2209,7 @@ iTextBuf *newRange_TextBuf(int font, int color, iRangecc text) { | |||
2203 | } | 2209 | } |
2204 | 2210 | ||
2205 | void draw_TextBuf(const iTextBuf *d, iInt2 pos, int color) { | 2211 | void draw_TextBuf(const iTextBuf *d, iInt2 pos, int color) { |
2212 | addv_I2(&pos, origin_Paint); | ||
2206 | const iColor clr = get_Color(color); | 2213 | const iColor clr = get_Color(color); |
2207 | SDL_SetTextureColorMod(d->texture, clr.r, clr.g, clr.b); | 2214 | SDL_SetTextureColorMod(d->texture, clr.r, clr.g, clr.b); |
2208 | SDL_RenderCopy(text_.render, | 2215 | SDL_RenderCopy(text_.render, |