]> icculus.org git repositories - dana/openbox.git/blob - otk/rendercontrol.cc
udpate to new api
[dana/openbox.git] / otk / rendercontrol.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 "rendercontrol.hh"
8 #include "truerendercontrol.hh"
9 #include "pseudorendercontrol.hh"
10 #include "rendertexture.hh"
11 #include "rendercolor.hh"
12 #include "renderstyle.hh"
13 #include "display.hh"
14 #include "screeninfo.hh"
15 #include "surface.hh"
16 #include "font.hh"
17 #include "ustring.hh"
18
19 extern "C" {
20 #ifdef    HAVE_STDLIB_H
21 #  include <stdlib.h>
22 #endif // HAVE_STDLIB_H
23
24 #include "../src/gettext.h"
25 #define _(str) gettext(str)
26 }
27
28 namespace otk {
29
30 RenderControl *RenderControl::getRenderControl(int screen)
31 {
32   // get the visual on the screen and return the correct type of RenderControl
33   int vclass = display->screenInfo(screen)->visual()->c_class;
34   switch (vclass) {
35   case TrueColor:
36     return new TrueRenderControl(screen);
37   case PseudoColor:
38   case StaticColor:
39     return new PseudoRenderControl(screen);
40   case GrayScale:
41   case StaticGray:
42     return new PseudoRenderControl(screen);
43   default:
44     printf(_("RenderControl: Unsupported visual %d specified. Aborting.\n"),
45            vclass);
46     ::exit(1);
47   }
48 }
49
50 RenderControl::RenderControl(int screen)
51   : _screen(screen)
52 {
53   printf("Initializing RenderControl\n");
54 }
55
56 RenderControl::~RenderControl()
57 {
58   printf("Destroying RenderControl\n");
59 }
60
61 void RenderControl::drawRoot(const RenderColor &color) const
62 {
63   Window root = display->screenInfo(_screen)->rootWindow();
64   XSetWindowBackground(**display, root, color.pixel());
65   XClearWindow(**display, root);
66 }
67
68 void RenderControl::drawString(Surface& sf, const Font &font, int x, int y,
69                                const RenderColor &color,
70                                const ustring &string) const
71 {
72   assert(sf._screen == _screen);
73   XftDraw *d = sf._xftdraw;
74   assert(d); // this means that the background hasn't been rendered yet!
75   
76   if (font._shadow) {
77     XftColor c;
78     c.color.red = 0;
79     c.color.green = 0;
80     c.color.blue = 0;
81     c.color.alpha = font._tint | font._tint << 8; // transparent shadow
82     c.pixel = BlackPixel(**display, _screen);
83
84     if (string.utf8())
85       XftDrawStringUtf8(d, &c, font._xftfont, x + font._offset,
86                         font._xftfont->ascent + y + font._offset,
87                         (FcChar8*)string.c_str(), string.bytes());
88     else
89       XftDrawString8(d, &c, font._xftfont, x + font._offset,
90                      font._xftfont->ascent + y + font._offset,
91                      (FcChar8*)string.c_str(), string.bytes());
92   }
93     
94   XftColor c;
95   c.color.red = color.red() | color.red() << 8;
96   c.color.green = color.green() | color.green() << 8;
97   c.color.blue = color.blue() | color.blue() << 8;
98   c.pixel = color.pixel();
99   c.color.alpha = 0xff | 0xff << 8; // no transparency in Color yet
100
101   if (string.utf8())
102     XftDrawStringUtf8(d, &c, font._xftfont, x, font._xftfont->ascent + y,
103                       (FcChar8*)string.c_str(), string.bytes());
104   else
105     XftDrawString8(d, &c, font._xftfont, x, font._xftfont->ascent + y,
106                    (FcChar8*)string.c_str(), string.bytes());
107   return;
108 }
109
110 void RenderControl::drawSolidBackground(Surface& sf,
111                                         const RenderTexture& texture) const
112 {
113   assert(_screen == sf._screen);
114   assert(_screen == texture.color().screen());
115   
116   if (texture.parentRelative()) return;
117   
118   sf.setPixmap(texture.color());
119
120   int width = sf.size().width(), height = sf.size().height();
121   int left = 0, top = 0, right = width - 1, bottom = height - 1;
122
123   if (texture.interlaced())
124     for (int i = 0; i < height; i += 2)
125       XDrawLine(**display, sf.pixmap(), texture.interlaceColor().gc(),
126                 0, i, width, i);
127
128   switch (texture.relief()) {
129   case RenderTexture::Raised:
130     switch (texture.bevel()) {
131     case RenderTexture::Bevel1:
132       XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
133                 left, bottom, right, bottom);
134       XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
135                 right, bottom, right, top);
136
137       XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
138                 left, top, right, top);
139       XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
140                 left, bottom, left, top);
141       break;
142     case RenderTexture::Bevel2:
143       XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
144                 left + 1, bottom - 2, right - 2, bottom - 2);
145       XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
146                 right - 2, bottom - 2, right - 2, top + 1);
147
148       XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
149                 left + 1, top + 1, right - 2, top + 1);
150       XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
151                 left + 1, bottom - 2, left + 1, top + 1);
152       break;
153     default:
154       assert(false); // unhandled RenderTexture::BevelType
155     }
156     break;
157   case RenderTexture::Sunken:
158     switch (texture.bevel()) {
159     case RenderTexture::Bevel1:
160       XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
161                 left, bottom, right, bottom);
162       XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
163                 right, bottom, right, top);
164
165       XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
166                 left, top, right, top);
167       XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
168                 left, bottom, left, top);
169       break;
170     case RenderTexture::Bevel2:
171       XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
172                 left + 1, bottom - 2, right - 2, bottom - 2);
173       XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
174                 right - 2, bottom - 2, right - 2, top + 1);
175
176       XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
177                 left + 1, top + 1, right - 2, top + 1);
178       XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
179                 left + 1, bottom - 2, left + 1, top + 1);
180       break;
181     default:
182       assert(false); // unhandled RenderTexture::BevelType
183     }
184     break;
185   case RenderTexture::Flat:
186     if (texture.border())
187       XDrawRectangle(**display, sf.pixmap(), texture.borderColor().gc(),
188                      left, top, right, bottom);
189     break;
190   default:
191     assert(false); // unhandled RenderTexture::ReliefType
192   }
193 }
194
195 }