]>
Dogcows Code - chaz/openbox/blob - render/render.c
18 static void RrPixel32_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 Rect 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
.RrPixel_data
);
49 l
->surface
.RrPixel_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
.RrPixel_data
+
57 l
->surface
.parentx
+ sw
* l
->surface
.parenty
);
58 dest
= l
->surface
.RrPixel_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 RrPixel32_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_MASK
:
104 if (l
->surface
.grad
!= RR_SURFACE_SOLID
)
105 RrPixel32_to_pixmap(l
, 0, 0, w
, h
);
107 if (l
->texture
[i
].data
.mask
.color
->gc
== None
)
108 RrColorAllocateGC(l
->texture
[i
].data
.mask
.color
);
109 RrPixmapMaskDraw(l
->pixmap
, &l
->texture
[i
].data
.mask
, &tarea
);
111 case RR_TEXTURE_RGBA
:
112 RrImageDraw(l
->surface
.RrPixel_data
,
113 &l
->texture
[i
].data
.rgba
, &tarea
);
120 if (l
->surface
.grad
!= RR_SURFACE_SOLID
)
121 RrPixel32_to_pixmap(l
, 0, 0, w
, h
);
125 XSetWindowBackgroundPixmap(RrDisplay(l
->inst
), win
, l
->pixmap
);
126 XClearWindow(RrDisplay(l
->inst
), win
);
127 if (oldp
) XFreePixmap(RrDisplay(l
->inst
), oldp
);
130 RrAppearance
*RrAppearanceNew(const RrInstance
*inst
, gint numtex
)
134 out
= g_new0(RrAppearance
, 1);
136 out
->textures
= numtex
;
137 if (numtex
) out
->texture
= g_new0(RrTexture
, numtex
);
142 RrAppearance
*RrAppearanceCopy(RrAppearance
*orig
)
144 RrSurface
*spo
, *spc
;
145 RrAppearance
*copy
= g_new(RrAppearance
, 1);
147 copy
->inst
= orig
->inst
;
149 spo
= &(orig
->surface
);
150 spc
= &(copy
->surface
);
151 spc
->grad
= spo
->grad
;
152 spc
->relief
= spo
->relief
;
153 spc
->bevel
= spo
->bevel
;
154 if (spo
->primary
!= NULL
)
155 spc
->primary
= RrColorNew(copy
->inst
,
159 else spc
->primary
= NULL
;
161 if (spo
->secondary
!= NULL
)
162 spc
->secondary
= RrColorNew(copy
->inst
,
166 else spc
->secondary
= NULL
;
168 if (spo
->border_color
!= NULL
)
169 spc
->border_color
= RrColorNew(copy
->inst
,
170 spo
->border_color
->r
,
171 spo
->border_color
->g
,
172 spo
->border_color
->b
);
173 else spc
->border_color
= NULL
;
175 if (spo
->bevel_dark
!= NULL
)
176 spc
->bevel_dark
= RrColorNew(copy
->inst
,
180 else spc
->bevel_dark
= NULL
;
182 if (spo
->bevel_light
!= NULL
)
183 spc
->bevel_light
= RrColorNew(copy
->inst
,
186 spo
->bevel_light
->b
);
187 else spc
->bevel_light
= NULL
;
189 spc
->interlaced
= spo
->interlaced
;
190 spc
->border
= spo
->border
;
191 spc
->RrPixel_data
= NULL
;
193 copy
->textures
= orig
->textures
;
194 copy
->texture
= g_memdup(orig
->texture
,
195 orig
->textures
* sizeof(RrTexture
));
197 copy
->xftdraw
= NULL
;
198 copy
->w
= copy
->h
= 0;
202 void RrAppearanceFree(RrAppearance
*a
)
206 if (a
->pixmap
!= None
) XFreePixmap(RrDisplay(a
->inst
), a
->pixmap
);
207 if (a
->xftdraw
!= NULL
) XftDrawDestroy(a
->xftdraw
);
211 RrColorFree(p
->primary
);
212 RrColorFree(p
->secondary
);
213 RrColorFree(p
->border_color
);
214 RrColorFree(p
->bevel_dark
);
215 RrColorFree(p
->bevel_light
);
216 g_free(p
->RrPixel_data
);
223 static void RrPixel32_to_pixmap(RrAppearance
*l
, gint x
, gint y
, gint w
, gint h
)
225 RrPixel32
*in
, *scratch
;
228 im
= XCreateImage(RrDisplay(l
->inst
), RrVisual(l
->inst
), RrDepth(l
->inst
),
229 ZPixmap
, 0, NULL
, w
, h
, 32, 0);
230 g_assert(im
!= NULL
);
232 in
= l
->surface
.RrPixel_data
;
235 im
->byte_order
= RrEndian
;
236 /* this malloc is a complete waste of time on normal 32bpp
237 as reduce_depth just sets im->data = data and returns
239 scratch
= g_new(RrPixel32
, im
->width
* im
->height
);
240 im
->data
= (char*) scratch
;
241 RrReduceDepth(l
->inst
, in
, im
);
242 XPutImage(RrDisplay(l
->inst
), out
,
243 DefaultGC(RrDisplay(l
->inst
), RrScreen(l
->inst
)),
244 im
, 0, 0, x
, y
, w
, h
);
250 void RrMinsize(RrAppearance
*l
, gint
*w
, gint
*h
)
256 for (i
= 0; i
< l
->textures
; ++i
) {
257 switch (l
->texture
[i
].type
) {
258 case RR_TEXTURE_NONE
:
260 case RR_TEXTURE_MASK
:
261 *w
= MAX(*w
, l
->texture
[i
].data
.mask
.mask
->width
);
262 *h
= MAX(*h
, l
->texture
[i
].data
.mask
.mask
->height
);
264 case RR_TEXTURE_TEXT
:
265 m
= RrFontMeasureString(l
->texture
[i
].data
.text
.font
,
266 l
->texture
[i
].data
.text
.string
,
267 l
->texture
[i
].data
.text
.shadow
,
268 l
->texture
[i
].data
.text
.offset
);
270 m
= RrFontHeight(l
->texture
[i
].data
.text
.font
,
271 l
->texture
[i
].data
.text
.shadow
,
272 l
->texture
[i
].data
.text
.offset
);
275 case RR_TEXTURE_RGBA
:
276 *w
+= MAX(*w
, l
->texture
[i
].data
.rgba
.width
);
277 *h
+= MAX(*h
, l
->texture
[i
].data
.rgba
.height
);
282 if (l
->surface
.relief
!= RR_RELIEF_FLAT
) {
283 switch (l
->surface
.bevel
) {
293 } else if (l
->surface
.border
) {
302 gboolean
RrPixmapToRGBA(const RrInstance
*inst
,
303 Pixmap pmap
, Pixmap mask
,
304 gint
*w
, gint
*h
, RrPixel32
**data
)
308 guint pw
, ph
, mw
, mh
, xb
, xd
, i
, x
, y
, di
;
309 XImage
*xi
, *xm
= NULL
;
311 if (!XGetGeometry(RrDisplay(inst
),
312 pmap
, &xr
, &xx
, &xy
, &pw
, &ph
, &xb
, &xd
))
315 if (!XGetGeometry(RrDisplay(inst
), mask
,
316 &xr
, &xx
, &xy
, &mw
, &mh
, &xb
, &xd
))
318 if (pw
!= mw
|| ph
!= mh
|| xd
!= 1)
322 xi
= XGetImage(RrDisplay(inst
), pmap
,
323 0, 0, pw
, ph
, 0xffffffff, ZPixmap
);
328 xm
= XGetImage(RrDisplay(inst
), mask
,
329 0, 0, mw
, mh
, 0xffffffff, ZPixmap
);
334 *data
= g_new(RrPixel32
, pw
* ph
);
335 RrIncreaseDepth(inst
, *data
, xi
);
338 /* apply transparency from the mask */
340 for (i
= 0, y
= 0; y
< ph
; ++y
) {
341 for (x
= 0; x
< pw
; ++x
, ++i
) {
342 if (!((((unsigned)xm
->data
[di
+ x
/ 8]) >> (x
% 8)) & 0x1))
343 (*data
)[i
] &= ~(0xff << RrDefaultAlphaOffset
);
345 di
+= xm
->bytes_per_line
;
This page took 0.056877 seconds and 4 git commands to generate.