]>
Dogcows Code - chaz/openbox/blob - render/render.c
18 static void pixel_data_to_pixmap(RrAppearance
*l
,
19 gint x
, gint y
, gint w
, gint h
);
21 void RrPaint(RrAppearance
*a
, Window win
, gint w
, gint h
)
23 int i
, transferred
= 0, sw
;
24 RrPixel32
*source
, *dest
;
26 RrRect tarea
; /* area in which to draw textures */
29 if (w
<= 0 || h
<= 0) return;
31 resized
= (a
->w
!= w
|| a
->h
!= h
);
33 oldp
= a
->pixmap
; /* save to free after changing the visible pixmap */
34 a
->pixmap
= XCreatePixmap(RrDisplay(a
->inst
),
35 RrRootWindow(a
->inst
),
36 w
, h
, RrDepth(a
->inst
));
38 g_assert(a
->pixmap
!= None
);
42 if (a
->xftdraw
!= NULL
)
43 XftDrawDestroy(a
->xftdraw
);
44 a
->xftdraw
= XftDrawCreate(RrDisplay(a
->inst
), a
->pixmap
,
45 RrVisual(a
->inst
), RrColormap(a
->inst
));
46 g_assert(a
->xftdraw
!= NULL
);
48 g_free(a
->surface
.pixel_data
);
49 a
->surface
.pixel_data
= g_new(RrPixel32
, w
* h
);
51 if (a
->surface
.grad
== RR_SURFACE_PARENTREL
) {
52 g_assert (a
->surface
.parent
);
53 g_assert (a
->surface
.parent
->w
);
55 sw
= a
->surface
.parent
->w
;
56 source
= (a
->surface
.parent
->surface
.pixel_data
+
57 a
->surface
.parentx
+ sw
* a
->surface
.parenty
);
58 dest
= a
->surface
.pixel_data
;
59 for (i
= 0; i
< h
; i
++, source
+= sw
, dest
+= w
) {
60 memcpy(dest
, source
, w
* sizeof(RrPixel32
));
67 RrMargins(a
, &l
, &t
, &r
, &b
);
68 RECT_SET(tarea
, l
, t
, w
- l
- r
, h
- t
- b
);
71 for (i
= 0; i
< a
->textures
; i
++) {
72 switch (a
->texture
[i
].type
) {
78 if (a
->surface
.grad
!= RR_SURFACE_SOLID
)
79 pixel_data_to_pixmap(a
, 0, 0, w
, h
);
81 if (a
->xftdraw
== NULL
) {
82 a
->xftdraw
= XftDrawCreate(RrDisplay(a
->inst
), a
->pixmap
,
86 RrFontDraw(a
->xftdraw
, &a
->texture
[i
].data
.text
, &tarea
);
88 case RR_TEXTURE_LINE_ART
:
91 if (a
->surface
.grad
!= RR_SURFACE_SOLID
)
92 pixel_data_to_pixmap(a
, 0, 0, w
, h
);
94 XDrawLine(RrDisplay(a
->inst
), a
->pixmap
,
95 RrColorGC(a
->texture
[i
].data
.lineart
.color
),
96 a
->texture
[i
].data
.lineart
.x1
,
97 a
->texture
[i
].data
.lineart
.y1
,
98 a
->texture
[i
].data
.lineart
.x2
,
99 a
->texture
[i
].data
.lineart
.y2
);
101 case RR_TEXTURE_MASK
:
104 if (a
->surface
.grad
!= RR_SURFACE_SOLID
)
105 pixel_data_to_pixmap(a
, 0, 0, w
, h
);
107 RrPixmapMaskDraw(a
->pixmap
, &a
->texture
[i
].data
.mask
, &tarea
);
109 case RR_TEXTURE_RGBA
:
110 g_assert(!transferred
);
111 RrImageDraw(a
->surface
.pixel_data
,
112 &a
->texture
[i
].data
.rgba
, &tarea
);
119 if (a
->surface
.grad
!= RR_SURFACE_SOLID
)
120 pixel_data_to_pixmap(a
, 0, 0, w
, h
);
123 XSetWindowBackgroundPixmap(RrDisplay(a
->inst
), win
, a
->pixmap
);
124 XClearWindow(RrDisplay(a
->inst
), win
);
125 if (oldp
) XFreePixmap(RrDisplay(a
->inst
), oldp
);
128 RrAppearance
*RrAppearanceNew(const RrInstance
*inst
, gint numtex
)
132 out
= g_new0(RrAppearance
, 1);
134 out
->textures
= numtex
;
135 if (numtex
) out
->texture
= g_new0(RrTexture
, numtex
);
140 RrAppearance
*RrAppearanceCopy(RrAppearance
*orig
)
142 RrSurface
*spo
, *spc
;
143 RrAppearance
*copy
= g_new(RrAppearance
, 1);
146 copy
->inst
= orig
->inst
;
148 spo
= &(orig
->surface
);
149 spc
= &(copy
->surface
);
150 spc
->grad
= spo
->grad
;
151 spc
->relief
= spo
->relief
;
152 spc
->bevel
= spo
->bevel
;
153 if (spo
->primary
!= NULL
)
154 spc
->primary
= RrColorNew(copy
->inst
,
158 else spc
->primary
= NULL
;
160 if (spo
->secondary
!= NULL
)
161 spc
->secondary
= RrColorNew(copy
->inst
,
165 else spc
->secondary
= NULL
;
167 if (spo
->border_color
!= NULL
)
168 spc
->border_color
= RrColorNew(copy
->inst
,
169 spo
->border_color
->r
,
170 spo
->border_color
->g
,
171 spo
->border_color
->b
);
172 else spc
->border_color
= NULL
;
174 if (spo
->interlace_color
!= NULL
)
175 spc
->interlace_color
= RrColorNew(copy
->inst
,
176 spo
->interlace_color
->r
,
177 spo
->interlace_color
->g
,
178 spo
->interlace_color
->b
);
179 else spc
->interlace_color
= NULL
;
181 if (spo
->bevel_dark
!= NULL
)
182 spc
->bevel_dark
= RrColorNew(copy
->inst
,
186 else spc
->bevel_dark
= NULL
;
188 if (spo
->bevel_light
!= NULL
)
189 spc
->bevel_light
= RrColorNew(copy
->inst
,
192 spo
->bevel_light
->b
);
193 else spc
->bevel_light
= NULL
;
195 spc
->interlaced
= spo
->interlaced
;
196 spc
->border
= spo
->border
;
198 spc
->parentx
= spc
->parenty
= 0;
199 spc
->pixel_data
= NULL
;
201 copy
->textures
= orig
->textures
;
202 copy
->texture
= g_memdup(orig
->texture
,
203 orig
->textures
* sizeof(RrTexture
));
204 for (i
= 0; i
< copy
->textures
; ++i
)
205 if (copy
->texture
[i
].type
== RR_TEXTURE_RGBA
) {
206 g_free(copy
->texture
[i
].data
.rgba
.cache
);
207 copy
->texture
[i
].data
.rgba
.cache
= NULL
;
210 copy
->xftdraw
= NULL
;
211 copy
->w
= copy
->h
= 0;
215 void RrAppearanceFree(RrAppearance
*a
)
221 if (a
->pixmap
!= None
) XFreePixmap(RrDisplay(a
->inst
), a
->pixmap
);
222 if (a
->xftdraw
!= NULL
) XftDrawDestroy(a
->xftdraw
);
223 for (i
= 0; i
< a
->textures
; ++i
)
224 if (a
->texture
[i
].type
== RR_TEXTURE_RGBA
) {
225 g_free(a
->texture
[i
].data
.rgba
.cache
);
226 a
->texture
[i
].data
.rgba
.cache
= NULL
;
231 RrColorFree(p
->primary
);
232 RrColorFree(p
->secondary
);
233 RrColorFree(p
->border_color
);
234 RrColorFree(p
->interlace_color
);
235 RrColorFree(p
->bevel_dark
);
236 RrColorFree(p
->bevel_light
);
237 g_free(p
->pixel_data
);
244 static void pixel_data_to_pixmap(RrAppearance
*l
,
245 gint x
, gint y
, gint w
, gint h
)
247 RrPixel32
*in
, *scratch
;
250 im
= XCreateImage(RrDisplay(l
->inst
), RrVisual(l
->inst
), RrDepth(l
->inst
),
251 ZPixmap
, 0, NULL
, w
, h
, 32, 0);
252 g_assert(im
!= NULL
);
254 in
= l
->surface
.pixel_data
;
257 /* this malloc is a complete waste of time on normal 32bpp
258 as reduce_depth just sets im->data = data and returns
260 scratch
= g_new(RrPixel32
, im
->width
* im
->height
);
261 im
->data
= (char*) scratch
;
262 RrReduceDepth(l
->inst
, in
, im
);
263 XPutImage(RrDisplay(l
->inst
), out
,
264 DefaultGC(RrDisplay(l
->inst
), RrScreen(l
->inst
)),
265 im
, 0, 0, x
, y
, w
, h
);
271 void RrMargins (RrAppearance
*a
, gint
*l
, gint
*t
, gint
*r
, gint
*b
)
273 *l
= *t
= *r
= *b
= 0;
275 if (a
->surface
.grad
!= RR_SURFACE_PARENTREL
) {
276 if (a
->surface
.relief
!= RR_RELIEF_FLAT
) {
277 switch (a
->surface
.bevel
) {
279 *l
= *t
= *r
= *b
= 1;
282 *l
= *t
= *r
= *b
= 2;
285 } else if (a
->surface
.border
) {
286 *l
= *t
= *r
= *b
= 1;
291 void RrMinsize(RrAppearance
*a
, gint
*w
, gint
*h
)
298 for (i
= 0; i
< a
->textures
; ++i
) {
299 switch (a
->texture
[i
].type
) {
300 case RR_TEXTURE_NONE
:
302 case RR_TEXTURE_MASK
:
303 *w
= MAX(*w
, a
->texture
[i
].data
.mask
.mask
->width
);
304 *h
= MAX(*h
, a
->texture
[i
].data
.mask
.mask
->height
);
306 case RR_TEXTURE_TEXT
:
307 m
= RrFontMeasureString(a
->texture
[i
].data
.text
.font
,
308 a
->texture
[i
].data
.text
.string
);
310 m
= RrFontHeight(a
->texture
[i
].data
.text
.font
);
313 case RR_TEXTURE_RGBA
:
314 *w
+= MAX(*w
, a
->texture
[i
].data
.rgba
.width
);
315 *h
+= MAX(*h
, a
->texture
[i
].data
.rgba
.height
);
317 case RR_TEXTURE_LINE_ART
:
318 *w
+= MAX(*w
, MAX(a
->texture
[i
].data
.lineart
.x1
,
319 a
->texture
[i
].data
.lineart
.x2
));
320 *h
+= MAX(*h
, MAX(a
->texture
[i
].data
.lineart
.y1
,
321 a
->texture
[i
].data
.lineart
.y2
));
326 RrMargins(a
, &l
, &t
, &r
, &b
);
335 gboolean
RrPixmapToRGBA(const RrInstance
*inst
,
336 Pixmap pmap
, Pixmap mask
,
337 gint
*w
, gint
*h
, RrPixel32
**data
)
341 guint pw
, ph
, mw
, mh
, xb
, xd
, i
, x
, y
, di
;
342 XImage
*xi
, *xm
= NULL
;
344 if (!XGetGeometry(RrDisplay(inst
),
345 pmap
, &xr
, &xx
, &xy
, &pw
, &ph
, &xb
, &xd
))
348 if (!XGetGeometry(RrDisplay(inst
), mask
,
349 &xr
, &xx
, &xy
, &mw
, &mh
, &xb
, &xd
))
351 if (pw
!= mw
|| ph
!= mh
|| xd
!= 1)
355 xi
= XGetImage(RrDisplay(inst
), pmap
,
356 0, 0, pw
, ph
, 0xffffffff, ZPixmap
);
361 xm
= XGetImage(RrDisplay(inst
), mask
,
362 0, 0, mw
, mh
, 0xffffffff, ZPixmap
);
367 *data
= g_new(RrPixel32
, pw
* ph
);
368 RrIncreaseDepth(inst
, *data
, xi
);
371 /* apply transparency from the mask */
373 for (i
= 0, y
= 0; y
< ph
; ++y
) {
374 for (x
= 0; x
< pw
; ++x
, ++i
) {
375 if (!((((unsigned)xm
->data
[di
+ x
/ 8]) >> (x
% 8)) & 0x1))
376 (*data
)[i
] &= ~(0xff << RrDefaultAlphaOffset
);
378 di
+= xm
->bytes_per_line
;
This page took 0.056184 seconds and 4 git commands to generate.