1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

code review

This commit is contained in:
Laserlicht 2023-09-10 20:52:35 +02:00 committed by GitHub
parent 20fd0d8901
commit 2cb28178ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 17 deletions

View File

@ -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<int>(backgroundDimLevel, 0, 255));
if(backgroundDimLevel > 0)
to.drawColor(targetRect, colorToFill, false);
to.drawColorBlended(targetRect, colorToFill);
return;
}
}

View File

@ -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()

View File

@ -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<std::string> & 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();

View File

@ -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)

View File

@ -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);