diff options
Diffstat (limited to 'src/ui/paint.c')
-rw-r--r-- | src/ui/paint.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/ui/paint.c b/src/ui/paint.c new file mode 100644 index 00000000..0a2e6cd3 --- /dev/null +++ b/src/ui/paint.c | |||
@@ -0,0 +1,58 @@ | |||
1 | #include "paint.h" | ||
2 | |||
3 | iLocalDef SDL_Renderer *renderer_Paint_(const iPaint *d) { | ||
4 | iAssert(d->dst); | ||
5 | return d->dst->render; | ||
6 | } | ||
7 | |||
8 | static void setColor_Paint_(const iPaint *d, int color) { | ||
9 | const iColor clr = get_Color(color & mask_ColorId); | ||
10 | SDL_SetRenderDrawColor(renderer_Paint_(d), clr.r, clr.g, clr.b, clr.a); | ||
11 | } | ||
12 | |||
13 | void init_Paint(iPaint *d) { | ||
14 | d->dst = get_Window(); | ||
15 | } | ||
16 | |||
17 | void setClip_Paint(iPaint *d, iRect rect) { | ||
18 | SDL_RenderSetClipRect(renderer_Paint_(d), (const SDL_Rect *) &rect); | ||
19 | } | ||
20 | |||
21 | void clearClip_Paint(iPaint *d) { | ||
22 | const SDL_Rect winRect = { 0, 0, d->dst->root->rect.size.x, d->dst->root->rect.size.y }; | ||
23 | SDL_RenderSetClipRect(renderer_Paint_(d), &winRect); | ||
24 | } | ||
25 | |||
26 | void drawRect_Paint(const iPaint *d, iRect rect, int color) { | ||
27 | iInt2 br = bottomRight_Rect(rect); | ||
28 | /* Keep the right/bottom edge visible in the window. */ | ||
29 | if (br.x == d->dst->root->rect.size.x) br.x--; | ||
30 | if (br.y == d->dst->root->rect.size.y) br.y--; | ||
31 | const SDL_Point edges[] = { | ||
32 | { left_Rect(rect), top_Rect(rect) }, | ||
33 | { br.x, top_Rect(rect) }, | ||
34 | { br.x, br.y }, | ||
35 | { left_Rect(rect), br.y }, | ||
36 | { left_Rect(rect), top_Rect(rect) } | ||
37 | }; | ||
38 | setColor_Paint_(d, color); | ||
39 | SDL_RenderDrawLines(renderer_Paint_(d), edges, iElemCount(edges)); | ||
40 | } | ||
41 | |||
42 | void drawRectThickness_Paint(const iPaint *d, iRect rect, int thickness, int color) { | ||
43 | thickness = iClamp(thickness, 1, 4); | ||
44 | while (thickness--) { | ||
45 | drawRect_Paint(d, rect, color); | ||
46 | shrink_Rect(&rect, one_I2()); | ||
47 | } | ||
48 | } | ||
49 | |||
50 | void fillRect_Paint(const iPaint *d, iRect rect, int color) { | ||
51 | setColor_Paint_(d, color); | ||
52 | SDL_RenderFillRect(renderer_Paint_(d), (SDL_Rect *) &rect); | ||
53 | } | ||
54 | |||
55 | void drawLines_Paint(const iPaint *d, const iInt2 *points, size_t count, int color) { | ||
56 | setColor_Paint_(d, color); | ||
57 | SDL_RenderDrawLines(renderer_Paint_(d), (const SDL_Point *) points, count); | ||
58 | } | ||