]> Dogcows Code - chaz/openbox/commitdiff
start on the rendering images code
authorDana Jansens <danakj@orodu.net>
Tue, 11 Feb 2003 23:58:33 +0000 (23:58 +0000)
committerDana Jansens <danakj@orodu.net>
Tue, 11 Feb 2003 23:58:33 +0000 (23:58 +0000)
otk/pseudorendercontrol.cc
otk/pseudorendercontrol.hh
otk/rendercontrol.cc
otk/rendercontrol.hh
otk/surface.cc
otk/truerendercontrol.cc
otk/truerendercontrol.hh

index e239a4f040172a996d8b9b775de69e0fb72118fc..1d55ee6473e64532223ea31c7a280702e1b5f1d8 100644 (file)
@@ -41,4 +41,9 @@ void PseudoRenderControl::drawBackground(Surface& sf,
   drawSolidBackground(sf, texture);
 }
 
+void PseudoRenderControl::drawImage(Surface &sf, int w, int h,
+                                    unsigned long *data) const
+{
+}
+
 }
index a1a12a811c56d0078e703946bb54e9e136a11e04..d834d5d773913e8632811a625e06ecec58a018ad 100644 (file)
@@ -28,6 +28,8 @@ public:
   virtual ~PseudoRenderControl();
 
   virtual void drawBackground(Surface& sf, const RenderTexture &texture) const;
+  virtual void drawImage(Surface &sf, int w, int h,
+                         unsigned long *data) const;
 };
 
 }
index ef02230ea3b8a4d976c4d2bf7e0af3f64b1bfcbc..edf4a470d5bff80f17d04f1b17ec7a2ffe4ce1a1 100644 (file)
@@ -214,9 +214,4 @@ void RenderControl::drawMask(Surface &sf, const RenderColor &color,
   XSetClipOrigin(**display, color.gc(), 0, 0);
 }
 
-void RenderControl::drawImage(Surface &sf, int w, int h,
-                              unsigned long *data) const
-{
-}
-
 }
index 49395c58fffb88231e3e9bfaad106f65d0b3de2f..253e6530670701d36040e7578c25638e8ae2a827 100644 (file)
@@ -88,7 +88,8 @@ public:
     The image must be specified in 32-bit packed ARGB format. The current
     background will be used for applying the alpha.
   */
-  virtual void drawImage(Surface &sf, int w, int h, unsigned long *data) const;
+  virtual void drawImage(Surface &sf, int w, int h,
+                         unsigned long *data) const = 0;
   
   //! Draws a string onto a Surface
   virtual void drawString(Surface &sf, const Font &font, int x, int y,
index 9fff018c3a67d79060d70ae269b6ec6b65cfd8f4..b7aadd0ff5f004a94d6d519e3a96f5bfc2c74a72 100644 (file)
@@ -46,14 +46,11 @@ void Surface::setPixmap(const RenderColor &color)
   XFillRectangle(**display, _pixmap, color.gc(), 0, 0,
                  _size.width(), _size.height());
 
-  pixel32 val = 0; // XXX set this from the color and shift amounts!
-  for (unsigned int i = 0, s = _size.width() * _size.height(); i < s; ++i) {
-    unsigned char *p = (unsigned char*)&_pixel_data[i];
-    *p = (unsigned char) (val >> 24);
-    *++p = (unsigned char) (val >> 16);
-    *++p = (unsigned char) (val >> 8);
-    *++p = (unsigned char) val;
-  }
+  pixel32 val = (color.red() << default_red_shift) &
+    (color.green() << default_green_shift) &
+    (color.blue() << default_blue_shift);
+  for (unsigned int i = 0, s = _size.width() * _size.height(); i < s; ++i)
+    _pixel_data[i] = val;
 }
 
 void Surface::setPixmap(XImage *image)
index 0b0e5a0b0e718fca0adea37e5ccdf3b6ccf5744c..62265d965609247c2dd7014bb1485971b11da508 100644 (file)
@@ -320,4 +320,62 @@ void TrueRenderControl::drawBackground(Surface& sf,
     drawGradientBackground(sf, texture);
 }
 
+
+void TrueRenderControl::drawImage(Surface &sf, int w, int h,
+                                  unsigned long *data) const
+{
+  pixel32 *bg = sf.pixelData();
+  int startx, x, y, c;
+  unsigned int i, e;
+  x = (sf.size().width() - w) / 2;
+  y = (sf.size().height() - h) / 2;
+
+  if (x < 0) x = 0;
+  if (y < 0) y = 0;
+
+  // XX SCALING!@!&*(@! to make it fit on the surface
+
+  startx = x;
+  
+  for (i = 0, c = 0, e = w*h; i < e; ++i) {
+    unsigned char alpha = data[i] >> 24;
+    unsigned char r = data[i];
+    unsigned char g = data[i] >> 8;
+    unsigned char b = data[i] >> 16;
+
+    // background color
+    unsigned char bgr = bg[i] >> default_red_shift;
+    unsigned char bgg = bg[i] >> default_green_shift;
+    unsigned char bgb = bg[i] >> default_blue_shift;
+      
+    r = bgr + (r - bgr) * alpha >> 8;
+    g = bgg + (g - bgg) * alpha >> 8;
+    b = bgb + (b - bgb) * alpha >> 8;
+
+    bg[i] = (r << default_red_shift) & (g << default_green_shift) &
+      (b << default_blue_shift);
+
+    if (++c >= w) {
+      ++y;
+      x = startx;
+      c = 0;
+    }
+  }
+
+  const ScreenInfo *info = display->screenInfo(_screen);
+  XImage *im = XCreateImage(**display, info->visual(), info->depth(),
+                            ZPixmap, 0, NULL, sf.size().width(),
+                            sf.size().height(), 32, 0);
+  im->byte_order = endian;
+
+  reduceDepth(sf, im);
+
+  im->data = (char*) bg;
+
+  sf.setPixmap(im);
+
+  im->data = NULL;
+  XDestroyImage(im);
+}
+
 }
index a1bc47dcc2e8c467d0113da2e6f9780a5f5f106b..71b94e62c0da9f38c031ad5cbdebca117e07dab2 100644 (file)
@@ -34,6 +34,9 @@ public:
   virtual ~TrueRenderControl();
 
   virtual void drawBackground(Surface& sf, const RenderTexture &texture) const;
+
+  virtual void drawImage(Surface &sf, int w, int h,
+                         unsigned long *data) const;
 };
 
 }
This page took 0.028096 seconds and 4 git commands to generate.