00001
00002 #ifndef __rendercolor_hh
00003 #define __rendercolor_hh
00004
00005 extern "C" {
00006 #include <X11/Xlib.h>
00007 }
00008
00009 #include <map>
00010
00011 namespace otk {
00012
00013 struct RGB {
00014 int r;
00015 int g;
00016 int b;
00017 RGB(int red, int green, int blue) : r(red), g(green), b(blue) {}
00018
00019 RGB(unsigned long color)
00020 : r((color >> 16) & 0xff),
00021 g((color >> 8) & 0xff),
00022 b((color) & 0xff) {}
00023 };
00024
00025 class RenderColor {
00026 private:
00027 struct CacheItem {
00028 GC gc;
00029 unsigned long pixel;
00030 int count;
00031 CacheItem(GC g, unsigned long p) : gc(g), pixel(p), count(0) {}
00032 };
00033 static std::map<unsigned long, CacheItem*> *_cache;
00034
00035 int _screen;
00036 unsigned char _red;
00037 unsigned char _green;
00038 unsigned char _blue;
00039 unsigned long _pixel;
00040
00041 GC _gc;
00042
00043 void create();
00044
00045 public:
00046 static void initialize();
00047 static void destroy();
00048
00049 RenderColor(int screen, unsigned char red,
00050 unsigned char green, unsigned char blue);
00051 RenderColor(int screen, RGB rgb);
00052 virtual ~RenderColor();
00053
00054 inline int screen() const { return _screen; }
00055 inline unsigned char red() const { return _red; }
00056 inline unsigned char green() const { return _green; }
00057 inline unsigned char blue() const { return _blue; }
00058 inline unsigned long pixel() const { return _pixel; }
00059 inline GC gc() const { return _gc; }
00060 };
00061
00062 }
00063
00064 #endif // __rendercolor_hh