]>
Dogcows Code - chaz/openbox/blob - otk/truerendercontrol.cc
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
18 #include "../src/gettext.h"
19 #define _(str) gettext(str)
24 TrueRenderControl::TrueRenderControl(int screen
)
25 : RenderControl(screen
),
30 const ScreenInfo
*info
= display
->screenInfo(_screen
);
31 XImage
*timage
= XCreateImage(**display
, info
->visual(), info
->depth(),
32 ZPixmap
, 0, NULL
, 1, 1, 32, 0);
33 printf("Initializing TrueColor RenderControl\n");
35 unsigned long red_mask
, green_mask
, blue_mask
;
37 // find the offsets for each color in the visual's masks
38 red_mask
= timage
->red_mask
;
39 green_mask
= timage
->green_mask
;
40 blue_mask
= timage
->blue_mask
;
42 while (! (red_mask
& 1)) { _red_offset
++; red_mask
>>= 1; }
43 while (! (green_mask
& 1)) { _green_offset
++; green_mask
>>= 1; }
44 while (! (blue_mask
& 1)) { _blue_offset
++; blue_mask
>>= 1; }
46 _red_shift
= _green_shift
= _blue_shift
= 8;
47 while (red_mask
) { red_mask
>>= 1; _red_shift
--; }
48 while (green_mask
) { green_mask
>>= 1; _green_shift
--; }
49 while (blue_mask
) { blue_mask
>>= 1; _blue_shift
--; }
53 TrueRenderControl::~TrueRenderControl()
55 printf("Destroying TrueColor RenderControl\n");
58 void TrueRenderControl::drawGradientBackground(
59 Surface
&sf
, const RenderTexture
&texture
) const
62 unsigned int w
= sf
.size().width(), h
= sf
.size().height();
65 const ScreenInfo
*info
= display
->screenInfo(_screen
);
66 XImage
*im
= XCreateImage(**display
, info
->visual(), info
->depth(),
67 ZPixmap
, 0, NULL
, w
, h
, 32, 0);
68 im
->byte_order
= endian
;
69 pixel32
*data
= new pixel32
[h
*w
];
72 switch (texture
.gradient()) {
73 case RenderTexture::Vertical
:
74 verticalGradient(sf
, texture
, data
);
76 case RenderTexture::Diagonal
:
77 diagonalGradient(sf
, texture
, data
);
79 case RenderTexture::CrossDiagonal
:
80 crossDiagonalGradient(sf
, texture
, data
);
83 printf("unhandled gradient\n");
86 if (texture
.relief() == RenderTexture::Flat
&& texture
.border()) {
87 r
= texture
.borderColor().red();
88 g
= texture
.borderColor().green();
89 b
= texture
.borderColor().blue();
90 current
= (r
<< default_red_shift
)
91 + (g
<< default_green_shift
)
92 + (b
<< default_blue_shift
);
93 for (off
= 0, x
= 0; x
< w
; ++x
, off
++) {
94 *(data
+ off
) = current
;
95 *(data
+ off
+ ((h
-1) * w
)) = current
;
97 for (off
= 0, x
= 0; x
< h
; ++x
, off
++) {
98 *(data
+ (off
* w
)) = current
;
99 *(data
+ (off
* w
) + w
- 1) = current
;
103 if (texture
.relief() != RenderTexture::Flat
) {
104 if (texture
.bevel() == RenderTexture::Bevel1
) {
105 if (w
>= 1 && h
>= 1) {
106 for (off
= 1, x
= 1; x
< w
- 1; ++x
, off
++)
107 highlight(data
+ off
,
108 data
+ off
+ (h
-1) * w
,
109 texture
.relief()==RenderTexture::Raised
);
110 for (off
= 0, x
= 0; x
< h
; ++x
, off
++)
111 highlight(data
+ off
* w
,
112 data
+ off
* w
+ w
- 1,
113 texture
.relief()==RenderTexture::Raised
);
117 if (texture
.bevel() == RenderTexture::Bevel2
) {
118 if (w
>= 2 && h
>= 2) {
119 for (off
= 2, x
= 2; x
< w
- 2; ++x
, off
++)
120 highlight(data
+ off
+ w
,
121 data
+ off
+ (h
-2) * w
,
122 texture
.relief()==RenderTexture::Raised
);
123 for (off
= 1, x
= 1; x
< h
-1; ++x
, off
++)
124 highlight(data
+ off
* w
+ 1,
125 data
+ off
* w
+ w
- 2,
126 texture
.relief()==RenderTexture::Raised
);
131 reduceDepth(im
, data
);
133 im
->data
= (char*) data
;
142 void TrueRenderControl::verticalGradient(Surface
&sf
,
143 const RenderTexture
&texture
,
149 unsigned int w
= sf
.size().width(), h
= sf
.size().height();
151 dr
= (float)(texture
.secondary_color().red() - texture
.color().red());
154 dg
= (float)(texture
.secondary_color().green() - texture
.color().green());
157 db
= (float)(texture
.secondary_color().blue() - texture
.color().blue());
160 for (unsigned int y
= 0; y
< h
; ++y
) {
161 r
= texture
.color().red() + (int)(dr
* y
);
162 g
= texture
.color().green() + (int)(dg
* y
);
163 b
= texture
.color().blue() + (int)(db
* y
);
164 current
= (r
<< default_red_shift
)
165 + (g
<< default_green_shift
)
166 + (b
<< default_blue_shift
);
167 for (unsigned int x
= 0; x
< w
; ++x
, ++data
)
172 void TrueRenderControl::diagonalGradient(Surface
&sf
,
173 const RenderTexture
&texture
,
177 float drx
, dgx
, dbx
, dry
, dgy
, dby
;
179 unsigned int w
= sf
.size().width(), h
= sf
.size().height();
181 for (unsigned int y
= 0; y
< h
; ++y
) {
182 drx
= (float)(texture
.secondary_color().red() - texture
.color().red());
186 dgx
= (float)(texture
.secondary_color().green() - texture
.color().green());
190 dbx
= (float)(texture
.secondary_color().blue() - texture
.color().blue());
193 for (unsigned int x
= 0; x
< w
; ++x
, ++data
) {
194 r
= texture
.color().red() + ((int)(drx
* x
) + (int)(dry
* y
))/2;
195 g
= texture
.color().green() + ((int)(dgx
* x
) + (int)(dgy
* y
))/2;
196 b
= texture
.color().blue() + ((int)(dbx
* x
) + (int)(dby
* y
))/2;
197 current
= (r
<< default_red_shift
)
198 + (g
<< default_green_shift
)
199 + (b
<< default_blue_shift
);
205 void TrueRenderControl::crossDiagonalGradient(Surface
&sf
,
206 const RenderTexture
&texture
,
210 float drx
, dgx
, dbx
, dry
, dgy
, dby
;
212 unsigned int w
= sf
.size().width(), h
= sf
.size().height();
214 for (unsigned int y
= 0; y
< h
; ++y
) {
215 drx
= (float)(texture
.secondary_color().red() - texture
.color().red());
219 dgx
= (float)(texture
.secondary_color().green() - texture
.color().green());
223 dbx
= (float)(texture
.secondary_color().blue() - texture
.color().blue());
226 for (int x
= w
; x
> 0; --x
, ++data
) {
227 r
= texture
.color().red() + ((int)(drx
* (x
-1)) + (int)(dry
* y
))/2;
228 g
= texture
.color().green() + ((int)(dgx
* (x
-1)) + (int)(dgy
* y
))/2;
229 b
= texture
.color().blue() + ((int)(dbx
* (x
-1)) + (int)(dby
* y
))/2;
230 current
= (r
<< default_red_shift
)
231 + (g
<< default_green_shift
)
232 + (b
<< default_blue_shift
);
238 void TrueRenderControl::reduceDepth(XImage
*im
, pixel32
*data
) const
240 // since pixel32 is the largest possible pixel size, we can share the array
243 pixel16
*p
= (pixel16
*) data
;
244 switch (im
->bits_per_pixel
) {
246 if ((_red_offset
!= default_red_shift
) ||
247 (_blue_offset
!= default_blue_shift
) ||
248 (_green_offset
!= default_green_shift
)) {
249 printf("cross endian conversion\n");
250 for (y
= 0; y
< im
->height
; y
++) {
251 for (x
= 0; x
< im
->width
; x
++) {
252 r
= (data
[x
] >> default_red_shift
) & 0xFF;
253 g
= (data
[x
] >> default_green_shift
) & 0xFF;
254 b
= (data
[x
] >> default_blue_shift
) & 0xFF;
255 data
[x
] = (r
<< _red_offset
) + (g
<< _green_offset
) +
263 for (y
= 0; y
< im
->height
; y
++) {
264 for (x
= 0; x
< im
->width
; x
++) {
265 r
= (data
[x
] >> default_red_shift
) & 0xFF;
267 g
= (data
[x
] >> default_green_shift
) & 0xFF;
268 g
= g
>> _green_shift
;
269 b
= (data
[x
] >> default_blue_shift
) & 0xFF;
270 b
= b
>> _blue_shift
;
271 p
[x
] = (r
<< _red_offset
) + (g
<< _green_offset
) + (b
<< _blue_offset
);
274 p
+= im
->bytes_per_line
/2;
278 printf("your bit depth is currently unhandled\n");
282 void TrueRenderControl::highlight(pixel32
*x
, pixel32
*y
, bool raised
) const
294 r
= (*up
>> default_red_shift
) & 0xFF;
296 g
= (*up
>> default_green_shift
) & 0xFF;
298 b
= (*up
>> default_blue_shift
) & 0xFF;
300 if (r
> 255) r
= 255;
301 if (g
> 255) g
= 255;
302 if (b
> 255) b
= 255;
303 *up
= (r
<< default_red_shift
) + (g
<< default_green_shift
)
304 + (b
<< default_blue_shift
);
306 r
= (*down
>> default_red_shift
) & 0xFF;
307 r
= (r
>> 1) + (r
>> 2);
308 g
= (*down
>> default_green_shift
) & 0xFF;
309 g
= (g
>> 1) + (g
>> 2);
310 b
= (*down
>> default_blue_shift
) & 0xFF;
311 b
= (b
>> 1) + (b
>> 2);
312 *down
= (r
<< default_red_shift
) + (g
<< default_green_shift
)
313 + (b
<< default_blue_shift
);
316 void TrueRenderControl::drawBackground(Surface
& sf
,
317 const RenderTexture
&texture
) const
319 assert(_screen
== sf
._screen
);
320 assert(_screen
== texture
.color().screen());
322 if (texture
.gradient() == RenderTexture::Solid
)
323 drawSolidBackground(sf
, texture
);
325 drawGradientBackground(sf
, texture
);
This page took 0.057494 seconds and 4 git commands to generate.