summaryrefslogtreecommitdiff
path: root/src/ui/paint.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-09-12 13:49:38 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-09-12 13:49:38 +0300
commit33620846cca5678fbd662ea1a48fad302727dae7 (patch)
tree322fb4ab2c1dd7dd3eceee0834f3e90d27838de4 /src/ui/paint.c
parent1410bbde7779efe3a20f603523547c8b8f55b6a1 (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/paint.c')
-rw-r--r--src/ui/paint.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/ui/paint.c b/src/ui/paint.c
index 79adb7d1..af62f908 100644
--- a/src/ui/paint.c
+++ b/src/ui/paint.c
@@ -24,6 +24,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
24 24
25#include <SDL_version.h> 25#include <SDL_version.h>
26 26
27iInt2 origin_Paint;
28
27iLocalDef SDL_Renderer *renderer_Paint_(const iPaint *d) { 29iLocalDef SDL_Renderer *renderer_Paint_(const iPaint *d) {
28 iAssert(d->dst); 30 iAssert(d->dst);
29 return d->dst->render; 31 return d->dst->render;
@@ -62,10 +64,11 @@ void endTarget_Paint(iPaint *d) {
62} 64}
63 65
64void setClip_Paint(iPaint *d, iRect rect) { 66void setClip_Paint(iPaint *d, iRect rect) {
65 rect = intersect_Rect(rect, rect_Root(get_Root())); 67 //rect = intersect_Rect(rect, rect_Root(get_Root()));
66 if (isEmpty_Rect(rect)) { 68 if (isEmpty_Rect(rect)) {
67 rect = init_Rect(0, 0, 1, 1); 69 rect = init_Rect(0, 0, 1, 1);
68 } 70 }
71 addv_I2(&rect.pos, origin_Paint);
69 SDL_RenderSetClipRect(renderer_Paint_(d), (const SDL_Rect *) &rect); 72 SDL_RenderSetClipRect(renderer_Paint_(d), (const SDL_Rect *) &rect);
70} 73}
71 74
@@ -85,6 +88,7 @@ void unsetClip_Paint(iPaint *d) {
85} 88}
86 89
87void drawRect_Paint(const iPaint *d, iRect rect, int color) { 90void drawRect_Paint(const iPaint *d, iRect rect, int color) {
91 addv_I2(&rect.pos, origin_Paint);
88 iInt2 br = bottomRight_Rect(rect); 92 iInt2 br = bottomRight_Rect(rect);
89 /* Keep the right/bottom edge visible in the window. */ 93 /* Keep the right/bottom edge visible in the window. */
90 if (br.x == d->dst->size.x) br.x--; 94 if (br.x == d->dst->size.x) br.x--;
@@ -115,11 +119,14 @@ void drawRectThickness_Paint(const iPaint *d, iRect rect, int thickness, int col
115} 119}
116 120
117void fillRect_Paint(const iPaint *d, iRect rect, int color) { 121void fillRect_Paint(const iPaint *d, iRect rect, int color) {
122 addv_I2(&rect.pos, origin_Paint);
118 setColor_Paint_(d, color); 123 setColor_Paint_(d, color);
124// printf("fillRect_Paint: %d,%d %dx%d\n", rect.pos.x, rect.pos.y, rect.size.x, rect.size.y);
119 SDL_RenderFillRect(renderer_Paint_(d), (SDL_Rect *) &rect); 125 SDL_RenderFillRect(renderer_Paint_(d), (SDL_Rect *) &rect);
120} 126}
121 127
122void drawSoftShadow_Paint(const iPaint *d, iRect inner, int thickness, int color, int alpha) { 128void drawSoftShadow_Paint(const iPaint *d, iRect inner, int thickness, int color, int alpha) {
129 addv_I2(&inner.pos, origin_Paint);
123 SDL_Renderer *render = renderer_Paint_(d); 130 SDL_Renderer *render = renderer_Paint_(d);
124 SDL_Texture *shadow = get_Window()->borderShadow; 131 SDL_Texture *shadow = get_Window()->borderShadow;
125 const iInt2 size = size_SDLTexture(shadow); 132 const iInt2 size = size_SDLTexture(shadow);
@@ -146,9 +153,14 @@ void drawSoftShadow_Paint(const iPaint *d, iRect inner, int thickness, int color
146 &(SDL_Rect){ outer.pos.x, inner.pos.y, thickness, inner.size.y }); 153 &(SDL_Rect){ outer.pos.x, inner.pos.y, thickness, inner.size.y });
147} 154}
148 155
149void drawLines_Paint(const iPaint *d, const iInt2 *points, size_t count, int color) { 156void drawLines_Paint(const iPaint *d, const iInt2 *points, size_t n, int color) {
150 setColor_Paint_(d, color); 157 setColor_Paint_(d, color);
151 SDL_RenderDrawLines(renderer_Paint_(d), (const SDL_Point *) points, count); 158 iInt2 *offsetPoints = malloc(sizeof(iInt2) * n);
159 for (size_t i = 0; i < n; i++) {
160 offsetPoints[i] = add_I2(points[i], origin_Paint);
161 }
162 SDL_RenderDrawLines(renderer_Paint_(d), (const SDL_Point *) offsetPoints, n);
163 free(offsetPoints);
152} 164}
153 165
154iInt2 size_SDLTexture(SDL_Texture *d) { 166iInt2 size_SDLTexture(SDL_Texture *d) {