1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
5 #endif // HAVE_CONFIG_H
7 #include "truerendercontrol.hh"
9 #include "screeninfo.hh"
11 #include "rendertexture.hh"
16 #endif // HAVE_STDLIB_H
19 #define _(str) gettext(str)
24 TrueRenderControl::TrueRenderControl(int screen)
25 : RenderControl(screen),
30 printf("Initializing TrueColor RenderControl\n");
32 Visual *visual = display->screenInfo(_screen)->visual();
33 unsigned long red_mask, green_mask, blue_mask;
35 // find the offsets for each color in the visual's masks
36 red_mask = visual->red_mask;
37 green_mask = visual->green_mask;
38 blue_mask = visual->blue_mask;
40 while (! (red_mask & 1)) { _red_offset++; red_mask >>= 1; }
41 while (! (green_mask & 1)) { _green_offset++; green_mask >>= 1; }
42 while (! (blue_mask & 1)) { _blue_offset++; blue_mask >>= 1; }
44 _red_shift = _green_shift = _blue_shift = 8;
45 while (red_mask) { red_mask >>= 1; _red_shift--; }
46 while (green_mask) { green_mask >>= 1; _green_shift--; }
47 while (blue_mask) { blue_mask >>= 1; _blue_shift--; }
50 TrueRenderControl::~TrueRenderControl()
52 printf("Destroying TrueColor RenderControl\n");
58 static inline void renderPixel(XImage *im, unsigned char *dp,
61 unsigned int bpp = im->bits_per_pixel + (im->byte_order == MSBFirst ? 1 : 0);
98 assert(false); // wtf?
102 void TrueRenderControl::drawGradientBackground(
103 Surface &sf, const RenderTexture &texture) const
105 int w = sf.width(), h = sf.height(), off, x, y;
107 const ScreenInfo *info = display->screenInfo(_screen);
108 XImage *im = XCreateImage(**display, info->visual(), info->depth(),
109 ZPixmap, 0, NULL, w, h, 32, 0);
111 pixel32 *data = new pixel32[sf.height()*sf.width()];
116 //XXX: move this to seperate vgrad function
117 dr = (float)(texture.secondary_color().red() - texture.color().red());
118 dr/= (float)sf.height();
120 dg = (float)(texture.secondary_color().green() - texture.color().green());
121 dg/= (float)sf.height();
123 db = (float)(texture.secondary_color().blue() - texture.color().blue());
124 db/= (float)sf.height();
126 for (y = 0; y < h; ++y) {
127 r = texture.color().red() + (int)(dr * y);
128 g = texture.color().green() + (int)(dg * y);
129 b = texture.color().blue() + (int)(db * y);
133 for (x = 0; x < w; ++x, dp ++)
138 if (texture.relief() == RenderTexture::Flat && texture.border()) {
139 r = texture.borderColor().red();
140 g = texture.borderColor().green();
141 b = texture.borderColor().blue();
145 for (off = 0, x = 0; x < w; ++x, off++) {
146 *(data + off) = current;
147 *(data + off + ((h-1) * w)) = current;
149 for (off = 0, x = 0; x < h; ++x, off++) {
150 *(data + (off * w)) = current;
151 *(data + (off * w) + w - 1) = current;
155 //XXX: any dithering should be done now
156 im->data = (char*) data;
165 void TrueRenderControl::drawBackground(Surface& sf,
166 const RenderTexture &texture) const
168 assert(_screen == sf._screen);
169 assert(_screen == texture.color().screen());
171 if (texture.gradient() == RenderTexture::Solid) {
172 drawSolidBackground(sf, texture);
174 drawGradientBackground(sf, texture);