From 0a72cb144d8b3b87ed5065b58ad267d579c23fb7 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Wed, 13 Mar 2019 11:00:09 +0100 Subject: [PATCH] Fix many warnings (mostly sign conversion) --- CIO/CFont.cpp | 4 +- CSurface.cpp | 4 +- SGE/sge_blib.cpp | 199 ++++++++++++++++------------------------- SGE/sge_bm_text.cpp | 17 ++-- SGE/sge_bm_text.h | 21 ++--- SGE/sge_collision.cpp | 21 +++-- SGE/sge_internal.h | 7 ++ SGE/sge_misc.cpp | 2 +- SGE/sge_primitives.cpp | 146 +++++++++++++++--------------- SGE/sge_primitives.h | 64 ++++++------- SGE/sge_shape.h | 4 +- SGE/sge_surface.cpp | 5 ++ SGE/sge_surface.h | 3 +- SGE/sge_textpp.cpp | 12 +-- 14 files changed, 234 insertions(+), 275 deletions(-) diff --git a/CIO/CFont.cpp b/CIO/CFont.cpp index c233f34..237b484 100644 --- a/CIO/CFont.cpp +++ b/CIO/CFont.cpp @@ -284,7 +284,7 @@ bool CFont::writeText(SDL_Surface* Surf_Dest, const char* string, int x, int y, // the index for the chiffre-picture in the global::bmpArray unsigned int chiffre_index = 0; // pointer to the chiffres - unsigned char* chiffre = (unsigned char*)string; + auto* chiffre = (const unsigned char*)string; // counter for the drawed pixels (cause we dont want to draw outside of the surface) int pos_x = x; int pos_y = y; @@ -450,7 +450,7 @@ bool CFont::writeText(SDL_Surface* Surf_Dest, const char* string, int x, int y, // if this was the last chiffre go in normal mode and write the text to the specified position if(*chiffre == '\0') { - chiffre = (unsigned char*)string; + chiffre = (const unsigned char*)string; if(align == ALIGN_MIDDLE) pos_x = x - (unsigned int)(pixel_ctr_w / 2); diff --git a/CSurface.cpp b/CSurface.cpp index e767686..58e9aaf 100644 --- a/CSurface.cpp +++ b/CSurface.cpp @@ -126,7 +126,7 @@ void CSurface::DrawPixel_Color(SDL_Surface* screen, int x, int y, Uint32 color) case 2: *(Uint16*)p = color; break; case 3: - if(SDL_BYTEORDER == SDL_LIL_ENDIAN) + if((SDL_BYTEORDER) == SDL_LIL_ENDIAN) { p[0] = color; p[1] = color >> 8; @@ -169,7 +169,7 @@ Uint32 CSurface::GetPixel(SDL_Surface* surface, int x, int y) case 2: return *(Uint16*)p; case 3: - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) + if((SDL_BYTEORDER) == SDL_BIG_ENDIAN) return p[0] << 16 | p[1] << 8 | p[2]; else return p[0] | p[1] << 8 | p[2] << 16; diff --git a/SGE/sge_blib.cpp b/SGE/sge_blib.cpp index ba2fa4b..add9ed5 100644 --- a/SGE/sge_blib.cpp +++ b/SGE/sge_blib.cpp @@ -22,7 +22,11 @@ #include "sge_blib.h" #include "sge_primitives.h" #include "sge_surface.h" +#include #include +#include + +using boost::numeric_cast; #define SWAP(x, y, temp) \ temp = x; \ @@ -45,9 +49,39 @@ extern void _AAmcLineAlpha(SDL_Surface* dst, Sint16 x1, Sint16 y1, Sint16 x2, Si Uint8 b2, Uint8 alpha); /* Macro to inline RGB mapping */ -#define MapRGB(format, r, g, b) \ - ((r) >> format->Rloss) << format->Rshift | ((g) >> format->Gloss) << format->Gshift | ((b) >> format->Bloss) << format->Bshift +static constexpr Uint32 MapRGB(const SDL_PixelFormat& format, Uint8 r, Uint8 g, Uint8 b) +{ + return ((Uint32)r >> format.Rloss) << format.Rshift | ((Uint32)g >> format.Gloss) << format.Gshift + | ((Uint32)b >> format.Bloss) << format.Bshift | format.Amask; +} +static constexpr Uint32 MapRGBFixPoint(const SDL_PixelFormat& format, Sint32 R, Sint32 G, Sint32 B) +{ + return MapRGB(format, static_cast(R >> 16), static_cast(G >> 16), static_cast(B >> 16)); +} + +/*static constexpr Uint8 GetR(const SDL_PixelFormat& format, Uint32 value) +{ + return (value & format.Rmask) >> format.Rshift; +} +static constexpr Uint8 GetG(const SDL_PixelFormat& format, Uint32 value) +{ + return (value & format.Gmask) >> format.Gshift; +} +static constexpr Uint8 GetB(const SDL_PixelFormat& format, Uint32 value) +{ + return (value & format.Bmask) >> format.Bshift; +}*/ +static constexpr Uint32 ScaleRGB(const SDL_PixelFormat& format, Uint32 value, Sint32 factor) +{ + const auto r = ((static_cast((value & format.Rmask) >> format.Rshift) * factor) >> 16); + const auto g = ((static_cast((value & format.Gmask) >> format.Gshift) * factor) >> 16); + const auto b = ((static_cast((value & format.Bmask) >> format.Bshift) * factor) >> 16); + const auto r8 = (Uint8)(r > 255 ? 255 : (r < 0 ? 0 : r)); + const auto g8 = (Uint8)(g > 255 ? 255 : (g < 0 ? 0 : g)); + const auto b8 = (Uint8)(b > 255 ? 255 : (b < 0 ? 0 : b)); + return MapRGB(format, r8, g8, b8); +} //================================================================================== // Draws a horisontal line, fading the colors //================================================================================== @@ -119,7 +153,7 @@ void _FadedLine(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 y, Uint8 r1, Uin { pixel = row + x; - *pixel = MapRGB(dest->format, R >> 16, G >> 16, B >> 16); + *pixel = MapRGBFixPoint(*dest->format, R, G, B); R += rstep; G += gstep; @@ -161,7 +195,7 @@ void _FadedLine(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 y, Uint8 r1, Uin { pixel = row + x; - *pixel = MapRGB(dest->format, R >> 16, G >> 16, B >> 16); + *pixel = MapRGBFixPoint(*dest->format, R, G, B); R += rstep; G += gstep; @@ -187,10 +221,7 @@ void sge_FadedLine(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 y, Uint8 r1, { return; } - if(x1 > x2) - sge_UpdateRect(dest, x1, y, x1 - x2 + 1, 1); - else - sge_UpdateRect(dest, x1, y, x2 - x1 + 1, 1); + sge_UpdateRect(dest, x1, y, absDiff(x1, x2) + 1, 1); } //================================================================================== @@ -358,7 +389,7 @@ void _TexturedLine(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 y, SDL_Surfac pixel = row + x; SDL_GetRGB(sge_GetPixel(source, srcx >> 16, srcy >> 16), source->format, &r, &g, &b); - *pixel = MapRGB(dest->format, r, g, b); + *pixel = MapRGB(*dest->format, r, g, b); srcx += xstep; srcy += ystep; @@ -401,7 +432,7 @@ void _TexturedLine(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 y, SDL_Surfac pixel = row + x; SDL_GetRGB(sge_GetPixel(source, srcx >> 16, srcy >> 16), source->format, &r, &g, &b); - *pixel = MapRGB(dest->format, r, g, b); + *pixel = MapRGB(*dest->format, r, g, b); srcx += xstep; srcy += ystep; @@ -530,7 +561,7 @@ void _FadedTexturedLine(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 y, SDL_S case 4: { /* Probably 32-bpp */ - Uint32* row = (Uint32*)dest->pixels + y * dest->pitch / sizeof(Uint32); + Uint32* row = (Uint32*)dest->pixels + (Uint32)y * dest->pitch / sizeof(Uint32); Uint16 pitch = source->pitch / sizeof(Uint32); @@ -560,14 +591,7 @@ void _FadedTexturedLine(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 y, SDL_S */ Uint32 pixel_value = *((Uint32*)source->pixels + (srcy >> 16) * pitch + (srcx >> 16)); - Sint16 r = (((pixel_value & srcFormat.Rmask) >> srcFormat.Rshift) * I) >> 16; - Sint16 g = (((pixel_value & srcFormat.Gmask) >> srcFormat.Gshift) * I) >> 16; - Sint16 b = (((pixel_value & srcFormat.Bmask) >> srcFormat.Bshift) * I) >> 16; - Uint8 r8 = (Uint8)(r > 255 ? 255 : (r < 0 ? 0 : r)); - Uint8 g8 = (Uint8)(g > 255 ? 255 : (g < 0 ? 0 : g)); - Uint8 b8 = (Uint8)(b > 255 ? 255 : (b < 0 ? 0 : b)); - //*pixel = SDL_MapRGB( dest->format, r1>>16, g1>>16, b1>>16 ); - *pixel = ((r8 << dstFormat.Rshift) + (g8 << dstFormat.Gshift) + (b8 << dstFormat.Bshift)); + *pixel = ScaleRGB(dstFormat, pixel_value, I); I += istep; @@ -613,7 +637,7 @@ void _FadedTexturedLine(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 y, SDL_S pixel = row + x; SDL_GetRGB(sge_GetPixel(source, srcx >> 16, srcy >> 16), &srcFormat, &r, &g, &b); - *pixel = MapRGB(dest->format, r, g, b); + *pixel = MapRGB(*dest->format, r, g, b); srcx += xstep; srcy += ystep; @@ -656,7 +680,7 @@ void _FadedTexturedLine(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 y, SDL_S pixel = row + x; SDL_GetRGB(sge_GetPixel(source, srcx >> 16, srcy >> 16), &srcFormat, &r, &g, &b); - *pixel = MapRGB(dest->format, r, g, b); + *pixel = MapRGB(*dest->format, r, g, b); srcx += xstep; srcy += ystep; @@ -760,7 +784,7 @@ void _FadedTexturedLineColorKey(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 case 3: { /* Slow 24-bpp mode, usually not used */ Uint8 *pixel, *srcpixel; - Uint8* row = (Uint8*)dest->pixels + y * dest->pitch; + Uint8* row = (Uint8*)dest->pixels + (Uint32)y * dest->pitch; Uint8 rshift8 = dstFormat.Rshift / 8; Uint8 gshift8 = dstFormat.Gshift / 8; @@ -789,10 +813,6 @@ void _FadedTexturedLineColorKey(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 Uint16 pitch = source->pitch / 4; - Uint8 r8, g8, b8; - Sint16 r, g, b; - // Uint32 r1,g1,b1; - for(x = x1; x <= x2; x++) { pixel = row + x; @@ -805,14 +825,7 @@ void _FadedTexturedLineColorKey(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 pixel_value = *((Uint32*)source->pixels + (srcy >> 16) * pitch + (srcx >> 16)); if(pixel_value != source->format->colorkey) { - r = ((((pixel_value & dstFormat.Rmask) >> dstFormat.Rshift) * I) >> 16); - g = ((((pixel_value & dstFormat.Gmask) >> dstFormat.Gshift) * I) >> 16); - b = ((((pixel_value & dstFormat.Bmask) >> dstFormat.Bshift) * I) >> 16); - r8 = (Uint8)(r > 255 ? 255 : (r < 0 ? 0 : r)); - g8 = (Uint8)(g > 255 ? 255 : (g < 0 ? 0 : g)); - b8 = (Uint8)(b > 255 ? 255 : (b < 0 ? 0 : b)); - //*pixel = SDL_MapRGB( dest->format, r1>>16, g1>>16, b1>>16 ); - *pixel = ((r8 << dstFormat.Rshift) + (g8 << dstFormat.Gshift) + (b8 << dstFormat.Bshift)); + *pixel = ScaleRGB(dstFormat, pixel_value, I); } I += istep; @@ -859,7 +872,7 @@ void _FadedTexturedLineColorKey(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 pixel = row + x; SDL_GetRGB(sge_GetPixel(source, srcx >> 16, srcy >> 16), source->format, &r, &g, &b); - *pixel = MapRGB(dest->format, r, g, b); + *pixel = MapRGB(*dest->format, r, g, b); srcx += xstep; srcy += ystep; @@ -902,7 +915,7 @@ void _FadedTexturedLineColorKey(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 pixel = row + x; SDL_GetRGB(sge_GetPixel(source, srcx >> 16, srcy >> 16), source->format, &r, &g, &b); - *pixel = MapRGB(dest->format, r, g, b); + *pixel = MapRGB(*dest->format, r, g, b); srcx += xstep; srcy += ystep; @@ -1039,8 +1052,6 @@ void _PreCalcFadedTexturedLine(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 y Uint16 pitch = source->pitch / 4; - Uint8 r8, g8, b8; - Sint16 r, g, b; // Uint32 r1,g1,b1; for(x = x1; x <= x2; x++) @@ -1051,17 +1062,8 @@ void _PreCalcFadedTexturedLine(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 y // r1=r*I; // g1=g*I; // b1=b*I; - r = ((((*((Uint32*)source->pixels + (srcy >> 16) * pitch + (srcx >> 16)) & dstFormat.Rmask) >> dstFormat.Rshift) * I) - >> 16); - g = ((((*((Uint32*)source->pixels + (srcy >> 16) * pitch + (srcx >> 16)) & dstFormat.Gmask) >> dstFormat.Gshift) * I) - >> 16); - b = ((((*((Uint32*)source->pixels + (srcy >> 16) * pitch + (srcx >> 16)) & dstFormat.Bmask) >> dstFormat.Bshift) * I) - >> 16); - r8 = (Uint8)(r > 255 ? 255 : (r < 0 ? 0 : r)); - g8 = (Uint8)(g > 255 ? 255 : (g < 0 ? 0 : g)); - b8 = (Uint8)(b > 255 ? 255 : (b < 0 ? 0 : b)); - //*pixel = SDL_MapRGB( dest->format, r1>>16, g1>>16, b1>>16 ); - *pixel = ((r8 << dstFormat.Rshift) + (g8 << dstFormat.Gshift) + (b8 << dstFormat.Bshift)); + const auto pixel_value = *((Uint32*)source->pixels + (srcy >> 16) * pitch + (srcx >> 16)); + *pixel = ScaleRGB(dstFormat, pixel_value, I); I += istep; @@ -1107,7 +1109,7 @@ void _PreCalcFadedTexturedLine(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 y pixel = row + x; SDL_GetRGB(sge_GetPixel(source, srcx >> 16, srcy >> 16), source->format, &r, &g, &b); - *pixel = MapRGB(dest->format, r, g, b); + *pixel = MapRGB(*dest->format, r, g, b); srcx += xstep; srcy += ystep; @@ -1150,7 +1152,7 @@ void _PreCalcFadedTexturedLine(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 y pixel = row + x; SDL_GetRGB(sge_GetPixel(source, srcx >> 16, srcy >> 16), source->format, &r, &g, &b); - *pixel = MapRGB(dest->format, r, g, b); + *pixel = MapRGB(*dest->format, r, g, b); srcx += xstep; srcy += ystep; @@ -1293,10 +1295,6 @@ void _PreCalcFadedTexturedLineColorKey(SDL_Surface* dest, Sint16 x1, Sint16 x2, Uint16 pitch = source->pitch / 4; - Uint8 r8, g8, b8; - Sint16 r, g, b; - // Uint32 r1,g1,b1; - for(x = x1; x <= x2; x++) { pixel = row + x; @@ -1305,17 +1303,8 @@ void _PreCalcFadedTexturedLineColorKey(SDL_Surface* dest, Sint16 x1, Sint16 x2, // r1=r*I; // g1=g*I; // b1=b*I; - r = ((((*((Uint32*)source->pixels + (srcy >> 16) * pitch + (srcx >> 16)) & dstFormat.Rmask) >> dstFormat.Rshift) * I) - >> 16); - g = ((((*((Uint32*)source->pixels + (srcy >> 16) * pitch + (srcx >> 16)) & dstFormat.Gmask) >> dstFormat.Gshift) * I) - >> 16); - b = ((((*((Uint32*)source->pixels + (srcy >> 16) * pitch + (srcx >> 16)) & dstFormat.Bmask) >> dstFormat.Bshift) * I) - >> 16); - r8 = (Uint8)(r > 255 ? 255 : (r < 0 ? 0 : r)); - g8 = (Uint8)(g > 255 ? 255 : (g < 0 ? 0 : g)); - b8 = (Uint8)(b > 255 ? 255 : (b < 0 ? 0 : b)); - //*pixel = SDL_MapRGB( dest->format, r1>>16, g1>>16, b1>>16 ); - *pixel = ((r8 << dstFormat.Rshift) + (g8 << dstFormat.Gshift) + (b8 << dstFormat.Bshift)); + const auto pixel_value = *((Uint32*)source->pixels + (srcy >> 16) * pitch + (srcx >> 16)); + *pixel = ScaleRGB(dstFormat, pixel_value, I); I += istep; @@ -1361,7 +1350,7 @@ void _PreCalcFadedTexturedLineColorKey(SDL_Surface* dest, Sint16 x1, Sint16 x2, pixel = row + x; SDL_GetRGB(sge_GetPixel(source, srcx >> 16, srcy >> 16), source->format, &r, &g, &b); - *pixel = MapRGB(dest->format, r, g, b); + *pixel = MapRGB(*dest->format, r, g, b); srcx += xstep; srcy += ystep; @@ -1404,7 +1393,7 @@ void _PreCalcFadedTexturedLineColorKey(SDL_Surface* dest, Sint16 x1, Sint16 x2, pixel = row + x; SDL_GetRGB(sge_GetPixel(source, srcx >> 16, srcy >> 16), source->format, &r, &g, &b); - *pixel = MapRGB(dest->format, r, g, b); + *pixel = MapRGB(*dest->format, r, g, b); srcx += xstep; srcy += ystep; @@ -1557,29 +1546,12 @@ void _PreCalcFadedTexturedLineColorKeys(SDL_Surface* dest, Sint16 x1, Sint16 x2, Uint16 pitch = source->pitch / 4; - Uint8 r8, g8, b8; - Sint16 r, g, b; - // Uint32 r1,g1,b1; - for(x = x1; x <= x2; x++) { pixel = row + x; - // SDL_GetRGB(*((Uint32 *)source->pixels + (srcy>>16)*pitch + (srcx>>16)), source->format, &r, &g, &b); - // r1=r*I; - // g1=g*I; - // b1=b*I; - r = ((((*((Uint32*)source->pixels + (srcy >> 16) * pitch + (srcx >> 16)) & dstFormat.Rmask) >> dstFormat.Rshift) * I) - >> 16); - g = ((((*((Uint32*)source->pixels + (srcy >> 16) * pitch + (srcx >> 16)) & dstFormat.Gmask) >> dstFormat.Gshift) * I) - >> 16); - b = ((((*((Uint32*)source->pixels + (srcy >> 16) * pitch + (srcx >> 16)) & dstFormat.Bmask) >> dstFormat.Bshift) * I) - >> 16); - r8 = (Uint8)(r > 255 ? 255 : (r < 0 ? 0 : r)); - g8 = (Uint8)(g > 255 ? 255 : (g < 0 ? 0 : g)); - b8 = (Uint8)(b > 255 ? 255 : (b < 0 ? 0 : b)); - //*pixel = SDL_MapRGB( dest->format, r1>>16, g1>>16, b1>>16 ); - *pixel = ((r8 << dstFormat.Rshift) + (g8 << dstFormat.Gshift) + (b8 << dstFormat.Bshift)); + const auto pixel_value = *((Uint32*)source->pixels + (srcy >> 16) * pitch + (srcx >> 16)); + *pixel = ScaleRGB(dstFormat, pixel_value, I); I += istep; @@ -1625,7 +1597,7 @@ void _PreCalcFadedTexturedLineColorKeys(SDL_Surface* dest, Sint16 x1, Sint16 x2, pixel = row + x; SDL_GetRGB(sge_GetPixel(source, srcx >> 16, srcy >> 16), source->format, &r, &g, &b); - *pixel = MapRGB(dest->format, r, g, b); + *pixel = MapRGB(*dest->format, r, g, b); srcx += xstep; srcy += ystep; @@ -1668,7 +1640,7 @@ void _PreCalcFadedTexturedLineColorKeys(SDL_Surface* dest, Sint16 x1, Sint16 x2, pixel = row + x; SDL_GetRGB(sge_GetPixel(source, srcx >> 16, srcy >> 16), source->format, &r, &g, &b); - *pixel = MapRGB(dest->format, r, g, b); + *pixel = MapRGB(*dest->format, r, g, b); srcx += xstep; srcy += ystep; @@ -1802,10 +1774,6 @@ void _FadedTexturedLineColorKeys(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 Uint16 pitch = source->pitch / 4; - Uint8 r8, g8, b8; - Sint16 r, g, b; - // Uint32 r1,g1,b1; - for(x = x1; x <= x2; x++) { isColorKey = false; @@ -1825,18 +1793,7 @@ void _FadedTexturedLineColorKeys(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 if(!isColorKey) { - // SDL_GetRGB(*((Uint32 *)source->pixels + (srcy>>16)*pitch + (srcx>>16)), source->format, &r, &g, &b); - // r1=r*I; - // g1=g*I; - // b1=b*I; - r = ((((pixel_value & dstFormat.Rmask) >> dstFormat.Rshift) * I) >> 16); - g = ((((pixel_value & dstFormat.Gmask) >> dstFormat.Gshift) * I) >> 16); - b = ((((pixel_value & dstFormat.Bmask) >> dstFormat.Bshift) * I) >> 16); - r8 = (Uint8)(r > 255 ? 255 : (r < 0 ? 0 : r)); - g8 = (Uint8)(g > 255 ? 255 : (g < 0 ? 0 : g)); - b8 = (Uint8)(b > 255 ? 255 : (b < 0 ? 0 : b)); - //*pixel = SDL_MapRGB( dest->format, r1>>16, g1>>16, b1>>16 ); - *pixel = ((r8 << dstFormat.Rshift) + (g8 << dstFormat.Gshift) + (b8 << dstFormat.Bshift)); + *pixel = ScaleRGB(dstFormat, pixel_value, I); } I += istep; @@ -1883,7 +1840,7 @@ void _FadedTexturedLineColorKeys(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 pixel = row + x; SDL_GetRGB(sge_GetPixel(source, srcx >> 16, srcy >> 16), source->format, &r, &g, &b); - *pixel = MapRGB(dest->format, r, g, b); + *pixel = MapRGB(*dest->format, r, g, b); srcx += xstep; srcy += ystep; @@ -1926,7 +1883,7 @@ void _FadedTexturedLineColorKeys(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 pixel = row + x; SDL_GetRGB(sge_GetPixel(source, srcx >> 16, srcy >> 16), source->format, &r, &g, &b); - *pixel = MapRGB(dest->format, r, g, b); + *pixel = MapRGB(*dest->format, r, g, b); srcx += xstep; srcy += ystep; @@ -1958,10 +1915,7 @@ void sge_TexturedLine(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 y, SDL_Sur { return; } - if(x1 > x2) - sge_UpdateRect(dest, x1, y, x1 - x2 + 1, 1); - else - sge_UpdateRect(dest, x1, y, x2 - x1 + 1, 1); + sge_UpdateRect(dest, x1, y, absDiff(x1, x2) + 1, 1); } void sge_FadedTexturedLine(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 y, SDL_Surface* source, Sint16 sx1, Sint16 sy1, Sint16 sx2, @@ -1985,10 +1939,7 @@ void sge_FadedTexturedLine(SDL_Surface* dest, Sint16 x1, Sint16 x2, Sint16 y, SD { return; } - if(x1 > x2) - sge_UpdateRect(dest, x1, y, x1 - x2 + 1, 1); - else - sge_UpdateRect(dest, x1, y, x2 - x1 + 1, 1); + sge_UpdateRect(dest, x1, y, absDiff(x1, x2) + 1, 1); } //================================================================================== @@ -2022,7 +1973,7 @@ void sge_Trigon(SDL_Surface* dest, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, S xmin = (xmin < x3) ? xmin : x3; ymin = (ymin < y3) ? ymin : y3; - sge_UpdateRect(dest, xmin, ymin, xmax - xmin + 1, ymax - ymin + 1); + sge_UpdateRect(dest, xmin, ymin, numeric_cast(xmax - xmin + 1), numeric_cast(ymax - ymin + 1)); } void sge_Trigon(SDL_Surface* dest, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint8 R, Uint8 G, Uint8 B) @@ -2061,7 +2012,7 @@ void sge_TrigonAlpha(SDL_Surface* dest, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 xmin = (xmin < x3) ? xmin : x3; ymin = (ymin < y3) ? ymin : y3; - sge_UpdateRect(dest, xmin, ymin, xmax - xmin + 1, ymax - ymin + 1); + sge_UpdateRect(dest, xmin, ymin, numeric_cast(xmax - xmin + 1), numeric_cast(ymax - ymin + 1)); } void sge_TrigonAlpha(SDL_Surface* dest, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint8 R, Uint8 G, Uint8 B, @@ -2214,7 +2165,7 @@ void sge_FilledTrigon(SDL_Surface* dest, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 xmax = (xmax > x3) ? xmax : x3; xmin = (xmin < x3) ? xmin : x3; - sge_UpdateRect(dest, xmin, y1, xmax - xmin + 1, y3 - y1 + 1); + sge_UpdateRect(dest, xmin, y1, numeric_cast(xmax - xmin + 1), numeric_cast(y3 - y1 + 1)); } void sge_FilledTrigon(SDL_Surface* dest, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint8 R, Uint8 G, Uint8 B) @@ -2307,7 +2258,7 @@ void sge_FilledTrigonAlpha(SDL_Surface* dest, Sint16 x1, Sint16 y1, Sint16 x2, S xmax = (xmax > x3) ? xmax : x3; xmin = (xmin < x3) ? xmin : x3; - sge_UpdateRect(dest, xmin, y1, xmax - xmin + 1, y3 - y1 + 1); + sge_UpdateRect(dest, xmin, y1, numeric_cast(xmax - xmin + 1), numeric_cast(y3 - y1 + 1)); } void sge_FilledTrigonAlpha(SDL_Surface* dest, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint8 R, Uint8 G, Uint8 B, @@ -2618,7 +2569,7 @@ void sge_TexturedTrigon(SDL_Surface* dest, Sint16 x1, Sint16 y1, Sint16 x2, Sint xmax = (xmax > x3) ? xmax : x3; xmin = (xmin < x3) ? xmin : x3; - sge_UpdateRect(dest, xmin, y1, xmax - xmin + 1, y3 - y1 + 1); + sge_UpdateRect(dest, xmin, y1, numeric_cast(xmax - xmin + 1), numeric_cast(y3 - y1 + 1)); } //================================================================================== @@ -2797,7 +2748,7 @@ void sge_FadedTexturedTrigon(SDL_Surface* dest, Sint16 x1, Sint16 y1, Sint16 x2, xmax = (xmax > x3) ? xmax : x3; xmin = (xmin < x3) ? xmin : x3; - sge_UpdateRect(dest, xmin, y1, xmax - xmin + 1, y3 - y1 + 1); + sge_UpdateRect(dest, xmin, y1, numeric_cast(xmax - xmin + 1), numeric_cast(y3 - y1 + 1)); } //================================================================================== @@ -2983,7 +2934,7 @@ void sge_PreCalcFadedTexturedTrigon(SDL_Surface* dest, Sint16 x1, Sint16 y1, Sin xmax = (xmax > x3) ? xmax : x3; xmin = (xmin < x3) ? xmin : x3; - sge_UpdateRect(dest, xmin, y1, xmax - xmin + 1, y3 - y1 + 1); + sge_UpdateRect(dest, xmin, y1, numeric_cast(xmax - xmin + 1), numeric_cast(y3 - y1 + 1)); } //================================================================================== @@ -3940,14 +3891,14 @@ class pline { public: virtual ~pline() = default; + pline* next; + Sint16 x1, x2, y1, y2; Sint32 fx, fm; Sint16 x; - pline* next; - virtual void update() { x = Sint16(fx >> 16); diff --git a/SGE/sge_bm_text.cpp b/SGE/sge_bm_text.cpp index e77feea..c860514 100644 --- a/SGE/sge_bm_text.cpp +++ b/SGE/sge_bm_text.cpp @@ -229,7 +229,7 @@ sge_bmpFont* sge_BF_OpenFont(char* file, Uint8 flags) // Draws string to surface with the selected font // Returns pos. and size of the drawn text //================================================================================== -SDL_Rect sge_BF_textout(SDL_Surface* surface, sge_bmpFont* font, char* string, Sint16 x, Sint16 y) +SDL_Rect sge_BF_textout(SDL_Surface* surface, sge_bmpFont* font, const char* string, Sint16 x, Sint16 y) { SDL_Rect ret; ret.x = 0; @@ -283,7 +283,7 @@ SDL_Rect sge_BF_textout(SDL_Surface* surface, sge_bmpFont* font, char* string, S ret.x = x; ret.y = y; - ret.w = xdest - x + font->CharWidth; + ret.w = static_cast(xdest - x) + font->CharWidth; ret.h = font->CharHeight; if(surface) @@ -295,7 +295,7 @@ SDL_Rect sge_BF_textout(SDL_Surface* surface, sge_bmpFont* font, char* string, S //================================================================================== // Returns the size (w and h) of the string (if rendered with font) //================================================================================== -SDL_Rect sge_BF_TextSize(sge_bmpFont* font, char* string) +SDL_Rect sge_BF_TextSize(sge_bmpFont* font, const char* string) { return sge_BF_textout(nullptr, font, string, 0, 0); } @@ -305,7 +305,7 @@ SDL_Rect sge_BF_TextSize(sge_bmpFont* font, char* string) // Returns pos. and size of the drawn text // * just like printf(char *format, ...) * //================================================================================== -SDL_Rect sge_BF_textoutf(SDL_Surface* surface, sge_bmpFont* font, Sint16 x, Sint16 y, char* format, ...) +SDL_Rect sge_BF_textoutf(SDL_Surface* surface, sge_bmpFont* font, Sint16 x, Sint16 y, const char* format, ...) { char buf[256]; @@ -464,7 +464,8 @@ void sge_BF_SetAlpha(sge_bmpFont* font, Uint8 alpha) //================================================================================== // BitmapText input //================================================================================== -int sge_BF_inputAlpha(SDL_Surface* screen, sge_bmpFont* font, char* string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y, int Alpha) +int sge_BF_inputAlpha(SDL_Surface* screen, sge_bmpFont* font, char* string, Uint8 flags, int pos, unsigned len, Sint16 x, Sint16 y, + int Alpha) { if(pos == 0 && len > 0) string[0] = '\0'; @@ -481,7 +482,7 @@ int sge_BF_inputAlpha(SDL_Surface* screen, sge_bmpFont* font, char* string, Uint return ret; } -int sge_BF_inputAlpha_UNI(SDL_Surface* screen, sge_bmpFont* font, Uint16* string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y, +int sge_BF_inputAlpha_UNI(SDL_Surface* screen, sge_bmpFont* font, Uint16* string, Uint8 flags, int pos, unsigned len, Sint16 x, Sint16 y, int Alpha) { sge_TextSurface text(screen, "", x, y); @@ -505,12 +506,12 @@ int sge_BF_inputAlpha_UNI(SDL_Surface* screen, sge_bmpFont* font, Uint16* string return ret; } -int sge_BF_input(SDL_Surface* screen, sge_bmpFont* font, char* string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y) +int sge_BF_input(SDL_Surface* screen, sge_bmpFont* font, char* string, Uint8 flags, int pos, unsigned len, Sint16 x, Sint16 y) { return sge_BF_inputAlpha(screen, font, string, flags, pos, len, x, y, SDL_ALPHA_OPAQUE); } -int sge_BF_input_UNI(SDL_Surface* screen, sge_bmpFont* font, Uint16* string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y) +int sge_BF_input_UNI(SDL_Surface* screen, sge_bmpFont* font, Uint16* string, Uint8 flags, int pos, unsigned len, Sint16 x, Sint16 y) { return sge_BF_inputAlpha_UNI(screen, font, string, flags, pos, len, x, y, SDL_ALPHA_OPAQUE); } diff --git a/SGE/sge_bm_text.h b/SGE/sge_bm_text.h index 48a6fda..d0a5f6f 100644 --- a/SGE/sge_bm_text.h +++ b/SGE/sge_bm_text.h @@ -36,8 +36,8 @@ typedef struct { SDL_Surface* FontSurface; - Sint16 CharWidth; - Sint16 CharHeight; + Uint16 CharWidth; + Uint16 CharHeight; Sint16* CharPos; Sint16 yoffs; Uint32 bcolor; @@ -48,23 +48,24 @@ typedef struct extern "C" { #endif DECLSPEC sge_bmpFont* sge_BF_CreateFont(SDL_Surface* surface, Uint8 flags); -DECLSPEC sge_bmpFont* sge_BF_OpenFont(char* file, Uint8 flags); +DECLSPEC sge_bmpFont* sge_BF_OpenFont(const char* file, Uint8 flags); DECLSPEC void sge_BF_CloseFont(sge_bmpFont* font); DECLSPEC void sge_BF_SetColor(sge_bmpFont* font, Uint8 R, Uint8 G, Uint8 B); DECLSPEC void sge_BF_SetAlpha(sge_bmpFont* font, Uint8 alpha); DECLSPEC Sint16 sge_BF_GetHeight(sge_bmpFont* font); DECLSPEC Sint16 sge_BF_GetWidth(sge_bmpFont* font); -DECLSPEC SDL_Rect sge_BF_TextSize(sge_bmpFont* font, char* string); +DECLSPEC SDL_Rect sge_BF_TextSize(sge_bmpFont* font, const char* string); -DECLSPEC SDL_Rect sge_BF_textout(SDL_Surface* surface, sge_bmpFont* font, char* string, Sint16 x, Sint16 y); +DECLSPEC SDL_Rect sge_BF_textout(SDL_Surface* surface, sge_bmpFont* font, const char* string, Sint16 x, Sint16 y); DECLSPEC __attribute__((format(printf, 5, 6))) SDL_Rect sge_BF_textoutf(SDL_Surface* surface, sge_bmpFont* font, Sint16 x, Sint16 y, - char* format, ...); + const char* format, ...); -DECLSPEC int sge_BF_input(SDL_Surface* screen, sge_bmpFont* font, char* string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y); -DECLSPEC int sge_BF_inputAlpha(SDL_Surface* screen, sge_bmpFont* font, char* string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y, +DECLSPEC int sge_BF_input(SDL_Surface* screen, sge_bmpFont* font, char* string, Uint8 flags, int pos, unsigned len, Sint16 x, Sint16 y); +DECLSPEC int sge_BF_inputAlpha(SDL_Surface* screen, sge_bmpFont* font, char* string, Uint8 flags, int pos, unsigned len, Sint16 x, Sint16 y, int Alpha); -DECLSPEC int sge_BF_input_UNI(SDL_Surface* screen, sge_bmpFont* font, Uint16* string, Uint8 flags, int pos, int len, Sint16 x, Sint16 y); -DECLSPEC int sge_BF_inputAlpha_UNI(SDL_Surface* screen, sge_bmpFont* font, Uint16* string, Uint8 flags, int pos, int len, Sint16 x, +DECLSPEC int sge_BF_input_UNI(SDL_Surface* screen, sge_bmpFont* font, Uint16* string, Uint8 flags, int pos, unsigned len, Sint16 x, + Sint16 y); +DECLSPEC int sge_BF_inputAlpha_UNI(SDL_Surface* screen, sge_bmpFont* font, Uint16* string, Uint8 flags, int pos, unsigned len, Sint16 x, Sint16 y, int Alpha); #ifdef _SGE_C } diff --git a/SGE/sge_collision.cpp b/SGE/sge_collision.cpp index 8de7284..b48c25e 100644 --- a/SGE/sge_collision.cpp +++ b/SGE/sge_collision.cpp @@ -39,7 +39,6 @@ sge_cdata* sge_make_cmap(SDL_Surface* img) sge_cdata* cdata; Uint8* map; Sint16 x, y; - Sint32 offs; int i; cdata = new(nothrow) sge_cdata; @@ -50,7 +49,7 @@ sge_cdata* sge_make_cmap(SDL_Surface* img) } cdata->w = img->w; cdata->h = img->h; - offs = (img->w * img->h) / 8; + const Uint32 offs = (Uint32)(img->w * img->h) / 8; cdata->map = new(nothrow) Uint8[offs + 2]; if(!cdata->map) { @@ -87,10 +86,10 @@ sge_cdata* sge_make_cmap(SDL_Surface* img) //================================================================================== int sge_bbcheck(sge_cdata* cd1, Sint16 x1, Sint16 y1, sge_cdata* cd2, Sint16 x2, Sint16 y2) { - Sint16 w1 = cd1->w; - Sint16 h1 = cd1->h; - Sint16 w2 = cd2->w; - Sint16 h2 = cd2->h; + const Uint16 w1 = cd1->w; + const Uint16 h1 = cd1->h; + const Uint16 w2 = cd2->w; + const Uint16 h2 = cd2->h; if(x1 < x2) { @@ -144,7 +143,7 @@ int sge_bbcheck(sge_cdata* cd1, Sint16 x1, Sint16 y1, sge_cdata* cd2, Sint16 x2, //================================================================================== // Checks bounding boxes for collision: 0-no collision 1-collision //================================================================================== -int _sge_bbcheck(Sint16 x1, Sint16 y1, Sint16 w1, Sint16 h1, Sint16 x2, Sint16 y2, Sint16 w2, Sint16 h2) +int _sge_bbcheck(Sint16 x1, Sint16 y1, Uint16 w1, Uint16 h1, Sint16 x2, Sint16 y2, Uint16 w2, Uint16 h2) { if(x1 < x2) { @@ -232,10 +231,10 @@ int _sge_cmcheck(sge_cdata* cd1, Sint16 x1, Sint16 y1, sge_cdata* cd2, Sint16 x2 if(!cd1->map || !cd2->map) return 0; - Sint16 w1 = cd1->w; - Sint16 h1 = cd1->h; - Sint16 w2 = cd2->w; - Sint16 h2 = cd2->h; + const Uint16 w1 = cd1->w; + const Uint16 h1 = cd1->h; + const Uint16 w2 = cd2->w; + const Uint16 h2 = cd2->h; // masks diff --git a/SGE/sge_internal.h b/SGE/sge_internal.h index 9ec4dec..4794b0f 100644 --- a/SGE/sge_internal.h +++ b/SGE/sge_internal.h @@ -30,6 +30,13 @@ #ifdef _SGE_C_AND_CPP #ifdef __cplusplus #define _SGE_C /* use extern "C" on base functions */ +#include +template +constexpr auto absDiff(T a, T b) +{ + using U = std::make_unsigned_t; + return static_cast(a > b ? a - b : b - a); +} #else #define sge_C_ONLY /* remove overloaded functions */ #define _SGE_NO_CLASSES /* no C++ classes */ diff --git a/SGE/sge_misc.cpp b/SGE/sge_misc.cpp index a0ecdf3..6f18112 100644 --- a/SGE/sge_misc.cpp +++ b/SGE/sge_misc.cpp @@ -82,7 +82,7 @@ Uint32 sge_Delay(Uint32 ticks) while(time_left > 0) { - time_left = ticks - (SDL_GetTicks() - start); + time_left = (Sint32)(ticks - (SDL_GetTicks() - start)); } return SDL_GetTicks() - start; diff --git a/SGE/sge_primitives.cpp b/SGE/sge_primitives.cpp index b31da0b..98f09e5 100644 --- a/SGE/sge_primitives.cpp +++ b/SGE/sge_primitives.cpp @@ -66,7 +66,7 @@ void _HLine(SDL_Surface* Surface, Sint16 x1, Sint16 x2, Sint16 y, Uint32 Color) SDL_Rect l; l.x = x1; l.y = y; - l.w = x2 - x1 + 1; + l.w = (Uint16)(x2 - x1) + 1; l.h = 1; SDL_FillRect(Surface, &l, Color); @@ -97,12 +97,12 @@ void sge_HLine(SDL_Surface* Surface, Sint16 x1, Sint16 x2, Sint16 y, Uint32 Colo SDL_Rect l; l.x = x1; l.y = y; - l.w = x2 - x1 + 1; + l.w = (Uint16)(x2 - x1) + 1; l.h = 1; SDL_FillRect(Surface, &l, Color); - sge_UpdateRect(Surface, x1, y, x2 - x1 + 1, 1); + sge_UpdateRect(Surface, x1, y, l.w, 1); } //================================================================================== @@ -169,7 +169,7 @@ void _VLine(SDL_Surface* Surface, Sint16 x, Sint16 y1, Sint16 y2, Uint32 Color) l.x = x; l.y = y1; l.w = 1; - l.h = y2 - y1 + 1; + l.h = (Uint16)(y2 - y1) + 1; SDL_FillRect(Surface, &l, Color); } @@ -200,11 +200,11 @@ void sge_VLine(SDL_Surface* Surface, Sint16 x, Sint16 y1, Sint16 y2, Uint32 Colo l.x = x; l.y = y1; l.w = 1; - l.h = y2 - y1 + 1; + l.h = (Uint16)(y2 - y1) + 1; SDL_FillRect(Surface, &l, Color); - sge_UpdateRect(Surface, x, y1, 1, y2 - y1 + 1); + sge_UpdateRect(Surface, x, y1, 1, l.h); } //================================================================================== @@ -432,7 +432,7 @@ void _Line(SDL_Surface* surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uin x = y = 0; Sint16 pixx = surface->format->BytesPerPixel; - Sint16 pixy = surface->pitch; + Sint16 pixy = (Sint16)surface->pitch; Uint8* pixel = (Uint8*)surface->pixels + y1 * pixy + x1 * pixx; pixx *= sdx; @@ -550,8 +550,7 @@ void sge_Line(SDL_Surface* Surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, SDL_UnlockSurface(Surface); } - sge_UpdateRect(Surface, (x1 < x2) ? x1 : x2, (y1 < y2) ? y1 : y2, ((x2 - x1) < 0) ? (x1 - x2 + 1) : (x2 - x1 + 1), - ((y2 - y1) < 0) ? (y1 - y2 + 1) : (y2 - y1 + 1)); + sge_UpdateRect(Surface, (x1 < x2) ? x1 : x2, (y1 < y2) ? y1 : y2, absDiff(x1, x2) + 1, absDiff(y1, y2) + 1); } //================================================================================== @@ -596,8 +595,7 @@ void sge_LineAlpha(SDL_Surface* Surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 SDL_UnlockSurface(Surface); } - sge_UpdateRect(Surface, (x1 < x2) ? x1 : x2, (y1 < y2) ? y1 : y2, ((x2 - x1) < 0) ? (x1 - x2 + 1) : (x2 - x1 + 1), - ((y2 - y1) < 0) ? (y1 - y2 + 1) : (y2 - y1 + 1)); + sge_UpdateRect(Surface, (x1 < x2) ? x1 : x2, (y1 < y2) ? y1 : y2, absDiff(x1, x2) + 1, absDiff(y1, y2) + 1); } //================================================================================== @@ -636,7 +634,7 @@ void _AALineAlpha(SDL_Surface* dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, /* Calculate distance */ Sint16 dx = xx1 - xx0; - Sint16 dy = yy1 - yy0; + Uint16 dy = yy1 - yy0; /* Adjust for negative dx and set xdir */ Sint16 xdir = 1; @@ -672,7 +670,7 @@ void _AALineAlpha(SDL_Surface* dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, /* y-major. Calculate 16-bit fixed point fractional part of a pixel that X advances every time Y advances 1 pixel, truncating the result so that we won't overrun the endpoint along the X axis */ - erradj = ((dx << 16) / dy) << 16; + erradj = ((Uint32)(dx << 16) / dy) << 16; /* draw all pixels other than the first and last */ x0pxdir = xx0 + xdir; @@ -710,7 +708,7 @@ void _AALineAlpha(SDL_Surface* dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, /* x-major line. Calculate 16-bit fixed-point fractional part of a pixel that Y advances each time X advances 1 pixel, truncating the result so that we won't overrun the endpoint along the X axis. */ - erradj = ((dy << 16) / dx) << 16; + erradj = (((Uint32)dy << 16) / (Uint32)dx) << 16; /* draw all pixels other than the first and last */ y0p1 = yy0 + 1; @@ -768,8 +766,7 @@ void sge_AALineAlpha(SDL_Surface* dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y SDL_UnlockSurface(dst); } - sge_UpdateRect(dst, (x1 < x2) ? x1 : x2, (y1 < y2) ? y1 : y2, ((x2 - x1) < 0) ? (x1 - x2 + 1) : (x2 - x1 + 1), - ((y2 - y1) < 0) ? (y1 - y2 + 1) : (y2 - y1 + 1)); + sge_UpdateRect(dst, (x1 < x2) ? x1 : x2, (y1 < y2) ? y1 : y2, absDiff(x1, x2) + 1, absDiff(y1, y2) + 1); } void sge_AALineAlpha(SDL_Surface* dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 alpha) @@ -882,8 +879,7 @@ void sge_mcLine(SDL_Surface* Surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2 SDL_UnlockSurface(Surface); } - sge_UpdateRect(Surface, (x1 < x2) ? x1 : x2, (y1 < y2) ? y1 : y2, ((x2 - x1) < 0) ? (x1 - x2 + 1) : (x2 - x1 + 1), - ((y2 - y1) < 0) ? (y1 - y2 + 1) : (y2 - y1 + 1)); + sge_UpdateRect(Surface, (x1 < x2) ? x1 : x2, (y1 < y2) ? y1 : y2, absDiff(x1, x2) + 1, absDiff(y1, y2) + 1); } void sge_mcLineAlpha(SDL_Surface* Surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 r1, Uint8 g1, Uint8 b1, Uint8 r2, Uint8 g2, @@ -904,8 +900,7 @@ void sge_mcLineAlpha(SDL_Surface* Surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint SDL_UnlockSurface(Surface); } - sge_UpdateRect(Surface, (x1 < x2) ? x1 : x2, (y1 < y2) ? y1 : y2, ((x2 - x1) < 0) ? (x1 - x2 + 1) : (x2 - x1 + 1), - ((y2 - y1) < 0) ? (y1 - y2 + 1) : (y2 - y1 + 1)); + sge_UpdateRect(Surface, (x1 < x2) ? x1 : x2, (y1 < y2) ? y1 : y2, absDiff(x1, x2) + 1, absDiff(y1, y2) + 1); } //================================================================================== @@ -938,7 +933,7 @@ void _AAmcLineAlpha(SDL_Surface* dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2 /* Calculate distance */ Sint16 dx = xx1 - xx0; - Sint16 dy = yy1 - yy0; + Uint16 dy = yy1 - yy0; /* Adjust for negative dx and set xdir */ Sint16 xdir = 1; @@ -977,7 +972,7 @@ void _AAmcLineAlpha(SDL_Surface* dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2 /* y-major. Calculate 16-bit fixed point fractional part of a pixel that X advances every time Y advances 1 pixel, truncating the result so that we won't overrun the endpoint along the X axis */ - erradj = ((dx << 16) / dy) << 16; + erradj = (((Uint32)dx << 16) / (Uint32)dy) << 16; rstep = Sint32((r2 - r1) << 16) / Sint32(dy); gstep = Sint32((g2 - g1) << 16) / Sint32(dy); @@ -1023,7 +1018,7 @@ void _AAmcLineAlpha(SDL_Surface* dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2 /* x-major line. Calculate 16-bit fixed-point fractional part of a pixel that Y advances each time X advances 1 pixel, truncating the result so that we won't overrun the endpoint along the X axis. */ - erradj = ((dy << 16) / dx) << 16; + erradj = (((Uint32)dy << 16) / (Uint32)dx) << 16; rstep = Sint32((r2 - r1) << 16) / Sint32(dx); gstep = Sint32((g2 - g1) << 16) / Sint32(dx); @@ -1086,8 +1081,7 @@ void sge_AAmcLineAlpha(SDL_Surface* dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 if(SDL_MUSTLOCK(dst) && _sge_lock) SDL_UnlockSurface(dst); - sge_UpdateRect(dst, (x1 < x2) ? x1 : x2, (y1 < y2) ? y1 : y2, ((x2 - x1) < 0) ? (x1 - x2 + 1) : (x2 - x1 + 1), - ((y2 - y1) < 0) ? (y1 - y2 + 1) : (y2 - y1 + 1)); + sge_UpdateRect(dst, (x1 < x2) ? x1 : x2, (y1 < y2) ? y1 : y2, absDiff(x1, x2) + 1, absDiff(y1, y2) + 1); } void sge_AAmcLine(SDL_Surface* Surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 r1, Uint8 g1, Uint8 b1, Uint8 r2, Uint8 g2, @@ -1110,10 +1104,10 @@ void sge_Rect(SDL_Surface* Surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, _VLine(Surface, x1, y1, y2, color); _VLine(Surface, x2, y1, y2, color); - sge_UpdateRect(Surface, x1, y1, x2 - x1, 1); - sge_UpdateRect(Surface, x1, y2, x2 - x1 + 1, 1); /* Hmm? */ - sge_UpdateRect(Surface, x1, y1, 1, y2 - y1); - sge_UpdateRect(Surface, x2, y1, 1, y2 - y1); + sge_UpdateRect(Surface, x1, y1, static_cast(x2 - x1), 1); + sge_UpdateRect(Surface, x1, y2, static_cast(x2 - x1) + 1, 1); /* Hmm? */ + sge_UpdateRect(Surface, x1, y1, 1, static_cast(y2 - y1)); + sge_UpdateRect(Surface, x2, y1, 1, static_cast(y2 - y1)); } //================================================================================== @@ -1143,10 +1137,10 @@ void sge_RectAlpha(SDL_Surface* Surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 SDL_UnlockSurface(Surface); } - sge_UpdateRect(Surface, x1, y1, x2 - x1, 1); - sge_UpdateRect(Surface, x1, y2, x2 - x1 + 1, 1); /* Hmm? */ - sge_UpdateRect(Surface, x1, y1, 1, y2 - y1); - sge_UpdateRect(Surface, x2, y1, 1, y2 - y1); + sge_UpdateRect(Surface, x1, y1, static_cast(x2 - x1), 1); + sge_UpdateRect(Surface, x1, y2, static_cast(x2 - x1) + 1, 1); /* Hmm? */ + sge_UpdateRect(Surface, x1, y1, 1, static_cast(y2 - y1)); + sge_UpdateRect(Surface, x2, y1, 1, static_cast(y2 - y1)); } //================================================================================== @@ -1192,12 +1186,12 @@ void sge_FilledRect(SDL_Surface* Surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint1 SDL_Rect area; area.x = x1; area.y = y1; - area.w = x2 - x1 + 1; - area.h = y2 - y1 + 1; + area.w = static_cast(x2 - x1) + 1; + area.h = static_cast(y2 - y1) + 1; SDL_FillRect(Surface, &area, color); - sge_UpdateRect(Surface, x1, y1, x2 - x1 + 1, y2 - y1 + 1); + sge_UpdateRect(Surface, area); } //================================================================================== @@ -1379,7 +1373,7 @@ void sge_FilledRectAlpha(SDL_Surface* surface, Sint16 x1, Sint16 y1, Sint16 x2, SDL_UnlockSurface(surface); } - sge_UpdateRect(surface, x1, y1, x2 - x1 + 1, y2 - y1 + 1); + sge_UpdateRect(surface, x1, y1, static_cast(x2 - x1) + 1, static_cast(y2 - y1) + 1); } void sge_FilledRectAlpha(SDL_Surface* Surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha) @@ -1391,7 +1385,7 @@ void sge_FilledRectAlpha(SDL_Surface* Surface, Sint16 x1, Sint16 y1, Sint16 x2, // Performs Callback at each ellipse point. // (from Allegro) //================================================================================== -void sge_DoEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color, +void sge_DoEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint32 color, void Callback(SDL_Surface* Surf, Sint16 X, Sint16 Y, Uint32 Color)) { int ix, iy; @@ -1506,7 +1500,7 @@ void sge_DoEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 r //================================================================================== // Performs Callback at each ellipse point. (RGB) //================================================================================== -void sge_DoEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint8 R, Uint8 G, Uint8 B, +void sge_DoEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint8 R, Uint8 G, Uint8 B, void Callback(SDL_Surface* Surf, Sint16 X, Sint16 Y, Uint32 Color)) { sge_DoEllipse(Surface, x, y, rx, ry, SDL_MapRGB(Surface->format, R, G, B), Callback); @@ -1515,7 +1509,7 @@ void sge_DoEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 r //================================================================================== // Draws an ellipse //================================================================================== -void sge_Ellipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color) +void sge_Ellipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint32 color) { if(SDL_MUSTLOCK(Surface) && _sge_lock) { @@ -1536,7 +1530,7 @@ void sge_Ellipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, //================================================================================== // Draws an ellipse (RGB) //================================================================================== -void sge_Ellipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint8 R, Uint8 G, Uint8 B) +void sge_Ellipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint8 R, Uint8 G, Uint8 B) { sge_Ellipse(Surface, x, y, rx, ry, SDL_MapRGB(Surface->format, R, G, B)); } @@ -1544,7 +1538,7 @@ void sge_Ellipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, //================================================================================== // Draws an ellipse (alpha) //================================================================================== -void sge_EllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color, Uint8 alpha) +void sge_EllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint32 color, Uint8 alpha) { if(SDL_MUSTLOCK(Surface) && _sge_lock) if(SDL_LockSurface(Surface) < 0) @@ -1564,7 +1558,7 @@ void sge_EllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint1 //================================================================================== // Draws an ellipse (alpha - RGB) //================================================================================== -void sge_EllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha) +void sge_EllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha) { sge_EllipseAlpha(Surface, x, y, rx, ry, SDL_MapRGB(Surface->format, R, G, B), alpha); } @@ -1572,7 +1566,7 @@ void sge_EllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint1 //================================================================================== // Draws a filled ellipse //================================================================================== -void sge_FilledEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color) +void sge_FilledEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint32 color) { int ix, iy; int h, i, j, k; @@ -1670,7 +1664,7 @@ void sge_FilledEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint //================================================================================== // Draws a filled ellipse (RGB) //================================================================================== -void sge_FilledEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint8 R, Uint8 G, Uint8 B) +void sge_FilledEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint8 R, Uint8 G, Uint8 B) { sge_FilledEllipse(Surface, x, y, rx, ry, SDL_MapRGB(Surface->format, R, G, B)); } @@ -1678,7 +1672,7 @@ void sge_FilledEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint //================================================================================== // Draws a filled ellipse (alpha) //================================================================================== -void sge_FilledEllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color, Uint8 alpha) +void sge_FilledEllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint32 color, Uint8 alpha) { int ix, iy; int h, i, j, k; @@ -1785,7 +1779,7 @@ void sge_FilledEllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, //================================================================================== // Draws a filled ellipse (alpha - RGB) //================================================================================== -void sge_FilledEllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha) +void sge_FilledEllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha) { sge_FilledEllipseAlpha(Surface, x, y, rx, ry, SDL_MapRGB(Surface->format, R, G, B), alpha); } @@ -1795,7 +1789,7 @@ void sge_FilledEllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, // Some of this code is taken from "TwinLib" (http://www.twinlib.org) written by // Nicolas Roard (nicolas@roard.com) //================================================================================== -void sge_AAEllipseAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint32 color, Uint8 alpha) +void sge_AAEllipseAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 rx, Uint16 ry, Uint32 color, Uint8 alpha) { /* Sanity check */ if(rx < 1) @@ -1979,7 +1973,7 @@ void sge_AAEllipseAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 rx, S //================================================================================== // Draws an anti-aliased ellipse (alpha - RGB) //================================================================================== -void sge_AAEllipseAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha) +void sge_AAEllipseAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 rx, Uint16 ry, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha) { sge_AAEllipseAlpha(surface, xc, yc, rx, ry, SDL_MapRGB(surface->format, R, G, B), alpha); } @@ -1987,7 +1981,7 @@ void sge_AAEllipseAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 rx, S //================================================================================== // Draws an anti-aliased ellipse //================================================================================== -void sge_AAEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint32 color) +void sge_AAEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 rx, Uint16 ry, Uint32 color) { sge_AAEllipseAlpha(surface, xc, yc, rx, ry, color, 255); } @@ -1995,7 +1989,7 @@ void sge_AAEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 //================================================================================== // Draws an anti-aliased ellipse (RGB) //================================================================================== -void sge_AAEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint8 R, Uint8 G, Uint8 B) +void sge_AAEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 rx, Uint16 ry, Uint8 R, Uint8 G, Uint8 B) { sge_AAEllipseAlpha(surface, xc, yc, rx, ry, SDL_MapRGB(surface->format, R, G, B), 255); } @@ -2004,7 +1998,7 @@ void sge_AAEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 // Draws a filled anti-aliased ellipse // This is just a quick hack... //================================================================================== -void sge_AAFilledEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint32 color) +void sge_AAFilledEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 rx, Uint16 ry, Uint32 color) { /* Sanity check */ if(rx < 1) @@ -2185,7 +2179,7 @@ void sge_AAFilledEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 rx, //================================================================================== // Draws a filled anti-aliased ellipse (RGB) //================================================================================== -void sge_AAFilledEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint8 R, Uint8 G, Uint8 B) +void sge_AAFilledEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 rx, Uint16 ry, Uint8 R, Uint8 G, Uint8 B) { sge_AAFilledEllipse(surface, xc, yc, rx, ry, SDL_MapRGB(surface->format, R, G, B)); } @@ -2193,12 +2187,12 @@ void sge_AAFilledEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 rx, //================================================================================== // Performs Callback at each circle point. //================================================================================== -void sge_DoCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint32 color, +void sge_DoCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint32 color, void Callback(SDL_Surface* Surf, Sint16 X, Sint16 Y, Uint32 Color)) { Sint16 cx = 0; - Sint16 cy = r; - Sint16 df = 1 - r; + Sint16 cy = (Sint16)r; + Sint16 df = 1 - (Sint16)r; Sint16 d_e = 3; Sint16 d_se = -2 * r + 5; @@ -2234,7 +2228,7 @@ void sge_DoCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint32 col //================================================================================== // Performs Callback at each circle point. (RGB) //================================================================================== -void sge_DoCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint8 R, Uint8 G, Uint8 B, +void sge_DoCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint8 R, Uint8 G, Uint8 B, void Callback(SDL_Surface* Surf, Sint16 X, Sint16 Y, Uint32 Color)) { sge_DoCircle(Surface, x, y, r, SDL_MapRGB(Surface->format, R, G, B), Callback); @@ -2243,7 +2237,7 @@ void sge_DoCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint8 R, U //================================================================================== // Draws a circle //================================================================================== -void sge_Circle(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint32 color) +void sge_Circle(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint32 color) { if(SDL_MUSTLOCK(Surface) && _sge_lock) { @@ -2264,7 +2258,7 @@ void sge_Circle(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint32 color //================================================================================== // Draws a circle (RGB) //================================================================================== -void sge_Circle(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint8 R, Uint8 G, Uint8 B) +void sge_Circle(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint8 R, Uint8 G, Uint8 B) { sge_Circle(Surface, x, y, r, SDL_MapRGB(Surface->format, R, G, B)); } @@ -2272,7 +2266,7 @@ void sge_Circle(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint8 R, Uin //================================================================================== // Draws a circle (alpha) //================================================================================== -void sge_CircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint32 color, Uint8 alpha) +void sge_CircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint32 color, Uint8 alpha) { if(SDL_MUSTLOCK(Surface) && _sge_lock) if(SDL_LockSurface(Surface) < 0) @@ -2292,7 +2286,7 @@ void sge_CircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint32 //================================================================================== // Draws a circle (alpha - RGB) //================================================================================== -void sge_CircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha) +void sge_CircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha) { sge_CircleAlpha(Surface, x, y, r, SDL_MapRGB(Surface->format, R, G, B), alpha); } @@ -2300,12 +2294,12 @@ void sge_CircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint8 R //================================================================================== // Draws a filled circle //================================================================================== -void sge_FilledCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint32 color) +void sge_FilledCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint32 color) { Sint16 cx = 0; - Sint16 cy = r; + Sint16 cy = (Sint16)r; bool draw = true; - Sint16 df = 1 - r; + Sint16 df = 1 - (Sint16)r; Sint16 d_e = 3; Sint16 d_se = -2 * r + 5; @@ -2349,7 +2343,7 @@ void sge_FilledCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint32 //================================================================================== // Draws a filled circle (RGB) //================================================================================== -void sge_FilledCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint8 R, Uint8 G, Uint8 B) +void sge_FilledCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint8 R, Uint8 G, Uint8 B) { sge_FilledCircle(Surface, x, y, r, SDL_MapRGB(Surface->format, R, G, B)); } @@ -2357,12 +2351,12 @@ void sge_FilledCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint8 //================================================================================== // Draws a filled circle (alpha) //================================================================================== -void sge_FilledCircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint32 color, Uint8 alpha) +void sge_FilledCircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint32 color, Uint8 alpha) { Sint16 cx = 0; - Sint16 cy = r; + Sint16 cy = (Sint16)r; bool draw = true; - Sint16 df = 1 - r; + Sint16 df = 1 - (Sint16)r; Sint16 d_e = 3; Sint16 d_se = -2 * r + 5; @@ -2415,7 +2409,7 @@ void sge_FilledCircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, U //================================================================================== // Draws a filled circle (alpha - RGB) //================================================================================== -void sge_FilledCircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha) +void sge_FilledCircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha) { sge_FilledCircleAlpha(Surface, x, y, r, SDL_MapRGB(Surface->format, R, G, B), alpha); } @@ -2423,7 +2417,7 @@ void sge_FilledCircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, U //================================================================================== // Draws an anti-aliased circle (alpha) //================================================================================== -void sge_AACircleAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 r, Uint32 color, Uint8 alpha) +void sge_AACircleAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 r, Uint32 color, Uint8 alpha) { sge_AAEllipseAlpha(surface, xc, yc, r, r, color, alpha); } @@ -2431,7 +2425,7 @@ void sge_AACircleAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 r, Uin //================================================================================== // Draws an anti-aliased circle (alpha - RGB) //================================================================================== -void sge_AACircleAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 r, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha) +void sge_AACircleAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 r, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha) { sge_AAEllipseAlpha(surface, xc, yc, r, r, SDL_MapRGB(surface->format, R, G, B), alpha); } @@ -2439,7 +2433,7 @@ void sge_AACircleAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 r, Uin //================================================================================== // Draws an anti-aliased circle //================================================================================== -void sge_AACircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 r, Uint32 color) +void sge_AACircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 r, Uint32 color) { sge_AAEllipseAlpha(surface, xc, yc, r, r, color, 255); } @@ -2447,7 +2441,7 @@ void sge_AACircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 r, Uint32 c //================================================================================== // Draws an anti-aliased circle (RGB) //================================================================================== -void sge_AACircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 r, Uint8 R, Uint8 G, Uint8 B) +void sge_AACircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 r, Uint8 R, Uint8 G, Uint8 B) { sge_AAEllipseAlpha(surface, xc, yc, r, r, SDL_MapRGB(surface->format, R, G, B), 255); } @@ -2455,7 +2449,7 @@ void sge_AACircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 r, Uint8 R, //================================================================================== // Draws a filled anti-aliased circle //================================================================================== -void sge_AAFilledCircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 r, Uint32 color) +void sge_AAFilledCircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 r, Uint32 color) { sge_AAFilledEllipse(surface, xc, yc, r, r, color); } @@ -2463,7 +2457,7 @@ void sge_AAFilledCircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 r, Ui //================================================================================== // Draws a filled anti-aliased circle (RGB) //================================================================================== -void sge_AAFilledCircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 r, Uint8 R, Uint8 G, Uint8 B) +void sge_AAFilledCircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 r, Uint8 R, Uint8 G, Uint8 B) { sge_AAFilledEllipse(surface, xc, yc, r, r, SDL_MapRGB(surface->format, R, G, B)); } @@ -2621,7 +2615,7 @@ void sge_AABezierAlpha(SDL_Surface* surface, Sint16 x1, Sint16 y1, Sint16 x2, Si _sge_update = update; _sge_lock = lock; - sge_UpdateRect(surface, xmin, ymin, xmax - xmin + 1, ymax - ymin + 1); + sge_UpdateRect(surface, xmin, ymin, (Uint16)(xmax - xmin) + 1, (Uint16)(ymax - ymin) + 1); } //================================================================================== diff --git a/SGE/sge_primitives.h b/SGE/sge_primitives.h index 56ad519..f1616c2 100644 --- a/SGE/sge_primitives.h +++ b/SGE/sge_primitives.h @@ -50,25 +50,25 @@ DECLSPEC void sge_RectAlpha(SDL_Surface* Surface, Sint16 x1, Sint16 y1, Sint16 x DECLSPEC void sge_FilledRect(SDL_Surface* Surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color); DECLSPEC void sge_FilledRectAlpha(SDL_Surface* surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color, Uint8 alpha); -DECLSPEC void sge_DoEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color, +DECLSPEC void sge_DoEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint32 color, void Callback(SDL_Surface* Surf, Sint16 X, Sint16 Y, Uint32 Color)); -DECLSPEC void sge_Ellipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color); -DECLSPEC void sge_EllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color, Uint8 alpha); -DECLSPEC void sge_FilledEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color); -DECLSPEC void sge_FilledEllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color, Uint8 alpha); -DECLSPEC void sge_AAEllipseAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint32 color, Uint8 alpha); -DECLSPEC void sge_AAEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint32 color); -DECLSPEC void sge_AAFilledEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint32 color); +DECLSPEC void sge_Ellipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint32 color); +DECLSPEC void sge_EllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint32 color, Uint8 alpha); +DECLSPEC void sge_FilledEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint32 color); +DECLSPEC void sge_FilledEllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint32 color, Uint8 alpha); +DECLSPEC void sge_AAEllipseAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 rx, Uint16 ry, Uint32 color, Uint8 alpha); +DECLSPEC void sge_AAEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 rx, Uint16 ry, Uint32 color); +DECLSPEC void sge_AAFilledEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 rx, Uint16 ry, Uint32 color); -DECLSPEC void sge_DoCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint32 color, +DECLSPEC void sge_DoCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint32 color, void Callback(SDL_Surface* Surf, Sint16 X, Sint16 Y, Uint32 Color)); -DECLSPEC void sge_Circle(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint32 color); -DECLSPEC void sge_CircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint32 color, Uint8 alpha); -DECLSPEC void sge_FilledCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint32 color); -DECLSPEC void sge_FilledCircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint32 color, Uint8 alpha); -DECLSPEC void sge_AACircleAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 r, Uint32 color, Uint8 alpha); -DECLSPEC void sge_AACircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 r, Uint32 color); -DECLSPEC void sge_AAFilledCircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 r, Uint32 color); +DECLSPEC void sge_Circle(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint32 color); +DECLSPEC void sge_CircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint32 color, Uint8 alpha); +DECLSPEC void sge_FilledCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint32 color); +DECLSPEC void sge_FilledCircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint32 color, Uint8 alpha); +DECLSPEC void sge_AACircleAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 r, Uint32 color, Uint8 alpha); +DECLSPEC void sge_AACircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 r, Uint32 color); +DECLSPEC void sge_AAFilledCircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 r, Uint32 color); DECLSPEC void sge_Bezier(SDL_Surface* surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Sint16 x4, Sint16 y4, int level, Uint32 color); @@ -97,25 +97,25 @@ DECLSPEC void sge_Rect(SDL_Surface* Surface, Sint16 x1, Sint16 y1, Sint16 x2, Si DECLSPEC void sge_RectAlpha(SDL_Surface* Surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha); DECLSPEC void sge_FilledRect(SDL_Surface* Surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 R, Uint8 G, Uint8 B); DECLSPEC void sge_FilledRectAlpha(SDL_Surface* Surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha); -DECLSPEC void sge_DoEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint8 R, Uint8 G, Uint8 B, +DECLSPEC void sge_DoEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint8 R, Uint8 G, Uint8 B, void Callback(SDL_Surface* Surf, Sint16 X, Sint16 Y, Uint32 Color)); -DECLSPEC void sge_Ellipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint8 R, Uint8 G, Uint8 B); -DECLSPEC void sge_EllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha); -DECLSPEC void sge_FilledEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint8 R, Uint8 G, Uint8 B); -DECLSPEC void sge_FilledEllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint8 R, Uint8 G, Uint8 B, +DECLSPEC void sge_Ellipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint8 R, Uint8 G, Uint8 B); +DECLSPEC void sge_EllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha); +DECLSPEC void sge_FilledEllipse(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint8 R, Uint8 G, Uint8 B); +DECLSPEC void sge_FilledEllipseAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 rx, Uint16 ry, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha); -DECLSPEC void sge_AAEllipseAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha); -DECLSPEC void sge_AAEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint8 R, Uint8 G, Uint8 B); -DECLSPEC void sge_AAFilledEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint8 R, Uint8 G, Uint8 B); -DECLSPEC void sge_DoCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint8 R, Uint8 G, Uint8 B, +DECLSPEC void sge_AAEllipseAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 rx, Uint16 ry, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha); +DECLSPEC void sge_AAEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 rx, Uint16 ry, Uint8 R, Uint8 G, Uint8 B); +DECLSPEC void sge_AAFilledEllipse(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 rx, Uint16 ry, Uint8 R, Uint8 G, Uint8 B); +DECLSPEC void sge_DoCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint8 R, Uint8 G, Uint8 B, void Callback(SDL_Surface* Surf, Sint16 X, Sint16 Y, Uint32 Color)); -DECLSPEC void sge_Circle(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint8 R, Uint8 G, Uint8 B); -DECLSPEC void sge_CircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha); -DECLSPEC void sge_FilledCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint8 R, Uint8 G, Uint8 B); -DECLSPEC void sge_FilledCircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Sint16 r, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha); -DECLSPEC void sge_AACircleAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 r, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha); -DECLSPEC void sge_AACircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 r, Uint8 R, Uint8 G, Uint8 B); -DECLSPEC void sge_AAFilledCircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Sint16 r, Uint8 R, Uint8 G, Uint8 B); +DECLSPEC void sge_Circle(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint8 R, Uint8 G, Uint8 B); +DECLSPEC void sge_CircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha); +DECLSPEC void sge_FilledCircle(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint8 R, Uint8 G, Uint8 B); +DECLSPEC void sge_FilledCircleAlpha(SDL_Surface* Surface, Sint16 x, Sint16 y, Uint16 r, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha); +DECLSPEC void sge_AACircleAlpha(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 r, Uint8 R, Uint8 G, Uint8 B, Uint8 alpha); +DECLSPEC void sge_AACircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 r, Uint8 R, Uint8 G, Uint8 B); +DECLSPEC void sge_AAFilledCircle(SDL_Surface* surface, Sint16 xc, Sint16 yc, Uint16 r, Uint8 R, Uint8 G, Uint8 B); DECLSPEC void sge_Bezier(SDL_Surface* surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Sint16 x4, Sint16 y4, int level, Uint8 R, Uint8 G, Uint8 B); DECLSPEC void sge_BezierAlpha(SDL_Surface* surface, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Sint16 x4, Sint16 y4, diff --git a/SGE/sge_shape.h b/SGE/sge_shape.h index 0cec3a0..9e226fa 100644 --- a/SGE/sge_shape.h +++ b/SGE/sge_shape.h @@ -142,8 +142,8 @@ class sge_shape inline Sint16 get_xpos() const { return current_pos.x; } inline Sint16 get_ypos() const { return current_pos.y; } - inline Sint16 get_w() const { return current_pos.w; } - inline Sint16 get_h() const { return current_pos.h; } + inline Uint16 get_w() const { return current_pos.w; } + inline Uint16 get_h() const { return current_pos.h; } }; //================================================================================== diff --git a/SGE/sge_surface.cpp b/SGE/sge_surface.cpp index 89f9746..9568f55 100644 --- a/SGE/sge_surface.cpp +++ b/SGE/sge_surface.cpp @@ -120,6 +120,11 @@ void sge_UpdateRect(SDL_Surface* screen, Sint16 x, Sint16 y, Uint16 w, Uint16 h) SDL_UpdateRect(screen, x, y, a, b); } +void sge_UpdateRect(SDL_Surface* screen, const SDL_Rect& area) +{ + sge_UpdateRect(screen, area.x, area.y, area.w, area.h); +} + //================================================================================== // Creates a 32bit (8/8/8/8) alpha surface // Map colors with sge_MapAlpha() and then use the Uint32 color versions of diff --git a/SGE/sge_surface.h b/SGE/sge_surface.h index 0e371b6..7bb2809 100644 --- a/SGE/sge_surface.h +++ b/SGE/sge_surface.h @@ -31,6 +31,8 @@ #define sge_get_sblock16 sge_read_block16 #define sge_get_sblock32 sge_read_block32 +DECLSPEC void sge_UpdateRect(SDL_Surface* screen, Sint16 x, Sint16 y, Uint16 w, Uint16 h); +DECLSPEC void sge_UpdateRect(SDL_Surface* screen, const SDL_Rect& area); #ifdef _SGE_C extern "C" { #endif @@ -40,7 +42,6 @@ DECLSPEC void sge_Lock_OFF(); DECLSPEC void sge_Lock_ON(); DECLSPEC Uint8 sge_getUpdate(); DECLSPEC Uint8 sge_getLock(); -DECLSPEC void sge_UpdateRect(SDL_Surface* screen, Sint16 x, Sint16 y, Uint16 w, Uint16 h); DECLSPEC SDL_Surface* sge_CreateAlphaSurface(Uint32 flags, int width, int height); DECLSPEC Uint32 sge_MapAlpha(Uint8 R, Uint8 G, Uint8 B, Uint8 A); DECLSPEC __attribute__((format(printf, 1, 2))) void sge_SetError(const char* format, ...); diff --git a/SGE/sge_textpp.cpp b/SGE/sge_textpp.cpp index 944aa9e..444ddca 100644 --- a/SGE/sge_textpp.cpp +++ b/SGE/sge_textpp.cpp @@ -422,7 +422,7 @@ bool sge_text::update_textSurface(bool force) SDL_FreeSurface(text_surface); string text = get_string(sCursor); - SDL_Rect size = sge_BF_TextSize(bm_font, (char*)(text.c_str())); + SDL_Rect size = sge_BF_TextSize(bm_font, text.c_str()); text_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, size.w, size.h, bm_font->FontSurface->format->BitsPerPixel, bm_font->FontSurface->format->Rmask, bm_font->FontSurface->format->Gmask, @@ -455,7 +455,7 @@ bool sge_text::update_textSurface(bool force) sge_ClearSurface(text_surface, bcol); } - sge_BF_textout(text_surface, bm_font, (char*)(text.c_str()), 0, 0); + sge_BF_textout(text_surface, bm_font, text.c_str(), 0, 0); SDL_SetColorKey(text_surface, SDL_SRCCOLORKEY, bcol); @@ -534,7 +534,7 @@ SDL_Rect sge_text::render_text(SDL_Surface* surface, Sint16 x, Sint16 y) if(alpha_level != SDL_ALPHA_OPAQUE && !bm_font->FontSurface->format->Amask) SDL_SetAlpha(bm_font->FontSurface, SDL_SRCALPHA, alpha_level); - return sge_BF_textout(surface, bm_font, (char*)(text.c_str()), x, y); + return sge_BF_textout(surface, bm_font, text.c_str(), x, y); } else { SDL_Rect ret; @@ -552,7 +552,7 @@ void sge_TextSurface::set_textSurface(SDL_Surface* new_surf) { if(bm_font->CharPos && bm_font->FontSurface->format->Amask) { - SDL_Rect size = sge_BF_TextSize(bm_font, (char*)(get_string(sCursor).c_str())); + SDL_Rect size = sge_BF_TextSize(bm_font, get_string(sCursor).c_str()); current_pos.w = size.w; current_pos.h = size.h; @@ -597,7 +597,7 @@ void sge_TextSsprite::set_textSurface(SDL_Surface* new_surf) { if(bm_font->CharPos && bm_font->FontSurface->format->Amask) { - SDL_Rect size = sge_BF_TextSize(bm_font, (char*)(get_string(sCursor).c_str())); + SDL_Rect size = sge_BF_TextSize(bm_font, get_string(sCursor).c_str()); current_pos.w = size.w; current_pos.h = size.h; @@ -650,7 +650,7 @@ void sge_TextSprite::set_textSurface(SDL_Surface* new_surf) { if(bm_font->CharPos && bm_font->FontSurface->format->Amask) { - SDL_Rect size = sge_BF_TextSize(bm_font, (char*)(get_string(sCursor).c_str())); + SDL_Rect size = sge_BF_TextSize(bm_font, get_string(sCursor).c_str()); current_pos.w = size.w; current_pos.h = size.h;