Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

/otk/surface.cc

Go to the documentation of this file.
00001 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
00002 
00003 #ifdef    HAVE_CONFIG_H
00004 #  include "../config.h"
00005 #endif // HAVE_CONFIG_H
00006 
00007 #include "surface.hh"
00008 #include "display.hh"
00009 #include "screeninfo.hh"
00010 #include "rendercolor.hh"
00011 
00012 extern "C" {
00013 #include <X11/Xutil.h>
00014 }
00015 
00016 namespace otk {
00017 
00018 Surface::Surface(int screen, const Point &size)
00019   : _screen(screen),
00020     _size(size),
00021     _pixmap(None),
00022     _xftdraw(0)
00023 {
00024 }
00025 
00026 Surface::~Surface()
00027 {
00028   destroyObjects();
00029 }
00030 
00031 void Surface::setPixmap(const RenderColor &color)
00032 {
00033   if (_pixmap == None)
00034     createObjects();
00035 
00036   XFillRectangle(**display, _pixmap, color.gc(), 0, 0,
00037                  _size.x(), _size.y());
00038 }
00039 
00040 void Surface::setPixmap(XImage *image)
00041 {
00042   assert(image->width == _size.x());
00043   assert(image->height == _size.y());
00044   
00045   if (_pixmap == None)
00046     createObjects();
00047 
00048   XPutImage(**display, _pixmap, DefaultGC(**display, _screen),
00049             image, 0, 0, 0, 0, _size.x(), _size.y());
00050 }
00051 
00052 void Surface::createObjects()
00053 {
00054   assert(_pixmap == None); assert(!_xftdraw);
00055 
00056   const ScreenInfo *info = display->screenInfo(_screen);
00057   
00058   _pixmap = XCreatePixmap(**display, info->rootWindow(),
00059                           _size.x(), _size.y(), info->depth());
00060   assert(_pixmap != None);
00061     
00062   _xftdraw = XftDrawCreate(**display, _pixmap,
00063                            info->visual(), info->colormap());
00064   assert(_xftdraw);
00065 }
00066 
00067 void Surface::destroyObjects()
00068 {
00069   if (_xftdraw) {
00070     XftDrawDestroy(_xftdraw);
00071     _xftdraw = 0;
00072   }
00073 
00074   if (_pixmap != None) {
00075     XFreePixmap(**display, _pixmap);
00076     _pixmap = None;
00077   }
00078 }
00079 
00080 }

Generated on Tue Feb 4 22:58:56 2003 for Openbox by doxygen1.3-rc2