1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Implemeted wider lines for upscaled mode

This commit is contained in:
Ivan Savenko 2024-07-25 14:12:20 +00:00
parent 095f5b5e60
commit 6a17c08b7e
4 changed files with 21 additions and 26 deletions

View File

@ -145,19 +145,14 @@ void Canvas::drawPoint(const Point & dest, const ColorRGBA & color)
void Canvas::drawLine(const Point & from, const Point & dest, const ColorRGBA & colorFrom, const ColorRGBA & colorDest) void Canvas::drawLine(const Point & from, const Point & dest, const ColorRGBA & colorFrom, const ColorRGBA & colorDest)
{ {
CSDL_Ext::drawLine(surface, transformPos(from), transformPos(dest), CSDL_Ext::toSDL(colorFrom), CSDL_Ext::toSDL(colorDest)); CSDL_Ext::drawLine(surface, transformPos(from), transformPos(dest), CSDL_Ext::toSDL(colorFrom), CSDL_Ext::toSDL(colorDest), getScalingFactor());
}
void Canvas::drawLineDashed(const Point & from, const Point & dest, const ColorRGBA & color)
{
CSDL_Ext::drawLineDashed(surface, transformPos(from), transformPos(dest), CSDL_Ext::toSDL(color));
} }
void Canvas::drawBorder(const Rect & target, const ColorRGBA & color, int width) void Canvas::drawBorder(const Rect & target, const ColorRGBA & color, int width)
{ {
Rect realTarget = target * getScalingFactor() + renderArea.topLeft(); Rect realTarget = target * getScalingFactor() + renderArea.topLeft();
CSDL_Ext::drawBorder(surface, realTarget.x, realTarget.y, realTarget.w, realTarget.h, CSDL_Ext::toSDL(color), width); CSDL_Ext::drawBorder(surface, realTarget.x, realTarget.y, realTarget.w, realTarget.h, CSDL_Ext::toSDL(color), width * getScalingFactor());
} }
void Canvas::drawBorderDashed(const Rect & target, const ColorRGBA & color) void Canvas::drawBorderDashed(const Rect & target, const ColorRGBA & color)

View File

@ -91,9 +91,6 @@ public:
/// renders continuous, 1-pixel wide line with color gradient /// renders continuous, 1-pixel wide line with color gradient
void drawLine(const Point & from, const Point & dest, const ColorRGBA & colorFrom, const ColorRGBA & colorDest); void drawLine(const Point & from, const Point & dest, const ColorRGBA & colorFrom, const ColorRGBA & colorDest);
/// renders dashed, 1-pixel wide line with specified color
void drawLineDashed(const Point & from, const Point & dest, const ColorRGBA & color);
/// renders rectangular, solid-color border in specified location /// renders rectangular, solid-color border in specified location
void drawBorder(const Rect & target, const ColorRGBA & color, int width = 1); void drawBorder(const Rect & target, const ColorRGBA & color, int width = 1);

View File

@ -449,32 +449,35 @@ static void drawLineY(SDL_Surface * sur, int x1, int y1, int x2, int y2, const S
} }
} }
void CSDL_Ext::drawLine(SDL_Surface * sur, const Point & from, const Point & dest, const SDL_Color & color1, const SDL_Color & color2) void CSDL_Ext::drawLine(SDL_Surface * sur, const Point & from, const Point & dest, const SDL_Color & color1, const SDL_Color & color2, int thickness)
{ {
//FIXME: duplicated code with drawLineDashed //FIXME: duplicated code with drawLineDashed
int width = std::abs(from.x - dest.x); int width = std::abs(from.x - dest.x);
int height = std::abs(from.y - dest.y); int height = std::abs(from.y - dest.y);
if ( width == 0 && height == 0) if(width == 0 && height == 0)
{ {
uint8_t *p = CSDL_Ext::getPxPtr(sur, from.x, from.y); uint8_t * p = CSDL_Ext::getPxPtr(sur, from.x, from.y);
ColorPutter<4>::PutColorAlpha(p, color1); ColorPutter<4>::PutColorAlpha(p, color1);
return; return;
} }
if (width > height) for(int i = 0; i < thickness; ++i)
{ {
if ( from.x < dest.x) if(width > height)
drawLineX(sur, from.x, from.y, dest.x, dest.y, color1, color2); {
if(from.x < dest.x)
drawLineX(sur, from.x, from.y + i, dest.x, dest.y + i, color1, color2);
else else
drawLineX(sur, dest.x, dest.y, from.x, from.y, color2, color1); drawLineX(sur, dest.x, dest.y + i, from.x, from.y + i, color2, color1);
} }
else else
{ {
if ( from.y < dest.y) if(from.y < dest.y)
drawLineY(sur, from.x, from.y, dest.x, dest.y, color1, color2); drawLineY(sur, from.x + i, from.y, dest.x + i, dest.y, color1, color2);
else else
drawLineY(sur, dest.x, dest.y, from.x, from.y, color2, color1); drawLineY(sur, dest.x + i, dest.y, from.x + i, from.y, color2, color1);
}
} }
} }

View File

@ -78,7 +78,7 @@ using TColorPutterAlpha = void (*)(uint8_t *&, const uint8_t &, const uint8_t &,
int blit8bppAlphaTo24bpp(const SDL_Surface * src, const Rect & srcRect, SDL_Surface * dst, const Point & dstPoint, uint8_t alpha); //blits 8 bpp surface with alpha channel to 24 bpp surface int blit8bppAlphaTo24bpp(const SDL_Surface * src, const Rect & srcRect, SDL_Surface * dst, const Point & dstPoint, uint8_t alpha); //blits 8 bpp surface with alpha channel to 24 bpp surface
uint32_t colorTouint32_t(const SDL_Color * color); //little endian only uint32_t colorTouint32_t(const SDL_Color * color); //little endian only
void drawLine(SDL_Surface * sur, const Point & from, const Point & dest, const SDL_Color & color1, const SDL_Color & color2); void drawLine(SDL_Surface * sur, const Point & from, const Point & dest, const SDL_Color & color1, const SDL_Color & color2, int width);
void drawLineDashed(SDL_Surface * sur, const Point & from, const Point & dest, const SDL_Color & color); void drawLineDashed(SDL_Surface * sur, const Point & from, const Point & dest, const SDL_Color & color);
void drawBorder(SDL_Surface * sur, int x, int y, int w, int h, const SDL_Color & color, int depth = 1); void drawBorder(SDL_Surface * sur, int x, int y, int w, int h, const SDL_Color & color, int depth = 1);