]> Dogcows Code - chaz/openbox/blob - otk/surface.cc
signed ints instead of unsigned ints again. less pain. pain bad.
[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 Size &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.width(), _size.height());
38 }
39
40 void Surface::setPixmap(XImage *image)
41 {
42 assert(image->width == _size.width());
43 assert(image->height == _size.height());
44
45 if (_pixmap == None)
46 createObjects();
47
48 XPutImage(**display, _pixmap, DefaultGC(**display, _screen),
49 image, 0, 0, 0, 0, _size.width(), _size.height());
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.width(), _size.height(), info->depth());
60 assert(_pixmap != None);
61
62 _xftdraw = XftDrawCreate(**display, _pixmap,
63 info->visual(), info->colormap());
64 assert(_xftdraw);
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 }
This page took 0.041221 seconds and 5 git commands to generate.