]>
Dogcows Code - chaz/openbox/blob - render/render.c
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
));
67 RECT_SET(tarea
, 0, 0, w
, h
);
68 if (l
->surface
.grad
!= RR_SURFACE_PARENTREL
) {
69 if (l
->surface
.relief
!= RR_RELIEF_FLAT
) {
70 switch (l
->surface
.bevel
) {
72 tarea
.x
+= 1; tarea
.y
+= 1;
73 tarea
.width
-= 2; tarea
.height
-= 2;
76 tarea
.x
+= 2; tarea
.y
+= 2;
77 tarea
.width
-= 4; tarea
.height
-= 4;
80 } else if (l
->surface
.border
) {
81 tarea
.x
+= 1; tarea
.y
+= 1;
82 tarea
.width
-= 2; tarea
.height
-= 2;
86 for (i
= 0; i
< l
->textures
; i
++) {
87 switch (l
->texture
[i
].type
) {
93 if (l
->surface
.grad
!= RR_SURFACE_SOLID
)
94 RrPixel32_to_pixmap(l
, 0, 0, w
, h
);
96 if (l
->xftdraw
== NULL
) {
97 l
->xftdraw
= XftDrawCreate(RrDisplay(l
->inst
), l
->pixmap
,
101 RrFontDraw(l
->xftdraw
, &l
->texture
[i
].data
.text
, &tarea
);
103 case RR_TEXTURE_MASK
:
106 if (l
->surface
.grad
!= RR_SURFACE_SOLID
)
107 RrPixel32_to_pixmap(l
, 0, 0, w
, h
);
109 if (l
->texture
[i
].data
.mask
.color
->gc
== None
)
110 RrColorAllocateGC(l
->texture
[i
].data
.mask
.color
);
111 RrPixmapMaskDraw(l
->pixmap
, &l
->texture
[i
].data
.mask
, &tarea
);
113 case RR_TEXTURE_RGBA
:
114 RrImageDraw(l
->surface
.RrPixel_data
,
115 &l
->texture
[i
].data
.rgba
, &tarea
);
122 if (l
->surface
.grad
!= RR_SURFACE_SOLID
)
123 RrPixel32_to_pixmap(l
, 0, 0, w
, h
);
127 XSetWindowBackgroundPixmap(RrDisplay(l
->inst
), win
, l
->pixmap
);
128 XClearWindow(RrDisplay(l
->inst
), win
);
129 if (oldp
) XFreePixmap(RrDisplay(l
->inst
), oldp
);
132 RrAppearance
*RrAppearanceNew(const RrInstance
*inst
, gint numtex
)
136 out
= g_new0(RrAppearance
, 1);
138 out
->textures
= numtex
;
139 if (numtex
) out
->texture
= g_new0(RrTexture
, numtex
);
144 RrAppearance
*RrAppearanceCopy(RrAppearance
*orig
)
146 RrSurface
*spo
, *spc
;
147 RrAppearance
*copy
= g_new(RrAppearance
, 1);
149 copy
->inst
= orig
->inst
;
151 spo
= &(orig
->surface
);
152 spc
= &(copy
->surface
);
153 spc
->grad
= spo
->grad
;
154 spc
->relief
= spo
->relief
;
155 spc
->bevel
= spo
->bevel
;
156 if (spo
->primary
!= NULL
)
157 spc
->primary
= RrColorNew(copy
->inst
,
161 else spc
->primary
= NULL
;
163 if (spo
->secondary
!= NULL
)
164 spc
->secondary
= RrColorNew(copy
->inst
,
168 else spc
->secondary
= NULL
;
170 if (spo
->border_color
!= NULL
)
171 spc
->border_color
= RrColorNew(copy
->inst
,
172 spo
->border_color
->r
,
173 spo
->border_color
->g
,
174 spo
->border_color
->b
);
175 else spc
->border_color
= NULL
;
177 if (spo
->bevel_dark
!= NULL
)
178 spc
->bevel_dark
= RrColorNew(copy
->inst
,
182 else spc
->bevel_dark
= NULL
;
184 if (spo
->bevel_light
!= NULL
)
185 spc
->bevel_light
= RrColorNew(copy
->inst
,
188 spo
->bevel_light
->b
);
189 else spc
->bevel_light
= NULL
;
191 spc
->interlaced
= spo
->interlaced
;
192 spc
->border
= spo
->border
;
193 spc
->RrPixel_data
= NULL
;
195 copy
->textures
= orig
->textures
;
196 copy
->texture
= g_memdup(orig
->texture
,
197 orig
->textures
* sizeof(RrTexture
));
199 copy
->xftdraw
= NULL
;
200 copy
->w
= copy
->h
= 0;
204 void RrAppearanceFree(RrAppearance
*a
)
208 if (a
->pixmap
!= None
) XFreePixmap(RrDisplay(a
->inst
), a
->pixmap
);
209 if (a
->xftdraw
!= NULL
) XftDrawDestroy(a
->xftdraw
);
213 RrColorFree(p
->primary
);
214 RrColorFree(p
->secondary
);
215 RrColorFree(p
->border_color
);
216 RrColorFree(p
->bevel_dark
);
217 RrColorFree(p
->bevel_light
);
218 g_free(p
->RrPixel_data
);
225 static void RrPixel32_to_pixmap(RrAppearance
*l
, gint x
, gint y
, gint w
, gint h
)
227 RrPixel32
*in
, *scratch
;
230 im
= XCreateImage(RrDisplay(l
->inst
), RrVisual(l
->inst
), RrDepth(l
->inst
),
231 ZPixmap
, 0, NULL
, w
, h
, 32, 0);
232 g_assert(im
!= NULL
);
234 in
= l
->surface
.RrPixel_data
;
237 im
->byte_order
= RrEndian
;
238 /* this malloc is a complete waste of time on normal 32bpp
239 as reduce_depth just sets im->data = data and returns
241 scratch
= g_new(RrPixel32
, im
->width
* im
->height
);
242 im
->data
= (char*) scratch
;
243 RrReduceDepth(l
->inst
, in
, im
);
244 XPutImage(RrDisplay(l
->inst
), out
,
245 DefaultGC(RrDisplay(l
->inst
), RrScreen(l
->inst
)),
246 im
, 0, 0, x
, y
, w
, h
);
252 void RrMinsize(RrAppearance
*l
, gint
*w
, gint
*h
)
258 for (i
= 0; i
< l
->textures
; ++i
) {
259 switch (l
->texture
[i
].type
) {
260 case RR_TEXTURE_NONE
:
262 case RR_TEXTURE_MASK
:
263 *w
= MAX(*w
, l
->texture
[i
].data
.mask
.mask
->width
);
264 *h
= MAX(*h
, l
->texture
[i
].data
.mask
.mask
->height
);
266 case RR_TEXTURE_TEXT
:
267 m
= RrFontMeasureString(l
->texture
[i
].data
.text
.font
,
268 l
->texture
[i
].data
.text
.string
,
269 l
->texture
[i
].data
.text
.shadow
,
270 l
->texture
[i
].data
.text
.offset
);
272 m
= RrFontHeight(l
->texture
[i
].data
.text
.font
,
273 l
->texture
[i
].data
.text
.shadow
,
274 l
->texture
[i
].data
.text
.offset
);
277 case RR_TEXTURE_RGBA
:
278 *w
+= MAX(*w
, l
->texture
[i
].data
.rgba
.width
);
279 *h
+= MAX(*h
, l
->texture
[i
].data
.rgba
.height
);
284 if (l
->surface
.relief
!= RR_RELIEF_FLAT
) {
285 switch (l
->surface
.bevel
) {
295 } else if (l
->surface
.border
) {
304 gboolean
RrPixmapToRGBA(const RrInstance
*inst
,
305 Pixmap pmap
, Pixmap mask
,
306 gint
*w
, gint
*h
, RrPixel32
**data
)
310 guint pw
, ph
, mw
, mh
, xb
, xd
, i
, x
, y
, di
;
311 XImage
*xi
, *xm
= NULL
;
313 if (!XGetGeometry(RrDisplay(inst
),
314 pmap
, &xr
, &xx
, &xy
, &pw
, &ph
, &xb
, &xd
))
317 if (!XGetGeometry(RrDisplay(inst
), mask
,
318 &xr
, &xx
, &xy
, &mw
, &mh
, &xb
, &xd
))
320 if (pw
!= mw
|| ph
!= mh
|| xd
!= 1)
324 xi
= XGetImage(RrDisplay(inst
), pmap
,
325 0, 0, pw
, ph
, 0xffffffff, ZPixmap
);
330 xm
= XGetImage(RrDisplay(inst
), mask
,
331 0, 0, mw
, mh
, 0xffffffff, ZPixmap
);
336 *data
= g_new(RrPixel32
, pw
* ph
);
337 RrIncreaseDepth(inst
, *data
, xi
);
340 /* apply transparency from the mask */
342 for (i
= 0, y
= 0; y
< ph
; ++y
) {
343 for (x
= 0; x
< pw
; ++x
, ++i
) {
344 if (!((((unsigned)xm
->data
[di
+ x
/ 8]) >> (x
% 8)) & 0x1))
345 (*data
)[i
] &= ~(0xff << RrDefaultAlphaOffset
);
347 di
+= xm
->bytes_per_line
;
This page took 0.048365 seconds and 4 git commands to generate.