X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=otk%2Fcolor.cc;h=a05336e5d9fd0d40faf872d118325e2d3629cf6b;hb=707f70682abe0dfaadbf76843a0dccb33f0eaeda;hp=ad30c7a3edc028e4c781773ad1f7fc9d46c182c8;hpb=85c41a1aec90b8daefc425596ea34b6f9d0e643c;p=chaz%2Fopenbox diff --git a/otk/color.cc b/otk/color.cc index ad30c7a3..a05336e5 100644 --- a/otk/color.cc +++ b/otk/color.cc @@ -11,45 +11,43 @@ extern "C" { #include #include "color.hh" -#include "basedisplay.hh" +#include "display.hh" +#include "screeninfo.hh" +namespace otk { -BColor::ColorCache BColor::colorcache; -bool BColor::cleancache = false; +Color::ColorCache Color::colorcache; +bool Color::cleancache = false; -BColor::BColor(const BaseDisplay * const _display, unsigned int _screen) - : allocated(false), r(-1), g(-1), b(-1), p(0), dpy(_display), scrn(_screen) +Color::Color(unsigned int _screen) + : allocated(false), r(-1), g(-1), b(-1), p(0), scrn(_screen) {} -BColor::BColor(int _r, int _g, int _b, - const BaseDisplay * const _display, unsigned int _screen) - : allocated(false), r(_r), g(_g), b(_b), p(0), dpy(_display), scrn(_screen) +Color::Color(int _r, int _g, int _b, unsigned int _screen) + : allocated(false), r(_r), g(_g), b(_b), p(0), scrn(_screen) {} -BColor::BColor(const std::string &_name, - const BaseDisplay * const _display, unsigned int _screen) - : allocated(false), r(-1), g(-1), b(-1), p(0), dpy(_display), scrn(_screen), +Color::Color(const std::string &_name, unsigned int _screen) + : allocated(false), r(-1), g(-1), b(-1), p(0), scrn(_screen), colorname(_name) { parseColorName(); } -BColor::~BColor(void) { +Color::~Color(void) { deallocate(); } -void BColor::setDisplay(const BaseDisplay * const _display, - unsigned int _screen) { - if (_display == display() && _screen == screen()) { +void Color::setScreen(unsigned int _screen) { + if (_screen == screen()) { // nothing to do return; } deallocate(); - dpy = _display; scrn = _screen; if (! colorname.empty()) { @@ -58,10 +56,10 @@ void BColor::setDisplay(const BaseDisplay * const _display, } -unsigned long BColor::pixel(void) const { +unsigned long Color::pixel(void) const { if (! allocated) { // mutable - BColor *that = (BColor *) this; + Color *that = (Color *) this; that->allocate(); } @@ -69,17 +67,15 @@ unsigned long BColor::pixel(void) const { } -void BColor::parseColorName(void) { - assert(dpy != 0); - +void Color::parseColorName(void) { if (colorname.empty()) { - fprintf(stderr, "BColor: empty colorname, cannot parse (using black)\n"); + fprintf(stderr, "Color: empty colorname, cannot parse (using black)\n"); setRGB(0, 0, 0); } if (scrn == ~(0u)) - scrn = DefaultScreen(display()->getXDisplay()); - Colormap colormap = display()->getScreenInfo(scrn)->getColormap(); + scrn = DefaultScreen(**display); + Colormap colormap = display->screenInfo(scrn)->colormap(); // get rgb values from colorname XColor xcol; @@ -88,9 +84,9 @@ void BColor::parseColorName(void) { xcol.blue = 0; xcol.pixel = 0; - if (! XParseColor(display()->getXDisplay(), colormap, + if (! XParseColor(**display, colormap, colorname.c_str(), &xcol)) { - fprintf(stderr, "BColor::allocate: color parse error: \"%s\"\n", + fprintf(stderr, "Color::allocate: color parse error: \"%s\"\n", colorname.c_str()); setRGB(0, 0, 0); return; @@ -100,15 +96,13 @@ void BColor::parseColorName(void) { } -void BColor::allocate(void) { - assert(dpy != 0); - - if (scrn == ~(0u)) scrn = DefaultScreen(display()->getXDisplay()); - Colormap colormap = display()->getScreenInfo(scrn)->getColormap(); +void Color::allocate(void) { + if (scrn == ~(0u)) scrn = DefaultScreen(**display); + Colormap colormap = display->screenInfo(scrn)->colormap(); if (! isValid()) { if (colorname.empty()) { - fprintf(stderr, "BColor: cannot allocate invalid color (using black)\n"); + fprintf(stderr, "Color: cannot allocate invalid color (using black)\n"); setRGB(0, 0, 0); } else { parseColorName(); @@ -116,7 +110,7 @@ void BColor::allocate(void) { } // see if we have allocated this color before - RGB rgb(display(), scrn, r, g, b); + RGB rgb(scrn, r, g, b); ColorCache::iterator it = colorcache.find(rgb); if (it != colorcache.end()) { // found @@ -133,8 +127,8 @@ void BColor::allocate(void) { xcol.blue = b | b << 8; xcol.pixel = 0; - if (! XAllocColor(display()->getXDisplay(), colormap, &xcol)) { - fprintf(stderr, "BColor::allocate: color alloc error: rgb:%x/%x/%x\n", + if (! XAllocColor(**display, colormap, &xcol)) { + fprintf(stderr, "Color::allocate: color alloc error: rgb:%x/%x/%x\n", r, g, b); xcol.pixel = 0; } @@ -149,13 +143,11 @@ void BColor::allocate(void) { } -void BColor::deallocate(void) { +void Color::deallocate(void) { if (! allocated) return; - assert(dpy != 0); - - ColorCache::iterator it = colorcache.find(RGB(display(), scrn, r, g, b)); + ColorCache::iterator it = colorcache.find(RGB(scrn, r, g, b)); if (it != colorcache.end()) { if ((*it).second.count >= 1) (*it).second.count--; @@ -168,23 +160,22 @@ void BColor::deallocate(void) { } -BColor &BColor::operator=(const BColor &c) { +Color &Color::operator=(const Color &c) { deallocate(); setRGB(c.r, c.g, c.b); colorname = c.colorname; - dpy = c.dpy; scrn = c.scrn; return *this; } -void BColor::cleanupColorCache(void) { +void Color::cleanupColorCache(void) { cleancache = true; } -void BColor::doCacheCleanup(void) { +void Color::doCacheCleanup(void) { // ### TODO - support multiple displays! ColorCache::iterator it = colorcache.begin(); if (it == colorcache.end()) { @@ -192,11 +183,11 @@ void BColor::doCacheCleanup(void) { return; } - const BaseDisplay* const display = (*it).first.display; unsigned long *pixels = new unsigned long[ colorcache.size() ]; - unsigned int i, count; + int i; + unsigned count; - for (i = 0; i < display->getNumberOfScreens(); i++) { + for (i = 0; i < ScreenCount(**display); i++) { count = 0; it = colorcache.begin(); @@ -213,11 +204,12 @@ void BColor::doCacheCleanup(void) { } if (count > 0) - XFreeColors(display->getXDisplay(), - display->getScreenInfo(i)->getColormap(), + XFreeColors(**display, display->screenInfo(i)->colormap(), pixels, count, 0); } delete [] pixels; cleancache = false; } + +}