]> Dogcows Code - chaz/openbox/blob - otk/surface.cc
doc the state functions better
[chaz/openbox] / 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 "rendercolor.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 RenderColor &color)
32 {
33 if (_pixmap == None)
34 createObjects();
35
36 XFillRectangle(**display, _pixmap, color.gc(), 0, 0,
37 _size.x(), _size.y());
38 }
39
40 void Surface::setPixmap(XImage *image)
41 {
42 assert(image->width == _size.x());
43 assert(image->height == _size.y());
44
45 if (_pixmap == None)
46 createObjects();
47
48 XPutImage(**display, _pixmap, DefaultGC(**display, _screen),
49 image, 0, 0, 0, 0, _size.x(), _size.y());
50 }
51
52 void Surface::createObjects()
53 {
54 assert(_pixmap == None); assert(!_xftdraw);
55
56 const ScreenInfo *info = display->screenInfo(_screen);
57
58 _pixmap = XCreatePixmap(**display, info->rootWindow(),
59 _size.x(), _size.y(), info->depth());
60
61 _xftdraw = XftDrawCreate(**display, _pixmap,
62 info->visual(), info->colormap());
63 }
64
65 void Surface::destroyObjects()
66 {
67 if (_xftdraw) {
68 XftDrawDestroy(_xftdraw);
69 _xftdraw = 0;
70 }
71
72 if (_pixmap != None) {
73 XFreePixmap(**display, _pixmap);
74 _pixmap = None;
75 }
76 }
77
78 }
This page took 0.038264 seconds and 4 git commands to generate.