]>
Dogcows Code - chaz/openbox/blob - render/render.c
5d444703e1a8afb1322fe8f39077eb7e6fd44995
18 static void RrPixel32_to_pixmap(RrAppearance
*l
, gint x
, gint y
, gint w
, gint h
);
20 void RrPaint(RrAppearance
*l
, Window win
, gint w
, gint h
)
22 int i
, transferred
= 0, sw
;
23 RrPixel32
*source
, *dest
;
25 Rect tarea
; /* area in which to draw textures */
28 if (w
<= 0 || h
<= 0) return;
30 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
));
40 g_assert(l
->pixmap
!= None
);
44 if (l
->xftdraw
!= NULL
)
45 XftDrawDestroy(l
->xftdraw
);
46 l
->xftdraw
= XftDrawCreate(RrDisplay(l
->inst
), l
->pixmap
,
47 RrVisual(l
->inst
), RrColormap(l
->inst
));
48 g_assert(l
->xftdraw
!= NULL
);
50 g_free(l
->surface
.RrPixel_data
);
51 l
->surface
.RrPixel_data
= g_new(RrPixel32
, w
* h
);
53 if (l
->surface
.grad
== RR_SURFACE_PARENTREL
) {
54 g_assert (l
->surface
.parent
);
55 g_assert (l
->surface
.parent
->w
);
57 sw
= l
->surface
.parent
->w
;
58 source
= (l
->surface
.parent
->surface
.RrPixel_data
+ l
->surface
.parentx
+
59 sw
* l
->surface
.parenty
);
60 dest
= l
->surface
.RrPixel_data
;
61 for (i
= 0; i
< h
; i
++, source
+= sw
, dest
+= w
) {
62 memcpy(dest
, source
, w
* sizeof(RrPixel32
));
64 } else if (l
->surface
.grad
== RR_SURFACE_SOLID
)
65 gradient_solid(l
, 0, 0, w
, h
);
67 gradient_render(&l
->surface
, w
, h
);
69 RECT_SET(tarea
, 0, 0, w
, h
);
70 if (l
->surface
.grad
!= RR_SURFACE_PARENTREL
) {
71 if (l
->surface
.relief
!= RR_RELIEF_FLAT
) {
72 switch (l
->surface
.bevel
) {
74 tarea
.x
+= 1; tarea
.y
+= 1;
75 tarea
.width
-= 2; tarea
.height
-= 2;
78 tarea
.x
+= 2; tarea
.y
+= 2;
79 tarea
.width
-= 4; tarea
.height
-= 4;
82 } else if (l
->surface
.border
) {
83 tarea
.x
+= 1; tarea
.y
+= 1;
84 tarea
.width
-= 2; tarea
.height
-= 2;
88 for (i
= 0; i
< l
->textures
; i
++) {
89 switch (l
->texture
[i
].type
) {
95 if (l
->surface
.grad
!= RR_SURFACE_SOLID
)
96 RrPixel32_to_pixmap(l
, 0, 0, w
, h
);
98 if (l
->xftdraw
== NULL
) {
99 l
->xftdraw
= XftDrawCreate(RrDisplay(l
->inst
), l
->pixmap
,
101 RrColormap(l
->inst
));
103 RrFontDraw(l
->xftdraw
, &l
->texture
[i
].data
.text
, &tarea
);
105 case RR_TEXTURE_MASK
:
108 if (l
->surface
.grad
!= RR_SURFACE_SOLID
)
109 RrPixel32_to_pixmap(l
, 0, 0, w
, h
);
111 if (l
->texture
[i
].data
.mask
.color
->gc
== None
)
112 color_allocate_gc(l
->texture
[i
].data
.mask
.color
);
113 RrPixmapMaskDraw(l
->pixmap
, &l
->texture
[i
].data
.mask
, &tarea
);
115 case RR_TEXTURE_RGBA
:
116 RrImageDraw(l
->surface
.RrPixel_data
,
117 &l
->texture
[i
].data
.rgba
, &tarea
);
124 if (l
->surface
.grad
!= RR_SURFACE_SOLID
)
125 RrPixel32_to_pixmap(l
, 0, 0, w
, h
);
129 XSetWindowBackgroundPixmap(RrDisplay(l
->inst
), win
, l
->pixmap
);
130 XClearWindow(RrDisplay(l
->inst
), win
);
131 if (oldp
) XFreePixmap(RrDisplay(l
->inst
), oldp
);
134 RrAppearance
*RrAppearanceNew(const RrInstance
*inst
, gint numtex
)
138 out
= g_new0(RrAppearance
, 1);
140 out
->textures
= numtex
;
141 if (numtex
) out
->texture
= g_new0(RrTexture
, numtex
);
146 RrAppearance
*RrAppearanceCopy(RrAppearance
*orig
)
148 RrSurface
*spo
, *spc
;
149 RrAppearance
*copy
= g_new(RrAppearance
, 1);
151 copy
->inst
= orig
->inst
;
153 spo
= &(orig
->surface
);
154 spc
= &(copy
->surface
);
155 spc
->grad
= spo
->grad
;
156 spc
->relief
= spo
->relief
;
157 spc
->bevel
= spo
->bevel
;
158 if (spo
->primary
!= NULL
)
159 spc
->primary
= RrColorNew(copy
->inst
,
163 else spc
->primary
= NULL
;
165 if (spo
->secondary
!= NULL
)
166 spc
->secondary
= RrColorNew(copy
->inst
,
170 else spc
->secondary
= NULL
;
172 if (spo
->border_color
!= NULL
)
173 spc
->border_color
= RrColorNew(copy
->inst
,
174 spo
->border_color
->r
,
175 spo
->border_color
->g
,
176 spo
->border_color
->b
);
177 else spc
->border_color
= NULL
;
179 if (spo
->bevel_dark
!= NULL
)
180 spc
->bevel_dark
= RrColorNew(copy
->inst
,
184 else spc
->bevel_dark
= NULL
;
186 if (spo
->bevel_light
!= NULL
)
187 spc
->bevel_light
= RrColorNew(copy
->inst
,
190 spo
->bevel_light
->b
);
191 else spc
->bevel_light
= NULL
;
193 spc
->interlaced
= spo
->interlaced
;
194 spc
->border
= spo
->border
;
195 spc
->RrPixel_data
= NULL
;
197 copy
->textures
= orig
->textures
;
198 copy
->texture
= g_memdup(orig
->texture
,
199 orig
->textures
* sizeof(RrTexture
));
201 copy
->xftdraw
= NULL
;
202 copy
->w
= copy
->h
= 0;
206 void RrAppearanceFree(RrAppearance
*a
)
210 if (a
->pixmap
!= None
) XFreePixmap(RrDisplay(a
->inst
), a
->pixmap
);
211 if (a
->xftdraw
!= NULL
) XftDrawDestroy(a
->xftdraw
);
215 RrColorFree(p
->primary
);
216 RrColorFree(p
->secondary
);
217 RrColorFree(p
->border_color
);
218 RrColorFree(p
->bevel_dark
);
219 RrColorFree(p
->bevel_light
);
220 g_free(p
->RrPixel_data
);
227 static void RrPixel32_to_pixmap(RrAppearance
*l
, gint x
, gint y
, gint w
, gint h
)
229 RrPixel32
*in
, *scratch
;
232 im
= XCreateImage(RrDisplay(l
->inst
), RrVisual(l
->inst
), RrDepth(l
->inst
),
233 ZPixmap
, 0, NULL
, w
, h
, 32, 0);
234 g_assert(im
!= NULL
);
236 in
= l
->surface
.RrPixel_data
;
239 im
->byte_order
= RrEndian
;
240 /* this malloc is a complete waste of time on normal 32bpp
241 as reduce_depth just sets im->data = data and returns
243 scratch
= g_new(RrPixel32
, im
->width
* im
->height
);
244 im
->data
= (char*) scratch
;
245 reduce_depth(l
->inst
, in
, im
);
246 XPutImage(RrDisplay(l
->inst
), out
,
247 DefaultGC(RrDisplay(l
->inst
), RrScreen(l
->inst
)),
248 im
, 0, 0, x
, y
, w
, h
);
254 void RrMinsize(RrAppearance
*l
, gint
*w
, gint
*h
)
260 for (i
= 0; i
< l
->textures
; ++i
) {
261 switch (l
->texture
[i
].type
) {
262 case RR_TEXTURE_NONE
:
264 case RR_TEXTURE_MASK
:
265 *w
= MAX(*w
, l
->texture
[i
].data
.mask
.mask
->width
);
266 *h
= MAX(*h
, l
->texture
[i
].data
.mask
.mask
->height
);
268 case RR_TEXTURE_TEXT
:
269 m
= RrFontMeasureString(l
->texture
[i
].data
.text
.font
,
270 l
->texture
[i
].data
.text
.string
,
271 l
->texture
[i
].data
.text
.shadow
,
272 l
->texture
[i
].data
.text
.offset
);
274 m
= RrFontHeight(l
->texture
[i
].data
.text
.font
,
275 l
->texture
[i
].data
.text
.shadow
,
276 l
->texture
[i
].data
.text
.offset
);
279 case RR_TEXTURE_RGBA
:
280 *w
+= MAX(*w
, l
->texture
[i
].data
.rgba
.width
);
281 *h
+= MAX(*h
, l
->texture
[i
].data
.rgba
.height
);
286 if (l
->surface
.relief
!= RR_RELIEF_FLAT
) {
287 switch (l
->surface
.bevel
) {
297 } else if (l
->surface
.border
) {
306 gboolean
RrPixmapToRGBA(const RrInstance
*inst
,
307 Pixmap pmap
, Pixmap mask
,
308 gint
*w
, gint
*h
, RrPixel32
**data
)
312 guint pw
, ph
, mw
, mh
, xb
, xd
, i
, x
, y
, di
;
313 XImage
*xi
, *xm
= NULL
;
315 if (!XGetGeometry(RrDisplay(inst
),
316 pmap
, &xr
, &xx
, &xy
, &pw
, &ph
, &xb
, &xd
))
319 if (!XGetGeometry(RrDisplay(inst
), mask
,
320 &xr
, &xx
, &xy
, &mw
, &mh
, &xb
, &xd
))
322 if (pw
!= mw
|| ph
!= mh
|| xd
!= 1)
326 xi
= XGetImage(RrDisplay(inst
), pmap
,
327 0, 0, pw
, ph
, 0xffffffff, ZPixmap
);
332 xm
= XGetImage(RrDisplay(inst
), mask
,
333 0, 0, mw
, mh
, 0xffffffff, ZPixmap
);
338 *data
= g_new(RrPixel32
, pw
* ph
);
339 increase_depth(inst
, *data
, xi
);
342 /* apply transparency from the mask */
344 for (i
= 0, y
= 0; y
< ph
; ++y
) {
345 for (x
= 0; x
< pw
; ++x
, ++i
) {
346 if (!((((unsigned)xm
->data
[di
+ x
/ 8]) >> (x
% 8)) & 0x1))
347 (*data
)[i
] &= ~(0xff << RrDefaultAlphaOffset
);
349 di
+= xm
->bytes_per_line
;
This page took 0.055186 seconds and 4 git commands to generate.