From 6d8828b47e291c0e85645adb60c8969a3f8facf4 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 5 May 2012 23:08:18 +0300 Subject: Improve images drawing and remove some useless code. --- src/CMakeLists.txt | 2 - src/Makefile.am | 2 - src/graphics.cpp | 15 +----- src/graphics.h | 6 --- src/gui/gui.cpp | 5 -- src/guichan/graphics.cpp | 5 +- src/guichan/sdl/sdlgraphics.cpp | 90 +++---------------------------- src/guichanfwd.h | 1 - src/resources/imageloader.cpp | 117 ---------------------------------------- src/resources/imageloader.h | 70 ------------------------ 10 files changed, 11 insertions(+), 302 deletions(-) delete mode 100644 src/resources/imageloader.cpp delete mode 100644 src/resources/imageloader.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 68a0966a9..604484dde 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -411,8 +411,6 @@ SET(SRCS resources/emotedb.h resources/image.cpp resources/image.h - resources/imageloader.cpp - resources/imageloader.h resources/imageset.h resources/imageset.cpp resources/imagewriter.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 1f6ebd60f..295391096 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -427,8 +427,6 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ resources/emotedb.h \ resources/image.cpp \ resources/image.h \ - resources/imageloader.cpp \ - resources/imageloader.h \ resources/imageset.h \ resources/imageset.cpp \ resources/imagewriter.cpp \ diff --git a/src/graphics.cpp b/src/graphics.cpp index 677172420..f72e495c6 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -30,8 +30,6 @@ #include "logger.h" #include "resources/image.h" -#include "resources/imageloader.h" - #include "utils/stringutils.h" #include @@ -358,7 +356,7 @@ bool Graphics::drawImage(Image *image, int x, int y) if (image) { return drawImage(image, 0, 0, x, y, - image->mBounds.w, image->mBounds.h); + image->mBounds.w, image->mBounds.h, false); } else { @@ -444,17 +442,6 @@ bool Graphics::drawImage(Image *image, int srcX, int srcY, int dstX, int dstY, } } -void Graphics::drawImage(gcn::Image const *image, int srcX, int srcY, - int dstX, int dstY, int width, int height) -{ - ProxyImage const *srcImage = - dynamic_cast< ProxyImage const * >(image); - if (!srcImage) - return; - drawImage(srcImage->getImage(), srcX, srcY, dstX, dstY, - width, height, true); -} - void Graphics::drawImagePattern(Image *image, int x, int y, int w, int h) { // Check that preconditions for blitting are met. diff --git a/src/graphics.h b/src/graphics.h index 9b69f2f60..805b3a02f 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -117,12 +117,6 @@ class Graphics : public gcn::SDLGraphics */ bool drawImage(Image *image, int x, int y); - /** - * Overrides with our own drawing method. - */ - void drawImage(gcn::Image const *image, int srcX, int srcY, - int dstX, int dstY, int width, int height); - /** * Draws a resclaled version of the image */ diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 1536feb68..ea6112262 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -42,7 +42,6 @@ #include "resources/image.h" #include "resources/imageset.h" -#include "resources/imageloader.h" #include "resources/resourcemanager.h" #include "utils/langs.h" @@ -89,10 +88,6 @@ Gui::Gui(Graphics *graphics): // Set graphics setGraphics(graphics); - // Set image loader - static ImageLoader imageLoader; - gcn::Image::setImageLoader(&imageLoader); - // Set input guiInput = new SDLInput; setInput(guiInput); diff --git a/src/guichan/graphics.cpp b/src/guichan/graphics.cpp index 0e414827c..1c99d899e 100644 --- a/src/guichan/graphics.cpp +++ b/src/guichan/graphics.cpp @@ -142,10 +142,9 @@ namespace gcn return mClipStack.top(); } - void Graphics::drawImage(const Image* image, int dstX, int dstY) + void Graphics::drawImage(const Image* image A_UNUSED, + int dstX A_UNUSED, int dstY A_UNUSED) { - drawImage(image, 0, 0, dstX, dstY, - image->getWidth(), image->getHeight()); } void Graphics::setFont(Font* font) diff --git a/src/guichan/sdl/sdlgraphics.cpp b/src/guichan/sdl/sdlgraphics.cpp index ae61a0432..63ed8bbc2 100644 --- a/src/guichan/sdl/sdlgraphics.cpp +++ b/src/guichan/sdl/sdlgraphics.cpp @@ -129,92 +129,18 @@ namespace gcn return mTarget; } - void SDLGraphics::drawImage(const Image* image, - int srcX, - int srcY, - int dstX, - int dstY, - int width, - int height) + void SDLGraphics::drawImage(const Image* image A_UNUSED, + int srcX A_UNUSED, + int srcY A_UNUSED, + int dstX A_UNUSED, + int dstY A_UNUSED, + int width A_UNUSED, + int height A_UNUSED) { - if (mClipStack.empty()) - { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a " - "draw funtion outside of _beginDraw() and _endDraw()?"); - } - - const ClipRectangle& top = mClipStack.top(); - - SDL_Rect src; - SDL_Rect dst; - src.x = srcX; - src.y = srcY; - src.w = width; - src.h = height; - dst.x = dstX + top.xOffset; - dst.y = dstY + top.yOffset; - - const SDLImage* srcImage = dynamic_cast(image); - - if (!srcImage) - { - throw GCN_EXCEPTION("Trying to draw an image of unknown format," - " must be an SDLImage."); - } - - SDL_BlitSurface(srcImage->getSurface(), &src, mTarget, &dst); } - void SDLGraphics::fillRectangle(const Rectangle& rectangle) + void SDLGraphics::fillRectangle(const Rectangle& rectangle A_UNUSED) { - if (mClipStack.empty()) - { - throw GCN_EXCEPTION("Clip stack is empty, perhaps you called a " - "draw funtion outside of _beginDraw() and _endDraw()?"); - } - - const ClipRectangle& top = mClipStack.top(); - - Rectangle area = rectangle; - area.x += top.xOffset; - area.y += top.yOffset; - - if (!area.isIntersecting(top)) - return; - - 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 ? - area.x + area.width : top.x + top.width; - int y2 = area.y + area.height < top.y + top.height ? - area.y + area.height : top.y + top.height; - int x, y; - - SDL_LockSurface(mTarget); - for (y = y1; y < y2; y++) - { - for (x = x1; x < x2; x++) - SDLputPixelAlpha(mTarget, x, y, mColor); - } - SDL_UnlockSurface(mTarget); - } - else - { - SDL_Rect rect; - rect.x = area.x; - rect.y = area.y; - rect.w = area.width; - rect.h = area.height; - - Uint32 color = SDL_MapRGBA(mTarget->format, - mColor.r, - mColor.g, - mColor.b, - mColor.a); - SDL_FillRect(mTarget, &rect, color); - } } void SDLGraphics::drawPoint(int x, int y) diff --git a/src/guichanfwd.h b/src/guichanfwd.h index 7ccc221b4..85a9c5cfa 100644 --- a/src/guichanfwd.h +++ b/src/guichanfwd.h @@ -53,7 +53,6 @@ namespace gcn class ImageButton; class InputEvent; class ImageFont; - class ImageLoader; class Input; class Key; class KeyEvent; diff --git a/src/resources/imageloader.cpp b/src/resources/imageloader.cpp deleted file mode 100644 index decf17189..000000000 --- a/src/resources/imageloader.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2007-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2012 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "resources/imageloader.h" - -#include "resources/image.h" -#include "resources/resourcemanager.h" - -#include - -#include - -#include "debug.h" - -#ifdef free -#undef free -#endif - -ProxyImage::ProxyImage(SDL_Surface *s): - mImage(nullptr), - mSDLImage(s) -{ -} - -ProxyImage::~ProxyImage() -{ - free(); -} - -void ProxyImage::free() -{ - if (mSDLImage) - { - SDL_FreeSurface(mSDLImage); - mSDLImage = nullptr; - } - else - { - delete mImage; - mImage = nullptr; - } -} - -int ProxyImage::getWidth() const -{ - if (mSDLImage) - return mSDLImage->w; - else if (mImage) - return mImage->mBounds.w; - else - return 0; -} - -int ProxyImage::getHeight() const -{ - if (mSDLImage) - return mSDLImage->h; - else if (mImage) - return mImage->mBounds.h; - else - return 0; -} - -gcn::Color ProxyImage::getPixel(int x, int y) -{ - return gcn::SDLgetPixel(mSDLImage, x, y); -} - -void ProxyImage::putPixel(int x, int y, gcn::Color const &color) -{ - if (!mSDLImage) - return; - gcn::SDLputPixel(mSDLImage, x, y, color); -} - -void ProxyImage::convertToDisplayFormat() -{ - if (!mSDLImage) - return; - - /* The picture is most probably full of the pink pixels Guichan uses for - transparency, as this function will only be called when setting an image - font. Get rid of them. */ - SDL_SetColorKey(mSDLImage, SDL_SRCCOLORKEY, - SDL_MapRGB(mSDLImage->format, 255, 0, 255)); - mImage = ::Image::load(mSDLImage); - SDL_FreeSurface(mSDLImage); - mSDLImage = nullptr; -} - -gcn::Image *ImageLoader::load(const std::string &filename, bool convert) -{ - ResourceManager *resman = ResourceManager::getInstance(); - ProxyImage *i = new ProxyImage(resman->loadSDLSurface(filename)); - if (convert) - i->convertToDisplayFormat(); - return i; -} diff --git a/src/resources/imageloader.h b/src/resources/imageloader.h deleted file mode 100644 index 1dcd046ca..000000000 --- a/src/resources/imageloader.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2007-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2012 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef IMAGELOADER_H -#define IMAGELOADER_H - -#include -#include - -#include - -class Image; -struct SDL_Surface; - -class ProxyImage : public gcn::Image -{ - public: - ProxyImage(SDL_Surface *); - ~ProxyImage(); - - void free(); - int getWidth() const; - int getHeight() const; - gcn::Color getPixel(int x, int y); - void putPixel(int x, int y, gcn::Color const &color); - void convertToDisplayFormat(); - - /** - * Gets the image handled by this proxy. - */ - ::Image *getImage() const - { return mImage; } - - private: - ::Image *mImage; /**< The real image. */ - - /** - * An SDL surface kept around until Guichan is done reading pixels from - * an OpenGL texture. - */ - SDL_Surface *mSDLImage; -}; - -class ImageLoader : public gcn::ImageLoader -{ - public: - gcn::Image *load(const std::string &filename, - bool convertToDisplayFormat); -}; - -#endif -- cgit v1.2.3-70-g09d2