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