From a8d90b8a84b5a21c53fb5d279dc983ae1e2c3217 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 22 Feb 2012 19:50:00 +0300 Subject: Fix code style. --- src/guichan/color.cpp | 18 +++++++++--------- src/guichan/defaultfont.cpp | 2 +- src/guichan/focushandler.cpp | 20 ++++++++++---------- src/guichan/include/guichan/sdl/sdlpixel.hpp | 23 +++++++++++++---------- src/guichan/sdl/sdlimage.cpp | 4 ++-- 5 files changed, 35 insertions(+), 32 deletions(-) (limited to 'src/guichan') diff --git a/src/guichan/color.cpp b/src/guichan/color.cpp index d3dc7a738..f58e7b58e 100644 --- a/src/guichan/color.cpp +++ b/src/guichan/color.cpp @@ -97,23 +97,23 @@ namespace gcn b - color.b, 255); - result.r = (result.r>255?255:(result.r<0?0:result.r)); - result.g = (result.g>255?255:(result.g<0?0:result.g)); - result.b = (result.b>255?255:(result.b<0?0:result.b)); + result.r = (result.r > 255 ? 255 : (result.r < 0 ? 0 : result.r)); + result.g = (result.g > 255 ? 255 : (result.g < 0 ? 0 : result.g)); + result.b = (result.b > 255 ? 255 : (result.b < 0 ? 0 : result.b)); return result; } Color Color::operator*(float value) const { - Color result((int)(r * value), - (int)(g * value), - (int)(b * value), + Color result(static_cast(r * value), + static_cast(g * value), + static_cast(b * value), a); - result.r = (result.r>255?255:(result.r<0?0:result.r)); - result.g = (result.g>255?255:(result.g<0?0:result.g)); - result.b = (result.b>255?255:(result.b<0?0:result.b)); + result.r = (result.r > 255 ? 255 : (result.r < 0 ? 0 : result.r)); + result.g = (result.g > 255 ? 255 : (result.g < 0 ? 0 : result.g)); + result.b = (result.b > 255 ? 255 : (result.b < 0 ? 0 : result.b)); return result; } diff --git a/src/guichan/defaultfont.cpp b/src/guichan/defaultfont.cpp index 8871d51de..70901bc8e 100644 --- a/src/guichan/defaultfont.cpp +++ b/src/guichan/defaultfont.cpp @@ -89,7 +89,7 @@ namespace gcn int DefaultFont::getStringIndexAt(const std::string& text, int x) const { - if (x > (int)text.size() * 8) + if (x > static_cast(text.size() * 8)) return text.size(); return x / 8; diff --git a/src/guichan/focushandler.cpp b/src/guichan/focushandler.cpp index 832a201ad..e3610fb1e 100644 --- a/src/guichan/focushandler.cpp +++ b/src/guichan/focushandler.cpp @@ -158,7 +158,7 @@ namespace gcn { int i; int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++i) + for (i = 0; i < static_cast(mWidgets.size()); ++i) { if (mWidgets[i] == mFocusedWidget) focusedWidget = i; @@ -167,7 +167,7 @@ namespace gcn // i is a counter that ensures that the following loop // won't get stuck in an infinite loop - i = (int)mWidgets.size(); + i = static_cast(mWidgets.size()); do { ++ focusedWidget; @@ -180,7 +180,7 @@ namespace gcn -- i; - if (focusedWidget >= (int)mWidgets.size()) + if (focusedWidget >= static_cast(mWidgets.size())) focusedWidget = 0; if (focusedWidget == focused) @@ -213,7 +213,7 @@ namespace gcn int i; int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++ i) + for (i = 0; i < static_cast(mWidgets.size()); ++ i) { if (mWidgets[i] == mFocusedWidget) focusedWidget = i; @@ -222,7 +222,7 @@ namespace gcn // i is a counter that ensures that the following loop // won't get stuck in an infinite loop - i = (int)mWidgets.size(); + i = static_cast(mWidgets.size()); do { -- focusedWidget; @@ -342,7 +342,7 @@ namespace gcn int i; int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++i) + for (i = 0; i < static_cast(mWidgets.size()); ++ i) { if (mWidgets[i] == mFocusedWidget) focusedWidget = i; @@ -352,7 +352,7 @@ namespace gcn // i is a counter that ensures that the following loop // won't get stuck in an infinite loop - i = (int)mWidgets.size(); + i = static_cast(mWidgets.size()); do { ++ focusedWidget; @@ -365,7 +365,7 @@ namespace gcn -- i; - if (focusedWidget >= (int)mWidgets.size()) + if (focusedWidget >= static_cast(mWidgets.size())) focusedWidget = 0; if (focusedWidget == focused) @@ -411,7 +411,7 @@ namespace gcn int i; int focusedWidget = -1; - for (i = 0; i < (int)mWidgets.size(); ++i) + for (i = 0; i < static_cast(mWidgets.size()); ++ i) { if (mWidgets[i] == mFocusedWidget) focusedWidget = i; @@ -421,7 +421,7 @@ namespace gcn // i is a counter that ensures that the following loop // won't get stuck in an infinite loop - i = (int)mWidgets.size(); + i = static_cast(mWidgets.size()); do { -- focusedWidget; diff --git a/src/guichan/include/guichan/sdl/sdlpixel.hpp b/src/guichan/include/guichan/sdl/sdlpixel.hpp index a0221ca7c..bfd08341b 100644 --- a/src/guichan/include/guichan/sdl/sdlpixel.hpp +++ b/src/guichan/include/guichan/sdl/sdlpixel.hpp @@ -68,7 +68,8 @@ namespace gcn SDL_LockSurface(surface); - Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + Uint8 *p = static_cast(surface->pixels) + + y * surface->pitch + x * bpp; unsigned int color = 0; @@ -79,7 +80,7 @@ namespace gcn break; case 2: - color = *(Uint16 *)p; + color = *reinterpret_cast(p); break; case 3: @@ -90,7 +91,7 @@ namespace gcn break; case 4: - color = *(Uint32 *)p; + color = *reinterpret_cast(p); break; default: @@ -123,7 +124,7 @@ namespace gcn SDL_LockSurface(surface); - Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + Uint8 *p = static_cast(surface->pixels) + y * surface->pitch + x * bpp; Uint32 pixel = SDL_MapRGB(surface->format, color.r, color.g, color.b); @@ -134,7 +135,7 @@ namespace gcn break; case 2: - *(Uint16 *)p = pixel; + *reinterpret_cast(p) = pixel; break; case 3: @@ -153,7 +154,7 @@ namespace gcn break; case 4: - *(Uint32 *)p = pixel; + *reinterpret_cast(p) = pixel; break; default: @@ -199,7 +200,7 @@ namespace gcn unsigned int r = ((src & f->Bmask) * a + (dst & f->Bmask) * (255 - a)) >> 8; - return (unsigned short)((b & f->Rmask) + return static_cast((b & f->Rmask) | (g & f->Gmask) | (r & f->Bmask)); } @@ -230,7 +231,8 @@ namespace gcn SDL_LockSurface(surface); - Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + Uint8 *p = static_cast(surface->pixels) + + y * surface->pitch + x * bpp; Uint32 pixel = SDL_MapRGB(surface->format, color.r, color.g, color.b); @@ -241,7 +243,7 @@ namespace gcn break; case 2: - *(Uint16 *)p = SDLAlpha16(pixel, *(Uint32 *)p, + *reinterpret_cast(p) = SDLAlpha16(pixel, *(Uint32 *)p, color.a, surface->format); break; @@ -275,7 +277,8 @@ namespace gcn break; case 4: - *(Uint32 *)p = SDLAlpha32(pixel, *(Uint32 *)p, color.a); + *reinterpret_cast(p) = SDLAlpha32(pixel, + *reinterpret_cast(p), color.a); break; default: break; diff --git a/src/guichan/sdl/sdlimage.cpp b/src/guichan/sdl/sdlimage.cpp index e4aadc465..4f9b9565c 100644 --- a/src/guichan/sdl/sdlimage.cpp +++ b/src/guichan/sdl/sdlimage.cpp @@ -130,8 +130,8 @@ namespace gcn for (i = 0; i < mSurface->w * mSurface->h; ++i) { - if (((unsigned int*)mSurface->pixels)[i] == SDL_MapRGB( - mSurface->format, 255, 0, 255)) + if ((static_cast(mSurface->pixels))[i] + == SDL_MapRGB(mSurface->format, 255, 0, 255)) { hasPink = true; break; -- cgit v1.2.3-60-g2f50