summaryrefslogtreecommitdiff
path: root/src/ui/paint.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-07-21 15:06:52 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-07-21 15:07:38 +0300
commitd773b499e595a43b9b1ae449262dcf13cabf2d02 (patch)
treeb1baeb12025a04f8316636b5d0ab18e30ceedb2c /src/ui/paint.c
Initial commit
Borrowing the app skeleton from Bitwise Harmony.
Diffstat (limited to 'src/ui/paint.c')
-rw-r--r--src/ui/paint.c58
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
3iLocalDef SDL_Renderer *renderer_Paint_(const iPaint *d) {
4 iAssert(d->dst);
5 return d->dst->render;
6}
7
8static 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
13void init_Paint(iPaint *d) {
14 d->dst = get_Window();
15}
16
17void setClip_Paint(iPaint *d, iRect rect) {
18 SDL_RenderSetClipRect(renderer_Paint_(d), (const SDL_Rect *) &rect);
19}
20
21void 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
26void 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
42void 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
50void 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
55void 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}