diff options
author | Mathias Gumz <akira at fluxbox dot org> | 2008-01-14 22:27:00 (GMT) |
---|---|---|
committer | Mathias Gumz <akira at fluxbox dot org> | 2008-01-14 22:27:00 (GMT) |
commit | e1db89e2d7d56afca5335550ee1c9ff87fd54ba4 (patch) | |
tree | 779b52814dedd08eb56d1875cb2f97bbcdd39e8b /src/FbTk | |
parent | c6099d777d844699fb8a4243921159898bc4f45c (diff) | |
download | fluxbox_lack-e1db89e2d7d56afca5335550ee1c9ff87fd54ba4.zip fluxbox_lack-e1db89e2d7d56afca5335550ee1c9ff87fd54ba4.tar.bz2 |
moved code a bit around, cleaned up some classes
Diffstat (limited to 'src/FbTk')
-rw-r--r-- | src/FbTk/FbPixmap.cc | 43 | ||||
-rw-r--r-- | src/FbTk/FbPixmap.hh | 17 | ||||
-rw-r--r-- | src/FbTk/ImageControl.cc | 23 | ||||
-rw-r--r-- | src/FbTk/ImageControl.hh | 42 | ||||
-rw-r--r-- | src/FbTk/Text.cc | 16 | ||||
-rw-r--r-- | src/FbTk/Text.hh | 10 | ||||
-rw-r--r-- | src/FbTk/TextButton.cc | 2 | ||||
-rw-r--r-- | src/FbTk/TextureRender.cc | 1 |
8 files changed, 71 insertions, 83 deletions
diff --git a/src/FbTk/FbPixmap.cc b/src/FbTk/FbPixmap.cc index bfd3ead..9d90c5a 100644 --- a/src/FbTk/FbPixmap.cc +++ b/src/FbTk/FbPixmap.cc | |||
@@ -38,21 +38,34 @@ using std::cerr; | |||
38 | 38 | ||
39 | namespace FbTk { | 39 | namespace FbTk { |
40 | 40 | ||
41 | Pixmap *FbPixmap::m_root_pixmaps = 0; | 41 | namespace { |
42 | 42 | ||
43 | const char* FbPixmap::root_prop_ids[] = { | 43 | Pixmap *root_pixmaps = 0; |
44 | |||
45 | const char* root_prop_ids[] = { | ||
44 | "_XROOTPMAP_ID", | 46 | "_XROOTPMAP_ID", |
45 | "_XSETROOT_ID", | 47 | "_XSETROOT_ID", |
46 | 0 | 48 | 0 |
47 | }; | 49 | }; |
48 | 50 | ||
49 | // same number as in root_prop_ids | 51 | // same number as in root_prop_ids |
50 | Atom FbPixmap::root_prop_atoms[] = { | 52 | Atom root_prop_atoms[] = { |
51 | None, | 53 | None, |
52 | None, | 54 | None, |
53 | None | 55 | None |
54 | }; | 56 | }; |
55 | 57 | ||
58 | void checkAtoms() { | ||
59 | |||
60 | Display* display = FbTk::App::instance()->display(); | ||
61 | for (int i=0; root_prop_ids[i] != 0; ++i) { | ||
62 | if (root_prop_atoms[i] == None) { | ||
63 | root_prop_atoms[i] = XInternAtom(display, root_prop_ids[i], False); | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | |||
68 | }; // end of anonymous namespace | ||
56 | 69 | ||
57 | FbPixmap::FbPixmap():m_pm(0), | 70 | FbPixmap::FbPixmap():m_pm(0), |
58 | m_width(0), m_height(0), | 71 | m_width(0), m_height(0), |
@@ -389,14 +402,14 @@ bool FbPixmap::rootwinPropertyNotify(int screen_num, Atom atom) { | |||
389 | 402 | ||
390 | // returns whether or not the background was changed | 403 | // returns whether or not the background was changed |
391 | bool FbPixmap::setRootPixmap(int screen_num, Pixmap pm) { | 404 | bool FbPixmap::setRootPixmap(int screen_num, Pixmap pm) { |
392 | if (!m_root_pixmaps) { | 405 | if (!root_pixmaps) { |
393 | m_root_pixmaps = new Pixmap[ScreenCount(display())]; | 406 | root_pixmaps = new Pixmap[ScreenCount(display())]; |
394 | for (int i=0; i < ScreenCount(display()); ++i) | 407 | for (int i=0; i < ScreenCount(display()); ++i) |
395 | m_root_pixmaps[i] = None; | 408 | root_pixmaps[i] = None; |
396 | } | 409 | } |
397 | 410 | ||
398 | if (m_root_pixmaps[screen_num] != pm) { | 411 | if (root_pixmaps[screen_num] != pm) { |
399 | m_root_pixmaps[screen_num] = pm; | 412 | root_pixmaps[screen_num] = pm; |
400 | FbWindow::updatedAlphaBackground(screen_num); | 413 | FbWindow::updatedAlphaBackground(screen_num); |
401 | return true; | 414 | return true; |
402 | } | 415 | } |
@@ -410,8 +423,8 @@ Pixmap FbPixmap::getRootPixmap(int screen_num, bool force_update) { | |||
410 | */ | 423 | */ |
411 | 424 | ||
412 | // check and see if if we have the pixmaps in cache | 425 | // check and see if if we have the pixmaps in cache |
413 | if (m_root_pixmaps && !force_update) | 426 | if (root_pixmaps && !force_update) |
414 | return m_root_pixmaps[screen_num]; | 427 | return root_pixmaps[screen_num]; |
415 | 428 | ||
416 | // else setup pixmap cache | 429 | // else setup pixmap cache |
417 | int numscreens = ScreenCount(display()); | 430 | int numscreens = ScreenCount(display()); |
@@ -460,15 +473,7 @@ Pixmap FbPixmap::getRootPixmap(int screen_num, bool force_update) { | |||
460 | setRootPixmap(i, root_pm); | 473 | setRootPixmap(i, root_pm); |
461 | } | 474 | } |
462 | 475 | ||
463 | return m_root_pixmaps[screen_num]; | 476 | return root_pixmaps[screen_num]; |
464 | } | ||
465 | |||
466 | void FbPixmap::checkAtoms() { | ||
467 | for (int i=0; root_prop_ids[i] != 0; ++i) { | ||
468 | if (root_prop_atoms[i] == None) { | ||
469 | root_prop_atoms[i] = XInternAtom(display(), root_prop_ids[i], False); | ||
470 | } | ||
471 | } | ||
472 | } | 477 | } |
473 | 478 | ||
474 | void FbPixmap::free() { | 479 | void FbPixmap::free() { |
diff --git a/src/FbTk/FbPixmap.hh b/src/FbTk/FbPixmap.hh index 7b3c8de..5c2e2b8 100644 --- a/src/FbTk/FbPixmap.hh +++ b/src/FbTk/FbPixmap.hh | |||
@@ -23,22 +23,22 @@ | |||
23 | #define FBTK_FBPIXMAP_HH | 23 | #define FBTK_FBPIXMAP_HH |
24 | 24 | ||
25 | #include "FbDrawable.hh" | 25 | #include "FbDrawable.hh" |
26 | #include "Text.hh" | 26 | #include "Text.hh" // for Orientation |
27 | 27 | ||
28 | namespace FbTk { | 28 | namespace FbTk { |
29 | 29 | ||
30 | /// a wrapper for X Pixmap | 30 | /// a wrapper for X Pixmap |
31 | class FbPixmap:public FbDrawable { | 31 | class FbPixmap:public FbDrawable { |
32 | public: | 32 | public: |
33 | FbPixmap(); | 33 | FbPixmap(); |
34 | /// copy pixmap | 34 | /// copy pixmap |
35 | FbPixmap(const FbPixmap ©); | 35 | FbPixmap(const FbPixmap ©); |
36 | /// creates a FbPixmap from X pixmap | 36 | /// creates a FbPixmap from X pixmap |
37 | explicit FbPixmap(Pixmap pm); | 37 | explicit FbPixmap(Pixmap pm); |
38 | FbPixmap(const FbDrawable &src, | 38 | FbPixmap(const FbDrawable &src, |
39 | unsigned int width, unsigned int height, | 39 | unsigned int width, unsigned int height, |
40 | unsigned int depth); | 40 | unsigned int depth); |
41 | FbPixmap(Drawable src, | 41 | FbPixmap(Drawable src, |
42 | unsigned int width, unsigned int height, | 42 | unsigned int width, unsigned int height, |
43 | unsigned int depth); | 43 | unsigned int depth); |
44 | 44 | ||
@@ -86,13 +86,6 @@ private: | |||
86 | // if pixmap not *owned* by this object (eg assigned from cache object) | 86 | // if pixmap not *owned* by this object (eg assigned from cache object) |
87 | bool m_dont_free; | 87 | bool m_dont_free; |
88 | 88 | ||
89 | /// Functions relating to the maintenance of root window pixmap caching | ||
90 | static void checkAtoms(); | ||
91 | |||
92 | // array of pixmaps: 1 per screen | ||
93 | static Pixmap *m_root_pixmaps; | ||
94 | static const char *root_prop_ids[]; | ||
95 | static Atom root_prop_atoms[]; | ||
96 | }; | 89 | }; |
97 | 90 | ||
98 | } // end namespace FbTk | 91 | } // end namespace FbTk |
diff --git a/src/FbTk/ImageControl.cc b/src/FbTk/ImageControl.cc index 1281b56..1fa2f65 100644 --- a/src/FbTk/ImageControl.cc +++ b/src/FbTk/ImageControl.cc | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "ImageControl.hh" | 25 | #include "ImageControl.hh" |
26 | 26 | ||
27 | #include "TextureRender.hh" | 27 | #include "TextureRender.hh" |
28 | #include "Texture.hh" | ||
28 | #include "App.hh" | 29 | #include "App.hh" |
29 | #include "SimpleCommand.hh" | 30 | #include "SimpleCommand.hh" |
30 | #include "I18n.hh" | 31 | #include "I18n.hh" |
@@ -67,15 +68,17 @@ using std::list; | |||
67 | 68 | ||
68 | namespace FbTk { | 69 | namespace FbTk { |
69 | 70 | ||
70 | // lookup table for texture | 71 | namespace { // anonymous |
71 | unsigned long *ImageControl::sqrt_table = 0; | 72 | |
73 | static unsigned long *sqrt_table = 0; /// lookup table | ||
74 | |||
72 | #ifdef TIMEDCACHE | 75 | #ifdef TIMEDCACHE |
73 | bool ImageControl::s_timed_cache = true; | 76 | bool s_timed_cache = true; |
74 | #else | 77 | #else |
75 | bool ImageControl::s_timed_cache = false; | 78 | bool s_timed_cache = false; |
76 | #endif // TIMEDCACHE | 79 | #endif // TIMEDCACHE |
77 | 80 | ||
78 | namespace { // anonymous | 81 | |
79 | 82 | ||
80 | inline unsigned long bsqrt(unsigned long x) { | 83 | inline unsigned long bsqrt(unsigned long x) { |
81 | if (x <= 0) return 0; | 84 | if (x <= 0) return 0; |
@@ -93,6 +96,14 @@ inline unsigned long bsqrt(unsigned long x) { | |||
93 | 96 | ||
94 | }; // end anonymous namespace | 97 | }; // end anonymous namespace |
95 | 98 | ||
99 | struct ImageControl::Cache { | ||
100 | Pixmap pixmap; | ||
101 | Pixmap texture_pixmap; | ||
102 | Orientation orient; | ||
103 | unsigned int count, width, height; | ||
104 | unsigned long pixel1, pixel2, texture; | ||
105 | }; | ||
106 | |||
96 | ImageControl::ImageControl(int screen_num, bool dither, | 107 | ImageControl::ImageControl(int screen_num, bool dither, |
97 | int cpc, unsigned long cache_timeout, unsigned long cmax): | 108 | int cpc, unsigned long cache_timeout, unsigned long cmax): |
98 | m_dither(dither), | 109 | m_dither(dither), |
@@ -148,7 +159,7 @@ ImageControl::~ImageControl() { | |||
148 | delete [] m_colors; | 159 | delete [] m_colors; |
149 | } | 160 | } |
150 | 161 | ||
151 | if (cache.size() > 0) { | 162 | if (!cache.empty()) { |
152 | CacheList::iterator it = cache.begin(); | 163 | CacheList::iterator it = cache.begin(); |
153 | CacheList::iterator it_end = cache.end(); | 164 | CacheList::iterator it_end = cache.end(); |
154 | for (; it != it_end; ++it) { | 165 | for (; it != it_end; ++it) { |
diff --git a/src/FbTk/ImageControl.hh b/src/FbTk/ImageControl.hh index d754a07..3c3cbb1 100644 --- a/src/FbTk/ImageControl.hh +++ b/src/FbTk/ImageControl.hh | |||
@@ -25,16 +25,17 @@ | |||
25 | #ifndef FBTK_IMAGECONTROL_HH | 25 | #ifndef FBTK_IMAGECONTROL_HH |
26 | #define FBTK_IMAGECONTROL_HH | 26 | #define FBTK_IMAGECONTROL_HH |
27 | 27 | ||
28 | // actually, Text is rather tool like, that's where orientation comes from | 28 | #include "Text.hh" // actually, Text is rather tool like, that's where orientation comes from |
29 | #include "Text.hh" | ||
30 | #include "Texture.hh" | ||
31 | #include "Timer.hh" | 29 | #include "Timer.hh" |
32 | #include "NotCopyable.hh" | 30 | #include "NotCopyable.hh" |
33 | 31 | ||
32 | #include <X11/Xlib.h> // for Visual* etc | ||
34 | #include <list> | 33 | #include <list> |
35 | 34 | ||
36 | namespace FbTk { | 35 | namespace FbTk { |
37 | 36 | ||
37 | class Texture; | ||
38 | |||
38 | /// Holds screen info, color tables and caches textures | 39 | /// Holds screen info, color tables and caches textures |
39 | class ImageControl: private NotCopyable { | 40 | class ImageControl: private NotCopyable { |
40 | public: | 41 | public: |
@@ -47,7 +48,7 @@ public: | |||
47 | int bitsPerPixel() const { return bits_per_pixel; } | 48 | int bitsPerPixel() const { return bits_per_pixel; } |
48 | #endif | 49 | #endif |
49 | int depth() const { return m_screen_depth; } | 50 | int depth() const { return m_screen_depth; } |
50 | int colorsPerChannel() const { return m_colors_per_channel; } | 51 | int colorsPerChannel() const { return m_colors_per_channel; } |
51 | int screenNumber() const { return m_screen_num; } | 52 | int screenNumber() const { return m_screen_num; } |
52 | Visual *visual() const { return m_visual; } | 53 | Visual *visual() const { return m_visual; } |
53 | unsigned long getSqrt(unsigned int val) const; | 54 | unsigned long getSqrt(unsigned int val) const; |
@@ -103,39 +104,18 @@ private: | |||
103 | int m_colors_per_channel; ///< number of colors per channel | 104 | int m_colors_per_channel; ///< number of colors per channel |
104 | int m_screen_depth; ///< bit depth of screen | 105 | int m_screen_depth; ///< bit depth of screen |
105 | int m_screen_num; ///< screen number | 106 | int m_screen_num; ///< screen number |
106 | unsigned char red_color_table[256], green_color_table[256], | 107 | unsigned char red_color_table[256]; |
107 | blue_color_table[256]; | 108 | unsigned char green_color_table[256]; |
109 | unsigned char blue_color_table[256]; | ||
110 | |||
108 | unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width, | 111 | unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width, |
109 | grad_buffer_height; | 112 | grad_buffer_height; |
110 | 113 | ||
111 | static unsigned long *sqrt_table; /// sqrt lookup table | 114 | struct Cache; |
112 | |||
113 | typedef struct Cache { | ||
114 | Pixmap pixmap; | ||
115 | Pixmap texture_pixmap; | ||
116 | Orientation orient; | ||
117 | unsigned int count, width, height; | ||
118 | unsigned long pixel1, pixel2, texture; | ||
119 | } Cache; | ||
120 | |||
121 | struct ltCacheEntry { | ||
122 | bool operator()(const Cache* s1, const Cache* s2) const { | ||
123 | return (s1->orient < s2->orient || s1->orient == s2->orient | ||
124 | && (s1->width < s2->width || s1->width == s2->width | ||
125 | && (s1->height < s2->height || s1->height == s2->height | ||
126 | && (s1->texture < s2->texture || s1->texture == s2->texture | ||
127 | && (s1->pixel1 < s2->pixel1 || s1->pixel1 == s2->pixel1 | ||
128 | && ((s1->texture & FbTk::Texture::GRADIENT) && s1->pixel2 < s2->pixel2) | ||
129 | ))))); | ||
130 | } | ||
131 | }; | ||
132 | |||
133 | |||
134 | unsigned long cache_max; | ||
135 | typedef std::list<Cache *> CacheList; | 115 | typedef std::list<Cache *> CacheList; |
136 | 116 | ||
137 | mutable CacheList cache; | 117 | mutable CacheList cache; |
138 | static bool s_timed_cache; | 118 | unsigned long cache_max; |
139 | }; | 119 | }; |
140 | 120 | ||
141 | } // end namespace FbTk | 121 | } // end namespace FbTk |
diff --git a/src/FbTk/Text.cc b/src/FbTk/Text.cc index 1e2851e..710b48a 100644 --- a/src/FbTk/Text.cc +++ b/src/FbTk/Text.cc | |||
@@ -28,15 +28,15 @@ | |||
28 | 28 | ||
29 | namespace FbTk { | 29 | namespace FbTk { |
30 | 30 | ||
31 | int doAlignment(int max_width, int bevel, FbTk::Justify justify, | 31 | int doAlignment(int max_width, int bevel, FbTk::Justify justify, |
32 | const FbTk::Font &font, const char * const text, | 32 | const FbTk::Font &font, const char * const text, |
33 | size_t textlen, size_t &newlen) { | 33 | unsigned int textlen, unsigned int &newlen) { |
34 | 34 | ||
35 | if (text == 0 || textlen == 0) | 35 | if (text == 0 || textlen == 0) |
36 | return 0; | 36 | return 0; |
37 | 37 | ||
38 | int l = font.textWidth(text, textlen) + bevel; | 38 | int l = font.textWidth(text, textlen) + bevel; |
39 | size_t dlen = textlen; | 39 | unsigned int dlen = textlen; |
40 | int dx = bevel; | 40 | int dx = bevel; |
41 | if (l > max_width) { | 41 | if (l > max_width) { |
42 | for (; dlen > 0; dlen--) { | 42 | for (; dlen > 0; dlen--) { |
@@ -51,14 +51,14 @@ int doAlignment(int max_width, int bevel, FbTk::Justify justify, | |||
51 | switch (justify) { | 51 | switch (justify) { |
52 | case FbTk::RIGHT: | 52 | case FbTk::RIGHT: |
53 | dx = max_width - l - bevel; | 53 | dx = max_width - l - bevel; |
54 | break; | 54 | break; |
55 | case FbTk::CENTER: | 55 | case FbTk::CENTER: |
56 | dx = (max_width - l)/2; | 56 | dx = (max_width - l)/2; |
57 | break; | 57 | break; |
58 | case FbTk::LEFT: | 58 | case FbTk::LEFT: |
59 | break; | 59 | break; |
60 | } | 60 | } |
61 | 61 | ||
62 | return dx; | 62 | return dx; |
63 | } | 63 | } |
64 | 64 | ||
diff --git a/src/FbTk/Text.hh b/src/FbTk/Text.hh index f2b4162..494d365 100644 --- a/src/FbTk/Text.hh +++ b/src/FbTk/Text.hh | |||
@@ -22,8 +22,6 @@ | |||
22 | #ifndef FBTK_TEXT_HH | 22 | #ifndef FBTK_TEXT_HH |
23 | #define FBTK_TEXT_HH | 23 | #define FBTK_TEXT_HH |
24 | 24 | ||
25 | #include <sys/types.h> | ||
26 | |||
27 | namespace FbTk { | 25 | namespace FbTk { |
28 | 26 | ||
29 | class Font; | 27 | class Font; |
@@ -37,7 +35,7 @@ enum Orientation { ROT0=0, ROT90, ROT180, ROT270 }; | |||
37 | */ | 35 | */ |
38 | int doAlignment(int max_width, int bevel, FbTk::Justify justify, | 36 | int doAlignment(int max_width, int bevel, FbTk::Justify justify, |
39 | const FbTk::Font &font, const char * const text, | 37 | const FbTk::Font &font, const char * const text, |
40 | size_t textlen, size_t &newlen); | 38 | unsigned int textlen, unsigned int &newlen); |
41 | 39 | ||
42 | /** | 40 | /** |
43 | There are 3 interesting translations: | 41 | There are 3 interesting translations: |
@@ -76,7 +74,7 @@ inline void translateCoords(Orientation orient, int &x, int &y, unsigned int w, | |||
76 | } | 74 | } |
77 | 75 | ||
78 | // still require w and h in ROT0 coords | 76 | // still require w and h in ROT0 coords |
79 | inline void untranslateCoords(Orientation orient, int &orig_x, int &orig_y, unsigned int w, unsigned int h) { | 77 | inline void untranslateCoords(Orientation orient, int orig_x, int orig_y, unsigned int w, unsigned int h) { |
80 | 78 | ||
81 | int x = orig_x; | 79 | int x = orig_x; |
82 | int y = orig_y; | 80 | int y = orig_y; |
@@ -102,7 +100,7 @@ inline void untranslateCoords(Orientation orient, int &orig_x, int &orig_y, unsi | |||
102 | 100 | ||
103 | // When positioning an X11 box inside another area, we need to | 101 | // When positioning an X11 box inside another area, we need to |
104 | // relocate the x,y coordinates | 102 | // relocate the x,y coordinates |
105 | inline void translatePosition(Orientation orient, int &x, int &y, unsigned int w, unsigned int h, unsigned int bw) { | 103 | inline void translatePosition(Orientation orient, int x, int y, unsigned int w, unsigned int h, unsigned int bw) { |
106 | 104 | ||
107 | switch(orient) { | 105 | switch(orient) { |
108 | case ROT0: | 106 | case ROT0: |
@@ -121,7 +119,7 @@ inline void translatePosition(Orientation orient, int &x, int &y, unsigned int w | |||
121 | 119 | ||
122 | } | 120 | } |
123 | 121 | ||
124 | inline void translateSize(Orientation orient, unsigned int &w, unsigned int &h) { | 122 | inline void translateSize(Orientation orient, unsigned int w, unsigned int h) { |
125 | if (orient == ROT0 || orient == ROT180) | 123 | if (orient == ROT0 || orient == ROT180) |
126 | return; | 124 | return; |
127 | 125 | ||
diff --git a/src/FbTk/TextButton.cc b/src/FbTk/TextButton.cc index 922eb74..85ac5c8 100644 --- a/src/FbTk/TextButton.cc +++ b/src/FbTk/TextButton.cc | |||
@@ -150,7 +150,7 @@ void TextButton::renderForeground(FbWindow &win, FbDrawable &drawable) { | |||
150 | } | 150 | } |
151 | 151 | ||
152 | void TextButton::drawText(int x_offset, int y_offset, FbDrawable *drawable) { | 152 | void TextButton::drawText(int x_offset, int y_offset, FbDrawable *drawable) { |
153 | size_t textlen = text().size(); | 153 | unsigned int textlen = text().size(); |
154 | // do text alignment | 154 | // do text alignment |
155 | 155 | ||
156 | unsigned int textw = width(), texth = height(); | 156 | unsigned int textw = width(), texth = height(); |
diff --git a/src/FbTk/TextureRender.cc b/src/FbTk/TextureRender.cc index 3f35951..c7c29c1 100644 --- a/src/FbTk/TextureRender.cc +++ b/src/FbTk/TextureRender.cc | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "TextureRender.hh" | 25 | #include "TextureRender.hh" |
26 | 26 | ||
27 | #include "ImageControl.hh" | 27 | #include "ImageControl.hh" |
28 | #include "Texture.hh" | ||
28 | #include "App.hh" | 29 | #include "App.hh" |
29 | #include "FbPixmap.hh" | 30 | #include "FbPixmap.hh" |
30 | #include "GContext.hh" | 31 | #include "GContext.hh" |