openbox/otk/rendercolor.hh

65 lines
1.3 KiB
C++
Raw Normal View History

// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
#ifndef __rendercolor_hh
#define __rendercolor_hh
extern "C" {
#include <X11/Xlib.h>
}
#include <map>
namespace otk {
struct RGB {
int r;
int g;
int b;
RGB(int red, int green, int blue) : r(red), g(green), b(blue) {}
// color is in ARGB format
RGB(unsigned long color)
: r((color >> 16) & 0xff),
g((color >> 8) & 0xff),
b((color) & 0xff) {}
};
2003-01-22 22:20:26 +00:00
class RenderColor {
2003-01-22 22:20:26 +00:00
private:
struct CacheItem {
GC gc;
2003-01-22 23:16:58 +00:00
unsigned long pixel;
int count;
2003-01-22 23:16:58 +00:00
CacheItem(GC g, unsigned long p) : gc(g), pixel(p), count(0) {}
};
static std::map<unsigned long, CacheItem*> *_cache;
int _screen;
unsigned char _red;
unsigned char _green;
unsigned char _blue;
2003-01-22 22:46:16 +00:00
unsigned long _pixel;
GC _gc;
2003-01-22 20:14:28 +00:00
void create();
public:
static void initialize();
static void destroy();
RenderColor(int screen, unsigned char red,
unsigned char green, unsigned char blue);
2003-01-22 20:14:28 +00:00
RenderColor(int screen, RGB rgb);
virtual ~RenderColor();
inline int screen() const { return _screen; }
inline unsigned char red() const { return _red; }
inline unsigned char green() const { return _green; }
inline unsigned char blue() const { return _blue; }
2003-01-22 22:46:16 +00:00
inline unsigned long pixel() const { return _pixel; }
inline GC gc() const { return _gc; }
};
}
#endif // __rendercolor_hh