summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gui/browserbox.cpp3
-rw-r--r--src/gui/gui.cpp23
-rw-r--r--src/resources/resourcemanager.cpp7
-rw-r--r--src/resources/resourcemanager.h5
-rw-r--r--src/resources/sdlimageloader.cpp84
-rw-r--r--src/resources/sdlimageloader.h37
8 files changed, 140 insertions, 29 deletions
diff --git a/ChangeLog b/ChangeLog
index cd779d3f..25ec1988 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-09-12 Björn Steinbrink <B.Steinbrink@gmx.de>
+
+ * M src/Makefile.am, src/gui/browserbox.cpp, src/gui/gui.cpp,
+ src/resources/resourcemanager.cpp, src/resources/resourcemanager.h,
+ src/resources/sdlimageloader.cpp, src/resources/sdlimageloader.h:
+ Added SDLImageLoader to make guichan support physfs. Removed
+ ResourceManager::getRealPath() because it's no longer needed.
+
2005-09-12 Bjørn Lindeijer <bjorn@lindeijer.nl>
* data/graphics/gui/hits_blue.png, data/graphics/gui/hits_red.png,
diff --git a/src/Makefile.am b/src/Makefile.am
index 53f158c6..5172a6d2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -123,6 +123,8 @@ tmw_SOURCES = graphic/spriteset.cpp \
resources/resource.h \
resources/resourcemanager.cpp \
resources/resourcemanager.h \
+ resources/sdlimageloader.h \
+ resources/sdlimageloader.cpp \
resources/soundeffect.h \
resources/soundeffect.cpp \
resources/buddylist.h \
diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp
index 5a87fa5b..3c389881 100644
--- a/src/gui/browserbox.cpp
+++ b/src/gui/browserbox.cpp
@@ -54,8 +54,7 @@ BrowserBox::BrowserBox(unsigned int mode):
#ifdef USE_OPENGL
if (config.getValue("opengl", 0)) {
browserFont = new gcn::ImageFont(
- ResourceManager::getInstance()->getRealPath(
- "graphics/gui/browserfont.png"),
+ "graphics/gui/browserfont.png",
" abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567"
"89:@!\"$%&/=?^+*#[]{}()<>_;'.,\\|-~`");
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 1c2b2063..3642b004 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -31,7 +31,6 @@
#include <guichan/opengl/openglimageloader.hpp>
#endif
-#include <guichan/sdl/sdlimageloader.hpp>
#include <guichan/sdl/sdlinput.hpp>
#include "focushandler.h"
@@ -52,6 +51,7 @@
#include "../resources/image.h"
#include "../resources/resourcemanager.h"
+#include "../resources/sdlimageloader.h"
extern Being* autoTarget;
@@ -92,13 +92,13 @@ Gui::Gui(Graphics *graphics):
if (config.getValue("opengl", 0)) {
// Set image loader
- mHostImageLoader = new gcn::SDLImageLoader();
+ mHostImageLoader = new SDLImageLoader();
mImageLoader = new gcn::OpenGLImageLoader(mHostImageLoader);
} else
#endif
{
// Set image loader
- mImageLoader = new gcn::SDLImageLoader();
+ mImageLoader = new SDLImageLoader();
}
// Set input
@@ -120,12 +120,9 @@ Gui::Gui(Graphics *graphics):
Window::setWindowContainer(guiTop);
setTop(guiTop);
- ResourceManager *resman = ResourceManager::getInstance();
-
// Set global font
try {
- mGuiFont = new gcn::ImageFont(
- resman->getRealPath("graphics/gui/sansserif8.png"),
+ mGuiFont = new gcn::ImageFont("graphics/gui/sansserif8.png",
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ["
"\\]^_`abcdefghijklmnopqrstuvwxyz{|}~|"
);
@@ -137,8 +134,7 @@ Gui::Gui(Graphics *graphics):
// Set speech font
try {
- speechFont = new gcn::ImageFont(
- resman->getRealPath("graphics/gui/rpgfont_wider.png"),
+ speechFont = new gcn::ImageFont("graphics/gui/rpgfont_wider.png",
" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789.,!?-+/():;%&`'*#=[]\"<>{}^~|_@&\\"
);
@@ -152,14 +148,11 @@ Gui::Gui(Graphics *graphics):
// Load hits' colourful fonts
try {
- hitRedFont = new gcn::ImageFont(
- resman->getRealPath("graphics/gui/hits_red.png"),
+ hitRedFont = new gcn::ImageFont("graphics/gui/hits_red.png",
"0123456789");
- hitBlueFont = new gcn::ImageFont(
- resman->getRealPath("graphics/gui/hits_blue.png"),
+ hitBlueFont = new gcn::ImageFont("graphics/gui/hits_blue.png",
"0123456789");
- hitYellowFont = new gcn::ImageFont(
- resman->getRealPath("graphics/gui/hits_yellow.png"),
+ hitYellowFont = new gcn::ImageFont("graphics/gui/hits_yellow.png",
"mis");
}
catch (gcn::Exception e)
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 3567ac35..39b8dfff 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -113,13 +113,6 @@ bool ResourceManager::isDirectory(const std::string &path)
return PHYSFS_isDirectory(path.c_str());
}
-std::string ResourceManager::getRealPath(const std::string &path)
-{
- const char *dirSep = PHYSFS_getDirSeparator();
-
- return std::string(PHYSFS_getRealDir(path.c_str())) + dirSep + path;
-}
-
Resource*
ResourceManager::get(const E_RESOURCE_TYPE &type, const std::string &idPath)
{
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index a5a01987..a11ea4cb 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -97,11 +97,6 @@ class ResourceManager
bool isDirectory(const std::string &path);
/**
- * Returns the real path to the given path in the PhysFS search path
- */
- std::string getRealPath(const std::string &path);
-
- /**
* Creates a resource and adds it to the resource map. The idPath is
* converted into the appropriate path for the current operating system
* and the resource is loaded.
diff --git a/src/resources/sdlimageloader.cpp b/src/resources/sdlimageloader.cpp
new file mode 100644
index 00000000..42bbf1ca
--- /dev/null
+++ b/src/resources/sdlimageloader.cpp
@@ -0,0 +1,84 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "sdlimageloader.h"
+
+#include <iostream>
+#include <string>
+#include <SDL_image.h>
+
+#include <guichan/exception.hpp>
+
+#include "resourcemanager.h"
+
+void SDLImageLoader::prepare(const std::string &filename)
+{
+ if (mCurrentImage)
+ {
+ throw GCN_EXCEPTION("Function called before finalizing or discarding last loaded image.");
+ }
+
+ ResourceManager *resman = ResourceManager::getInstance();
+
+ int fileSize;
+ void *buffer = resman->loadFile(filename, fileSize);
+
+ SDL_Surface *tmp = NULL;
+ if (buffer) {
+ SDL_RWops *rw = SDL_RWFromMem(buffer, fileSize);
+ tmp = IMG_Load_RW(rw, 1);
+ ::free(buffer);
+ }
+
+ if (!tmp)
+ {
+ throw GCN_EXCEPTION(std::string("Unable to load image file: ")+filename);
+ }
+
+ Uint32 rmask, gmask, bmask, amask;
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ rmask = 0xff000000;
+ gmask = 0x00ff0000;
+ bmask = 0x0000ff00;
+ amask = 0x000000ff;
+#else
+ rmask = 0x000000ff;
+ gmask = 0x0000ff00;
+ bmask = 0x00ff0000;
+ amask = 0xff000000;
+#endif
+
+ mCurrentImage = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, 32,
+ rmask, gmask, bmask, amask);
+
+ if (!mCurrentImage)
+ {
+ throw GCN_EXCEPTION(std::string("Not enough memory to load: ")+filename);
+ }
+
+ SDL_Surface* tmp2 = SDL_ConvertSurface(tmp, mCurrentImage->format, SDL_SWSURFACE);
+ SDL_FreeSurface(tmp);
+ SDL_FreeSurface(mCurrentImage);
+
+ mCurrentImage = tmp2;
+}
diff --git a/src/resources/sdlimageloader.h b/src/resources/sdlimageloader.h
new file mode 100644
index 00000000..b34b98fe
--- /dev/null
+++ b/src/resources/sdlimageloader.h
@@ -0,0 +1,37 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World 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.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMW_SDLIMAGELOADER_H
+#define _TMW_SDLIMAGELOADER_H
+
+#include <iosfwd>
+
+#include <guichan/sdl/sdlimageloader.hpp>
+
+class SDLImageLoader : public gcn::SDLImageLoader
+{
+ public:
+ void prepare(const std::string &filename);
+};
+
+#endif