summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-09-22 11:36:31 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-09-22 11:36:31 +0300
commitc6182b6b4158a3227546ae55895b72a326db19fb (patch)
tree8841cf408132a55959916384309b5daab844e11a /src
parentf55e327bdcdefc1c130febcc8f3a03062fba782e (diff)
Drawing with alpha blending
Diffstat (limited to 'src')
-rw-r--r--src/ui/paint.c5
-rw-r--r--src/ui/paint.h1
-rw-r--r--src/ui/text.c6
-rw-r--r--src/ui/text.h2
4 files changed, 11 insertions, 3 deletions
diff --git a/src/ui/paint.c b/src/ui/paint.c
index d0a4a579..9c6711f1 100644
--- a/src/ui/paint.c
+++ b/src/ui/paint.c
@@ -31,13 +31,14 @@ iLocalDef SDL_Renderer *renderer_Paint_(const iPaint *d) {
31 31
32static void setColor_Paint_(const iPaint *d, int color) { 32static void setColor_Paint_(const iPaint *d, int color) {
33 const iColor clr = get_Color(color & mask_ColorId); 33 const iColor clr = get_Color(color & mask_ColorId);
34 SDL_SetRenderDrawColor(renderer_Paint_(d), clr.r, clr.g, clr.b, clr.a); 34 SDL_SetRenderDrawColor(renderer_Paint_(d), clr.r, clr.g, clr.b, clr.a * d->alpha / 255);
35} 35}
36 36
37void init_Paint(iPaint *d) { 37void init_Paint(iPaint *d) {
38 d->dst = get_Window(); 38 d->dst = get_Window();
39 d->setTarget = NULL; 39 d->setTarget = NULL;
40 d->oldTarget = NULL; 40 d->oldTarget = NULL;
41 d->alpha = 255;
41} 42}
42 43
43void beginTarget_Paint(iPaint *d, SDL_Texture *target) { 44void beginTarget_Paint(iPaint *d, SDL_Texture *target) {
diff --git a/src/ui/paint.h b/src/ui/paint.h
index 28931815..89a01da6 100644
--- a/src/ui/paint.h
+++ b/src/ui/paint.h
@@ -33,6 +33,7 @@ struct Impl_Paint {
33 iWindow * dst; 33 iWindow * dst;
34 SDL_Texture *setTarget; 34 SDL_Texture *setTarget;
35 SDL_Texture *oldTarget; 35 SDL_Texture *oldTarget;
36 uint8_t alpha;
36}; 37};
37 38
38void init_Paint (iPaint *); 39void init_Paint (iPaint *);
diff --git a/src/ui/text.c b/src/ui/text.c
index 8d4661ac..b2110bb6 100644
--- a/src/ui/text.c
+++ b/src/ui/text.c
@@ -302,6 +302,10 @@ void deinit_Text(void) {
302 iRelease(d->ansiEscape); 302 iRelease(d->ansiEscape);
303} 303}
304 304
305void setOpacity_Text(float opacity) {
306 SDL_SetTextureAlphaMod(text_.cache, iClamp(opacity, 0.0f, 1.0f) * 255 + 0.5f);
307}
308
305void setContentFontSize_Text(float fontSizeFactor) { 309void setContentFontSize_Text(float fontSizeFactor) {
306 fontSizeFactor *= contentScale_Text_; 310 fontSizeFactor *= contentScale_Text_;
307 iAssert(fontSizeFactor > 0); 311 iAssert(fontSizeFactor > 0);
@@ -490,7 +494,7 @@ static enum iFontId fontId_Text_(const iFont *font) {
490} 494}
491 495
492iLocalDef iBool isWrapBoundary_(iChar a, iChar b) { 496iLocalDef iBool isWrapBoundary_(iChar a, iChar b) {
493 if (b == '/' || b == '-' || b == ',' || b == ';' || b == ':') { 497 if (b == '/' || b == '-' || b == ',' || b == ';' || b == ':' || b == '.') {
494 return iTrue; 498 return iTrue;
495 } 499 }
496 return !isSpace_Char(a) && isSpace_Char(b); 500 return !isSpace_Char(a) && isSpace_Char(b);
diff --git a/src/ui/text.h b/src/ui/text.h
index 7dc4aa38..71c2ba43 100644
--- a/src/ui/text.h
+++ b/src/ui/text.h
@@ -130,6 +130,8 @@ enum iAlignment {
130 right_Alignment, 130 right_Alignment,
131}; 131};
132 132
133void setOpacity_Text (float opacity);
134
133void draw_Text (int fontId, iInt2 pos, int color, const char *text, ...); 135void draw_Text (int fontId, iInt2 pos, int color, const char *text, ...);
134void drawAlign_Text (int fontId, iInt2 pos, int color, enum iAlignment align, const char *text, ...); 136void drawAlign_Text (int fontId, iInt2 pos, int color, enum iAlignment align, const char *text, ...);
135void drawCentered_Text (int fontId, iRect rect, iBool alignVisual, int color, const char *text, ...); 137void drawCentered_Text (int fontId, iRect rect, iBool alignVisual, int color, const char *text, ...);