X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=otk%2Fsurface.cc;h=9dfb88898043faaac22541e4060c4bbb03e63649;hb=dddac554808d7352a06733938cfddc19839b99d0;hp=af9da7a6eac492a6b7c2fce3b7bd58bd48c9a75e;hpb=0ba441fe8f379ec506000f7fa29f867cb6bc0d51;p=chaz%2Fopenbox diff --git a/otk/surface.cc b/otk/surface.cc index af9da7a6..9dfb8889 100644 --- a/otk/surface.cc +++ b/otk/surface.cc @@ -7,6 +7,7 @@ #include "surface.hh" #include "display.hh" #include "screeninfo.hh" +#include "rendercolor.hh" extern "C" { #include @@ -14,22 +15,12 @@ extern "C" { namespace otk { -Surface::Surface(int screen) - : _screen(screen), - _size(1, 1), - _pm(None), - _xftdraw(0) -{ - createObjects(); -} - Surface::Surface(int screen, const Point &size) : _screen(screen), _size(size), - _pm(None), + _pixmap(None), _xftdraw(0) { - createObjects(); } Surface::~Surface() @@ -37,36 +28,53 @@ Surface::~Surface() destroyObjects(); } -void Surface::createObjects() +void Surface::setPixmap(const RenderColor &color) { - assert(_pm == None); assert(!_xftdraw); + if (_pixmap == None) + createObjects(); - const ScreenInfo *info = display->screenInfo(_screen); + XFillRectangle(**display, _pixmap, color.gc(), 0, 0, + _size.x(), _size.y()); +} + +void Surface::setPixmap(XImage *image) +{ + assert(image->width == _size.x()); + assert(image->height == _size.y()); - _pm = XCreatePixmap(**display, info->rootWindow(), _size.x(), _size.y(), - info->depth()); + if (_pixmap == None) + createObjects(); - _xftdraw = XftDrawCreate(**display, _pm, info->visual(), info->colormap()); + XPutImage(**display, _pixmap, DefaultGC(**display, _screen), + image, 0, 0, 0, 0, _size.x(), _size.y()); } -void Surface::destroyObjects() +void Surface::createObjects() { - assert(_pm != None); assert(_xftdraw); - - XftDrawDestroy(_xftdraw); - _xftdraw = 0; + assert(_pixmap == None); assert(!_xftdraw); - XFreePixmap(**display, _pm); - _pm = None; + const ScreenInfo *info = display->screenInfo(_screen); + + _pixmap = XCreatePixmap(**display, info->rootWindow(), + _size.x(), _size.y(), info->depth()); + assert(_pixmap != None); + + _xftdraw = XftDrawCreate(**display, _pixmap, + info->visual(), info->colormap()); + assert(_xftdraw); } -void Surface::setSize(int w, int h) +void Surface::destroyObjects() { - if (w == _size.x() && h == _size.y()) return; // no change - - _size.setPoint(w, h); - destroyObjects(); - createObjects(); + if (_xftdraw) { + XftDrawDestroy(_xftdraw); + _xftdraw = 0; + } + + if (_pixmap != None) { + XFreePixmap(**display, _pixmap); + _pixmap = None; + } } }