00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "Image.hh"
00025 #include "StringUtil.hh"
00026
00027 #ifdef HAVE_CONFIG_H
00028 #include "config.h"
00029 #endif // HAVE_CONFIG_H
00030
00031 #ifdef HAVE_XPM
00032 #include "ImageXPM.hh"
00033 #endif
00034
00035 #include <list>
00036 #include <iostream>
00037 using namespace std;
00038
00039 namespace FbTk {
00040
00041 Image::ImageMap Image::s_image_map;
00042 Image::StringList Image::s_search_paths;
00043
00044 PixmapWithMask *Image::load(const std::string &filename, int screen_num) {
00045
00046 #ifdef HAVE_XPM
00047
00048
00049 static ImageXPM xpm;
00050 #endif // HAVE_XPM
00051
00052 if (filename == "")
00053 return false;
00054
00055
00056 std::string extension(StringUtil::toUpper(StringUtil::findExtension(filename)));
00057
00058
00059 if (s_image_map[extension] == 0)
00060 return false;
00061
00062
00063 PixmapWithMask *pm = s_image_map[extension]->load(filename, screen_num);
00064
00065 if (pm == 0 && s_search_paths.size()) {
00066
00067 std::string base_filename = StringUtil::basename(filename);
00068 std::string path = "";
00069
00070 StringList::iterator it = s_search_paths.begin();
00071 StringList::iterator it_end = s_search_paths.end();
00072 for (; it != it_end && pm == 0; ++it) {
00073
00074 path = StringUtil::expandFilename(*it);
00075 pm = s_image_map[extension]->load(path + "/" + base_filename, screen_num);
00076 }
00077
00078 }
00079
00080 return pm;
00081 }
00082
00083 bool Image::registerType(const std::string &type, ImageBase &base) {
00084
00085 string ucase_type = StringUtil::toUpper(type);
00086
00087
00088 if (s_image_map[ucase_type] != 0 &&
00089 s_image_map[ucase_type] != &base)
00090 return false;
00091
00092 if (s_image_map[ucase_type] == &base)
00093 return true;
00094
00095 s_image_map[ucase_type] = &base;
00096
00097 return true;
00098 }
00099
00100 void Image::remove(ImageBase &base) {
00101
00102 ImageMap::iterator it = s_image_map.begin();
00103 ImageMap::iterator it_end = s_image_map.end();
00104 std::list<std::string> remove_list;
00105 for (; it != it_end; ++it) {
00106 if (it->second == &base)
00107 remove_list.push_back(it->first);
00108 }
00109
00110 while (!remove_list.empty()) {
00111 s_image_map.erase(remove_list.back());
00112 remove_list.pop_back();
00113 }
00114 }
00115
00116 void Image::addSearchPath(const std::string &search_path) {
00117 s_search_paths.push_back(search_path);
00118 }
00119
00120 void Image::removeSearchPath(const std::string &search_path) {
00121 s_search_paths.remove(search_path);
00122 }
00123
00124 void Image::removeAllSearchPaths() {
00125 s_search_paths.clear();
00126 }
00127
00128 };