moved code a bit around, cleaned up some classes
This commit is contained in:
parent
c6099d777d
commit
e1db89e2d7
9 changed files with 72 additions and 83 deletions
|
@ -38,21 +38,34 @@ using std::cerr;
|
|||
|
||||
namespace FbTk {
|
||||
|
||||
Pixmap *FbPixmap::m_root_pixmaps = 0;
|
||||
namespace {
|
||||
|
||||
const char* FbPixmap::root_prop_ids[] = {
|
||||
Pixmap *root_pixmaps = 0;
|
||||
|
||||
const char* root_prop_ids[] = {
|
||||
"_XROOTPMAP_ID",
|
||||
"_XSETROOT_ID",
|
||||
0
|
||||
};
|
||||
|
||||
// same number as in root_prop_ids
|
||||
Atom FbPixmap::root_prop_atoms[] = {
|
||||
Atom root_prop_atoms[] = {
|
||||
None,
|
||||
None,
|
||||
None
|
||||
};
|
||||
|
||||
void checkAtoms() {
|
||||
|
||||
Display* display = FbTk::App::instance()->display();
|
||||
for (int i=0; root_prop_ids[i] != 0; ++i) {
|
||||
if (root_prop_atoms[i] == None) {
|
||||
root_prop_atoms[i] = XInternAtom(display, root_prop_ids[i], False);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}; // end of anonymous namespace
|
||||
|
||||
FbPixmap::FbPixmap():m_pm(0),
|
||||
m_width(0), m_height(0),
|
||||
|
@ -389,14 +402,14 @@ bool FbPixmap::rootwinPropertyNotify(int screen_num, Atom atom) {
|
|||
|
||||
// returns whether or not the background was changed
|
||||
bool FbPixmap::setRootPixmap(int screen_num, Pixmap pm) {
|
||||
if (!m_root_pixmaps) {
|
||||
m_root_pixmaps = new Pixmap[ScreenCount(display())];
|
||||
if (!root_pixmaps) {
|
||||
root_pixmaps = new Pixmap[ScreenCount(display())];
|
||||
for (int i=0; i < ScreenCount(display()); ++i)
|
||||
m_root_pixmaps[i] = None;
|
||||
root_pixmaps[i] = None;
|
||||
}
|
||||
|
||||
if (m_root_pixmaps[screen_num] != pm) {
|
||||
m_root_pixmaps[screen_num] = pm;
|
||||
if (root_pixmaps[screen_num] != pm) {
|
||||
root_pixmaps[screen_num] = pm;
|
||||
FbWindow::updatedAlphaBackground(screen_num);
|
||||
return true;
|
||||
}
|
||||
|
@ -410,8 +423,8 @@ Pixmap FbPixmap::getRootPixmap(int screen_num, bool force_update) {
|
|||
*/
|
||||
|
||||
// check and see if if we have the pixmaps in cache
|
||||
if (m_root_pixmaps && !force_update)
|
||||
return m_root_pixmaps[screen_num];
|
||||
if (root_pixmaps && !force_update)
|
||||
return root_pixmaps[screen_num];
|
||||
|
||||
// else setup pixmap cache
|
||||
int numscreens = ScreenCount(display());
|
||||
|
@ -460,15 +473,7 @@ Pixmap FbPixmap::getRootPixmap(int screen_num, bool force_update) {
|
|||
setRootPixmap(i, root_pm);
|
||||
}
|
||||
|
||||
return m_root_pixmaps[screen_num];
|
||||
}
|
||||
|
||||
void FbPixmap::checkAtoms() {
|
||||
for (int i=0; root_prop_ids[i] != 0; ++i) {
|
||||
if (root_prop_atoms[i] == None) {
|
||||
root_prop_atoms[i] = XInternAtom(display(), root_prop_ids[i], False);
|
||||
}
|
||||
}
|
||||
return root_pixmaps[screen_num];
|
||||
}
|
||||
|
||||
void FbPixmap::free() {
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#define FBTK_FBPIXMAP_HH
|
||||
|
||||
#include "FbDrawable.hh"
|
||||
#include "Text.hh"
|
||||
#include "Text.hh" // for Orientation
|
||||
|
||||
namespace FbTk {
|
||||
|
||||
|
@ -86,13 +86,6 @@ private:
|
|||
// if pixmap not *owned* by this object (eg assigned from cache object)
|
||||
bool m_dont_free;
|
||||
|
||||
/// Functions relating to the maintenance of root window pixmap caching
|
||||
static void checkAtoms();
|
||||
|
||||
// array of pixmaps: 1 per screen
|
||||
static Pixmap *m_root_pixmaps;
|
||||
static const char *root_prop_ids[];
|
||||
static Atom root_prop_atoms[];
|
||||
};
|
||||
|
||||
} // end namespace FbTk
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "ImageControl.hh"
|
||||
|
||||
#include "TextureRender.hh"
|
||||
#include "Texture.hh"
|
||||
#include "App.hh"
|
||||
#include "SimpleCommand.hh"
|
||||
#include "I18n.hh"
|
||||
|
@ -67,15 +68,17 @@ using std::list;
|
|||
|
||||
namespace FbTk {
|
||||
|
||||
// lookup table for texture
|
||||
unsigned long *ImageControl::sqrt_table = 0;
|
||||
namespace { // anonymous
|
||||
|
||||
static unsigned long *sqrt_table = 0; /// lookup table
|
||||
|
||||
#ifdef TIMEDCACHE
|
||||
bool ImageControl::s_timed_cache = true;
|
||||
bool s_timed_cache = true;
|
||||
#else
|
||||
bool ImageControl::s_timed_cache = false;
|
||||
bool s_timed_cache = false;
|
||||
#endif // TIMEDCACHE
|
||||
|
||||
namespace { // anonymous
|
||||
|
||||
|
||||
inline unsigned long bsqrt(unsigned long x) {
|
||||
if (x <= 0) return 0;
|
||||
|
@ -93,6 +96,14 @@ inline unsigned long bsqrt(unsigned long x) {
|
|||
|
||||
}; // end anonymous namespace
|
||||
|
||||
struct ImageControl::Cache {
|
||||
Pixmap pixmap;
|
||||
Pixmap texture_pixmap;
|
||||
Orientation orient;
|
||||
unsigned int count, width, height;
|
||||
unsigned long pixel1, pixel2, texture;
|
||||
};
|
||||
|
||||
ImageControl::ImageControl(int screen_num, bool dither,
|
||||
int cpc, unsigned long cache_timeout, unsigned long cmax):
|
||||
m_dither(dither),
|
||||
|
@ -148,7 +159,7 @@ ImageControl::~ImageControl() {
|
|||
delete [] m_colors;
|
||||
}
|
||||
|
||||
if (cache.size() > 0) {
|
||||
if (!cache.empty()) {
|
||||
CacheList::iterator it = cache.begin();
|
||||
CacheList::iterator it_end = cache.end();
|
||||
for (; it != it_end; ++it) {
|
||||
|
|
|
@ -25,16 +25,17 @@
|
|||
#ifndef FBTK_IMAGECONTROL_HH
|
||||
#define FBTK_IMAGECONTROL_HH
|
||||
|
||||
// actually, Text is rather tool like, that's where orientation comes from
|
||||
#include "Text.hh"
|
||||
#include "Texture.hh"
|
||||
#include "Text.hh" // actually, Text is rather tool like, that's where orientation comes from
|
||||
#include "Timer.hh"
|
||||
#include "NotCopyable.hh"
|
||||
|
||||
#include <X11/Xlib.h> // for Visual* etc
|
||||
#include <list>
|
||||
|
||||
namespace FbTk {
|
||||
|
||||
class Texture;
|
||||
|
||||
/// Holds screen info, color tables and caches textures
|
||||
class ImageControl: private NotCopyable {
|
||||
public:
|
||||
|
@ -47,7 +48,7 @@ public:
|
|||
int bitsPerPixel() const { return bits_per_pixel; }
|
||||
#endif
|
||||
int depth() const { return m_screen_depth; }
|
||||
int colorsPerChannel() const { return m_colors_per_channel; }
|
||||
int colorsPerChannel() const { return m_colors_per_channel; }
|
||||
int screenNumber() const { return m_screen_num; }
|
||||
Visual *visual() const { return m_visual; }
|
||||
unsigned long getSqrt(unsigned int val) const;
|
||||
|
@ -103,39 +104,18 @@ private:
|
|||
int m_colors_per_channel; ///< number of colors per channel
|
||||
int m_screen_depth; ///< bit depth of screen
|
||||
int m_screen_num; ///< screen number
|
||||
unsigned char red_color_table[256], green_color_table[256],
|
||||
blue_color_table[256];
|
||||
unsigned char red_color_table[256];
|
||||
unsigned char green_color_table[256];
|
||||
unsigned char blue_color_table[256];
|
||||
|
||||
unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width,
|
||||
grad_buffer_height;
|
||||
|
||||
static unsigned long *sqrt_table; /// sqrt lookup table
|
||||
|
||||
typedef struct Cache {
|
||||
Pixmap pixmap;
|
||||
Pixmap texture_pixmap;
|
||||
Orientation orient;
|
||||
unsigned int count, width, height;
|
||||
unsigned long pixel1, pixel2, texture;
|
||||
} Cache;
|
||||
|
||||
struct ltCacheEntry {
|
||||
bool operator()(const Cache* s1, const Cache* s2) const {
|
||||
return (s1->orient < s2->orient || s1->orient == s2->orient
|
||||
&& (s1->width < s2->width || s1->width == s2->width
|
||||
&& (s1->height < s2->height || s1->height == s2->height
|
||||
&& (s1->texture < s2->texture || s1->texture == s2->texture
|
||||
&& (s1->pixel1 < s2->pixel1 || s1->pixel1 == s2->pixel1
|
||||
&& ((s1->texture & FbTk::Texture::GRADIENT) && s1->pixel2 < s2->pixel2)
|
||||
)))));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
unsigned long cache_max;
|
||||
struct Cache;
|
||||
typedef std::list<Cache *> CacheList;
|
||||
|
||||
mutable CacheList cache;
|
||||
static bool s_timed_cache;
|
||||
unsigned long cache_max;
|
||||
};
|
||||
|
||||
} // end namespace FbTk
|
||||
|
|
|
@ -30,13 +30,13 @@ namespace FbTk {
|
|||
|
||||
int doAlignment(int max_width, int bevel, FbTk::Justify justify,
|
||||
const FbTk::Font &font, const char * const text,
|
||||
size_t textlen, size_t &newlen) {
|
||||
unsigned int textlen, unsigned int &newlen) {
|
||||
|
||||
if (text == 0 || textlen == 0)
|
||||
return 0;
|
||||
|
||||
int l = font.textWidth(text, textlen) + bevel;
|
||||
size_t dlen = textlen;
|
||||
unsigned int dlen = textlen;
|
||||
int dx = bevel;
|
||||
if (l > max_width) {
|
||||
for (; dlen > 0; dlen--) {
|
||||
|
@ -51,12 +51,12 @@ int doAlignment(int max_width, int bevel, FbTk::Justify justify,
|
|||
switch (justify) {
|
||||
case FbTk::RIGHT:
|
||||
dx = max_width - l - bevel;
|
||||
break;
|
||||
break;
|
||||
case FbTk::CENTER:
|
||||
dx = (max_width - l)/2;
|
||||
break;
|
||||
break;
|
||||
case FbTk::LEFT:
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
return dx;
|
||||
|
|
|
@ -22,8 +22,6 @@
|
|||
#ifndef FBTK_TEXT_HH
|
||||
#define FBTK_TEXT_HH
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace FbTk {
|
||||
|
||||
class Font;
|
||||
|
@ -37,7 +35,7 @@ enum Orientation { ROT0=0, ROT90, ROT180, ROT270 };
|
|||
*/
|
||||
int doAlignment(int max_width, int bevel, FbTk::Justify justify,
|
||||
const FbTk::Font &font, const char * const text,
|
||||
size_t textlen, size_t &newlen);
|
||||
unsigned int textlen, unsigned int &newlen);
|
||||
|
||||
/**
|
||||
There are 3 interesting translations:
|
||||
|
@ -76,7 +74,7 @@ inline void translateCoords(Orientation orient, int &x, int &y, unsigned int w,
|
|||
}
|
||||
|
||||
// still require w and h in ROT0 coords
|
||||
inline void untranslateCoords(Orientation orient, int &orig_x, int &orig_y, unsigned int w, unsigned int h) {
|
||||
inline void untranslateCoords(Orientation orient, int orig_x, int orig_y, unsigned int w, unsigned int h) {
|
||||
|
||||
int x = orig_x;
|
||||
int y = orig_y;
|
||||
|
@ -102,7 +100,7 @@ inline void untranslateCoords(Orientation orient, int &orig_x, int &orig_y, unsi
|
|||
|
||||
// When positioning an X11 box inside another area, we need to
|
||||
// relocate the x,y coordinates
|
||||
inline void translatePosition(Orientation orient, int &x, int &y, unsigned int w, unsigned int h, unsigned int bw) {
|
||||
inline void translatePosition(Orientation orient, int x, int y, unsigned int w, unsigned int h, unsigned int bw) {
|
||||
|
||||
switch(orient) {
|
||||
case ROT0:
|
||||
|
@ -121,7 +119,7 @@ inline void translatePosition(Orientation orient, int &x, int &y, unsigned int w
|
|||
|
||||
}
|
||||
|
||||
inline void translateSize(Orientation orient, unsigned int &w, unsigned int &h) {
|
||||
inline void translateSize(Orientation orient, unsigned int w, unsigned int h) {
|
||||
if (orient == ROT0 || orient == ROT180)
|
||||
return;
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ void TextButton::renderForeground(FbWindow &win, FbDrawable &drawable) {
|
|||
}
|
||||
|
||||
void TextButton::drawText(int x_offset, int y_offset, FbDrawable *drawable) {
|
||||
size_t textlen = text().size();
|
||||
unsigned int textlen = text().size();
|
||||
// do text alignment
|
||||
|
||||
unsigned int textw = width(), texth = height();
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "TextureRender.hh"
|
||||
|
||||
#include "ImageControl.hh"
|
||||
#include "Texture.hh"
|
||||
#include "App.hh"
|
||||
#include "FbPixmap.hh"
|
||||
#include "GContext.hh"
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "../src/FbTk/I18n.hh"
|
||||
#include "../src/FbTk/ImageControl.hh"
|
||||
#include "../src/FbTk/Texture.hh"
|
||||
#include "../src/FbTk/GContext.hh"
|
||||
#include "../src/FbRootWindow.hh"
|
||||
|
||||
|
|
Loading…
Reference in a new issue