]> Dogcows Code - chaz/openbox/blobdiff - otk/imagecontrol.cc
provide the strut for the frame's size instead of an area rect
[chaz/openbox] / otk / imagecontrol.cc
index 062c959d7dea9b86529b2f7fa6eb65d1ad5a23fb..ab8f5c50ca2bd03caf250d5f1ebcf67227351333 100644 (file)
@@ -1,4 +1,4 @@
-// -*- mode: C++; indent-tabs-mode: nil; -*-
+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
 
 #ifdef    HAVE_CONFIG_H
 #  include "../config.h"
@@ -39,12 +39,12 @@ static unsigned long bsqrt(unsigned long x) {
   }
 }
 
-BImageControl *ctrl = 0;
+ImageControl *ctrl = 0;
 
-BImageControl::BImageControl(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;
@@ -52,14 +52,10 @@ BImageControl::BImageControl(const ScreenInfo *scrn,
   setColorsPerChannel(_cpc);
 
   cache_max = cmax;
-  if (cache_timeout) {
-    // XXX: FIX THIS
-    timer = 0;/*new BTimer(this);
-    timer->setTimeout(cache_timeout);
-    timer->start();*/
-  } else {
-    timer = (ob::BTimer *) 0;
-  }
+  if (cache_timeout)
+    timer = new Timer(cache_timeout, (Timer::TimeoutHandler)timeout, this);
+  else
+    timer = (Timer *) 0;
 
   colors = (XColor *) 0;
   ncolors = 0;
@@ -69,13 +65,13 @@ BImageControl::BImageControl(const ScreenInfo *scrn,
 
   sqrt_table = (unsigned long *) 0;
 
-  screen_depth = screeninfo->getDepth();
-  window = screeninfo->getRootWindow();
-  screen_number = screeninfo->getScreenNumber();
-  colormap = screeninfo->getColormap();
+  screen_depth = screeninfo->depth();
+  window = screeninfo->rootWindow();
+  screen_number = screeninfo->screen();
+  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(const ScreenInfo *scrn,
 
     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(const ScreenInfo *scrn,
 
     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(const ScreenInfo *scrn,
        }
 
     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(const ScreenInfo *scrn,
     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(const ScreenInfo *scrn,
            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(const ScreenInfo *scrn,
 
     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(const ScreenInfo *scrn,
     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(const ScreenInfo *scrn,
       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(const ScreenInfo *scrn,
     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(const ScreenInfo *scrn,
            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(const ScreenInfo *scrn,
   }
 
   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,18 +410,18 @@ 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
 
-    timeout();
+    timeout(this);
   }
 
   return pixmap;
 }
 
 
-void BImageControl::removeImage(Pixmap pixmap) {
+void ImageControl::removeImage(Pixmap pixmap) {
   if (! pixmap)
     return;
 
@@ -440,11 +434,11 @@ void BImageControl::removeImage(Pixmap pixmap) {
   }
 
   if (! timer)
-    timeout();
+    timeout(this);
 }
 
 
-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,17 +540,17 @@ 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(void) {
+void ImageControl::timeout(ImageControl *t) {
   CacheCleaner cleaner;
-  std::for_each(cache.begin(), cache.end(), cleaner);
-  cache.remove_if(cleaner.ref_check);
+  std::for_each(t->cache.begin(), t->cache.end(), cleaner);
+  t->cache.remove_if(cleaner.ref_check);
 }
 
 }
This page took 0.035161 seconds and 4 git commands to generate.