diff options
Diffstat (limited to 'src/ui/paint.c')
-rw-r--r-- | src/ui/paint.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/ui/paint.c b/src/ui/paint.c index 85e75f15..264ca0d8 100644 --- a/src/ui/paint.c +++ b/src/ui/paint.c | |||
@@ -1,5 +1,7 @@ | |||
1 | #include "paint.h" | 1 | #include "paint.h" |
2 | 2 | ||
3 | #include <SDL_version.h> | ||
4 | |||
3 | iLocalDef SDL_Renderer *renderer_Paint_(const iPaint *d) { | 5 | iLocalDef SDL_Renderer *renderer_Paint_(const iPaint *d) { |
4 | iAssert(d->dst); | 6 | iAssert(d->dst); |
5 | return d->dst->render; | 7 | return d->dst->render; |
@@ -12,6 +14,18 @@ static void setColor_Paint_(const iPaint *d, int color) { | |||
12 | 14 | ||
13 | void init_Paint(iPaint *d) { | 15 | void init_Paint(iPaint *d) { |
14 | d->dst = get_Window(); | 16 | d->dst = get_Window(); |
17 | d->oldTarget = NULL; | ||
18 | } | ||
19 | |||
20 | void beginTarget_Paint(iPaint *d, SDL_Texture *target) { | ||
21 | SDL_Renderer *rend = renderer_Paint_(d); | ||
22 | d->oldTarget = SDL_GetRenderTarget(rend); | ||
23 | SDL_SetRenderTarget(rend, target); | ||
24 | } | ||
25 | |||
26 | void endTarget_Paint(iPaint *d) { | ||
27 | SDL_SetRenderTarget(renderer_Paint_(d), d->oldTarget); | ||
28 | d->oldTarget = NULL; | ||
15 | } | 29 | } |
16 | 30 | ||
17 | void setClip_Paint(iPaint *d, iRect rect) { | 31 | void setClip_Paint(iPaint *d, iRect rect) { |
@@ -19,8 +33,12 @@ void setClip_Paint(iPaint *d, iRect rect) { | |||
19 | } | 33 | } |
20 | 34 | ||
21 | void unsetClip_Paint(iPaint *d) { | 35 | void unsetClip_Paint(iPaint *d) { |
36 | #if SDL_VERSION_ATLEAST(2, 0, 12) | ||
37 | SDL_RenderSetClipRect(renderer_Paint_(d), NULL); | ||
38 | #else | ||
22 | const SDL_Rect winRect = { 0, 0, d->dst->root->rect.size.x, d->dst->root->rect.size.y }; | 39 | 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); | 40 | SDL_RenderSetClipRect(renderer_Paint_(d), &winRect); |
41 | #endif | ||
24 | } | 42 | } |
25 | 43 | ||
26 | void drawRect_Paint(const iPaint *d, iRect rect, int color) { | 44 | void drawRect_Paint(const iPaint *d, iRect rect, int color) { |
@@ -56,3 +74,9 @@ void drawLines_Paint(const iPaint *d, const iInt2 *points, size_t count, int col | |||
56 | setColor_Paint_(d, color); | 74 | setColor_Paint_(d, color); |
57 | SDL_RenderDrawLines(renderer_Paint_(d), (const SDL_Point *) points, count); | 75 | SDL_RenderDrawLines(renderer_Paint_(d), (const SDL_Point *) points, count); |
58 | } | 76 | } |
77 | |||
78 | iInt2 size_SDLTexture(SDL_Texture *d) { | ||
79 | iInt2 size; | ||
80 | SDL_QueryTexture(d, NULL, NULL, &size.x, &size.y); | ||
81 | return size; | ||
82 | } | ||