]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Image.cc
library class revamped as manager, goodbye tilemap
[chaz/yoink] / src / Moof / Image.cc
index 51e7ad836962139c55d29543f15dc60a22cac559..ee44dd75dcacb319f331411df02e9c28da92407b 100644 (file)
 #include <cstdio>              // FILE
 #include <cstring>             // strncmp
 
+#include <boost/algorithm/string.hpp>
+
 #include <SDL/SDL.h>
 #include <png.h>
 
 #include "Core.hh"
 #include "Error.hh"
 #include "Image.hh"
-#include "Library.hh"
 #include "Log.hh"
+#include "Manager.hh"
 
 
 namespace Mf {
 
 
-class Image::Impl : public Library<Impl>
+class Image::Impl : public Manager<Impl>
 {
 public:
 
-       explicit Impl(const std::string& name, bool flipped = false) :
-               Library<Impl>(name),
+       explicit Impl() :
                mContext(0),
-               mPixels(0)
-       {
-               init(getName(), flipped);
-       }
+               mPixels(0) {}
 
        ~Impl()
        {
@@ -89,23 +87,12 @@ public:
        }
 
 
-       SDL_Surface*    mContext;
-       char*                   mPixels;
-
-       unsigned                mDepth;
-       GLuint                  mColorMode;
-
-       std::string             mComment;
-
-
-private:
-
-       Backend                 mBackend;
-
-       bool init(const std::string& filePath, bool flipped)
+       bool init(const std::string& name, bool flipped = false)
        {
-               logInfo("opening image file...");
-               FILE* fp = fopen(filePath.c_str(), "rb");
+               std::string path = Image::getPath(name);
+
+               logInfo << "opening image file " << path << std::endl;
+               FILE* fp = fopen(path.c_str(), "rb");
                if (!fp) return false;
 
                png_byte        signature[8];
@@ -185,7 +172,7 @@ private:
                logInfo << "num texts: " << numTexts << std::endl;
                for (int i = 0; i < numTexts; ++i)
                {
-                       if (strncmp(texts[i].key, "Comment", 7) == 0)
+                       if (strncmp(texts[i].key, "TextureInfo", 11) == 0)
                        {
                                mComment = texts[i].text;
                                break;
@@ -248,6 +235,19 @@ private:
 
                return mContext;
        }
+
+
+       SDL_Surface*    mContext;
+       char*                   mPixels;
+
+       unsigned                mDepth;
+       GLuint                  mColorMode;
+
+       std::string             mComment;
+
+private:
+
+       Backend                 mBackend;
 };
 
 
@@ -281,7 +281,7 @@ unsigned Image::getPitch() const
        return mImpl->mContext->pitch;
 }
 
-GLuint Image::getColorMode() const
+GLuint Image::getMode() const
 {
        return mImpl->mColorMode;
 }
@@ -315,11 +315,19 @@ void Image::setAsIcon() const
 }
 
 
-
 std::string Image::getPath(const std::string& name)
 {
-       std::string path = Resource::getPath("images/" + name + ".png");
-       return path;
+       if (boost::find_last(name, ".png"))
+       {
+               return Resource::getPath(name);
+       }
+       else
+       {
+               std::string path("images/");
+               path += name;
+               path += ".png";
+               return Resource::getPath(path);
+       }
 }
 
 
This page took 0.021808 seconds and 4 git commands to generate.