]> Dogcows Code - chaz/openbox/blobdiff - src/Image.cc
Fixing the stupid case when an invalid key is given and epist would hog the keyboard
[chaz/openbox] / src / Image.cc
index c20c4f7c981af1c4a1507c57d027edbabafafc5c..2094c00382995ca82f17a66a691bd5c10e0af50b 100644 (file)
@@ -41,11 +41,11 @@ using std::min;
 #include "Texture.hh"
 
 
-BImage::BImage(BImageControl *c, unsigned int w, unsigned int h) {
+BImage::BImage(BImageControl *c, int w, int h) {
   control = c;
 
-  width = ((signed) w > 0) ? w : 1;
-  height = ((signed) h > 0) ? h : 1;
+  width = (w > 0) ? w : 1;
+  height = (h > 0) ? h : 1;
 
   red = new unsigned char[width * height];
   green = new unsigned char[width * height];
@@ -66,18 +66,18 @@ BImage::BImage(BImageControl *c, unsigned int w, unsigned int h) {
 
 
 BImage::~BImage(void) {
-  if (red) delete [] red;
-  if (green) delete [] green;
-  if (blue) delete [] blue;
+  delete [] red;
+  delete [] green;
+  delete [] blue;
 }
 
 
 Pixmap BImage::render(const BTexture &texture) {
-  if ((texture.texture() & BTexture::Parent_Relative))
+  if (texture.texture() & BTexture::Parent_Relative)
     return ParentRelative;
-  else if ((texture.texture() & BTexture::Solid))
+  else if (texture.texture() & BTexture::Solid)
     return render_solid(texture);
-  else if ((texture.texture() & BTexture::Gradient))
+  else if (texture.texture() & BTexture::Gradient)
     return render_gradient(texture);
   return None;
 }
@@ -103,54 +103,61 @@ Pixmap BImage::render_solid(const BTexture &texture) {
 
   if (texture.texture() & BTexture::Interlaced) {
     BPen peninterlace(texture.colorTo());
-    register unsigned int i = 0;
-    for (; i < height; i += 2)
+    for (unsigned int i = 0; i < height; i += 2)
       XDrawLine(display, pixmap, peninterlace.gc(), 0, i, width, i);
   }
 
+  int left = 0, top = 0, right = width - 1, bottom = height - 1;
+
+  if (texture.texture() & BTexture::Border) {
+    BPen penborder(texture.borderColor());
+    XDrawRectangle(display, pixmap, penborder.gc(),
+                   left, top, right, bottom);
+  }
+
   if (texture.texture() & BTexture::Bevel1) {
     if (texture.texture() & BTexture::Raised) {
       XDrawLine(display, pixmap, penshadow.gc(),
-                0, height - 1, width - 1, height - 1);
+                left, bottom, right, bottom);
       XDrawLine(display, pixmap, penshadow.gc(),
-                width - 1, height - 1, width - 1, 0);
+                right, bottom, right, top);
 
       XDrawLine(display, pixmap, penlight.gc(),
-                0, 0, width - 1, 0);
+                left, top, right, top);
       XDrawLine(display, pixmap, penlight.gc(),
-                0, height - 1, 0, 0);
+                left, bottom, left, top);
     } else if (texture.texture() & BTexture::Sunken) {
       XDrawLine(display, pixmap, penlight.gc(),
-                0, height - 1, width - 1, height - 1);
+                left, bottom, right, bottom);
       XDrawLine(display, pixmap, penlight.gc(),
-                width - 1, height - 1, width - 1, 0);
+                right, bottom, right, top);
 
       XDrawLine(display, pixmap, penshadow.gc(),
-                0, 0, width - 1, 0);
+                left, top, right, top);
       XDrawLine(display, pixmap, penshadow.gc(),
-                0, height - 1, 0, 0);
+                left, bottom, left, top);
     }
   } else if (texture.texture() & BTexture::Bevel2) {
     if (texture.texture() & BTexture::Raised) {
       XDrawLine(display, pixmap, penshadow.gc(),
-                1, height - 3, width - 3, height - 3);
+                left + 1, bottom - 2, right - 2, bottom - 2);
       XDrawLine(display, pixmap, penshadow.gc(),
-                width - 3, height - 3, width - 3, 1);
+                right - 2, bottom - 2, right - 2, top + 1);
 
       XDrawLine(display, pixmap, penlight.gc(),
-                1, 1, width - 3, 1);
+                left + 1, top + 1, right - 2, top + 1);
       XDrawLine(display, pixmap, penlight.gc(),
-                1, height - 3, 1, 1);
+                left + 1, bottom - 2, left + 1, top + 1);
     } else if (texture.texture() & BTexture::Sunken) {
       XDrawLine(display, pixmap, penlight.gc(),
-                1, height - 3, width - 3, height - 3);
+                left + 1, bottom - 2, right - 2, bottom - 2);
       XDrawLine(display, pixmap, penlight.gc(),
-                width - 3, height - 3, width - 3, 1);
+                right - 2, bottom - 2, right - 2, top + 1);
 
       XDrawLine(display, pixmap, penshadow.gc(),
-                1, 1, width - 3, 1);
+                left + 1, top + 1, right - 2, top + 1);
       XDrawLine(display, pixmap, penshadow.gc(),
-                1, height - 3, 1, 1);
+                left + 1, bottom - 2, left + 1, top + 1);
     }
   }
 
@@ -159,7 +166,7 @@ Pixmap BImage::render_solid(const BTexture &texture) {
 
 
 Pixmap BImage::render_gradient(const BTexture &texture) {
int inverted = 0;
 bool inverted = False;
 
   interlaced = texture.texture() & BTexture::Interlaced;
 
@@ -167,12 +174,12 @@ Pixmap BImage::render_gradient(const BTexture &texture) {
     from = texture.colorTo();
     to = texture.color();
 
-    if (! (texture.texture() & BTexture::Invert)) inverted = 1;
+    if (! (texture.texture() & BTexture::Invert)) inverted = True;
   } else {
     from = texture.color();
     to = texture.colorTo();
 
-    if (texture.texture() & BTexture::Invert) inverted = 1;
+    if (texture.texture() & BTexture::Invert) inverted = True;
   }
 
   control->getGradientBuffers(width, height, &xtable, &ytable);
@@ -189,11 +196,11 @@ Pixmap BImage::render_gradient(const BTexture &texture) {
   if (texture.texture() & BTexture::Bevel1) bevel1();
   else if (texture.texture() & BTexture::Bevel2) bevel2();
 
-  if (inverted) invert();
+  if (texture.texture() & BTexture::Border) border(texture);
 
-  Pixmap pixmap = renderPixmap();
+  if (inverted) invert();
 
-  return pixmap;
+  return renderPixmap();
 
 }
 
@@ -461,6 +468,8 @@ XImage *BImage::renderXImage(void) {
   unsigned int o = image->bits_per_pixel +
     ((image->byte_order == MSBFirst) ? 1 : 0);
 
+  bool unsupported = False;
+
   if (control->doDither() && width > 1 && height > 1) {
     switch (control->getVisual()->c_class) {
     case TrueColor:
@@ -478,23 +487,18 @@ XImage *BImage::renderXImage(void) {
     }
 
     default:
-      fprintf(stderr, i18n(ImageSet, ImageUnsupVisual,
-                           "BImage::renderXImage: unsupported visual\n"));
-      delete [] d;
-      XDestroyImage(image);
-      return (XImage *) 0;
+      unsupported = True;
     }
   } else {
-    register unsigned int x, y, r, g, b, offset;
-
+    unsigned int x, y, r, g, b, offset;
     unsigned char *pixel_data = d, *ppixel_data = d;
     unsigned long pixel;
 
     switch (control->getVisual()->c_class) {
     case StaticColor:
     case PseudoColor:
-      for (y = 0, offset = 0; y < height; y++) {
-        for (x = 0; x < width; x++, offset++) {
+      for (y = 0, offset = 0; y < height; ++y) {
+        for (x = 0; x < width; ++x, ++offset) {
          r = red_table[red[offset]];
           g = green_table[green[offset]];
          b = blue_table[blue[offset]];
@@ -542,15 +546,20 @@ XImage *BImage::renderXImage(void) {
       break;
 
     default:
-      fprintf(stderr, i18n(ImageSet, ImageUnsupVisual,
-                           "BImage::renderXImage: unsupported visual\n"));
-      delete [] d;
-      XDestroyImage(image);
-      return (XImage *) 0;
+      unsupported = True;
     }
   }
 
+  if (unsupported) {
+    fprintf(stderr, i18n(ImageSet, ImageUnsupVisual,
+                         "BImage::renderXImage: unsupported visual\n"));
+    delete [] d;
+    XDestroyImage(image);
+    return (XImage *) 0;
+  }
+
   image->data = (char *) d;
+
   return image;
 }
 
@@ -571,7 +580,9 @@ Pixmap BImage::renderPixmap(void) {
   if (! image) {
     XFreePixmap(control->getBaseDisplay()->getXDisplay(), pixmap);
     return None;
-  } else if (! image->data) {
+  }
+
+  if (! image->data) {
     XDestroyImage(image);
     XFreePixmap(control->getBaseDisplay()->getXDisplay(), pixmap);
     return None;
@@ -810,6 +821,50 @@ void BImage::bevel2(void) {
 }
 
 
+void BImage::border(const BTexture &texture) {
+  if (width < 2 || height < 2) return;
+  
+  register unsigned int i;
+  int r = texture.borderColor().red(),
+    g = texture.borderColor().green(),
+    b = texture.borderColor().blue();
+
+  unsigned char *pr, *pg, *pb;
+
+  // top line
+  pr = red;
+  pg = green;
+  pb = blue;
+  for (i = 0; i < width; ++i) {
+    *pr++ = r;
+    *pg++ = g;
+    *pb++ = b;
+  }
+
+  if (height > 2) {
+    // left and right lines (pr,pg,pb are already lined up)
+    for (i = 1; i < height - 1; ++i) {
+      *pr = r;
+      *pg = g;
+      *pb = b;
+      pr += width - 1;
+      pg += width - 1;
+      pb += width - 1;
+      *pr++ = r;
+      *pg++ = g;
+      *pb++ = b;
+    }
+  }
+
+  // bottom line (pr,pg,pb are already lined up)
+  for (i = 0; i < width; ++i) {
+    *pr++ = r;
+    *pg++ = g;
+    *pb++ = b;
+  }
+}
+
+
 void BImage::invert(void) {
   register unsigned int i, j, wh = (width * height) - 1;
   unsigned char tmp;
This page took 0.0326149999999999 seconds and 4 git commands to generate.