]> icculus.org git repositories - dana/openbox.git/blob - otk/surface.cc
new authors. this is how we dooo iiiit...
[dana/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
11 extern "C" {
12 #include <X11/Xutil.h>
13 }
14
15 namespace otk {
16
17 Surface::Surface(int screen)
18   : _screen(screen),
19     _size(1, 1),
20     _im(0),
21     _pm(None),
22     _xftdraw(0)
23 {
24   createObjects();
25 }
26
27 Surface::Surface(int screen, const Point &size)
28   : _screen(screen),
29     _size(size),
30     _im(0),
31     _pm(None),
32     _xftdraw(0)
33 {
34   createObjects();
35 }
36
37 Surface::~Surface()
38 {
39   destroyObjects();
40 }
41
42 void Surface::createObjects()
43 {
44   assert(!_im); assert(_pm == None); assert(!_xftdraw);
45
46   const ScreenInfo *info = display->screenInfo(_screen);
47   
48   _im = XCreateImage(**display, info->visual(), info->depth(),
49                      ZPixmap, 0, NULL, _size.x(), _size.y(), 32, 0);
50
51   _pm = XCreatePixmap(**display, info->rootWindow(), _size.x(), _size.y(),
52                       info->depth());
53
54   _xftdraw = XftDrawCreate(**display, _pm, info->visual(), info->colormap());
55 }
56
57 void Surface::destroyObjects()
58 {
59   assert(_im); assert(_pm != None); assert(_xftdraw);
60
61   XftDrawDestroy(_xftdraw);
62   _xftdraw = 0;
63
64   XFreePixmap(**display, _pm);
65   _pm = None;
66
67   // do the delete ourselves cuz we alloc it with new not malloc
68   delete [] _im->data;
69   _im->data = NULL;
70   XDestroyImage(_im);
71   _im = 0;
72 }
73
74 void Surface::setSize(int w, int h)
75 {
76   if (w == _size.x() && h == _size.y()) return; // no change
77   
78   _size.setPoint(w, h);
79   destroyObjects();
80   createObjects();
81 }
82
83 }