]>
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
*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 g_message("%d %d -> %d %d",
108 l
->texture
[i
].data
.lineart
.x1
,
109 l
->texture
[i
].data
.lineart
.y1
,
110 l
->texture
[i
].data
.lineart
.x2
,
111 l
->texture
[i
].data
.lineart
.y2
);
112 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
,
113 RrColorGC(l
->texture
[i
].data
.lineart
.color
),
114 l
->texture
[i
].data
.lineart
.x1
,
115 l
->texture
[i
].data
.lineart
.y1
,
116 l
->texture
[i
].data
.lineart
.x2
,
117 l
->texture
[i
].data
.lineart
.y2
);
119 case RR_TEXTURE_MASK
:
122 if (l
->surface
.grad
!= RR_SURFACE_SOLID
)
123 pixel_data_to_pixmap(l
, 0, 0, w
, h
);
125 RrPixmapMaskDraw(l
->pixmap
, &l
->texture
[i
].data
.mask
, &tarea
);
127 case RR_TEXTURE_RGBA
:
128 g_assert(!transferred
);
129 RrImageDraw(l
->surface
.pixel_data
,
130 &l
->texture
[i
].data
.rgba
, &tarea
);
137 if (l
->surface
.grad
!= RR_SURFACE_SOLID
)
138 pixel_data_to_pixmap(l
, 0, 0, w
, h
);
141 XSetWindowBackgroundPixmap(RrDisplay(l
->inst
), win
, l
->pixmap
);
142 XClearWindow(RrDisplay(l
->inst
), win
);
143 if (oldp
) XFreePixmap(RrDisplay(l
->inst
), oldp
);
146 RrAppearance
*RrAppearanceNew(const RrInstance
*inst
, gint numtex
)
150 out
= g_new0(RrAppearance
, 1);
152 out
->textures
= numtex
;
153 if (numtex
) out
->texture
= g_new0(RrTexture
, numtex
);
158 RrAppearance
*RrAppearanceCopy(RrAppearance
*orig
)
160 RrSurface
*spo
, *spc
;
161 RrAppearance
*copy
= g_new(RrAppearance
, 1);
164 copy
->inst
= orig
->inst
;
166 spo
= &(orig
->surface
);
167 spc
= &(copy
->surface
);
168 spc
->grad
= spo
->grad
;
169 spc
->relief
= spo
->relief
;
170 spc
->bevel
= spo
->bevel
;
171 if (spo
->primary
!= NULL
)
172 spc
->primary
= RrColorNew(copy
->inst
,
176 else spc
->primary
= NULL
;
178 if (spo
->secondary
!= NULL
)
179 spc
->secondary
= RrColorNew(copy
->inst
,
183 else spc
->secondary
= NULL
;
185 if (spo
->border_color
!= NULL
)
186 spc
->border_color
= RrColorNew(copy
->inst
,
187 spo
->border_color
->r
,
188 spo
->border_color
->g
,
189 spo
->border_color
->b
);
190 else spc
->border_color
= NULL
;
192 if (spo
->bevel_dark
!= NULL
)
193 spc
->bevel_dark
= RrColorNew(copy
->inst
,
197 else spc
->bevel_dark
= NULL
;
199 if (spo
->bevel_light
!= NULL
)
200 spc
->bevel_light
= RrColorNew(copy
->inst
,
203 spo
->bevel_light
->b
);
204 else spc
->bevel_light
= NULL
;
206 spc
->interlaced
= spo
->interlaced
;
207 spc
->border
= spo
->border
;
209 spc
->parentx
= spc
->parenty
= 0;
210 spc
->pixel_data
= NULL
;
212 copy
->textures
= orig
->textures
;
213 copy
->texture
= g_memdup(orig
->texture
,
214 orig
->textures
* sizeof(RrTexture
));
215 for (i
= 0; i
< copy
->textures
; ++i
)
216 if (copy
->texture
[i
].type
== RR_TEXTURE_RGBA
) {
217 g_free(copy
->texture
[i
].data
.rgba
.cache
);
218 copy
->texture
[i
].data
.rgba
.cache
= NULL
;
221 copy
->xftdraw
= NULL
;
222 copy
->w
= copy
->h
= 0;
226 void RrAppearanceFree(RrAppearance
*a
)
232 if (a
->pixmap
!= None
) XFreePixmap(RrDisplay(a
->inst
), a
->pixmap
);
233 if (a
->xftdraw
!= NULL
) XftDrawDestroy(a
->xftdraw
);
234 for (i
= 0; i
< a
->textures
; ++i
)
235 if (a
->texture
[i
].type
== RR_TEXTURE_RGBA
) {
236 g_free(a
->texture
[i
].data
.rgba
.cache
);
237 a
->texture
[i
].data
.rgba
.cache
= NULL
;
242 RrColorFree(p
->primary
);
243 RrColorFree(p
->secondary
);
244 RrColorFree(p
->border_color
);
245 RrColorFree(p
->bevel_dark
);
246 RrColorFree(p
->bevel_light
);
247 g_free(p
->pixel_data
);
254 static void pixel_data_to_pixmap(RrAppearance
*l
,
255 gint x
, gint y
, gint w
, gint h
)
257 RrPixel32
*in
, *scratch
;
260 im
= XCreateImage(RrDisplay(l
->inst
), RrVisual(l
->inst
), RrDepth(l
->inst
),
261 ZPixmap
, 0, NULL
, w
, h
, 32, 0);
262 g_assert(im
!= NULL
);
264 in
= l
->surface
.pixel_data
;
267 im
->byte_order
= LSBFirst
;
268 /* this malloc is a complete waste of time on normal 32bpp
269 as reduce_depth just sets im->data = data and returns
271 scratch
= g_new(RrPixel32
, im
->width
* im
->height
);
272 im
->data
= (char*) scratch
;
273 RrReduceDepth(l
->inst
, in
, im
);
274 XPutImage(RrDisplay(l
->inst
), out
,
275 DefaultGC(RrDisplay(l
->inst
), RrScreen(l
->inst
)),
276 im
, 0, 0, x
, y
, w
, h
);
282 void RrMinsize(RrAppearance
*l
, gint
*w
, gint
*h
)
288 for (i
= 0; i
< l
->textures
; ++i
) {
289 switch (l
->texture
[i
].type
) {
290 case RR_TEXTURE_NONE
:
292 case RR_TEXTURE_MASK
:
293 *w
= MAX(*w
, l
->texture
[i
].data
.mask
.mask
->width
);
294 *h
= MAX(*h
, l
->texture
[i
].data
.mask
.mask
->height
);
296 case RR_TEXTURE_TEXT
:
297 m
= RrFontMeasureString(l
->texture
[i
].data
.text
.font
,
298 l
->texture
[i
].data
.text
.string
);
300 m
= RrFontHeight(l
->texture
[i
].data
.text
.font
);
303 case RR_TEXTURE_RGBA
:
304 *w
+= MAX(*w
, l
->texture
[i
].data
.rgba
.width
);
305 *h
+= MAX(*h
, l
->texture
[i
].data
.rgba
.height
);
307 case RR_TEXTURE_LINE_ART
:
308 *w
+= MAX(*w
, MAX(l
->texture
[i
].data
.lineart
.x1
,
309 l
->texture
[i
].data
.lineart
.x2
));
310 *h
+= MAX(*h
, MAX(l
->texture
[i
].data
.lineart
.y1
,
311 l
->texture
[i
].data
.lineart
.y2
));
316 if (l
->surface
.relief
!= RR_RELIEF_FLAT
) {
317 switch (l
->surface
.bevel
) {
327 } else if (l
->surface
.border
) {
336 gboolean
RrPixmapToRGBA(const RrInstance
*inst
,
337 Pixmap pmap
, Pixmap mask
,
338 gint
*w
, gint
*h
, RrPixel32
**data
)
342 guint pw
, ph
, mw
, mh
, xb
, xd
, i
, x
, y
, di
;
343 XImage
*xi
, *xm
= NULL
;
345 if (!XGetGeometry(RrDisplay(inst
),
346 pmap
, &xr
, &xx
, &xy
, &pw
, &ph
, &xb
, &xd
))
349 if (!XGetGeometry(RrDisplay(inst
), mask
,
350 &xr
, &xx
, &xy
, &mw
, &mh
, &xb
, &xd
))
352 if (pw
!= mw
|| ph
!= mh
|| xd
!= 1)
356 xi
= XGetImage(RrDisplay(inst
), pmap
,
357 0, 0, pw
, ph
, 0xffffffff, ZPixmap
);
362 xm
= XGetImage(RrDisplay(inst
), mask
,
363 0, 0, mw
, mh
, 0xffffffff, ZPixmap
);
368 *data
= g_new(RrPixel32
, pw
* ph
);
369 RrIncreaseDepth(inst
, *data
, xi
);
372 /* apply transparency from the mask */
374 for (i
= 0, y
= 0; y
< ph
; ++y
) {
375 for (x
= 0; x
< pw
; ++x
, ++i
) {
376 if (!((((unsigned)xm
->data
[di
+ x
/ 8]) >> (x
% 8)) & 0x1))
377 (*data
)[i
] &= ~(0xff << RrDefaultAlphaOffset
);
379 di
+= xm
->bytes_per_line
;
This page took 0.050781 seconds and 4 git commands to generate.