]>
Dogcows Code - chaz/openbox/blob - render.c
8bde9c6f0416dc10247a9cd36586087666b08d19
18 static void pixel_data_to_pixmap(RrAppearance
*l
,
19 gint x
, gint y
, gint w
, gint h
);
21 void RrPaint(RrAppearance
*l
, 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
= (l
->w
!= w
|| l
->h
!= h
);
33 oldp
= l
->pixmap
; /* save to free after changing the visible pixmap */
34 l
->pixmap
= XCreatePixmap(RrDisplay(l
->inst
),
35 RrRootWindow(l
->inst
),
36 w
, h
, RrDepth(l
->inst
));
38 g_assert(l
->pixmap
!= None
);
42 if (l
->xftdraw
!= NULL
)
43 XftDrawDestroy(l
->xftdraw
);
44 l
->xftdraw
= XftDrawCreate(RrDisplay(l
->inst
), l
->pixmap
,
45 RrVisual(l
->inst
), RrColormap(l
->inst
));
46 g_assert(l
->xftdraw
!= NULL
);
48 g_free(l
->surface
.pixel_data
);
49 l
->surface
.pixel_data
= g_new(RrPixel32
, w
* h
);
51 if (l
->surface
.grad
== RR_SURFACE_PARENTREL
) {
52 g_assert (l
->surface
.parent
);
53 g_assert (l
->surface
.parent
->w
);
55 sw
= l
->surface
.parent
->w
;
56 source
= (l
->surface
.parent
->surface
.pixel_data
+
57 l
->surface
.parentx
+ sw
* l
->surface
.parenty
);
58 dest
= l
->surface
.pixel_data
;
59 for (i
= 0; i
< h
; i
++, source
+= sw
, dest
+= w
) {
60 memcpy(dest
, source
, w
* sizeof(RrPixel32
));
65 RECT_SET(tarea
, 0, 0, w
, h
);
66 if (l
->surface
.grad
!= RR_SURFACE_PARENTREL
) {
67 if (l
->surface
.relief
!= RR_RELIEF_FLAT
) {
68 switch (l
->surface
.bevel
) {
70 tarea
.x
+= 1; tarea
.y
+= 1;
71 tarea
.width
-= 2; tarea
.height
-= 2;
74 tarea
.x
+= 2; tarea
.y
+= 2;
75 tarea
.width
-= 4; tarea
.height
-= 4;
78 } else if (l
->surface
.border
) {
79 tarea
.x
+= 1; tarea
.y
+= 1;
80 tarea
.width
-= 2; tarea
.height
-= 2;
84 for (i
= 0; i
< l
->textures
; i
++) {
85 switch (l
->texture
[i
].type
) {
91 if (l
->surface
.grad
!= RR_SURFACE_SOLID
)
92 pixel_data_to_pixmap(l
, 0, 0, w
, h
);
94 if (l
->xftdraw
== NULL
) {
95 l
->xftdraw
= XftDrawCreate(RrDisplay(l
->inst
), l
->pixmap
,
99 RrFontDraw(l
->xftdraw
, &l
->texture
[i
].data
.text
, &tarea
);
101 case RR_TEXTURE_LINE_ART
:
104 if (l
->surface
.grad
!= RR_SURFACE_SOLID
)
105 pixel_data_to_pixmap(l
, 0, 0, w
, h
);
107 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
,
108 RrColorGC(l
->texture
[i
].data
.lineart
.color
),
109 l
->texture
[i
].data
.lineart
.x1
,
110 l
->texture
[i
].data
.lineart
.y1
,
111 l
->texture
[i
].data
.lineart
.x2
,
112 l
->texture
[i
].data
.lineart
.y2
);
114 case RR_TEXTURE_MASK
:
117 if (l
->surface
.grad
!= RR_SURFACE_SOLID
)
118 pixel_data_to_pixmap(l
, 0, 0, w
, h
);
120 RrPixmapMaskDraw(l
->pixmap
, &l
->texture
[i
].data
.mask
, &tarea
);
122 case RR_TEXTURE_RGBA
:
123 g_assert(!transferred
);
124 RrImageDraw(l
->surface
.pixel_data
,
125 &l
->texture
[i
].data
.rgba
, &tarea
);
132 if (l
->surface
.grad
!= RR_SURFACE_SOLID
)
133 pixel_data_to_pixmap(l
, 0, 0, w
, h
);
136 XSetWindowBackgroundPixmap(RrDisplay(l
->inst
), win
, l
->pixmap
);
137 XClearWindow(RrDisplay(l
->inst
), win
);
138 if (oldp
) XFreePixmap(RrDisplay(l
->inst
), oldp
);
141 RrAppearance
*RrAppearanceNew(const RrInstance
*inst
, gint numtex
)
145 out
= g_new0(RrAppearance
, 1);
147 out
->textures
= numtex
;
148 if (numtex
) out
->texture
= g_new0(RrTexture
, numtex
);
153 RrAppearance
*RrAppearanceCopy(RrAppearance
*orig
)
155 RrSurface
*spo
, *spc
;
156 RrAppearance
*copy
= g_new(RrAppearance
, 1);
159 copy
->inst
= orig
->inst
;
161 spo
= &(orig
->surface
);
162 spc
= &(copy
->surface
);
163 spc
->grad
= spo
->grad
;
164 spc
->relief
= spo
->relief
;
165 spc
->bevel
= spo
->bevel
;
166 if (spo
->primary
!= NULL
)
167 spc
->primary
= RrColorNew(copy
->inst
,
171 else spc
->primary
= NULL
;
173 if (spo
->secondary
!= NULL
)
174 spc
->secondary
= RrColorNew(copy
->inst
,
178 else spc
->secondary
= NULL
;
180 if (spo
->border_color
!= NULL
)
181 spc
->border_color
= RrColorNew(copy
->inst
,
182 spo
->border_color
->r
,
183 spo
->border_color
->g
,
184 spo
->border_color
->b
);
185 else spc
->border_color
= NULL
;
187 if (spo
->interlace_color
!= NULL
)
188 spc
->interlace_color
= RrColorNew(copy
->inst
,
189 spo
->interlace_color
->r
,
190 spo
->interlace_color
->g
,
191 spo
->interlace_color
->b
);
192 else spc
->interlace_color
= NULL
;
194 if (spo
->bevel_dark
!= NULL
)
195 spc
->bevel_dark
= RrColorNew(copy
->inst
,
199 else spc
->bevel_dark
= NULL
;
201 if (spo
->bevel_light
!= NULL
)
202 spc
->bevel_light
= RrColorNew(copy
->inst
,
205 spo
->bevel_light
->b
);
206 else spc
->bevel_light
= NULL
;
208 spc
->interlaced
= spo
->interlaced
;
209 spc
->border
= spo
->border
;
211 spc
->parentx
= spc
->parenty
= 0;
212 spc
->pixel_data
= NULL
;
214 copy
->textures
= orig
->textures
;
215 copy
->texture
= g_memdup(orig
->texture
,
216 orig
->textures
* sizeof(RrTexture
));
217 for (i
= 0; i
< copy
->textures
; ++i
)
218 if (copy
->texture
[i
].type
== RR_TEXTURE_RGBA
) {
219 g_free(copy
->texture
[i
].data
.rgba
.cache
);
220 copy
->texture
[i
].data
.rgba
.cache
= NULL
;
223 copy
->xftdraw
= NULL
;
224 copy
->w
= copy
->h
= 0;
228 void RrAppearanceFree(RrAppearance
*a
)
234 if (a
->pixmap
!= None
) XFreePixmap(RrDisplay(a
->inst
), a
->pixmap
);
235 if (a
->xftdraw
!= NULL
) XftDrawDestroy(a
->xftdraw
);
236 for (i
= 0; i
< a
->textures
; ++i
)
237 if (a
->texture
[i
].type
== RR_TEXTURE_RGBA
) {
238 g_free(a
->texture
[i
].data
.rgba
.cache
);
239 a
->texture
[i
].data
.rgba
.cache
= NULL
;
244 RrColorFree(p
->primary
);
245 RrColorFree(p
->secondary
);
246 RrColorFree(p
->border_color
);
247 RrColorFree(p
->interlace_color
);
248 RrColorFree(p
->bevel_dark
);
249 RrColorFree(p
->bevel_light
);
250 g_free(p
->pixel_data
);
257 static void pixel_data_to_pixmap(RrAppearance
*l
,
258 gint x
, gint y
, gint w
, gint h
)
260 RrPixel32
*in
, *scratch
;
263 im
= XCreateImage(RrDisplay(l
->inst
), RrVisual(l
->inst
), RrDepth(l
->inst
),
264 ZPixmap
, 0, NULL
, w
, h
, 32, 0);
265 g_assert(im
!= NULL
);
267 in
= l
->surface
.pixel_data
;
270 im
->byte_order
= LSBFirst
;
271 /* this malloc is a complete waste of time on normal 32bpp
272 as reduce_depth just sets im->data = data and returns
274 scratch
= g_new(RrPixel32
, im
->width
* im
->height
);
275 im
->data
= (char*) scratch
;
276 RrReduceDepth(l
->inst
, in
, im
);
277 XPutImage(RrDisplay(l
->inst
), out
,
278 DefaultGC(RrDisplay(l
->inst
), RrScreen(l
->inst
)),
279 im
, 0, 0, x
, y
, w
, h
);
285 void RrMinsize(RrAppearance
*l
, gint
*w
, gint
*h
)
291 for (i
= 0; i
< l
->textures
; ++i
) {
292 switch (l
->texture
[i
].type
) {
293 case RR_TEXTURE_NONE
:
295 case RR_TEXTURE_MASK
:
296 *w
= MAX(*w
, l
->texture
[i
].data
.mask
.mask
->width
);
297 *h
= MAX(*h
, l
->texture
[i
].data
.mask
.mask
->height
);
299 case RR_TEXTURE_TEXT
:
300 m
= RrFontMeasureString(l
->texture
[i
].data
.text
.font
,
301 l
->texture
[i
].data
.text
.string
);
303 m
= RrFontHeight(l
->texture
[i
].data
.text
.font
);
306 case RR_TEXTURE_RGBA
:
307 *w
+= MAX(*w
, l
->texture
[i
].data
.rgba
.width
);
308 *h
+= MAX(*h
, l
->texture
[i
].data
.rgba
.height
);
310 case RR_TEXTURE_LINE_ART
:
311 *w
+= MAX(*w
, MAX(l
->texture
[i
].data
.lineart
.x1
,
312 l
->texture
[i
].data
.lineart
.x2
));
313 *h
+= MAX(*h
, MAX(l
->texture
[i
].data
.lineart
.y1
,
314 l
->texture
[i
].data
.lineart
.y2
));
319 if (l
->surface
.relief
!= RR_RELIEF_FLAT
) {
320 switch (l
->surface
.bevel
) {
330 } else if (l
->surface
.border
) {
339 gboolean
RrPixmapToRGBA(const RrInstance
*inst
,
340 Pixmap pmap
, Pixmap mask
,
341 gint
*w
, gint
*h
, RrPixel32
**data
)
345 guint pw
, ph
, mw
, mh
, xb
, xd
, i
, x
, y
, di
;
346 XImage
*xi
, *xm
= NULL
;
348 if (!XGetGeometry(RrDisplay(inst
),
349 pmap
, &xr
, &xx
, &xy
, &pw
, &ph
, &xb
, &xd
))
352 if (!XGetGeometry(RrDisplay(inst
), mask
,
353 &xr
, &xx
, &xy
, &mw
, &mh
, &xb
, &xd
))
355 if (pw
!= mw
|| ph
!= mh
|| xd
!= 1)
359 xi
= XGetImage(RrDisplay(inst
), pmap
,
360 0, 0, pw
, ph
, 0xffffffff, ZPixmap
);
365 xm
= XGetImage(RrDisplay(inst
), mask
,
366 0, 0, mw
, mh
, 0xffffffff, ZPixmap
);
371 *data
= g_new(RrPixel32
, pw
* ph
);
372 RrIncreaseDepth(inst
, *data
, xi
);
375 /* apply transparency from the mask */
377 for (i
= 0, y
= 0; y
< ph
; ++y
) {
378 for (x
= 0; x
< pw
; ++x
, ++i
) {
379 if (!((((unsigned)xm
->data
[di
+ x
/ 8]) >> (x
% 8)) & 0x1))
380 (*data
)[i
] &= ~(0xff << RrDefaultAlphaOffset
);
382 di
+= xm
->bytes_per_line
;
This page took 0.053434 seconds and 3 git commands to generate.