aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Image.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/Image.cc')
-rw-r--r--src/FbTk/Image.cc37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/FbTk/Image.cc b/src/FbTk/Image.cc
index 8df80b5..277808a 100644
--- a/src/FbTk/Image.cc
+++ b/src/FbTk/Image.cc
@@ -39,7 +39,10 @@
39#include <list> 39#include <list>
40#include <iostream> 40#include <iostream>
41#include <set> 41#include <set>
42using namespace std; 42
43using std::string;
44using std::list;
45using std::set;
43 46
44namespace FbTk { 47namespace FbTk {
45 48
@@ -60,9 +63,9 @@ void Image::init() {
60 63
61void Image::shutdown() { 64void Image::shutdown() {
62 65
63 std::set<ImageBase*> handlers; 66 set<ImageBase*> handlers;
64 67
65 // one imagehandler could be registered 68 // one imagehandler could be registered
66 // for more than one type 69 // for more than one type
67 ImageMap::iterator it = s_image_map.begin(); 70 ImageMap::iterator it = s_image_map.begin();
68 ImageMap::iterator it_end = s_image_map.end(); 71 ImageMap::iterator it_end = s_image_map.end();
@@ -72,8 +75,8 @@ void Image::shutdown() {
72 } 75 }
73 76
74 // free the unique handlers 77 // free the unique handlers
75 std::set<ImageBase*>::iterator handler_it = handlers.begin(); 78 set<ImageBase*>::iterator handler_it = handlers.begin();
76 std::set<ImageBase*>::iterator handler_it_end = handlers.end(); 79 set<ImageBase*>::iterator handler_it_end = handlers.end();
77 for(; handler_it != handler_it_end; handler_it++) { 80 for(; handler_it != handler_it_end; handler_it++) {
78 delete (*handler_it); 81 delete (*handler_it);
79 } 82 }
@@ -81,26 +84,26 @@ void Image::shutdown() {
81 s_image_map.clear(); 84 s_image_map.clear();
82} 85}
83 86
84PixmapWithMask *Image::load(const std::string &filename, int screen_num) { 87PixmapWithMask *Image::load(const string &filename, int screen_num) {
85 88
86 89
87 if (filename == "") 90 if (filename == "")
88 return false; 91 return false;
89 92
90 // determine file ending 93 // determine file ending
91 std::string extension(StringUtil::toUpper(StringUtil::findExtension(filename))); 94 string extension(StringUtil::toUpper(StringUtil::findExtension(filename)));
92 95
93 // valid handle? 96 // valid handle?
94 if (s_image_map.find(extension) == s_image_map.end()) 97 if (s_image_map.find(extension) == s_image_map.end())
95 return false; 98 return false;
96 99
97 // load file 100 // load file
98 PixmapWithMask *pm = s_image_map[extension]->load(filename, screen_num); 101 PixmapWithMask *pm = s_image_map[extension]->load(filename, screen_num);
99 // failed?, try different search paths 102 // failed?, try different search paths
100 if (pm == 0 && s_search_paths.size()) { 103 if (pm == 0 && s_search_paths.size()) {
101 // first we need to get basename of current filename 104 // first we need to get basename of current filename
102 std::string base_filename = StringUtil::basename(filename); 105 string base_filename = StringUtil::basename(filename);
103 std::string path = ""; 106 string path = "";
104 // append each search path and try to load 107 // append each search path and try to load
105 StringList::iterator it = s_search_paths.begin(); 108 StringList::iterator it = s_search_paths.begin();
106 StringList::iterator it_end = s_search_paths.end(); 109 StringList::iterator it_end = s_search_paths.end();
@@ -115,13 +118,13 @@ PixmapWithMask *Image::load(const std::string &filename, int screen_num) {
115 return pm; 118 return pm;
116} 119}
117 120
118bool Image::registerType(const std::string &type, ImageBase &base) { 121bool Image::registerType(const string &type, ImageBase &base) {
119 122
120 string ucase_type = StringUtil::toUpper(type); 123 string ucase_type = StringUtil::toUpper(type);
121 124
122 // not empty and not this base? 125 // not empty and not this base?
123 if (s_image_map[ucase_type] != 0 && 126 if (s_image_map[ucase_type] != 0 &&
124 s_image_map[ucase_type] != &base) 127 s_image_map[ucase_type] != &base)
125 return false; 128 return false;
126 // already registered? 129 // already registered?
127 if (s_image_map[ucase_type] == &base) 130 if (s_image_map[ucase_type] == &base)
@@ -136,7 +139,7 @@ void Image::remove(ImageBase &base) {
136 // find and remove all referenses to base 139 // find and remove all referenses to base
137 ImageMap::iterator it = s_image_map.begin(); 140 ImageMap::iterator it = s_image_map.begin();
138 ImageMap::iterator it_end = s_image_map.end(); 141 ImageMap::iterator it_end = s_image_map.end();
139 std::list<std::string> remove_list; 142 list<string> remove_list;
140 for (; it != it_end; ++it) { 143 for (; it != it_end; ++it) {
141 if (it->second == &base) 144 if (it->second == &base)
142 remove_list.push_back(it->first); 145 remove_list.push_back(it->first);
@@ -148,11 +151,11 @@ void Image::remove(ImageBase &base) {
148 } 151 }
149} 152}
150 153
151void Image::addSearchPath(const std::string &search_path) { 154void Image::addSearchPath(const string &search_path) {
152 s_search_paths.push_back(search_path); 155 s_search_paths.push_back(search_path);
153} 156}
154 157
155void Image::removeSearchPath(const std::string &search_path) { 158void Image::removeSearchPath(const string &search_path) {
156 s_search_paths.remove(search_path); 159 s_search_paths.remove(search_path);
157} 160}
158 161