From 3c374b32aafb85dca19d39d5e431c6efe0302f27 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 26 Aug 2012 18:40:15 +0300 Subject: Add const to graphics class. --- src/graphics.cpp | 209 ++++++++++++++++++++++++------------------- src/graphics.h | 142 ++++++++++++++++------------- src/normalopenglgraphics.cpp | 76 +++++++++------- src/normalopenglgraphics.h | 57 ++++++------ src/resources/image.cpp | 2 +- src/resources/image.h | 2 +- src/safeopenglgraphics.cpp | 77 +++++++++------- src/safeopenglgraphics.h | 75 +++++++++------- 8 files changed, 357 insertions(+), 283 deletions(-) diff --git a/src/graphics.cpp b/src/graphics.cpp index 36cbde8d0..c217fed05 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -88,13 +88,14 @@ Graphics::~Graphics() _endDraw(); } -void Graphics::setSync(bool sync) +void Graphics::setSync(const bool sync) { mSync = sync; } -void Graphics::setMainFlags(int w, int h, int bpp, bool fs, - bool hwaccel, bool resize, bool noFrame) +void Graphics::setMainFlags(const int w, const int h, const int bpp, + const bool fs, const bool hwaccel, + const bool resize, const bool noFrame) { logger->log("graphics backend: %s", getName().c_str()); logger->log("Setting video mode %dx%d %s", @@ -109,7 +110,7 @@ void Graphics::setMainFlags(int w, int h, int bpp, bool fs, mNoFrame = noFrame; } -int Graphics::getOpenGLFlags() +int Graphics::getOpenGLFlags() const { #ifdef USE_OPENGL int displayFlags = SDL_ANYFORMAT | SDL_OPENGL; @@ -200,7 +201,7 @@ bool Graphics::setOpenGLMode() #endif } -int Graphics::getSoftwareFlags() +int Graphics::getSoftwareFlags() const { int displayFlags = SDL_ANYFORMAT; @@ -236,7 +237,7 @@ void Graphics::updateMemoryInfo() #endif } -int Graphics::getMemoryUsage() +int Graphics::getMemoryUsage() const { #ifdef USE_OPENGL if (!mStartFreeMem) @@ -253,8 +254,9 @@ int Graphics::getMemoryUsage() return 0; } -bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, - bool hwaccel, bool resize, bool noFrame) +bool Graphics::setVideoMode(const int w, const int h, const int bpp, + const bool fs, const bool hwaccel, + const bool resize, const bool noFrame) { setMainFlags(w, h, bpp, fs, hwaccel, resize, noFrame); @@ -282,7 +284,7 @@ bool Graphics::videoInfo() imageHelper->dumpSurfaceFormat(mTarget); - const SDL_VideoInfo *vi = SDL_GetVideoInfo(); + const SDL_VideoInfo *const vi = SDL_GetVideoInfo(); if (!vi) return false; @@ -308,7 +310,7 @@ bool Graphics::videoInfo() return true; } -bool Graphics::setFullscreen(bool fs) +bool Graphics::setFullscreen(const bool fs) { if (mFullscreen == fs) return true; @@ -317,7 +319,7 @@ bool Graphics::setFullscreen(bool fs) mEnableResize, mNoFrame); } -bool Graphics::resizeScreen(int width, int height) +bool Graphics::resizeScreen(const int width, const int height) { if (mWidth == width && mHeight == height) return true; @@ -327,7 +329,7 @@ bool Graphics::resizeScreen(int width, int height) _endDraw(); - bool success = setVideoMode(width, height, mBpp, + const bool success = setVideoMode(width, height, mBpp, mFullscreen, mHWAccel, mEnableResize, mNoFrame); // If it didn't work, try to restore the previous size. If that didn't @@ -369,11 +371,12 @@ bool Graphics::drawImage(const Image *image, int x, int y) } } -bool Graphics::drawRescaledImage(Image *image, int srcX, int srcY, +bool Graphics::drawRescaledImage(Image *const image, int srcX, int srcY, int dstX, int dstY, - int width, int height, - int desiredWidth, int desiredHeight, - bool useColor A_UNUSED) + const int width, const int height, + const int desiredWidth, + const int desiredHeight, + const bool useColor A_UNUSED) { // Check that preconditions for blitting are met. if (!mTarget || !image) @@ -413,8 +416,9 @@ bool Graphics::drawRescaledImage(Image *image, int srcX, int srcY, return returnValue; } -bool Graphics::drawImage2(const Image *image, int srcX, int srcY, - int dstX, int dstY, int width, int height, bool) +bool Graphics::drawImage2(const Image *const image, int srcX, int srcY, + int dstX, int dstY, const int width, + const int height, const bool useColor A_UNUSED) { // Check that preconditions for blitting are met. if (!mTarget || !image || !image->mSDLSurface) @@ -447,7 +451,9 @@ bool Graphics::drawImage2(const Image *image, int srcX, int srcY, } } -void Graphics::drawImagePattern(const Image *image, int x, int y, int w, int h) +void Graphics::drawImagePattern(const Image *const image, + const int x, const int y, + const int w, const int h) { // Check that preconditions for blitting are met. if (!mTarget || !image) @@ -463,15 +469,15 @@ void Graphics::drawImagePattern(const Image *image, int x, int y, int w, int h) for (int py = 0; py < h; py += ih) // Y position on pattern plane { - int dh = (py + ih >= h) ? h - py : ih; - int srcY = image->mBounds.y; - int dstY = y + py + mClipStack.top().yOffset; + const int dh = (py + ih >= h) ? h - py : ih; + const int srcY = image->mBounds.y; + const int dstY = y + py + mClipStack.top().yOffset; for (int px = 0; px < w; px += iw) // X position on pattern plane { - int dw = (px + iw >= w) ? w - px : iw; - int srcX = image->mBounds.x; - int dstX = x + px + mClipStack.top().xOffset; + const int dw = (px + iw >= w) ? w - px : iw; + const int srcX = image->mBounds.x; + const int dstX = x + px + mClipStack.top().xOffset; SDL_Rect dstRect; SDL_Rect srcRect; @@ -487,9 +493,11 @@ void Graphics::drawImagePattern(const Image *image, int x, int y, int w, int h) } } -void Graphics::drawRescaledImagePattern(Image *image, int x, int y, - int w, int h, int scaledWidth, - int scaledHeight) +void Graphics::drawRescaledImagePattern(const Image *const image, + const int x, const int y, + const int w, const int h, + const int scaledWidth, + const int scaledHeight) { // Check that preconditions for blitting are met. if (!mTarget || !image) @@ -512,15 +520,15 @@ void Graphics::drawRescaledImagePattern(Image *image, int x, int y, for (int py = 0; py < h; py += ih) // Y position on pattern plane { - int dh = (py + ih >= h) ? h - py : ih; - int srcY = tmpImage->mBounds.y; - int dstY = y + py + mClipStack.top().yOffset; + const int dh = (py + ih >= h) ? h - py : ih; + const int srcY = tmpImage->mBounds.y; + const int dstY = y + py + mClipStack.top().yOffset; for (int px = 0; px < w; px += iw) // X position on pattern plane { - int dw = (px + iw >= w) ? w - px : iw; - int srcX = tmpImage->mBounds.x; - int dstX = x + px + mClipStack.top().xOffset; + const int dw = (px + iw >= w) ? w - px : iw; + const int srcX = tmpImage->mBounds.x; + const int dstX = x + px + mClipStack.top().xOffset; SDL_Rect dstRect; SDL_Rect srcRect; @@ -539,12 +547,17 @@ void Graphics::drawRescaledImagePattern(Image *image, int x, int y, delete tmpImage; } -void Graphics::drawImageRect(int x, int y, int w, int h, - Image *topLeft, Image *topRight, - Image *bottomLeft, Image *bottomRight, - Image *top, Image *right, - Image *bottom, Image *left, - Image *center) +void Graphics::drawImageRect(const int x, const int y, + const int w, const int h, + const Image *const topLeft, + const Image *const topRight, + const Image *const bottomLeft, + const Image *const bottomRight, + const Image *const top, + const Image *const right, + const Image *const bottom, + const Image *const left, + const Image *const center) { const bool drawMain = center && topLeft && topRight && bottomLeft && bottomRight; @@ -599,7 +612,8 @@ void Graphics::drawImageRect(int x, int y, int w, int h, imgRect.grid[4]); } -void Graphics::drawImageRect2(GraphicsVertexes* vert, const ImageRect &imgRect) +void Graphics::drawImageRect2(GraphicsVertexes *const vert, + const ImageRect &imgRect) { if (!vert) return; @@ -644,11 +658,12 @@ void Graphics::drawImageRect2(GraphicsVertexes* vert, const ImageRect &imgRect) } } -void Graphics::drawImagePattern2(GraphicsVertexes *vert, const Image *img) +void Graphics::drawImagePattern2(GraphicsVertexes *const vert, + const Image *const img) { // here not checking input parameters - std::vector *arr = vert->getRectsSDL(); + std::vector *const arr = vert->getRectsSDL(); for (std::vector::const_iterator it = arr->begin(), it_end = arr->end(); it != it_end; ++it) @@ -658,13 +673,18 @@ void Graphics::drawImagePattern2(GraphicsVertexes *vert, const Image *img) } } -bool Graphics::calcImageRect(GraphicsVertexes* vert, - int x, int y, int w, int h, - Image *topLeft, Image *topRight, - Image *bottomLeft, Image *bottomRight, - Image *top, Image *right, - Image *bottom, Image *left, - Image *center) +bool Graphics::calcImageRect(GraphicsVertexes *const vert, + const int x, const int y, + const int w, const int h, + const Image *const topLeft, + const Image *const topRight, + const Image *const bottomLeft, + const Image *const bottomRight, + const Image *const top, + const Image *const right, + const Image *const bottom, + const Image *const left, + const Image *const center) { if (!vert) return false; @@ -716,8 +736,10 @@ bool Graphics::calcImageRect(GraphicsVertexes* vert, return 0; } -void Graphics::calcImagePattern(GraphicsVertexes* vert, - Image *image, int x, int y, int w, int h) +void Graphics::calcImagePattern(GraphicsVertexes* const vert, + const Image *const image, + const int x, const int y, + const int w, const int h) { // Check that preconditions for blitting are met. if (!vert || !mTarget || !image || !image->mSDLSurface || !vert->sdl) @@ -738,15 +760,15 @@ void Graphics::calcImagePattern(GraphicsVertexes* vert, for (int py = 0; py < h; py += ih) // Y position on pattern plane { - int dh = (py + ih >= h) ? h - py : ih; - int srcY = image->mBounds.y; - int dstY = y + py + mClipStack.top().yOffset; + const int dh = (py + ih >= h) ? h - py : ih; + const int srcY = image->mBounds.y; + const int dstY = y + py + mClipStack.top().yOffset; for (int px = 0; px < w; px += iw) // X position on pattern plane { - int dw = (px + iw >= w) ? w - px : iw; - int srcX = image->mBounds.x; - int dstX = x + px + mClipStack.top().xOffset; + const int dw = (px + iw >= w) ? w - px : iw; + const int srcX = image->mBounds.x; + const int dstX = x + px + mClipStack.top().xOffset; SDL_Rect dstRect; SDL_Rect srcRect; @@ -767,13 +789,13 @@ void Graphics::calcImagePattern(GraphicsVertexes* vert, vert->incPtr(1); } -void Graphics::calcTile(ImageVertexes *vert, int x, int y) +void Graphics::calcTile(ImageVertexes *const vert, int x, int y) { // Check that preconditions for blitting are met. if (!vert || !vert->image || !vert->image->mSDLSurface) return; - const Image *image = vert->image; + const Image *const image = vert->image; x += mClipStack.top().xOffset; y += mClipStack.top().yOffset; @@ -797,13 +819,13 @@ void Graphics::calcTile(ImageVertexes *vert, int x, int y) } } -void Graphics::drawTile(ImageVertexes *vert) +void Graphics::drawTile(const ImageVertexes *const vert) { // vert and img must be != 0 - Image *img = vert->image; - DoubleRects *rects = &vert->sdl; + const Image *const img = vert->image; + const DoubleRects *const rects = &vert->sdl; DoubleRects::const_iterator it = rects->begin(); - DoubleRects::const_iterator it_end = rects->end(); + const DoubleRects::const_iterator it_end = rects->end(); while (it != it_end) { SDL_LowerBlit(img->mSDLSurface, &(*it)->src, mTarget, &(*it)->dst); @@ -827,18 +849,18 @@ void Graphics::updateScreen() SDL_Surface *Graphics::getScreenshot() { #if SDL_BYTEORDER == SDL_BIG_ENDIAN - int rmask = 0xff000000; - int gmask = 0x00ff0000; - int bmask = 0x0000ff00; + const int rmask = 0xff000000; + const int gmask = 0x00ff0000; + const int bmask = 0x0000ff00; #else - int rmask = 0x000000ff; - int gmask = 0x0000ff00; - int bmask = 0x00ff0000; + const int rmask = 0x000000ff; + const int gmask = 0x0000ff00; + const int bmask = 0x00ff0000; #endif - int amask = 0x00000000; + const int amask = 0x00000000; - SDL_Surface *screenshot = SDL_CreateRGBSurface(SDL_SWSURFACE, mTarget->w, - mTarget->h, 24, rmask, gmask, bmask, amask); + SDL_Surface *const screenshot = SDL_CreateRGBSurface(SDL_SWSURFACE, + mTarget->w, mTarget->h, 24, rmask, gmask, bmask, amask); if (screenshot) SDL_BlitSurface(mTarget, nullptr, screenshot, nullptr); @@ -846,7 +868,8 @@ SDL_Surface *Graphics::getScreenshot() return screenshot; } -bool Graphics::drawNet(int x1, int y1, int x2, int y2, int width, int height) +bool Graphics::drawNet(const int x1, const int y1, const int x2, const int y2, + const int width, const int height) { for (int y = y1; y < y2; y += height) drawLine(x1, y, x2, y); @@ -857,8 +880,8 @@ bool Graphics::drawNet(int x1, int y1, int x2, int y2, int width, int height) return true; } -bool Graphics::calcWindow(GraphicsVertexes* vert, - int x, int y, int w, int h, +bool Graphics::calcWindow(GraphicsVertexes *const vert, + const int x, const int y, const int w, const int h, const ImageRect &imgRect) { return calcImageRect(vert, x, y, w, h, @@ -867,8 +890,10 @@ bool Graphics::calcWindow(GraphicsVertexes* vert, imgRect.grid[4]); } -int Graphics::SDL_FakeUpperBlit(SDL_Surface *src, SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect) +int Graphics::SDL_FakeUpperBlit(const SDL_Surface *const src, + SDL_Rect *const srcrect, + SDL_Surface *const dst, + SDL_Rect *dstrect) const { SDL_Rect fulldst; int srcx, srcy, w, h; @@ -927,7 +952,7 @@ int Graphics::SDL_FakeUpperBlit(SDL_Surface *src, SDL_Rect *srcrect, /* clip the destination rectangle against the clip rectangle */ { - SDL_Rect *clip = &dst->clip_rect; + const SDL_Rect *const clip = &dst->clip_rect; int dx, dy; dx = clip->x - dstrect->x; @@ -985,18 +1010,18 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle) if (mAlpha) { - int x1 = area.x > top.x ? area.x : top.x; - int y1 = area.y > top.y ? area.y : top.y; - int x2 = area.x + area.width < top.x + top.width ? + const int x1 = area.x > top.x ? area.x : top.x; + const int y1 = area.y > top.y ? area.y : top.y; + const int x2 = area.x + area.width < top.x + top.width ? area.x + area.width : top.x + top.width; - int y2 = area.y + area.height < top.y + top.height ? + const int y2 = area.y + area.height < top.y + top.height ? area.y + area.height : top.y + top.height; int x, y; SDL_LockSurface(mTarget); const int bpp = mTarget->format->BytesPerPixel; - uint32_t pixel = SDL_MapRGB(mTarget->format, + const uint32_t pixel = SDL_MapRGB(mTarget->format, static_cast(mColor.r), static_cast(mColor.g), static_cast(mColor.b)); @@ -1005,7 +1030,7 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle) case 1: for (y = y1; y < y2; y++) { - uint8_t *p = static_cast(mTarget->pixels) + uint8_t *const p = static_cast(mTarget->pixels) + y * mTarget->pitch; for (x = x1; x < x2; x++) *(p + x) = static_cast(pixel); @@ -1014,11 +1039,11 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle) case 2: for (y = y1; y < y2; y++) { - uint8_t *p0 = static_cast(mTarget->pixels) + uint8_t *const p0 = static_cast(mTarget->pixels) + y * mTarget->pitch; for (x = x1; x < x2; x++) { - uint8_t *p = p0 + x * 2; + uint8_t *const p = p0 + x * 2; *reinterpret_cast(p) = gcn::SDLAlpha16( static_cast(pixel), *reinterpret_cast(p), @@ -1035,11 +1060,11 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle) for (y = y1; y < y2; y++) { - uint8_t *p0 = static_cast(mTarget->pixels) + uint8_t *const p0 = static_cast(mTarget->pixels) + y * mTarget->pitch; for (x = x1; x < x2; x++) { - uint8_t *p = p0 + x * 3; + uint8_t *const p = p0 + x * 3; #if SDL_BYTEORDER == SDL_BIG_ENDIAN p[2] = static_cast((p[2] * ca + cb) >> 8); p[1] = static_cast((p[1] * ca + cg) >> 8); @@ -1111,12 +1136,12 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle) for (y = y1; y < y2; y++) { - uint32_t *p0 = reinterpret_cast( + uint32_t *const p0 = reinterpret_cast( static_cast(mTarget->pixels) + y * mTarget->pitch); for (x = x1; x < x2; x++) { - uint32_t *p = p0 + x; + uint32_t *const p = p0 + x; const uint32_t dst = *p; *p = cB[dst & 0xff] | cG[(dst & 0xff00) >> 8] | cR[(dst & 0xff0000) >> 16]; @@ -1139,7 +1164,7 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle) rect.w = static_cast(area.width); rect.h = static_cast(area.height); - uint32_t color = SDL_MapRGBA(mTarget->format, + const uint32_t color = SDL_MapRGBA(mTarget->format, static_cast(mColor.r), static_cast(mColor.g), static_cast(mColor.b), diff --git a/src/graphics.h b/src/graphics.h index 06461efe4..bee74850b 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -97,7 +97,7 @@ class Graphics : public gcn::SDLGraphics * Sets whether vertical refresh syncing is enabled. Takes effect after * the next call to setVideoMode(). Only implemented on MacOS for now. */ - void setSync(bool sync); + void setSync(const bool sync); bool getSync() const { return mSync; } @@ -105,18 +105,19 @@ class Graphics : public gcn::SDLGraphics /** * Try to create a window with the given settings. */ - virtual bool setVideoMode(int w, int h, int bpp, bool fs, - bool hwaccel, bool resize, bool noFrame); + virtual bool setVideoMode(const int w, const int h, const int bpp, + const bool fs, const bool hwaccel, + const bool resize, const bool noFrame); /** * Set fullscreen mode. */ - bool setFullscreen(bool fs); + bool setFullscreen(const bool fs); /** * Resize the window to the specified size. */ - bool resizeScreen(int width, int height); + bool resizeScreen(const int width, const int height); /** * Blits an image onto the screen. @@ -129,10 +130,10 @@ class Graphics : public gcn::SDLGraphics /** * Draws a resclaled version of the image */ - bool drawRescaledImage(Image *image, int srcX, int srcY, + bool drawRescaledImage(Image *const image, int srcX, int srcY, int dstX, int dstY, - int width, int height, - int desiredWidth, int desiredHeight) + const int width, const int height, + const int desiredWidth, const int desiredHeight) { return drawRescaledImage(image, srcX, srcY, dstX, dstY, @@ -144,35 +145,41 @@ class Graphics : public gcn::SDLGraphics /** * Draws a resclaled version of the image */ - virtual bool drawRescaledImage(Image *image, int srcX, int srcY, - int dstX, int dstY, - int width, int height, - int desiredWidth, int desiredHeight, - bool useColor = false); + virtual bool drawRescaledImage(Image *const image, int srcX, + int srcY, int dstX, int dstY, + const int width, const int height, + const int desiredWidth, + const int desiredHeight, + const bool useColor = false); - virtual void drawImagePattern(const Image *image, - int x, int y, - int w, int h); + virtual void drawImagePattern(const Image *const image, + const int x, const int y, + const int w, const int h); /** * Draw a pattern based on a rescaled version of the given image... */ - virtual void drawRescaledImagePattern(Image *image, - int x, int y, int w, int h, - int scaledWidth, - int scaledHeight); + virtual void drawRescaledImagePattern(const Image *const image, + const int x, const int y, + const int w, const int h, + const int scaledWidth, + const int scaledHeight); /** * Draws a rectangle using images. 4 corner images, 4 side images and 1 * image for the inside. */ - void drawImageRect(int x, int y, int w, int h, - Image *topLeft, Image *topRight, - Image *bottomLeft, Image *bottomRight, - Image *top, Image *right, - Image *bottom, Image *left, - Image *center); + void drawImageRect(const int x, const int y, const int w, const int h, + const Image *const topLeft, + const Image *const topRight, + const Image *const bottomLeft, + const Image *const bottomRight, + const Image *const top, + const Image *const right, + const Image *const bottom, + const Image *const left, + const Image *const center); /** * Draws a rectangle using images. 4 corner images, 4 side images and 1 @@ -181,30 +188,36 @@ class Graphics : public gcn::SDLGraphics void drawImageRect(int x, int y, int w, int h, const ImageRect &imgRect); - virtual bool calcImageRect(GraphicsVertexes* vert, - int x, int y, int w, int h, - Image *topLeft, Image *topRight, - Image *bottomLeft, Image *bottomRight, - Image *top, Image *right, - Image *bottom, Image *left, - Image *center); - - virtual void calcImagePattern(GraphicsVertexes* vert, Image *image, - int x, int y, - int w, int h); - - virtual void calcTile(ImageVertexes *vert, int x, int y); - - virtual void drawTile(ImageVertexes *vert); - - virtual void drawImageRect2(GraphicsVertexes* vert, + virtual bool calcImageRect(GraphicsVertexes *const vert, + const int x, const int y, + const int w, const int h, + const Image *const topLeft, + const Image *const topRight, + const Image *const bottomLeft, + const Image *const bottomRight, + const Image *const top, + const Image *const right, + const Image *const bottom, + const Image *const left, + const Image *const center); + + virtual void calcImagePattern(GraphicsVertexes *const vert, + const Image *const image, + const int x, const int y, + const int w, const int h); + + virtual void calcTile(ImageVertexes *const vert, int x, int y); + + virtual void drawTile(const ImageVertexes *const vert); + + virtual void drawImageRect2(GraphicsVertexes *const vert, const ImageRect &imgRect); - virtual void drawImagePattern2(GraphicsVertexes *vert, - const Image *img); + virtual void drawImagePattern2(GraphicsVertexes *const vert, + const Image *const img); - bool calcWindow(GraphicsVertexes* vert, - int x, int y, int w, int h, + bool calcWindow(GraphicsVertexes *const vert, + const int x, const int y, const int w, const int h, const ImageRect &imgRect); /** @@ -215,7 +228,7 @@ class Graphics : public gcn::SDLGraphics const ImageRect &imgRect) { drawImageRect(area.x, area.y, area.width, area.height, imgRect); } - void setBlitMode(BlitMode mode) + void setBlitMode(const BlitMode mode) { mBlitMode = mode; } BlitMode getBlitMode() const @@ -247,10 +260,11 @@ class Graphics : public gcn::SDLGraphics virtual void prepareScreenshot() { } - int getMemoryUsage(); + int getMemoryUsage() const; - virtual bool drawNet(int x1, int y1, int x2, int y2, - int width, int height); + virtual bool drawNet(const int x1, const int y1, + const int x2, const int y2, + const int width, const int height); gcn::Font *getFont() const { return mFont; } @@ -258,13 +272,13 @@ class Graphics : public gcn::SDLGraphics gcn::ClipRectangle &getTopClip() { return mClipStack.top(); } - void setRedraw(bool n) + void setRedraw(const bool n) { mRedraw = n; } bool getRedraw() const { return mRedraw; } - void setSecure(bool n) + void setSecure(const bool n) { mSecure = n; } bool getSecure() const @@ -282,13 +296,13 @@ class Graphics : public gcn::SDLGraphics bool getDoubleBuffer() const { return mDoubleBuffer; } - int getOpenGL() + int getOpenGL() const { return mOpenGL; } - void setNoFrame(bool n) + void setNoFrame(const bool n) { mNoFrame = n; } - const std::string &getName() + const std::string &getName() const { return mName; } int mWidth; @@ -301,19 +315,19 @@ class Graphics : public gcn::SDLGraphics * @return true if the image was blitted properly * false otherwise. */ - virtual bool drawImage2(const Image *image, + virtual bool drawImage2(const Image *const image, int srcX, int srcY, int dstX, int dstY, - int width, int height, - bool useColor); + const int width, const int height, + const bool useColor); void setMainFlags(int w, int h, int bpp, bool fs, bool hwaccel, bool resize, bool noFrame); - int getOpenGLFlags(); + int getOpenGLFlags() const; - int getSoftwareFlags(); + int getSoftwareFlags() const; bool setOpenGLMode(); @@ -321,8 +335,10 @@ class Graphics : public gcn::SDLGraphics bool videoInfo(); - int SDL_FakeUpperBlit(SDL_Surface *src, SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect); + int SDL_FakeUpperBlit(const SDL_Surface *const src, + SDL_Rect *const srcrect, + SDL_Surface *const dst, + SDL_Rect *dstrect) const; int mBpp; bool mFullscreen; diff --git a/src/normalopenglgraphics.cpp b/src/normalopenglgraphics.cpp index 89223838d..32ab1f6c2 100644 --- a/src/normalopenglgraphics.cpp +++ b/src/normalopenglgraphics.cpp @@ -73,9 +73,10 @@ NormalOpenGLGraphics::~NormalOpenGLGraphics() delete [] mIntVertArray; } -bool NormalOpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, - bool hwaccel, bool resize, - bool noFrame) +bool NormalOpenGLGraphics::setVideoMode(const int w, const int h, + const int bpp, const bool fs, + const bool hwaccel, const bool resize, + const bool noFrame) { setMainFlags(w, h, bpp, fs, hwaccel, resize, noFrame); @@ -143,7 +144,7 @@ static inline void drawQuad(const Image *image, } } -static inline void drawRescaledQuad(Image *image, +static inline void drawRescaledQuad(const Image *const image, int srcX, int srcY, int dstX, int dstY, int width, int height, int desiredWidth, int desiredHeight) @@ -206,9 +207,11 @@ static inline void drawRescaledQuad(Image *image, } -bool NormalOpenGLGraphics::drawImage2(const Image *image, int srcX, int srcY, +bool NormalOpenGLGraphics::drawImage2(const Image *const image, + int srcX, int srcY, int dstX, int dstY, - int width, int height, bool useColor) + const int width, const int height, + const bool useColor) { if (!image) return false; @@ -239,12 +242,12 @@ bool NormalOpenGLGraphics::drawImage2(const Image *image, int srcX, int srcY, return true; } -bool NormalOpenGLGraphics::drawRescaledImage(Image *image, int srcX, int srcY, - int dstX, int dstY, - int width, int height, - int desiredWidth, - int desiredHeight, - bool useColor) +bool NormalOpenGLGraphics::drawRescaledImage(Image *const image, int srcX, + int srcY, int dstX, int dstY, + const int width, const int height, + const int desiredWidth, + const int desiredHeight, + const bool useColor) { return drawRescaledImage(image, srcX, srcY, dstX, dstY, @@ -253,12 +256,13 @@ bool NormalOpenGLGraphics::drawRescaledImage(Image *image, int srcX, int srcY, useColor, true); } -bool NormalOpenGLGraphics::drawRescaledImage(Image *image, int srcX, int srcY, - int dstX, int dstY, - int width, int height, - int desiredWidth, - int desiredHeight, - bool useColor, bool smooth) +bool NormalOpenGLGraphics::drawRescaledImage(Image *const image, int srcX, + int srcY, int dstX, int dstY, + const int width, const int height, + const int desiredWidth, + const int desiredHeight, + const bool useColor, + bool smooth) { if (!image) return false; @@ -317,8 +321,9 @@ bool NormalOpenGLGraphics::drawRescaledImage(Image *image, int srcX, int srcY, return true; } -void NormalOpenGLGraphics::drawImagePattern(const Image *image, int x, int y, - int w, int h) +void NormalOpenGLGraphics::drawImagePattern(const Image *const image, + const int x, const int y, + const int w, const int h) { if (!image) return; @@ -452,11 +457,11 @@ void NormalOpenGLGraphics::drawImagePattern(const Image *image, int x, int y, static_cast(mColor.a)); } -void NormalOpenGLGraphics::drawRescaledImagePattern(Image *image, - int x, int y, - int w, int h, - int scaledWidth, - int scaledHeight) +void NormalOpenGLGraphics::drawRescaledImagePattern(const Image *const image, + const int x, const int y, + const int w, const int h, + const int scaledWidth, + const int scaledHeight) { if (!image) return; @@ -608,8 +613,8 @@ void NormalOpenGLGraphics::drawRescaledImagePattern(Image *image, static_cast(mColor.a)); } -void NormalOpenGLGraphics::drawImagePattern2(GraphicsVertexes *vert, - const Image *image) +void NormalOpenGLGraphics::drawImagePattern2(GraphicsVertexes *const vert, + const Image *const image) { if (!image) return; @@ -669,9 +674,10 @@ void NormalOpenGLGraphics::drawImagePattern2(GraphicsVertexes *vert, } -void NormalOpenGLGraphics::calcImagePattern(GraphicsVertexes* vert, - Image *image, - int x, int y, int w, int h) +void NormalOpenGLGraphics::calcImagePattern(GraphicsVertexes *const vert, + const Image *const image, + const int x, const int y, + const int w, const int h) { if (!image) { @@ -809,7 +815,8 @@ void NormalOpenGLGraphics::calcImagePattern(GraphicsVertexes* vert, vert->incPtr(1); } -void NormalOpenGLGraphics::calcTile(ImageVertexes *vert, int dstX, int dstY) +void NormalOpenGLGraphics::calcTile(ImageVertexes *const vert, + int dstX, int dstY) { if (!vert) return; @@ -926,7 +933,7 @@ void NormalOpenGLGraphics::calcTile(ImageVertexes *vert, int dstX, int dstY) ogl->ptr = vp; } -void NormalOpenGLGraphics::drawTile(ImageVertexes *vert) +void NormalOpenGLGraphics::drawTile(const ImageVertexes *const vert) { if (!vert) return; @@ -1216,8 +1223,9 @@ void NormalOpenGLGraphics::drawRectangle(const gcn::Rectangle& rect, glEnableClientState(GL_TEXTURE_COORD_ARRAY); } -bool NormalOpenGLGraphics::drawNet(int x1, int y1, int x2, int y2, - int width, int height) +bool NormalOpenGLGraphics::drawNet(const int x1, const int y1, + const int x2, const int y2, + const int width, const int height) { unsigned int vp = 0; const unsigned int vLimit = vertexBufSize * 4; diff --git a/src/normalopenglgraphics.h b/src/normalopenglgraphics.h index 875b04bee..45973941a 100644 --- a/src/normalopenglgraphics.h +++ b/src/normalopenglgraphics.h @@ -46,47 +46,53 @@ class NormalOpenGLGraphics : public Graphics ~NormalOpenGLGraphics(); - bool setVideoMode(int w, int h, int bpp, bool fs, - bool hwaccel, bool resize, bool noFrame); + bool setVideoMode(const int w, const int h, const int bpp, + const bool fs, const bool hwaccel, + const bool resize, const bool noFrame); /** * Draws a resclaled version of the image */ - bool drawRescaledImage(Image *image, int srcX, int srcY, + bool drawRescaledImage(Image *const image, int srcX, int srcY, int dstX, int dstY, - int width, int height, - int desiredWidth, int desiredHeight, - bool useColor); + const int width, const int height, + const int desiredWidth, const int desiredHeight, + const bool useColor); /** * Used to get the smooth rescale option over the standard function. */ - bool drawRescaledImage(Image *image, int srcX, int srcY, + bool drawRescaledImage(Image *const image, int srcX, int srcY, int dstX, int dstY, - int width, int height, - int desiredWidth, int desiredHeight, - bool useColor, bool smooth); + const int width, const int height, + const int desiredWidth, const int desiredHeight, + const bool useColor, bool smooth); - void drawImagePattern(const Image *image, - int x, int y, - int w, int h); + void drawImagePattern(const Image *const image, + const int x, const int y, + const int w, const int h); /** * Draw a pattern based on a rescaled version of the given image... */ - void drawRescaledImagePattern(Image *image, - int x, int y, int w, int h, - int scaledWidth, int scaledHeight); + void drawRescaledImagePattern(const Image *const image, + const int x, const int y, + const int w, const int h, + const int scaledWidth, + const int scaledHeight); - void calcImagePattern(GraphicsVertexes* vert, Image *image, - int x, int y, int w, int h); + void calcImagePattern(GraphicsVertexes *const vert, + const Image *const image, + const int x, const int y, + const int w, const int h); - void calcTile(ImageVertexes *vert, int x, int y); + void calcTile(ImageVertexes *const vert, int x, int y); - void drawTile(ImageVertexes *vert); + void drawTile(const ImageVertexes *const vert); - void drawImagePattern2(GraphicsVertexes *vert, const Image *image); + void drawImagePattern2(GraphicsVertexes *const vert, + const Image *const image); void updateScreen(); @@ -133,7 +139,8 @@ class NormalOpenGLGraphics : public Graphics void prepareScreenshot(); - bool drawNet(int x1, int y1, int x2, int y2, int width, int height); + bool drawNet(const int x1, const int y1, const int x2, const int y2, + const int width, const int height); int getMemoryUsage(); @@ -144,11 +151,11 @@ class NormalOpenGLGraphics : public Graphics static GLuint mLastImage; protected: - bool drawImage2(const Image *image, + bool drawImage2(const Image *const image, int srcX, int srcY, int dstX, int dstY, - int width, int height, - bool useColor); + const int width, const int height, + const bool useColor); void setTexturingAndBlending(bool enable); diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 9c5909b8d..3b91b3f31 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -286,7 +286,7 @@ void Image::setAlpha(float alpha) } } -Image* Image::SDLgetScaledImage(int width, int height) +Image* Image::SDLgetScaledImage(const int width, const int height) const { // No scaling on incorrect new values. if (width == 0 || height == 0) diff --git a/src/resources/image.h b/src/resources/image.h index 84895125c..4798c87af 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -128,7 +128,7 @@ class Image : public Resource * * @return A new Image* object. */ - Image* SDLgetScaledImage(int width, int height); + Image* SDLgetScaledImage(const int width, const int height) const; /** * Get the alpha Channel of a SDL surface. diff --git a/src/safeopenglgraphics.cpp b/src/safeopenglgraphics.cpp index 1cc9bc3d8..306298eeb 100644 --- a/src/safeopenglgraphics.cpp +++ b/src/safeopenglgraphics.cpp @@ -57,8 +57,9 @@ SafeOpenGLGraphics::~SafeOpenGLGraphics() { } -bool SafeOpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, - bool hwaccel, bool resize, bool noFrame) +bool SafeOpenGLGraphics::setVideoMode(const int w, const int h, const int bpp, + const bool fs, const bool hwaccel, + const bool resize, const bool noFrame) { setMainFlags(w, h, bpp, fs, hwaccel, resize, noFrame); @@ -103,7 +104,7 @@ static inline void drawQuad(const Image *image, } } -static inline void drawRescaledQuad(Image *image, int srcX, int srcY, +static inline void drawRescaledQuad(const Image *const image, int srcX, int srcY, int dstX, int dstY, int width, int height, int desiredWidth, int desiredHeight) { @@ -142,9 +143,11 @@ static inline void drawRescaledQuad(Image *image, int srcX, int srcY, } -bool SafeOpenGLGraphics::drawImage2(const Image *image, int srcX, int srcY, +bool SafeOpenGLGraphics::drawImage2(const Image *const image, + int srcX, int srcY, int dstX, int dstY, - int width, int height, bool useColor) + const int width, const int height, + const bool useColor) { if (!image) return false; @@ -175,11 +178,12 @@ bool SafeOpenGLGraphics::drawImage2(const Image *image, int srcX, int srcY, return true; } -bool SafeOpenGLGraphics::drawRescaledImage(Image *image, int srcX, int srcY, - int dstX, int dstY, - int width, int height, - int desiredWidth, int desiredHeight, - bool useColor) +bool SafeOpenGLGraphics::drawRescaledImage(Image *const image, int srcX, + int srcY, int dstX, int dstY, + const int width, const int height, + const int desiredWidth, + const int desiredHeight, + const bool useColor) { return drawRescaledImage(image, srcX, srcY, dstX, dstY, @@ -188,11 +192,13 @@ bool SafeOpenGLGraphics::drawRescaledImage(Image *image, int srcX, int srcY, useColor, true); } -bool SafeOpenGLGraphics::drawRescaledImage(Image *image, int srcX, int srcY, - int dstX, int dstY, - int width, int height, - int desiredWidth, int desiredHeight, - bool useColor, bool smooth) +bool SafeOpenGLGraphics::drawRescaledImage(Image *const image, int srcX, + int srcY, int dstX, int dstY, + const int width, const int height, + const int desiredWidth, + const int desiredHeight, + const bool useColor, + bool smooth) { if (!image) return false; @@ -253,8 +259,9 @@ bool SafeOpenGLGraphics::drawRescaledImage(Image *image, int srcX, int srcY, /* Optimising the functions that Graphics::drawImagePattern would call, * so that glBegin...glEnd are outside the main loop. */ -void SafeOpenGLGraphics::drawImagePattern(const Image *image, int x, int y, - int w, int h) +void SafeOpenGLGraphics::drawImagePattern(const Image *const image, + const int x, const int y, + const int w, const int h) { if (!image) return; @@ -297,10 +304,11 @@ void SafeOpenGLGraphics::drawImagePattern(const Image *image, int x, int y, static_cast(mColor.a)); } -void SafeOpenGLGraphics::drawRescaledImagePattern(Image *image, int x, int y, - int w, int h, - int scaledWidth, - int scaledHeight) +void SafeOpenGLGraphics::drawRescaledImagePattern(const Image *const image, + const int x, const int y, + const int w, const int h, + const int scaledWidth, + const int scaledHeight) { if (!image) return; @@ -348,17 +356,18 @@ void SafeOpenGLGraphics::drawRescaledImagePattern(Image *image, int x, int y, static_cast(mColor.b), static_cast(mColor.a)); } -bool SafeOpenGLGraphics::calcImageRect(GraphicsVertexes* vert, - int x, int y, int w, int h, - Image *topLeft A_UNUSED, - Image *topRight A_UNUSED, - Image *bottomLeft A_UNUSED, - Image *bottomRight A_UNUSED, - Image *top A_UNUSED, - Image *right A_UNUSED, - Image *bottom A_UNUSED, - Image *left A_UNUSED, - Image *center A_UNUSED) +bool SafeOpenGLGraphics::calcImageRect(GraphicsVertexes *const vert, + const int x, const int y, + const int w, const int h, + const Image *const topLeft A_UNUSED, + const Image *const topRight A_UNUSED, + const Image *const bottomLeft A_UNUSED, + const Image *const bottomRight A_UNUSED, + const Image *const top A_UNUSED, + const Image *const right A_UNUSED, + const Image *const bottom A_UNUSED, + const Image *const left A_UNUSED, + const Image *const center A_UNUSED) { if (!vert) return false; @@ -367,13 +376,13 @@ bool SafeOpenGLGraphics::calcImageRect(GraphicsVertexes* vert, return true; } -void SafeOpenGLGraphics::calcTile(ImageVertexes *vert A_UNUSED, +void SafeOpenGLGraphics::calcTile(ImageVertexes *const vert A_UNUSED, int x A_UNUSED, int y A_UNUSED) { } -void SafeOpenGLGraphics::drawTile(ImageVertexes *vert A_UNUSED) +void SafeOpenGLGraphics::drawTile(const ImageVertexes *const vert A_UNUSED) { } diff --git a/src/safeopenglgraphics.h b/src/safeopenglgraphics.h index 8a5f7bc17..a1d744282 100644 --- a/src/safeopenglgraphics.h +++ b/src/safeopenglgraphics.h @@ -43,51 +43,60 @@ class SafeOpenGLGraphics : public Graphics ~SafeOpenGLGraphics(); - bool setVideoMode(int w, int h, int bpp, bool fs, - bool hwaccel, bool resize, bool noFrame); + bool setVideoMode(const int w, const int h, const int bpp, + const bool fs, const bool hwaccel, + const bool resize, const bool noFrame); /** * Draws a resclaled version of the image */ - bool drawRescaledImage(Image *image, int srcX, int srcY, + bool drawRescaledImage(Image *const image, int srcX, int srcY, int dstX, int dstY, - int width, int height, - int desiredWidth, int desiredHeight, - bool useColor); + const int width, const int height, + const int desiredWidth, const int desiredHeight, + const bool useColor); /** * Used to get the smooth rescale option over the standard function. */ - bool drawRescaledImage(Image *image, int srcX, int srcY, + bool drawRescaledImage(Image *const image, int srcX, int srcY, int dstX, int dstY, - int width, int height, - int desiredWidth, int desiredHeight, - bool useColor, bool smooth); + const int width, const int height, + const int desiredWidth, const int desiredHeight, + const bool useColor, bool smooth); - void drawImagePattern(const Image *image, - int x, int y, - int w, int h); + void drawImagePattern(const Image *const image, + const int x, const int y, + const int w, const int h); /** * Draw a pattern based on a rescaled version of the given image... */ - void drawRescaledImagePattern(Image *image, - int x, int y, int w, int h, - int scaledWidth, int scaledHeight); - - bool calcImageRect(GraphicsVertexes* vert, - int x, int y, int w, int h, - Image *topLeft, Image *topRight, - Image *bottomLeft, Image *bottomRight, - Image *top, Image *right, - Image *bottom, Image *left, - Image *center); - - void drawImageRect2(GraphicsVertexes* vert, const ImageRect &imgRect); - - void calcTile(ImageVertexes *vert, int x, int y); - - void drawTile(ImageVertexes *vert); + void drawRescaledImagePattern(const Image *const image, + const int x, const int y, + const int w, const int h, + const int scaledWidth, + const int scaledHeight); + + bool calcImageRect(GraphicsVertexes *const vert, + const int x, const int y, + const int w, const int h, + const Image *const topLeft, + const Image *const topRight, + const Image *const bottomLeft, + const Image *const bottomRight, + const Image *const top, + const Image *const right, + const Image *const bottom, + const Image *const left, + const Image *const center); + + void drawImageRect2(GraphicsVertexes *const vert, + const ImageRect &imgRect); + + void calcTile(ImageVertexes *const vert, int x, int y); + + void drawTile(const ImageVertexes *const vert); void updateScreen(); @@ -123,11 +132,11 @@ class SafeOpenGLGraphics : public Graphics static GLuint mLastImage; protected: - bool drawImage2(const Image *image, + bool drawImage2(const Image *const image, int srcX, int srcY, int dstX, int dstY, - int width, int height, - bool useColor); + const int width, const int height, + const bool useColor); void setTexturingAndBlending(bool enable); -- cgit v1.2.3-70-g09d2