1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
5 #endif // HAVE_CONFIG_H
7 #include "rendercontrol.hh"
8 #include "truerendercontrol.hh"
9 #include "pseudorendercontrol.hh"
10 #include "rendertexture.hh"
11 #include "rendercolor.hh"
12 #include "renderstyle.hh"
14 #include "screeninfo.hh"
22 #endif // HAVE_STDLIB_H
24 #include "../src/gettext.h"
25 #define _(str) gettext(str)
30 RenderControl *RenderControl::getRenderControl(int screen)
32 // get the visual on the screen and return the correct type of RenderControl
33 int vclass = display->screenInfo(screen)->visual()->c_class;
36 return new TrueRenderControl(screen);
39 return new PseudoRenderControl(screen);
42 return new PseudoRenderControl(screen);
44 printf(_("RenderControl: Unsupported visual %d specified. Aborting.\n"),
50 RenderControl::RenderControl(int screen)
53 printf("Initializing RenderControl\n");
56 RenderControl::~RenderControl()
58 printf("Destroying RenderControl\n");
61 void RenderControl::drawRoot(const RenderColor &color) const
63 Window root = display->screenInfo(_screen)->rootWindow();
64 XSetWindowBackground(**display, root, color.pixel());
65 XClearWindow(**display, root);
68 void RenderControl::drawString(Surface& sf, const Font &font, int x, int y,
69 const RenderColor &color,
70 const ustring &string) const
72 assert(sf._screen == _screen);
73 XftDraw *d = sf._xftdraw;
74 assert(d); // this means that the background hasn't been rendered yet!
81 c.color.alpha = font._tint | font._tint << 8; // transparent shadow
82 c.pixel = BlackPixel(**display, _screen);
85 XftDrawStringUtf8(d, &c, font._xftfont, x + font._offset,
86 font._xftfont->ascent + y + font._offset,
87 (FcChar8*)string.c_str(), string.bytes());
89 XftDrawString8(d, &c, font._xftfont, x + font._offset,
90 font._xftfont->ascent + y + font._offset,
91 (FcChar8*)string.c_str(), string.bytes());
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
102 XftDrawStringUtf8(d, &c, font._xftfont, x, font._xftfont->ascent + y,
103 (FcChar8*)string.c_str(), string.bytes());
105 XftDrawString8(d, &c, font._xftfont, x, font._xftfont->ascent + y,
106 (FcChar8*)string.c_str(), string.bytes());
110 void RenderControl::drawSolidBackground(Surface& sf,
111 const RenderTexture& texture) const
113 assert(_screen == sf._screen);
114 assert(_screen == texture.color().screen());
116 if (texture.parentRelative()) return;
118 sf.setPixmap(texture.color());
120 int width = sf.size().width(), height = sf.size().height();
121 int left = 0, top = 0, right = width - 1, bottom = height - 1;
123 if (texture.interlaced())
124 for (int i = 0; i < height; i += 2)
125 XDrawLine(**display, sf.pixmap(), texture.interlaceColor().gc(),
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);
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);
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);
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);
154 assert(false); // unhandled RenderTexture::BevelType
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);
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);
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);
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);
182 assert(false); // unhandled RenderTexture::BevelType
185 case RenderTexture::Flat:
186 if (texture.border())
187 XDrawRectangle(**display, sf.pixmap(), texture.borderColor().gc(),
188 left, top, right, bottom);
191 assert(false); // unhandled RenderTexture::ReliefType