]> icculus.org git repositories - mikachu/openbox.git/blob - otk/surface.cc
widegt using new render system
[mikachu/openbox.git] / otk / surface.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #ifdef    HAVE_CONFIG_H
4 #  include "../config.h"
5 #endif // HAVE_CONFIG_H
6
7 #include "surface.hh"
8 #include "display.hh"
9 #include "screeninfo.hh"
10 #include "gccache.hh"
11
12 extern "C" {
13 #include <X11/Xutil.h>
14 }
15
16 namespace otk {
17
18 Surface::Surface(int screen, const Point &size)
19   : _screen(screen),
20     _size(size),
21     _pixmap(None),
22     _xftdraw(0)
23 {
24 }
25
26 Surface::~Surface()
27 {
28   destroyObjects();
29 }
30
31 void Surface::setPixmap(const Color &color)
32 {
33   if (_pixmap == None)
34     createObjects();
35
36   Pen p(color);
37   XFillRectangle(**display, _pixmap, p.gc(), 0, 0,
38                  _size.x(), _size.y());
39 }
40
41 void Surface::setPixmap(XImage *image)
42 {
43   printf("SET PIXMAP\n");
44   assert(image->width == _size.x());
45   assert(image->height == _size.y());
46   
47   if (_pixmap == None)
48     createObjects();
49
50   XPutImage(**display, _pixmap, DefaultGC(**display, _screen),
51             image, 0, 0, 0, 0, _size.x(), _size.y());
52 }
53
54 void Surface::createObjects()
55 {
56   assert(_pixmap == None); assert(!_xftdraw);
57
58   const ScreenInfo *info = display->screenInfo(_screen);
59   
60   _pixmap = XCreatePixmap(**display, info->rootWindow(),
61                           _size.x(), _size.y(), info->depth());
62     
63   _xftdraw = XftDrawCreate(**display, _pixmap,
64                            info->visual(), info->colormap());
65 }
66
67 void Surface::destroyObjects()
68 {
69   if (_xftdraw) {
70     XftDrawDestroy(_xftdraw);
71     _xftdraw = 0;
72   }
73
74   if (_pixmap != None) {
75     XFreePixmap(**display, _pixmap);
76     _pixmap = None;
77   }
78 }
79
80 }