X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=otk%2Fimagecontrol.cc;h=ab8f5c50ca2bd03caf250d5f1ebcf67227351333;hb=00bc993775b916de76772bdc5e31618076194797;hp=09823b8e2499e8f30ed8ee0d3dead765727de8b3;hpb=06de24ec6666578759eff2b348e50f5e8e20f3bd;p=chaz%2Fopenbox diff --git a/otk/imagecontrol.cc b/otk/imagecontrol.cc index 09823b8e..ab8f5c50 100644 --- a/otk/imagecontrol.cc +++ b/otk/imagecontrol.cc @@ -39,13 +39,12 @@ static unsigned long bsqrt(unsigned long x) { } } -BImageControl *ctrl = 0; +ImageControl *ctrl = 0; -BImageControl::BImageControl(OBTimerQueueManager *timermanager, - const ScreenInfo *scrn, - bool _dither, int _cpc, - unsigned long cache_timeout, - unsigned long cmax) { +ImageControl::ImageControl(const ScreenInfo *scrn, + bool _dither, int _cpc, + unsigned long cache_timeout, + unsigned long cmax) { if (! ctrl) ctrl = this; screeninfo = scrn; @@ -53,13 +52,10 @@ BImageControl::BImageControl(OBTimerQueueManager *timermanager, setColorsPerChannel(_cpc); cache_max = cmax; - if (cache_timeout) { - timer = new OBTimer(timermanager, (OBTimeoutHandler)timeout, this); - timer->setTimeout(cache_timeout); - timer->start(); - } else { - timer = (OBTimer *) 0; - } + if (cache_timeout) + timer = new Timer(cache_timeout, (Timer::TimeoutHandler)timeout, this); + else + timer = (Timer *) 0; colors = (XColor *) 0; ncolors = 0; @@ -75,7 +71,7 @@ BImageControl::BImageControl(OBTimerQueueManager *timermanager, colormap = screeninfo->colormap(); int count; - XPixmapFormatValues *pmv = XListPixmapFormats(OBDisplay::display, + XPixmapFormatValues *pmv = XListPixmapFormats(**display, &count); if (pmv) { bits_per_pixel = 0; @@ -129,7 +125,7 @@ BImageControl::BImageControl(OBTimerQueueManager *timermanager, if (colors_per_channel < 2 || ncolors > (1 << screen_depth)) { fprintf(stderr, - "BImageControl::BImageControl: invalid colormap size %d " + "ImageControl::ImageControl: invalid colormap size %d " "(%d/%d/%d) - reducing", ncolors, colors_per_channel, colors_per_channel, colors_per_channel); @@ -139,7 +135,7 @@ BImageControl::BImageControl(OBTimerQueueManager *timermanager, colors = new XColor[ncolors]; if (! colors) { - fprintf(stderr, "BImageControl::BImageControl: error allocating " + fprintf(stderr, "ImageControl::ImageControl: error allocating " "colormap\n"); exit(1); } @@ -168,7 +164,7 @@ BImageControl::BImageControl(OBTimerQueueManager *timermanager, } for (i = 0; i < ncolors; i++) { - if (! XAllocColor(OBDisplay::display, colormap, &colors[i])) { + if (! XAllocColor(**display, colormap, &colors[i])) { fprintf(stderr, "couldn't alloc color %i %i %i\n", colors[i].red, colors[i].green, colors[i].blue); colors[i].flags = 0; @@ -183,7 +179,7 @@ BImageControl::BImageControl(OBTimerQueueManager *timermanager, for (i = 0; i < incolors; i++) icolors[i].pixel = i; - XQueryColors(OBDisplay::display, colormap, icolors, incolors); + XQueryColors(**display, colormap, icolors, incolors); for (i = 0; i < ncolors; i++) { if (! colors[i].flags) { unsigned long chk = 0xffffffff, pixel, close = 0; @@ -205,7 +201,7 @@ BImageControl::BImageControl(OBTimerQueueManager *timermanager, colors[i].green = icolors[close].green; colors[i].blue = icolors[close].blue; - if (XAllocColor(OBDisplay::display, colormap, + if (XAllocColor(**display, colormap, &colors[i])) { colors[i].flags = DoRed|DoGreen|DoBlue; break; @@ -234,7 +230,7 @@ BImageControl::BImageControl(OBTimerQueueManager *timermanager, if (colors_per_channel < 2 || ncolors > (1 << screen_depth)) { fprintf(stderr, - "BImageControl::BImageControl: invalid colormap size %d " + "ImageControl::ImageControl: invalid colormap size %d " "(%d/%d/%d) - reducing", ncolors, colors_per_channel, colors_per_channel, colors_per_channel); @@ -245,7 +241,7 @@ BImageControl::BImageControl(OBTimerQueueManager *timermanager, colors = new XColor[ncolors]; if (! colors) { fprintf(stderr, - "BImageControl::BImageControl: error allocating colormap\n"); + "ImageControl::ImageControl: error allocating colormap\n"); exit(1); } @@ -262,7 +258,7 @@ BImageControl::BImageControl(OBTimerQueueManager *timermanager, colors[i].blue = (i * 0xffff) / (colors_per_channel - 1);; colors[i].flags = DoRed|DoGreen|DoBlue; - if (! XAllocColor(OBDisplay::display, colormap, + if (! XAllocColor(**display, colormap, &colors[i])) { fprintf(stderr, "couldn't alloc color %i %i %i\n", colors[i].red, colors[i].green, colors[i].blue); @@ -279,7 +275,7 @@ BImageControl::BImageControl(OBTimerQueueManager *timermanager, for (i = 0; i < incolors; i++) icolors[i].pixel = i; - XQueryColors(OBDisplay::display, colormap, icolors, incolors); + XQueryColors(**display, colormap, icolors, incolors); for (i = 0; i < ncolors; i++) { if (! colors[i].flags) { unsigned long chk = 0xffffffff, pixel, close = 0; @@ -301,7 +297,7 @@ BImageControl::BImageControl(OBTimerQueueManager *timermanager, colors[i].green = icolors[close].green; colors[i].blue = icolors[close].blue; - if (XAllocColor(OBDisplay::display, colormap, + if (XAllocColor(**display, colormap, &colors[i])) { colors[i].flags = DoRed|DoGreen|DoBlue; break; @@ -315,14 +311,14 @@ BImageControl::BImageControl(OBTimerQueueManager *timermanager, } default: - fprintf(stderr, "BImageControl::BImageControl: unsupported visual %d\n", + fprintf(stderr, "ImageControl::ImageControl: unsupported visual %d\n", getVisual()->c_class); exit(1); } } -BImageControl::~BImageControl(void) { +ImageControl::~ImageControl(void) { delete [] sqrt_table; delete [] grad_xbuffer; @@ -335,32 +331,30 @@ BImageControl::~BImageControl(void) { for (int i = 0; i < ncolors; i++) *(pixels + i) = (*(colors + i)).pixel; - XFreeColors(OBDisplay::display, colormap, pixels, ncolors, 0); + XFreeColors(**display, colormap, pixels, ncolors, 0); delete [] colors; } if (! cache.empty()) { //#ifdef DEBUG - fprintf(stderr, "BImageContol::~BImageControl: pixmap cache - " + fprintf(stderr, "ImageContol::~ImageControl: pixmap cache - " "releasing %d pixmaps\n", cache.size()); //#endif CacheContainer::iterator it = cache.begin(); const CacheContainer::iterator end = cache.end(); for (; it != end; ++it) - XFreePixmap(OBDisplay::display, it->pixmap); + XFreePixmap(**display, it->pixmap); } - if (timer) { - timer->stop(); + if (timer) delete timer; - } } -Pixmap BImageControl::searchCache(const unsigned int width, +Pixmap ImageControl::searchCache(const unsigned int width, const unsigned int height, const unsigned long texture, - const BColor &c1, const BColor &c2) { + const Color &c1, const Color &c2) { if (cache.empty()) return None; @@ -370,7 +364,7 @@ Pixmap BImageControl::searchCache(const unsigned int width, CachedImage& tmp = *it; if (tmp.width == width && tmp.height == height && tmp.texture == texture && tmp.pixel1 == c1.pixel()) - if (texture & BTexture::Gradient) { + if (texture & Texture::Gradient) { if (tmp.pixel2 == c2.pixel()) { tmp.count++; return tmp.pixmap; @@ -384,15 +378,15 @@ Pixmap BImageControl::searchCache(const unsigned int width, } -Pixmap BImageControl::renderImage(unsigned int width, unsigned int height, - const BTexture &texture) { - if (texture.texture() & BTexture::Parent_Relative) return ParentRelative; +Pixmap ImageControl::renderImage(unsigned int width, unsigned int height, + const Texture &texture) { + if (texture.texture() & Texture::Parent_Relative) return ParentRelative; Pixmap pixmap = searchCache(width, height, texture.texture(), texture.color(), texture.colorTo()); if (pixmap) return pixmap; - BImage image(this, width, height); + Image image(this, width, height); pixmap = image.render(texture); if (! pixmap) @@ -407,7 +401,7 @@ Pixmap BImageControl::renderImage(unsigned int width, unsigned int height, tmp.texture = texture.texture(); tmp.pixel1 = texture.color().pixel(); - if (texture.texture() & BTexture::Gradient) + if (texture.texture() & Texture::Gradient) tmp.pixel2 = texture.colorTo().pixel(); else tmp.pixel2 = 0l; @@ -416,7 +410,7 @@ Pixmap BImageControl::renderImage(unsigned int width, unsigned int height, if (cache.size() > cache_max) { #ifdef DEBUG - fprintf(stderr, "BImageControl::renderImage: cache is large, " + fprintf(stderr, "ImageControl::renderImage: cache is large, " "forcing cleanout\n"); #endif // DEBUG @@ -427,7 +421,7 @@ Pixmap BImageControl::renderImage(unsigned int width, unsigned int height, } -void BImageControl::removeImage(Pixmap pixmap) { +void ImageControl::removeImage(Pixmap pixmap) { if (! pixmap) return; @@ -444,7 +438,7 @@ void BImageControl::removeImage(Pixmap pixmap) { } -void BImageControl::getColorTables(unsigned char **rmt, unsigned char **gmt, +void ImageControl::getColorTables(unsigned char **rmt, unsigned char **gmt, unsigned char **bmt, int *roff, int *goff, int *boff, int *rbit, int *gbit, int *bbit) { @@ -462,13 +456,13 @@ void BImageControl::getColorTables(unsigned char **rmt, unsigned char **gmt, } -void BImageControl::getXColorTable(XColor **c, int *n) { +void ImageControl::getXColorTable(XColor **c, int *n) { if (c) *c = colors; if (n) *n = ncolors; } -void BImageControl::getGradientBuffers(unsigned int w, +void ImageControl::getGradientBuffers(unsigned int w, unsigned int h, unsigned int **xbuf, unsigned int **ybuf) @@ -496,10 +490,10 @@ void BImageControl::getGradientBuffers(unsigned int w, } -void BImageControl::installRootColormap(void) { +void ImageControl::installRootColormap(void) { int ncmap = 0; Colormap *cmaps = - XListInstalledColormaps(OBDisplay::display, window, &ncmap); + XListInstalledColormaps(**display, window, &ncmap); if (cmaps) { bool install = True; @@ -508,14 +502,14 @@ void BImageControl::installRootColormap(void) { install = False; if (install) - XInstallColormap(OBDisplay::display, colormap); + XInstallColormap(**display, colormap); XFree(cmaps); } } -void BImageControl::setColorsPerChannel(int cpc) { +void ImageControl::setColorsPerChannel(int cpc) { if (cpc < 2) cpc = 2; if (cpc > 6) cpc = 6; @@ -523,7 +517,7 @@ void BImageControl::setColorsPerChannel(int cpc) { } -unsigned long BImageControl::getSqrt(unsigned int x) { +unsigned long ImageControl::getSqrt(unsigned int x) { if (! sqrt_table) { // build sqrt table for use with elliptic gradient @@ -538,7 +532,7 @@ unsigned long BImageControl::getSqrt(unsigned int x) { struct ZeroRefCheck { - inline bool operator()(const BImageControl::CachedImage &image) const { + inline bool operator()(const ImageControl::CachedImage &image) const { return (image.count == 0); } }; @@ -546,14 +540,14 @@ struct ZeroRefCheck { struct CacheCleaner { ZeroRefCheck ref_check; CacheCleaner() {} - inline void operator()(const BImageControl::CachedImage& image) const { + inline void operator()(const ImageControl::CachedImage& image) const { if (ref_check(image)) - XFreePixmap(OBDisplay::display, image.pixmap); + XFreePixmap(**display, image.pixmap); } }; -void BImageControl::timeout(BImageControl *t) { +void ImageControl::timeout(ImageControl *t) { CacheCleaner cleaner; std::for_each(t->cache.begin(), t->cache.end(), cleaner); t->cache.remove_if(cleaner.ref_check);