]> Dogcows Code - chaz/openbox/blob - otk/rendercolor.hh
add the pixel to the cache
[chaz/openbox] / otk / rendercolor.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef __rendercolor_hh
3 #define __rendercolor_hh
4
5 extern "C" {
6 #include <X11/Xlib.h>
7 }
8
9 #include <map>
10
11 namespace otk {
12
13 class RenderColor {
14 public:
15 struct RGB {
16 int r;
17 int g;
18 int b;
19 RGB(int red, int green, int blue) : r(red), g(green), b(blue) {}
20 // color is in ARGB format
21 RGB(unsigned long color)
22 : r((color >> 16) & 0xff),
23 g((color >> 8) & 0xff),
24 b((color) & 0xff) {}
25 };
26
27 private:
28 struct CacheItem {
29 GC gc;
30 unsigned long pixel;
31 int count;
32 CacheItem(GC g, unsigned long p) : gc(g), pixel(p), count(0) {}
33 };
34 static std::map<unsigned long, CacheItem*> *_cache;
35
36 int _screen;
37 unsigned char _red;
38 unsigned char _green;
39 unsigned char _blue;
40 unsigned long _pixel;
41
42 GC _gc;
43
44 void create();
45
46 public:
47 static void initialize();
48 static void destroy();
49
50 RenderColor(int screen, unsigned char red,
51 unsigned char green, unsigned char blue);
52 RenderColor(int screen, RGB rgb);
53 virtual ~RenderColor();
54
55 inline int screen() const { return _screen; }
56 inline unsigned char red() const { return _red; }
57 inline unsigned char green() const { return _green; }
58 inline unsigned char blue() const { return _blue; }
59 inline unsigned long pixel() const { return _pixel; }
60 inline GC gc() const { return _gc; }
61 };
62
63 }
64
65 #endif // __rendercolor_hh
This page took 0.039572 seconds and 5 git commands to generate.