From 20fd0d8901d607604aa188b8fb6d2ce8da2bb040 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 2 Sep 2023 18:35:32 +0200 Subject: [PATCH 1/2] fix cursor issue --- client/adventureMap/AdventureMapInterface.cpp | 2 +- client/render/Canvas.cpp | 4 ++-- client/render/Canvas.h | 4 ++-- client/renderSDL/SDL_Extensions.cpp | 18 ++++++++++++------ client/renderSDL/SDL_Extensions.h | 2 +- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/client/adventureMap/AdventureMapInterface.cpp b/client/adventureMap/AdventureMapInterface.cpp index af5f1a5a1..d77a939b6 100644 --- a/client/adventureMap/AdventureMapInterface.cpp +++ b/client/adventureMap/AdventureMapInterface.cpp @@ -175,7 +175,7 @@ void AdventureMapInterface::dim(Canvas & to) Rect targetRect(0, 0, GH.screenDimensions().x, GH.screenDimensions().y); ColorRGBA colorToFill(0, 0, 0, std::clamp(backgroundDimLevel, 0, 255)); if(backgroundDimLevel > 0) - to.drawColor(targetRect, colorToFill); + to.drawColor(targetRect, colorToFill, false); return; } } diff --git a/client/render/Canvas.cpp b/client/render/Canvas.cpp index bf779cc18..f087df4f8 100644 --- a/client/render/Canvas.cpp +++ b/client/render/Canvas.cpp @@ -166,11 +166,11 @@ void Canvas::drawText(const Point & position, const EFonts & font, const ColorRG } } -void Canvas::drawColor(const Rect & target, const ColorRGBA & color) +void Canvas::drawColor(const Rect & target, const ColorRGBA & color, const bool replace) { Rect realTarget = target + renderArea.topLeft(); - CSDL_Ext::fillRect(surface, realTarget, CSDL_Ext::toSDL(color)); + CSDL_Ext::fillRect(surface, realTarget, CSDL_Ext::toSDL(color), replace); } SDL_Surface * Canvas::getInternalSurface() diff --git a/client/render/Canvas.h b/client/render/Canvas.h index 773be3cae..82ea82019 100644 --- a/client/render/Canvas.h +++ b/client/render/Canvas.h @@ -93,8 +93,8 @@ public: /// renders multiple lines of text with specified parameters void drawText(const Point & position, const EFonts & font, const ColorRGBA & colorDest, ETextAlignment alignment, const std::vector & text ); - /// fills selected area with solid color - void drawColor(const Rect & target, const ColorRGBA & color); + /// fills selected area with solid color, allows replacing or overdrawing + void drawColor(const Rect & target, const ColorRGBA & color, const bool replace = true); /// Compatibility method. AVOID USAGE. To be removed once SDL abstraction layer is finished. SDL_Surface * getInternalSurface(); diff --git a/client/renderSDL/SDL_Extensions.cpp b/client/renderSDL/SDL_Extensions.cpp index 7b5e8b4c0..459f3f200 100644 --- a/client/renderSDL/SDL_Extensions.cpp +++ b/client/renderSDL/SDL_Extensions.cpp @@ -799,15 +799,21 @@ void CSDL_Ext::fillSurface( SDL_Surface *dst, const SDL_Color & color ) fillRect(dst, allSurface, color); } -void CSDL_Ext::fillRect( SDL_Surface *dst, const Rect & dstrect, const SDL_Color & color ) +void CSDL_Ext::fillRect( SDL_Surface *dst, const Rect & dstrect, const SDL_Color & color, const bool replace) { SDL_Rect newRect = CSDL_Ext::toSDL(dstrect); - uint32_t sdlColor = SDL_MapRGBA(dst->format, color.r, color.g, color.b, color.a); - SDL_Surface * tmp = SDL_CreateRGBSurface(0, newRect.w, newRect.h, dst->format->BitsPerPixel, dst->format->Rmask, dst->format->Gmask, dst->format->Bmask, dst->format->Amask); - SDL_FillRect(tmp, NULL, sdlColor); - SDL_BlitSurface(tmp, NULL, dst, &newRect); - SDL_FreeSurface(tmp); + + // replacing or overdrawing (relevant for transparency) + if(replace) + SDL_FillRect(dst, &newRect, sdlColor); + else + { + SDL_Surface * tmp = SDL_CreateRGBSurface(0, newRect.w, newRect.h, dst->format->BitsPerPixel, dst->format->Rmask, dst->format->Gmask, dst->format->Bmask, dst->format->Amask); + SDL_FillRect(tmp, NULL, sdlColor); + SDL_BlitSurface(tmp, NULL, dst, &newRect); + SDL_FreeSurface(tmp); + } } STRONG_INLINE static uint32_t mapColor(SDL_Surface * surface, SDL_Color color) diff --git a/client/renderSDL/SDL_Extensions.h b/client/renderSDL/SDL_Extensions.h index 6239c82ed..630bd09e0 100644 --- a/client/renderSDL/SDL_Extensions.h +++ b/client/renderSDL/SDL_Extensions.h @@ -58,7 +58,7 @@ using TColorPutterAlpha = void (*)(uint8_t *&, const uint8_t &, const uint8_t &, void blitSurface(SDL_Surface * src, SDL_Surface * dst, const Point & dest); void fillSurface(SDL_Surface * dst, const SDL_Color & color); - void fillRect(SDL_Surface * dst, const Rect & dstrect, const SDL_Color & color); + void fillRect(SDL_Surface * dst, const Rect & dstrect, const SDL_Color & color, const bool replace = true); void updateRect(SDL_Surface * surface, const Rect & rect); From 2cb28178aecc8fc10d5b2a2bb0d975d0e786eb28 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 10 Sep 2023 20:52:35 +0200 Subject: [PATCH 2/2] code review --- client/adventureMap/AdventureMapInterface.cpp | 2 +- client/render/Canvas.cpp | 11 +++++++-- client/render/Canvas.h | 7 ++++-- client/renderSDL/SDL_Extensions.cpp | 24 ++++++++++--------- client/renderSDL/SDL_Extensions.h | 3 ++- 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/client/adventureMap/AdventureMapInterface.cpp b/client/adventureMap/AdventureMapInterface.cpp index d77a939b6..188720cc8 100644 --- a/client/adventureMap/AdventureMapInterface.cpp +++ b/client/adventureMap/AdventureMapInterface.cpp @@ -175,7 +175,7 @@ void AdventureMapInterface::dim(Canvas & to) Rect targetRect(0, 0, GH.screenDimensions().x, GH.screenDimensions().y); ColorRGBA colorToFill(0, 0, 0, std::clamp(backgroundDimLevel, 0, 255)); if(backgroundDimLevel > 0) - to.drawColor(targetRect, colorToFill, false); + to.drawColorBlended(targetRect, colorToFill); return; } } diff --git a/client/render/Canvas.cpp b/client/render/Canvas.cpp index f087df4f8..908d5c5a6 100644 --- a/client/render/Canvas.cpp +++ b/client/render/Canvas.cpp @@ -166,11 +166,18 @@ void Canvas::drawText(const Point & position, const EFonts & font, const ColorRG } } -void Canvas::drawColor(const Rect & target, const ColorRGBA & color, const bool replace) +void Canvas::drawColor(const Rect & target, const ColorRGBA & color) { Rect realTarget = target + renderArea.topLeft(); - CSDL_Ext::fillRect(surface, realTarget, CSDL_Ext::toSDL(color), replace); + CSDL_Ext::fillRect(surface, realTarget, CSDL_Ext::toSDL(color)); +} + +void Canvas::drawColorBlended(const Rect & target, const ColorRGBA & color) +{ + Rect realTarget = target + renderArea.topLeft(); + + CSDL_Ext::fillRectBlended(surface, realTarget, CSDL_Ext::toSDL(color)); } SDL_Surface * Canvas::getInternalSurface() diff --git a/client/render/Canvas.h b/client/render/Canvas.h index 82ea82019..591e8fc07 100644 --- a/client/render/Canvas.h +++ b/client/render/Canvas.h @@ -93,8 +93,11 @@ public: /// renders multiple lines of text with specified parameters void drawText(const Point & position, const EFonts & font, const ColorRGBA & colorDest, ETextAlignment alignment, const std::vector & text ); - /// fills selected area with solid color, allows replacing or overdrawing - void drawColor(const Rect & target, const ColorRGBA & color, const bool replace = true); + /// fills selected area with solid color + void drawColor(const Rect & target, const ColorRGBA & color); + + /// fills selected area with blended color + void drawColorBlended(const Rect & target, const ColorRGBA & color); /// Compatibility method. AVOID USAGE. To be removed once SDL abstraction layer is finished. SDL_Surface * getInternalSurface(); diff --git a/client/renderSDL/SDL_Extensions.cpp b/client/renderSDL/SDL_Extensions.cpp index 459f3f200..f1717644e 100644 --- a/client/renderSDL/SDL_Extensions.cpp +++ b/client/renderSDL/SDL_Extensions.cpp @@ -799,21 +799,23 @@ void CSDL_Ext::fillSurface( SDL_Surface *dst, const SDL_Color & color ) fillRect(dst, allSurface, color); } -void CSDL_Ext::fillRect( SDL_Surface *dst, const Rect & dstrect, const SDL_Color & color, const bool replace) +void CSDL_Ext::fillRect( SDL_Surface *dst, const Rect & dstrect, const SDL_Color & color) +{ + SDL_Rect newRect = CSDL_Ext::toSDL(dstrect); + + uint32_t sdlColor = SDL_MapRGBA(dst->format, color.r, color.g, color.b, color.a); + SDL_FillRect(dst, &newRect, sdlColor); +} + +void CSDL_Ext::fillRectBlended( SDL_Surface *dst, const Rect & dstrect, const SDL_Color & color) { SDL_Rect newRect = CSDL_Ext::toSDL(dstrect); uint32_t sdlColor = SDL_MapRGBA(dst->format, color.r, color.g, color.b, color.a); - // replacing or overdrawing (relevant for transparency) - if(replace) - SDL_FillRect(dst, &newRect, sdlColor); - else - { - SDL_Surface * tmp = SDL_CreateRGBSurface(0, newRect.w, newRect.h, dst->format->BitsPerPixel, dst->format->Rmask, dst->format->Gmask, dst->format->Bmask, dst->format->Amask); - SDL_FillRect(tmp, NULL, sdlColor); - SDL_BlitSurface(tmp, NULL, dst, &newRect); - SDL_FreeSurface(tmp); - } + SDL_Surface * tmp = SDL_CreateRGBSurface(0, newRect.w, newRect.h, dst->format->BitsPerPixel, dst->format->Rmask, dst->format->Gmask, dst->format->Bmask, dst->format->Amask); + SDL_FillRect(tmp, NULL, sdlColor); + SDL_BlitSurface(tmp, NULL, dst, &newRect); + SDL_FreeSurface(tmp); } STRONG_INLINE static uint32_t mapColor(SDL_Surface * surface, SDL_Color color) diff --git a/client/renderSDL/SDL_Extensions.h b/client/renderSDL/SDL_Extensions.h index 630bd09e0..712ff5c79 100644 --- a/client/renderSDL/SDL_Extensions.h +++ b/client/renderSDL/SDL_Extensions.h @@ -58,7 +58,8 @@ using TColorPutterAlpha = void (*)(uint8_t *&, const uint8_t &, const uint8_t &, void blitSurface(SDL_Surface * src, SDL_Surface * dst, const Point & dest); void fillSurface(SDL_Surface * dst, const SDL_Color & color); - void fillRect(SDL_Surface * dst, const Rect & dstrect, const SDL_Color & color, const bool replace = true); + void fillRect(SDL_Surface * dst, const Rect & dstrect, const SDL_Color & color); + void fillRectBlended(SDL_Surface * dst, const Rect & dstrect, const SDL_Color & color); void updateRect(SDL_Surface * surface, const Rect & rect);