X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=otk%2Ftruerendercontrol.cc;h=05a1d676775d6ef03dbf5723c0ae6245dcb37463;hb=46441f7d60c008b11a170516734ae7a5932a738e;hp=a1995c4ce7032d76e367c550ff3b53b2bdafba93;hpb=a4dd208a7955e25bca710d4bcf355de7e608b9e1;p=chaz%2Fopenbox diff --git a/otk/truerendercontrol.cc b/otk/truerendercontrol.cc index a1995c4c..05a1d676 100644 --- a/otk/truerendercontrol.cc +++ b/otk/truerendercontrol.cc @@ -8,6 +8,7 @@ #include "display.hh" #include "screeninfo.hh" #include "surface.hh" +#include "rendertexture.hh" extern "C" { #ifdef HAVE_STDLIB_H @@ -20,7 +21,7 @@ extern "C" { namespace otk { -TrueRenderControl::TrueRenderControl(const ScreenInfo *screen) +TrueRenderControl::TrueRenderControl(int screen) : RenderControl(screen), _red_offset(0), _green_offset(0), @@ -28,12 +29,13 @@ TrueRenderControl::TrueRenderControl(const ScreenInfo *screen) { printf("Initializing TrueColor RenderControl\n"); + Visual *visual = display->screenInfo(_screen)->visual(); unsigned long red_mask, green_mask, blue_mask; // find the offsets for each color in the visual's masks - red_mask = screen->visual()->red_mask; - green_mask = screen->visual()->green_mask; - blue_mask = screen->visual()->blue_mask; + red_mask = visual->red_mask; + green_mask = visual->green_mask; + blue_mask = visual->blue_mask; while (! (red_mask & 1)) { _red_offset++; red_mask >>= 1; } while (! (green_mask & 1)) { _green_offset++; green_mask >>= 1; } @@ -52,6 +54,7 @@ TrueRenderControl::~TrueRenderControl() } + static inline void renderPixel(XImage *im, unsigned char *dp, unsigned long pixel) { @@ -96,40 +99,61 @@ static inline void renderPixel(XImage *im, unsigned char *dp, } } -void TrueRenderControl::drawBackground(Surface *sf, - const RenderTexture &texture) const +void TrueRenderControl::drawGradientBackground( + Surface &sf, const RenderTexture &texture) const { - assert(sf); - - int w = sf->width(), h = sf->height(); + int w = sf.width(), h = sf.height(); - XImage *im = XCreateImage(**display, _screen->visual(), _screen->depth(), - ZPixmap, 0, NULL, w, h, 32, 0); - - unsigned char *data = new unsigned char[im->bytes_per_line * h]; - unsigned char *dp = data; + const ScreenInfo *info = display->screenInfo(_screen); + XImage *im = XCreateImage(**display, info->visual(), info->depth(), + ZPixmap, 0, NULL, w, h, 32, 0); + + pixel32 *data = new pixel32[sf.height()*sf.width()]; + pixel32 current; + pixel32 *dp = data; + float dr, dg, db; + unsigned int r,g,b; + + dr = (float)(texture.secondary_color().red() - texture.color().red()); + dr/= (float)sf.height(); + + dg = (float)(texture.secondary_color().green() - texture.color().green()); + dg/= (float)sf.height(); + + db = (float)(texture.secondary_color().blue() - texture.color().blue()); + db/= (float)sf.height(); + + for (int y = 0; y < h; ++y) { + r = texture.color().red() + (int)(dr * y); + g = texture.color().green() + (int)(dg * y); + b = texture.color().blue() + (int)(db * y); + current = (r << 16) + + (g << 8) + + b; + for (int x = 0; x < w; ++x, dp ++) + *dp = current; + } + + im->data = (char*) data; + + sf.setPixmap(im); + + delete [] im->data; + im->data = NULL; + XDestroyImage(im); +} - for (int y = 0; y < h/3; ++y) - for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8) - renderPixel(im, dp, (255*x/w) << _red_offset << _red_shift); - for (int y = 0; y < h/3; ++y) - for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8) - renderPixel(im, dp, (255*x/w) << _green_offset << _green_shift); - for (int y = 0; y < h/3; ++y) - for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8) - renderPixel(im, dp, (255*x/w) << _blue_offset << _blue_shift); +void TrueRenderControl::drawBackground(Surface& sf, + const RenderTexture &texture) const +{ + assert(_screen == sf._screen); + assert(_screen == texture.color().screen()); - im->data = (char*) data; - - if (!sf->_pm) - sf->_pm = XCreatePixmap(**display, _screen->rootWindow(), w, h, - _screen->depth()); - XPutImage(**display, sf->_pm, DefaultGC(**display, _screen->screen()), - im, 0, 0, 0, 0, w, h); - - //delete [] image->data; - //image->data = NULL; - XDestroyImage(im); + if (texture.gradient() == RenderTexture::Solid) { + drawSolidBackground(sf, texture); + } else { + drawGradientBackground(sf, texture); + } } }