X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=otk%2Frendercolor.cc;h=5da218ea92f84f101620240714e270ab89be83e8;hb=99b226f39df2d7df0349c576012e97f5d662a9a6;hp=e5cbb7cba45d8b99a55387adde6a59b27c5729f9;hpb=01a37dfe1888f1ac6da7ab12c6e4d59ce104d12c;p=chaz%2Fopenbox diff --git a/otk/rendercolor.cc b/otk/rendercolor.cc index e5cbb7cb..5da218ea 100644 --- a/otk/rendercolor.cc +++ b/otk/rendercolor.cc @@ -28,23 +28,21 @@ RenderColor::RenderColor(int screen, unsigned char red, : _screen(screen), _red(red), _green(green), - _blue(blue), - _allocated(false), - _created(false) + _blue(blue) { + create(); } RenderColor::RenderColor(int screen, RGB rgb) : _screen(screen), _red(rgb.r), _green(rgb.g), - _blue(rgb.b), - _allocated(false), - _created(false) + _blue(rgb.b) { + create(); } -void RenderColor::create() const +void RenderColor::create() { unsigned long color = _blue | _green << 8 | _red << 16; @@ -67,7 +65,6 @@ void RenderColor::create() const xcol.blue = (_blue << 8) | _blue; display->renderControl(_screen)->allocateColor(&xcol); - _allocated = true; _pixel = xcol.pixel; gcv.foreground = _pixel; @@ -81,41 +78,23 @@ void RenderColor::create() const _cache[_screen][color] = item; ++item->count; } - - _created = true; -} - -unsigned long RenderColor::pixel() const -{ - if (!_created) create(); - return _pixel; -} - -GC RenderColor::gc() const -{ - if (!_created) create(); - return _gc; } RenderColor::~RenderColor() { unsigned long color = _blue | _green << 8 | _red << 16; - if (_created) { - CacheItem *item = _cache[_screen][color]; - assert(item); // better be... - - if (--item->count <= 0) { - // remove from the cache - XFreeGC(**display, _gc); - _cache[_screen][color] = 0; - delete item; - - if (_allocated) { - const ScreenInfo *info = display->screenInfo(_screen); - XFreeColors(**display, info->colormap(), &_pixel, 1, 0); - } - } + CacheItem *item = _cache[_screen][color]; + assert(item); // better be... + + if (--item->count <= 0) { + // remove from the cache + XFreeGC(**display, _gc); + _cache[_screen][color] = 0; + delete item; + + const ScreenInfo *info = display->screenInfo(_screen); + XFreeColors(**display, info->colormap(), &_pixel, 1, 0); } }