aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/App.cc2
-rw-r--r--src/FbTk/Image.cc45
-rw-r--r--src/FbTk/Image.hh30
3 files changed, 21 insertions, 56 deletions
diff --git a/src/FbTk/App.cc b/src/FbTk/App.cc
index 25c338f..39cd36e 100644
--- a/src/FbTk/App.cc
+++ b/src/FbTk/App.cc
@@ -49,14 +49,12 @@ App::App(const char *displayname):m_done(false), m_display(0) {
49 throw std::string("Couldn't connect to XServer"); 49 throw std::string("Couldn't connect to XServer");
50 50
51 FbStringUtil::init(); 51 FbStringUtil::init();
52 Image::init();
53} 52}
54 53
55App::~App() { 54App::~App() {
56 if (m_display != 0) { 55 if (m_display != 0) {
57 56
58 Font::shutdown(); 57 Font::shutdown();
59 Image::shutdown();
60 58
61 XCloseDisplay(m_display); 59 XCloseDisplay(m_display);
62 m_display = 0; 60 m_display = 0;
diff --git a/src/FbTk/Image.cc b/src/FbTk/Image.cc
index 020f9c6..0c7b5fc 100644
--- a/src/FbTk/Image.cc
+++ b/src/FbTk/Image.cc
@@ -42,50 +42,31 @@ using std::string;
42using std::list; 42using std::list;
43using std::set; 43using std::set;
44 44
45namespace FbTk {
46 45
47Image::ImageMap Image::s_image_map; 46namespace {
48Image::StringList Image::s_search_paths;
49 47
48typedef std::map<std::string, FbTk::ImageBase *> ImageMap;
49typedef std::list<std::string> StringList;
50 50
51void Image::init() { 51ImageMap s_image_map;
52StringList s_search_paths;
52 53
53// create imagehandlers for their extensions
54#ifdef HAVE_XPM
55 new ImageXPM();
56#endif // HAVE_XPM
57#ifdef HAVE_IMLIB2 54#ifdef HAVE_IMLIB2
58 new ImageImlib2(); 55FbTk::ImageImlib2 imlib2_loader;
59#endif // HAVE_IMLIB2 56#endif
60} 57#ifdef HAVE_XPM
61 58FbTk::ImageXPM xpm_loader;
62void Image::shutdown() { 59#endif
63
64 set<ImageBase*> handlers;
65 60
66 // one imagehandler could be registered
67 // for more than one type
68 ImageMap::iterator it = s_image_map.begin();
69 ImageMap::iterator it_end = s_image_map.end();
70 for (; it != it_end; it++) {
71 if (it->second)
72 handlers.insert(it->second);
73 }
74 61
75 // free the unique handlers 62}; // end of anonymous namespace
76 set<ImageBase*>::iterator handler_it = handlers.begin();
77 set<ImageBase*>::iterator handler_it_end = handlers.end();
78 for(; handler_it != handler_it_end; handler_it++) {
79 delete (*handler_it);
80 }
81 63
82 s_image_map.clear(); 64namespace FbTk {
83}
84 65
85PixmapWithMask *Image::load(const string &filename, int screen_num) { 66PixmapWithMask *Image::load(const string &filename, int screen_num) {
86 67
87 68
88 if (filename == "") 69 if (filename.empty())
89 return false; 70 return false;
90 71
91 // determine file ending 72 // determine file ending
diff --git a/src/FbTk/Image.hh b/src/FbTk/Image.hh
index acb5879..3c731ad 100644
--- a/src/FbTk/Image.hh
+++ b/src/FbTk/Image.hh
@@ -32,37 +32,24 @@ class ImageBase;
32class PixmapWithMask; 32class PixmapWithMask;
33 33
34/// loads images 34/// loads images
35class Image { 35namespace Image {
36public:
37
38 /// called at FbTk::App creation time, init some internal stuff
39 static void init();
40
41 /// called at FbTk:App destruction time, frees stuff allocated by init()
42 static void shutdown();
43 36
44 /// @return an instance of PixmapWithMask on success, 0 on failure 37 /// @return an instance of PixmapWithMask on success, 0 on failure
45 static PixmapWithMask *load(const std::string &filename, int screen_num); 38 PixmapWithMask *load(const std::string &filename, int screen_num);
46 /// for register file type and imagebase 39 /// for register file type and imagebase
47 /// @return false on failure 40 /// @return false on failure
48 static bool registerType(const std::string &type, ImageBase &base); 41 bool registerType(const std::string &type, ImageBase &base);
49 /// removes a imagebase class from register 42 /// removes a imagebase class from register
50 /// @return false on failure 43 /// @return false on failure
51 static void remove(ImageBase &base); 44 void remove(ImageBase &base);
52 /// adds a path to search images from 45 /// adds a path to search images from
53 static void addSearchPath(const std::string &search_path); 46 void addSearchPath(const std::string &search_path);
54 /// removes a path to search images from 47 /// removes a path to search images from
55 static void removeSearchPath(const std::string &search_path); 48 void removeSearchPath(const std::string &search_path);
56 /// adds a path to search images from 49 /// adds a path to search images from
57 static void removeAllSearchPaths(); 50 void removeAllSearchPaths();
58 /// locates an image in the search path 51 /// locates an image in the search path
59 static std::string locateFile(const std::string &filename); 52 std::string locateFile(const std::string &filename);
60private:
61 typedef std::map<std::string, ImageBase *> ImageMap;
62 typedef std::list<std::string> StringList;
63
64 static ImageMap s_image_map;
65 static StringList s_search_paths;
66}; 53};
67 54
68/// common interface for all image classes 55/// common interface for all image classes
@@ -76,4 +63,3 @@ public:
76 63
77#endif // IMAGE_HH 64#endif // IMAGE_HH
78 65
79