aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authormathias <mathias>2004-12-21 23:42:09 (GMT)
committermathias <mathias>2004-12-21 23:42:09 (GMT)
commitbc7c988561f79edb03b2ece80bb4ba0c8c73fc2e (patch)
treea48f394504f8b44cdab668ef69daf054c178500c /src/FbTk
parent7e41a1494a65ecdb05c7a34c274693cbd950647f (diff)
downloadfluxbox_pavel-bc7c988561f79edb03b2ece80bb4ba0c8c73fc2e.zip
fluxbox_pavel-bc7c988561f79edb03b2ece80bb4ba0c8c73fc2e.tar.bz2
adds imlib2-support to fluxbox: allows us to load several imageformats
besides xpm. to get imlib2 support in fluxbox one has to ./configure --enable-imblib2 default is disabled. a fluxbox-binary that supports imlib2 will have IMLIB2 in "fluxbox -info"-output explanation to the changed files: * xft.m4 -> acinclude.m4 + added ac_path_generic.m4 (from http://ac-archive.sourceforge.net/Miscellaneous/ac_path_generic.html) * configure.in, Makefile.am, src/FbTk/Makefile.am changed to handle imlib2-support * Font.cc/hh Image.cc/hh App.cc fluxbox.cc consistent way of init for global stuff for fonts and imagehandlers. * rest of changes just add the imlib2-code, pretty straightforward
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/App.cc9
-rw-r--r--src/FbTk/Font.cc11
-rw-r--r--src/FbTk/Font.hh19
-rw-r--r--src/FbTk/Image.cc45
-rw-r--r--src/FbTk/Image.hh7
-rw-r--r--src/FbTk/ImageImlib2.cc147
-rw-r--r--src/FbTk/ImageImlib2.hh39
-rw-r--r--src/FbTk/Makefile.am6
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
54App::~App() { 59App::~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 {
229bool Font::m_multibyte = false; 229bool Font::m_multibyte = false;
230bool Font::m_utf8mode = false; 230bool Font::m_utf8mode = false;
231 231
232// some initialisation for using fonts 232
233void fontInit() { 233void Font::init() {
234 setlocale(LC_CTYPE, ""); 234 // must be set before the first XFontSet is created
235 setlocale(LC_CTYPE, "");
236}
237
238void Font::shutdown() {
239
235} 240}
236 241
237Font::Font(const char *name, bool antialias): 242Font::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
41namespace FbTk { 41namespace FbTk {
42 42
43void fontInit();
44
45class FontImp; 43class FontImp;
46class FbDrawable; 44class FbDrawable;
47 45
@@ -51,6 +49,19 @@ class FbDrawable;
51class Font { 49class Font {
52public: 50public:
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>
37using namespace std; 42using namespace std;
38 43
39namespace FbTk { 44namespace FbTk {
@@ -41,13 +46,41 @@ namespace FbTk {
41Image::ImageMap Image::s_image_map; 46Image::ImageMap Image::s_image_map;
42Image::StringList Image::s_search_paths; 47Image::StringList Image::s_search_paths;
43 48
44PixmapWithMask *Image::load(const std::string &filename, int screen_num) {
45 49
50void 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
61void 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
82PixmapWithMask *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
37class Image { 37class Image {
38public: 38public:
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
34namespace {
35
36typedef std::map<int, Imlib_Context> ScreenImlibContextContainer;
37typedef ScreenImlibContextContainer::iterator ScreenImlibContext;
38
39ScreenImlibContextContainer contexts;
40
41}; // anon namespace
42
43
44namespace FbTk {
45
46ImageImlib2::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
75ImageImlib2::~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
84PixmapWithMask *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"
28namespace FbTk {
29
30class ImageImlib2: public ImageBase {
31public:
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
11if XPM 11if XPM
12xpm_SOURCE= ImageXPM.hh ImageXPM.cc 12xpm_SOURCE= ImageXPM.hh ImageXPM.cc
13endif 13endif
14if IMLIB2
15imlib2_SOURCE= ImageImlib2.hh ImageImlib2.cc
16endif
14 17
15libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \ 18libFbTk_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}