From c6182b6b4158a3227546ae55895b72a326db19fb Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Tue, 22 Sep 2020 11:36:31 +0300 Subject: Drawing with alpha blending --- src/ui/paint.c | 5 +++-- src/ui/paint.h | 1 + src/ui/text.c | 6 +++++- src/ui/text.h | 2 ++ 4 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src') 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) { static void setColor_Paint_(const iPaint *d, int color) { const iColor clr = get_Color(color & mask_ColorId); - SDL_SetRenderDrawColor(renderer_Paint_(d), clr.r, clr.g, clr.b, clr.a); + SDL_SetRenderDrawColor(renderer_Paint_(d), clr.r, clr.g, clr.b, clr.a * d->alpha / 255); } void init_Paint(iPaint *d) { - d->dst = get_Window(); + d->dst = get_Window(); d->setTarget = NULL; d->oldTarget = NULL; + d->alpha = 255; } void 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 { iWindow * dst; SDL_Texture *setTarget; SDL_Texture *oldTarget; + uint8_t alpha; }; void 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) { iRelease(d->ansiEscape); } +void setOpacity_Text(float opacity) { + SDL_SetTextureAlphaMod(text_.cache, iClamp(opacity, 0.0f, 1.0f) * 255 + 0.5f); +} + void setContentFontSize_Text(float fontSizeFactor) { fontSizeFactor *= contentScale_Text_; iAssert(fontSizeFactor > 0); @@ -490,7 +494,7 @@ static enum iFontId fontId_Text_(const iFont *font) { } iLocalDef iBool isWrapBoundary_(iChar a, iChar b) { - if (b == '/' || b == '-' || b == ',' || b == ';' || b == ':') { + if (b == '/' || b == '-' || b == ',' || b == ';' || b == ':' || b == '.') { return iTrue; } 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 { right_Alignment, }; +void setOpacity_Text (float opacity); + void draw_Text (int fontId, iInt2 pos, int color, const char *text, ...); void drawAlign_Text (int fontId, iInt2 pos, int color, enum iAlignment align, const char *text, ...); void drawCentered_Text (int fontId, iRect rect, iBool alignVisual, int color, const char *text, ...); -- cgit v1.2.3