]> Dogcows Code - chaz/openbox/blob - otk/rendercontrol.cc
doc the state functions better
[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 "rendertexture.hh"
10 #include "rendercolor.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 GrayRenderControl(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 }
55
56 RenderControl::~RenderControl()
57 {
58 printf("Destroying RenderControl\n");
59
60
61 }
62
63 void RenderControl::drawRoot(const RenderColor &color) const
64 {
65 Window root = display->screenInfo(_screen)->rootWindow();
66 XSetWindowBackground(**display, root, color.pixel());
67 XClearWindow(**display, root);
68 }
69
70 void RenderControl::drawString(Surface& sf, const Font &font, int x, int y,
71 const RenderColor &color,
72 const ustring &string) const
73 {
74 assert(sf._screen == _screen);
75 XftDraw *d = sf._xftdraw;
76 assert(d); // this means that the background hasn't been rendered yet!
77
78 if (font._shadow) {
79 XftColor c;
80 c.color.red = 0;
81 c.color.green = 0;
82 c.color.blue = 0;
83 c.color.alpha = font._tint | font._tint << 8; // transparent shadow
84 c.pixel = BlackPixel(**display, _screen);
85
86 if (string.utf8())
87 XftDrawStringUtf8(d, &c, font._xftfont, x + font._offset,
88 font._xftfont->ascent + y + font._offset,
89 (FcChar8*)string.c_str(), string.bytes());
90 else
91 XftDrawString8(d, &c, font._xftfont, x + font._offset,
92 font._xftfont->ascent + y + font._offset,
93 (FcChar8*)string.c_str(), string.bytes());
94 }
95
96 XftColor c;
97 c.color.red = color.red() | color.red() << 8;
98 c.color.green = color.green() | color.green() << 8;
99 c.color.blue = color.blue() | color.blue() << 8;
100 c.pixel = color.pixel();
101 c.color.alpha = 0xff | 0xff << 8; // no transparency in Color yet
102
103 if (string.utf8())
104 XftDrawStringUtf8(d, &c, font._xftfont, x, font._xftfont->ascent + y,
105 (FcChar8*)string.c_str(), string.bytes());
106 else
107 XftDrawString8(d, &c, font._xftfont, x, font._xftfont->ascent + y,
108 (FcChar8*)string.c_str(), string.bytes());
109 return;
110 }
111
112 void RenderControl::drawSolidBackground(Surface& sf,
113 const RenderTexture& texture) const
114 {
115 assert(_screen == sf._screen);
116 assert(_screen == texture.color().screen());
117
118 if (texture.parentRelative()) return;
119
120 sf.setPixmap(texture.color());
121
122 int width = sf.width(), height = sf.height();
123 int left = 0, top = 0, right = width - 1, bottom = height - 1;
124
125 if (texture.interlaced())
126 for (int i = 0; i < height; i += 2)
127 XDrawLine(**display, sf.pixmap(), texture.interlaceColor().gc(),
128 0, i, width, i);
129
130 switch (texture.relief()) {
131 case RenderTexture::Raised:
132 switch (texture.bevel()) {
133 case RenderTexture::Bevel1:
134 XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
135 left, bottom, right, bottom);
136 XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
137 right, bottom, right, top);
138
139 XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
140 left, top, right, top);
141 XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
142 left, bottom, left, top);
143 break;
144 case RenderTexture::Bevel2:
145 XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
146 left + 1, bottom - 2, right - 2, bottom - 2);
147 XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
148 right - 2, bottom - 2, right - 2, top + 1);
149
150 XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
151 left + 1, top + 1, right - 2, top + 1);
152 XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
153 left + 1, bottom - 2, left + 1, top + 1);
154 break;
155 default:
156 assert(false); // unhandled RenderTexture::BevelType
157 }
158 break;
159 case RenderTexture::Sunken:
160 switch (texture.bevel()) {
161 case RenderTexture::Bevel1:
162 XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
163 left, bottom, right, bottom);
164 XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
165 right, bottom, right, top);
166
167 XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
168 left, top, right, top);
169 XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
170 left, bottom, left, top);
171 break;
172 case RenderTexture::Bevel2:
173 XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
174 left + 1, bottom - 2, right - 2, bottom - 2);
175 XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
176 right - 2, bottom - 2, right - 2, top + 1);
177
178 XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
179 left + 1, top + 1, right - 2, top + 1);
180 XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
181 left + 1, bottom - 2, left + 1, top + 1);
182 break;
183 default:
184 assert(false); // unhandled RenderTexture::BevelType
185 }
186 break;
187 case RenderTexture::Flat:
188 if (texture.border())
189 XDrawRectangle(**display, sf.pixmap(), texture.borderColor().gc(),
190 left, top, right, bottom);
191 break;
192 default:
193 assert(false); // unhandled RenderTexture::ReliefType
194 }
195 }
196
197 }
This page took 0.042297 seconds and 4 git commands to generate.