diff options
Diffstat (limited to 'src/FbTk')
-rw-r--r-- | src/FbTk/App.cc | 9 | ||||
-rw-r--r-- | src/FbTk/Font.cc | 11 | ||||
-rw-r--r-- | src/FbTk/Font.hh | 19 | ||||
-rw-r--r-- | src/FbTk/Image.cc | 45 | ||||
-rw-r--r-- | src/FbTk/Image.hh | 7 | ||||
-rw-r--r-- | src/FbTk/ImageImlib2.cc | 147 | ||||
-rw-r--r-- | src/FbTk/ImageImlib2.hh | 39 | ||||
-rw-r--r-- | src/FbTk/Makefile.am | 6 |
8 files changed, 267 insertions, 16 deletions
diff --git a/src/FbTk/App.cc b/src/FbTk/App.cc index 2479944..c48ccb1 100644 --- a/src/FbTk/App.cc +++ b/src/FbTk/App.cc | |||
@@ -20,6 +20,8 @@ | |||
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | #include "App.hh" | 22 | #include "App.hh" |
23 | #include "Font.hh" | ||
24 | #include "Image.hh" | ||
23 | 25 | ||
24 | #include "EventManager.hh" | 26 | #include "EventManager.hh" |
25 | 27 | ||
@@ -49,10 +51,17 @@ App::App(const char *displayname):m_done(false), m_display(0) { | |||
49 | if (displayname != 0 && displayname[0] == '\0') | 51 | if (displayname != 0 && displayname[0] == '\0') |
50 | displayname = 0; | 52 | displayname = 0; |
51 | m_display = XOpenDisplay(displayname); | 53 | m_display = XOpenDisplay(displayname); |
54 | |||
55 | Font::init(); | ||
56 | Image::init(); | ||
52 | } | 57 | } |
53 | 58 | ||
54 | App::~App() { | 59 | App::~App() { |
55 | if (m_display != 0) { | 60 | if (m_display != 0) { |
61 | |||
62 | Font::shutdown(); | ||
63 | Image::shutdown(); | ||
64 | |||
56 | XCloseDisplay(m_display); | 65 | XCloseDisplay(m_display); |
57 | m_display = 0; | 66 | m_display = 0; |
58 | } | 67 | } |
diff --git a/src/FbTk/Font.cc b/src/FbTk/Font.cc index e2e3dec..c7193f7 100644 --- a/src/FbTk/Font.cc +++ b/src/FbTk/Font.cc | |||
@@ -229,9 +229,14 @@ namespace FbTk { | |||
229 | bool Font::m_multibyte = false; | 229 | bool Font::m_multibyte = false; |
230 | bool Font::m_utf8mode = false; | 230 | bool Font::m_utf8mode = false; |
231 | 231 | ||
232 | // some initialisation for using fonts | 232 | |
233 | void fontInit() { | 233 | void Font::init() { |
234 | setlocale(LC_CTYPE, ""); | 234 | // must be set before the first XFontSet is created |
235 | setlocale(LC_CTYPE, ""); | ||
236 | } | ||
237 | |||
238 | void Font::shutdown() { | ||
239 | |||
235 | } | 240 | } |
236 | 241 | ||
237 | Font::Font(const char *name, bool antialias): | 242 | Font::Font(const char *name, bool antialias): |
diff --git a/src/FbTk/Font.hh b/src/FbTk/Font.hh index d299848..f6742cb 100644 --- a/src/FbTk/Font.hh +++ b/src/FbTk/Font.hh | |||
@@ -40,8 +40,6 @@ | |||
40 | 40 | ||
41 | namespace FbTk { | 41 | namespace FbTk { |
42 | 42 | ||
43 | void fontInit(); | ||
44 | |||
45 | class FontImp; | 43 | class FontImp; |
46 | class FbDrawable; | 44 | class FbDrawable; |
47 | 45 | ||
@@ -51,6 +49,19 @@ class FbDrawable; | |||
51 | class Font { | 49 | class Font { |
52 | public: | 50 | public: |
53 | 51 | ||
52 | /// called at FbTk::App creation time, initializes some stuff | ||
53 | static void init(); | ||
54 | |||
55 | /// called at FbTk::App destruction time, cleans up what was inited first | ||
56 | static void shutdown(); | ||
57 | |||
58 | /// @return true if multibyte is enabled, else false | ||
59 | static bool multibyte() { return m_multibyte; } | ||
60 | /// @return true if utf-8 mode is enabled, else false | ||
61 | static bool utf8() { return m_utf8mode; } | ||
62 | |||
63 | |||
64 | |||
54 | Font(const char *name=0, bool antialias = false); | 65 | Font(const char *name=0, bool antialias = false); |
55 | virtual ~Font(); | 66 | virtual ~Font(); |
56 | /** | 67 | /** |
@@ -60,10 +71,6 @@ public: | |||
60 | */ | 71 | */ |
61 | bool load(const std::string &name); | 72 | bool load(const std::string &name); |
62 | 73 | ||
63 | /// @return true if multibyte is enabled, else false | ||
64 | static bool multibyte() { return m_multibyte; } | ||
65 | /// @return true if utf-8 mode is enabled, else false | ||
66 | static bool utf8() { return m_utf8mode; } | ||
67 | void setAntialias(bool flag); | 74 | void setAntialias(bool flag); |
68 | inline void setShadow(bool flag) { m_shadow = flag; if (m_shadow) setHalo(false); } | 75 | inline void setShadow(bool flag) { m_shadow = flag; if (m_shadow) setHalo(false); } |
69 | inline void setHalo(bool flag) { m_halo = flag; if (m_halo) setShadow(false); } | 76 | inline void setHalo(bool flag) { m_halo = flag; if (m_halo) setShadow(false); } |
diff --git a/src/FbTk/Image.cc b/src/FbTk/Image.cc index 1026a92..a7ff7e5 100644 --- a/src/FbTk/Image.cc +++ b/src/FbTk/Image.cc | |||
@@ -1,5 +1,5 @@ | |||
1 | // Image.cc for FbTk - Fluxbox ToolKit | 1 | // Image.cc for FbTk - Fluxbox ToolKit |
2 | // Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net) | 2 | // Copyright (c) 2003-2004 Henrik Kinnunen (fluxgen at users.sourceforge.net) |
3 | // | 3 | // |
4 | // Permission is hereby granted, free of charge, to any person obtaining a | 4 | // Permission is hereby granted, free of charge, to any person obtaining a |
5 | // copy of this software and associated documentation files (the "Software"), | 5 | // copy of this software and associated documentation files (the "Software"), |
@@ -30,10 +30,15 @@ | |||
30 | 30 | ||
31 | #ifdef HAVE_XPM | 31 | #ifdef HAVE_XPM |
32 | #include "ImageXPM.hh" | 32 | #include "ImageXPM.hh" |
33 | #endif /// HAVE_XPM | 33 | #endif // HAVE_XPM |
34 | |||
35 | #ifdef HAVE_IMLIB2 | ||
36 | #include "ImageImlib2.hh" | ||
37 | #endif // HAVE_IMLIB2 | ||
34 | 38 | ||
35 | #include <list> | 39 | #include <list> |
36 | #include <iostream> | 40 | #include <iostream> |
41 | #include <set> | ||
37 | using namespace std; | 42 | using namespace std; |
38 | 43 | ||
39 | namespace FbTk { | 44 | namespace FbTk { |
@@ -41,13 +46,41 @@ namespace FbTk { | |||
41 | Image::ImageMap Image::s_image_map; | 46 | Image::ImageMap Image::s_image_map; |
42 | Image::StringList Image::s_search_paths; | 47 | Image::StringList Image::s_search_paths; |
43 | 48 | ||
44 | PixmapWithMask *Image::load(const std::string &filename, int screen_num) { | ||
45 | 49 | ||
50 | void Image::init() { | ||
51 | |||
52 | // create imagehandlers for their extensions | ||
46 | #ifdef HAVE_XPM | 53 | #ifdef HAVE_XPM |
47 | // we must do this because static linkage with libFbTk will not init | 54 | new ImageXPM(); |
48 | // a static autoreg variable for it | ||
49 | static ImageXPM xpm; | ||
50 | #endif // HAVE_XPM | 55 | #endif // HAVE_XPM |
56 | #ifdef HAVE_IMLIB2 | ||
57 | new ImageImlib2(); | ||
58 | #endif // HAVE_IMLIB2 | ||
59 | } | ||
60 | |||
61 | void Image::shutdown() { | ||
62 | |||
63 | std::set<ImageBase*> handlers; | ||
64 | |||
65 | // one imagehandler could be registered | ||
66 | // for more than one type | ||
67 | ImageMap::iterator it = s_image_map.begin(); | ||
68 | ImageMap::iterator it_end = s_image_map.end(); | ||
69 | for (; it != it_end; it++) | ||
70 | handlers.insert(it->second); | ||
71 | |||
72 | // free the unique handlers | ||
73 | std::set<ImageBase*>::iterator handler_it = handlers.begin(); | ||
74 | std::set<ImageBase*>::iterator handler_it_end = handlers.end(); | ||
75 | for(; handler_it != handler_it_end; handler_it++) { | ||
76 | delete (*handler_it); | ||
77 | } | ||
78 | |||
79 | s_image_map.clear(); | ||
80 | } | ||
81 | |||
82 | PixmapWithMask *Image::load(const std::string &filename, int screen_num) { | ||
83 | |||
51 | 84 | ||
52 | if (filename == "") | 85 | if (filename == "") |
53 | return false; | 86 | return false; |
diff --git a/src/FbTk/Image.hh b/src/FbTk/Image.hh index 6e0bf53..eaa66ae 100644 --- a/src/FbTk/Image.hh +++ b/src/FbTk/Image.hh | |||
@@ -36,6 +36,13 @@ class PixmapWithMask; | |||
36 | /// loads images | 36 | /// loads images |
37 | class Image { | 37 | class Image { |
38 | public: | 38 | public: |
39 | |||
40 | /// called at FbTk::App creation time, init some internal stuff | ||
41 | static void init(); | ||
42 | |||
43 | /// called at FbTk:App destruction time, frees stuff allocated by init() | ||
44 | static void shutdown(); | ||
45 | |||
39 | /// @return an instance of PixmapWithMask on success, 0 on failure | 46 | /// @return an instance of PixmapWithMask on success, 0 on failure |
40 | static PixmapWithMask *load(const std::string &filename, int screen_num); | 47 | static PixmapWithMask *load(const std::string &filename, int screen_num); |
41 | /// for register file type and imagebase | 48 | /// for register file type and imagebase |
diff --git a/src/FbTk/ImageImlib2.cc b/src/FbTk/ImageImlib2.cc new file mode 100644 index 0000000..82079a3 --- /dev/null +++ b/src/FbTk/ImageImlib2.cc | |||
@@ -0,0 +1,147 @@ | |||
1 | // ImageImlib2.cc for FbTk - Fluxbox ToolKit | ||
2 | // Copyright (c) 2004 Mathias Gumz <akira at fluxbox dot org> | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | // $Id: $ | ||
23 | |||
24 | #include "ImageImlib2.hh" | ||
25 | |||
26 | #include "App.hh" | ||
27 | #include "PixmapWithMask.hh" | ||
28 | |||
29 | #include <X11/xpm.h> | ||
30 | |||
31 | #include <Imlib2.h> | ||
32 | #include <map> | ||
33 | |||
34 | namespace { | ||
35 | |||
36 | typedef std::map<int, Imlib_Context> ScreenImlibContextContainer; | ||
37 | typedef ScreenImlibContextContainer::iterator ScreenImlibContext; | ||
38 | |||
39 | ScreenImlibContextContainer contexts; | ||
40 | |||
41 | }; // anon namespace | ||
42 | |||
43 | |||
44 | namespace FbTk { | ||
45 | |||
46 | ImageImlib2::ImageImlib2() { | ||
47 | |||
48 | // lets have a 2mb cache inside imlib, holds | ||
49 | // uncompressed images | ||
50 | imlib_set_cache_size(2048 * 1024); | ||
51 | |||
52 | // TODO: this are the potential candidates, | ||
53 | // choose only sane ones. open for discussion | ||
54 | char* format_list[] = { | ||
55 | "PNG", // pngloader | ||
56 | "JPEG", "JPG", "JFI", "JFIF", // jpegloader | ||
57 | // "TIFF", "TIF", // tiffloader | ||
58 | "PNM", "PPM", "PGM", "PBM", "PAM", // pnmloader | ||
59 | // "TGA", // tgaloader | ||
60 | // "IFF", "ILBM", "LBM", // lbmloader | ||
61 | // "GIF", // gifloader | ||
62 | // "ARGB", "AGR", // argbloader | ||
63 | // "BMP", // bmploader | ||
64 | // "BZ2", // bzloader | ||
65 | // "GZ", // gzloader | ||
66 | NULL | ||
67 | }; | ||
68 | |||
69 | char** format = NULL; | ||
70 | for(format = format_list; *format != NULL; format++) { | ||
71 | Image::registerType(*format, *this); | ||
72 | } | ||
73 | } | ||
74 | |||
75 | ImageImlib2::~ImageImlib2() { | ||
76 | ScreenImlibContext it = contexts.begin(); | ||
77 | ScreenImlibContext it_end = contexts.end(); | ||
78 | for (; it != it_end; it++) { | ||
79 | imlib_context_free(it->second); | ||
80 | } | ||
81 | contexts.clear(); | ||
82 | } | ||
83 | |||
84 | PixmapWithMask *ImageImlib2::load(const std::string &filename, int screen_num) const { | ||
85 | |||
86 | Display *dpy = FbTk::App::instance()->display(); | ||
87 | |||
88 | // init imlib2 if needed, the settings for each screen may differ | ||
89 | ScreenImlibContext screen_context = contexts.find(screen_num); | ||
90 | if (screen_context == contexts.end()) { | ||
91 | |||
92 | Imlib_Context new_context = imlib_context_new(); | ||
93 | imlib_context_push(new_context); | ||
94 | |||
95 | imlib_context_set_display(dpy); | ||
96 | imlib_context_set_drawable(RootWindow(dpy, screen_num)); | ||
97 | imlib_context_set_colormap(DefaultColormap(dpy, screen_num)); | ||
98 | imlib_context_set_visual(DefaultVisual(dpy, screen_num)); | ||
99 | |||
100 | imlib_context_pop(); | ||
101 | |||
102 | contexts[screen_num] = new_context; | ||
103 | screen_context = contexts.find(screen_num); | ||
104 | } | ||
105 | |||
106 | if (screen_context == contexts.end()) { | ||
107 | #ifdef DEBUG | ||
108 | cerr << "ImageImlib2::load: error, couldnt find a valid Imlib_Context.\n"; | ||
109 | #endif // DEBUG | ||
110 | return 0; | ||
111 | } | ||
112 | |||
113 | // now load the stuff | ||
114 | Imlib_Context context = screen_context->second; | ||
115 | imlib_context_push(context); | ||
116 | Imlib_Image image = imlib_load_image_immediately(filename.c_str()); | ||
117 | if (image) { // loading was ok | ||
118 | imlib_context_set_image(image); | ||
119 | |||
120 | Pixmap pm = 0, mask = 0; | ||
121 | imlib_render_pixmaps_for_whole_image(&pm, &mask); | ||
122 | |||
123 | // pm and mask belong to imlib, so we have to copy them | ||
124 | FbPixmap fbpm; | ||
125 | FbPixmap fbmask; | ||
126 | |||
127 | fbpm.copy(pm); | ||
128 | fbmask.copy(mask); | ||
129 | |||
130 | // mark pm and mask as freeable in imlib | ||
131 | imlib_free_image(); | ||
132 | imlib_free_pixmap_and_mask(pm); | ||
133 | |||
134 | imlib_context_pop(); | ||
135 | |||
136 | PixmapWithMask* result = new PixmapWithMask(); | ||
137 | result->pixmap() = fbpm; | ||
138 | result->mask() = fbmask; | ||
139 | return result; | ||
140 | } | ||
141 | |||
142 | // loading failure | ||
143 | imlib_context_pop(); | ||
144 | return 0; | ||
145 | } | ||
146 | |||
147 | } // end namespace FbTk | ||
diff --git a/src/FbTk/ImageImlib2.hh b/src/FbTk/ImageImlib2.hh new file mode 100644 index 0000000..85aca68 --- /dev/null +++ b/src/FbTk/ImageImlib2.hh | |||
@@ -0,0 +1,39 @@ | |||
1 | // ImageImlib2.hh for FbTk - Fluxbox ToolKit | ||
2 | // Copyright (c) 2004 Mathias Gumz (akira at fluxbox dot org) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | // $Id:$ | ||
23 | |||
24 | #ifndef FBTK_IMAGEIMLIB2_HH | ||
25 | #define FBTK_IMAGEIMLIB2_HH | ||
26 | |||
27 | #include "Image.hh" | ||
28 | namespace FbTk { | ||
29 | |||
30 | class ImageImlib2: public ImageBase { | ||
31 | public: | ||
32 | ImageImlib2(); | ||
33 | ~ImageImlib2(); | ||
34 | PixmapWithMask *load(const std::string &filename, int screen_num) const; | ||
35 | }; | ||
36 | |||
37 | } // end namespace FbTk | ||
38 | |||
39 | #endif // FBTK_IMAGEIMLIB2_HH | ||
diff --git a/src/FbTk/Makefile.am b/src/FbTk/Makefile.am index be9b3ef..47ed58f 100644 --- a/src/FbTk/Makefile.am +++ b/src/FbTk/Makefile.am | |||
@@ -11,6 +11,9 @@ endif | |||
11 | if XPM | 11 | if XPM |
12 | xpm_SOURCE= ImageXPM.hh ImageXPM.cc | 12 | xpm_SOURCE= ImageXPM.hh ImageXPM.cc |
13 | endif | 13 | endif |
14 | if IMLIB2 | ||
15 | imlib2_SOURCE= ImageImlib2.hh ImageImlib2.cc | ||
16 | endif | ||
14 | 17 | ||
15 | libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \ | 18 | libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \ |
16 | FileUtil.hh FileUtil.cc \ | 19 | FileUtil.hh FileUtil.cc \ |
@@ -48,4 +51,5 @@ libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \ | |||
48 | MenuIcon.hh MenuIcon.cc \ | 51 | MenuIcon.hh MenuIcon.cc \ |
49 | ${xpm_SOURCE} \ | 52 | ${xpm_SOURCE} \ |
50 | ${xft_SOURCE} \ | 53 | ${xft_SOURCE} \ |
51 | ${xmb_SOURCE} | 54 | ${xmb_SOURCE} \ |
55 | ${imlib2_SOURCE} | ||