X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FImage.cc;h=ee44dd75dcacb319f331411df02e9c28da92407b;hp=51e7ad836962139c55d29543f15dc60a22cac559;hb=e973a129b5b83b628ba3f09e8c95682fc74080cd;hpb=4f9eb9259092994de9690cf12f11437c35a6791e diff --git a/src/Moof/Image.cc b/src/Moof/Image.cc index 51e7ad8..ee44dd7 100644 --- a/src/Moof/Image.cc +++ b/src/Moof/Image.cc @@ -29,30 +29,28 @@ #include // FILE #include // strncmp +#include + #include #include #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 +class Image::Impl : public Manager { public: - explicit Impl(const std::string& name, bool flipped = false) : - Library(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); + } }