using namespace instead of a useless class
This commit is contained in:
parent
f3bd8e7565
commit
93924af160
3 changed files with 21 additions and 56 deletions
|
@ -49,14 +49,12 @@ App::App(const char *displayname):m_done(false), m_display(0) {
|
|||
throw std::string("Couldn't connect to XServer");
|
||||
|
||||
FbStringUtil::init();
|
||||
Image::init();
|
||||
}
|
||||
|
||||
App::~App() {
|
||||
if (m_display != 0) {
|
||||
|
||||
Font::shutdown();
|
||||
Image::shutdown();
|
||||
|
||||
XCloseDisplay(m_display);
|
||||
m_display = 0;
|
||||
|
|
|
@ -42,50 +42,31 @@ using std::string;
|
|||
using std::list;
|
||||
using std::set;
|
||||
|
||||
namespace FbTk {
|
||||
|
||||
Image::ImageMap Image::s_image_map;
|
||||
Image::StringList Image::s_search_paths;
|
||||
namespace {
|
||||
|
||||
typedef std::map<std::string, FbTk::ImageBase *> ImageMap;
|
||||
typedef std::list<std::string> StringList;
|
||||
|
||||
void Image::init() {
|
||||
ImageMap s_image_map;
|
||||
StringList s_search_paths;
|
||||
|
||||
// create imagehandlers for their extensions
|
||||
#ifdef HAVE_XPM
|
||||
new ImageXPM();
|
||||
#endif // HAVE_XPM
|
||||
#ifdef HAVE_IMLIB2
|
||||
new ImageImlib2();
|
||||
#endif // HAVE_IMLIB2
|
||||
}
|
||||
FbTk::ImageImlib2 imlib2_loader;
|
||||
#endif
|
||||
#ifdef HAVE_XPM
|
||||
FbTk::ImageXPM xpm_loader;
|
||||
#endif
|
||||
|
||||
void Image::shutdown() {
|
||||
|
||||
set<ImageBase*> handlers;
|
||||
}; // end of anonymous namespace
|
||||
|
||||
// one imagehandler could be registered
|
||||
// for more than one type
|
||||
ImageMap::iterator it = s_image_map.begin();
|
||||
ImageMap::iterator it_end = s_image_map.end();
|
||||
for (; it != it_end; it++) {
|
||||
if (it->second)
|
||||
handlers.insert(it->second);
|
||||
}
|
||||
|
||||
// free the unique handlers
|
||||
set<ImageBase*>::iterator handler_it = handlers.begin();
|
||||
set<ImageBase*>::iterator handler_it_end = handlers.end();
|
||||
for(; handler_it != handler_it_end; handler_it++) {
|
||||
delete (*handler_it);
|
||||
}
|
||||
|
||||
s_image_map.clear();
|
||||
}
|
||||
namespace FbTk {
|
||||
|
||||
PixmapWithMask *Image::load(const string &filename, int screen_num) {
|
||||
|
||||
|
||||
if (filename == "")
|
||||
if (filename.empty())
|
||||
return false;
|
||||
|
||||
// determine file ending
|
||||
|
|
|
@ -32,37 +32,24 @@ class ImageBase;
|
|||
class PixmapWithMask;
|
||||
|
||||
/// loads images
|
||||
class Image {
|
||||
public:
|
||||
|
||||
/// called at FbTk::App creation time, init some internal stuff
|
||||
static void init();
|
||||
|
||||
/// called at FbTk:App destruction time, frees stuff allocated by init()
|
||||
static void shutdown();
|
||||
namespace Image {
|
||||
|
||||
/// @return an instance of PixmapWithMask on success, 0 on failure
|
||||
static PixmapWithMask *load(const std::string &filename, int screen_num);
|
||||
PixmapWithMask *load(const std::string &filename, int screen_num);
|
||||
/// for register file type and imagebase
|
||||
/// @return false on failure
|
||||
static bool registerType(const std::string &type, ImageBase &base);
|
||||
bool registerType(const std::string &type, ImageBase &base);
|
||||
/// removes a imagebase class from register
|
||||
/// @return false on failure
|
||||
static void remove(ImageBase &base);
|
||||
void remove(ImageBase &base);
|
||||
/// adds a path to search images from
|
||||
static void addSearchPath(const std::string &search_path);
|
||||
void addSearchPath(const std::string &search_path);
|
||||
/// removes a path to search images from
|
||||
static void removeSearchPath(const std::string &search_path);
|
||||
void removeSearchPath(const std::string &search_path);
|
||||
/// adds a path to search images from
|
||||
static void removeAllSearchPaths();
|
||||
void removeAllSearchPaths();
|
||||
/// locates an image in the search path
|
||||
static std::string locateFile(const std::string &filename);
|
||||
private:
|
||||
typedef std::map<std::string, ImageBase *> ImageMap;
|
||||
typedef std::list<std::string> StringList;
|
||||
|
||||
static ImageMap s_image_map;
|
||||
static StringList s_search_paths;
|
||||
std::string locateFile(const std::string &filename);
|
||||
};
|
||||
|
||||
/// common interface for all image classes
|
||||
|
@ -76,4 +63,3 @@ public:
|
|||
|
||||
#endif // IMAGE_HH
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue