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