7 #include <X11/extensions/shape.h>
10 /* doesn't set win or parent */
11 static struct RrSurface *surface_new(enum RrSurfaceType type,
14 struct RrSurface *sur;
16 sur = malloc(sizeof(struct RrSurface));
18 sur->shape_base = None;
19 sur->shape_base_x = 0;
20 sur->shape_base_y = 0;
21 sur->ntextures = numtex;
23 sur->texture = malloc(sizeof(struct RrTexture) * numtex);
24 memset(sur->texture, 0, sizeof(struct RrTexture) * numtex);
36 static Window create_window(struct RrInstance *inst, Window parent)
38 XSetWindowAttributes attrib;
41 attrib.event_mask = ExposureMask;
42 win = XCreateWindow(RrDisplay(inst), parent, 0, 0, 1, 1, 0,
43 RrDepth(inst), InputOutput, RrVisual(inst),
44 CWEventMask, &attrib);
48 struct RrSurface *RrSurfaceNewProto(enum RrSurfaceType type,
51 struct RrSurface *sur;
53 sur = surface_new(type, numtex);
61 struct RrSurface *RrSurfaceNew(struct RrInstance *inst,
62 enum RrSurfaceType type,
66 struct RrSurface *sur;
68 sur = surface_new(type, numtex);
74 RrInstaceAddSurface(sur);
78 struct RrSurface *RrSurfaceNewChild(enum RrSurfaceType type,
79 struct RrSurface *parent,
82 struct RrSurface *sur;
84 /* can't be a child of a prototype! */
86 if (!parent->inst) return NULL;
88 sur = surface_new(type, numtex);
89 sur->inst = parent->inst;
90 sur->win = create_window(sur->inst, parent->win);
94 parent->children = g_slist_append(parent->children, sur);
96 RrInstaceAddSurface(sur);
100 /* doesn't set win or parent */
101 static struct RrSurface *surface_copy(struct RrSurface *orig)
103 struct RrSurface *sur;
105 sur = malloc(sizeof(struct RrSurface));
106 sur->type = orig->type;
108 case RR_SURFACE_PLANAR:
109 sur->data = orig->data;
111 case RR_SURFACE_NONPLANAR:
114 case RR_SURFACE_NONE:
117 sur->ntextures = orig->ntextures;
118 sur->texture = malloc(sizeof(struct RrTexture) * sur->ntextures);
119 memcpy(sur->texture, orig->texture,
120 sizeof(struct RrTexture) * sur->ntextures);
124 struct RrSurface *RrSurfaceCopy(struct RrInstance *inst,
125 struct RrSurface *orig,
128 struct RrSurface *sur;
130 sur = surface_copy(orig);
136 RrInstaceAddSurface(sur);
140 struct RrSurface *RrSurfaceCopyChild(struct RrSurface *orig,
141 struct RrSurface *parent)
143 struct RrSurface *sur;
145 /* can't be a child of a prototype! */
146 assert(parent->inst);
147 if (!parent->inst) return NULL;
149 sur = surface_copy(orig);
150 sur->inst = parent->inst;
151 sur->win = create_window(sur->inst, parent->win);
152 sur->parent = parent;
155 parent->children = g_slist_append(parent->children, sur);
157 RrInstaceAddSurface(sur);
161 void RrSurfaceFree(struct RrSurface *sur)
166 sur->parent->children = g_slist_remove(sur->parent->children, sur);
168 RrInstaceRemoveSurface(sur);
169 for (i = 0; i < sur->ntextures; ++i)
170 RrTextureFreeContents(&sur->texture[i]);
173 if (sur->parent && sur->win)
174 XDestroyWindow(RrDisplay(sur->inst), sur->win);
179 void RrSurfaceSetPos(struct RrSurface *sur,
183 RrSurfaceSetArea(sur, x, y, sur->w, sur->h);
186 void RrSurfaceSetSize(struct RrSurface *sur,
190 RrSurfaceSetArea(sur, sur->x, sur->y, w, h);
193 void RrSurfaceSetArea(struct RrSurface *sur,
199 assert(w > 0 && h > 0);
200 if (!(w > 0 && h > 0)) return;
207 XMoveResizeWindow(RrDisplay(sur->inst), sur->win, x, y, w, h);
210 Window RrSurfaceWindow(struct RrSurface *sur)
212 /* can't get a window for a prototype */
214 if (!sur->inst) return None;
219 struct RrTexture *RrSurfaceTexture(struct RrSurface *sur, int texnum)
221 assert(texnum < sur->ntextures);
222 return &(sur->texture[texnum]);
225 void RrSurfaceMinSize(struct RrSurface *sur, int *w, int *h)
231 case RR_SURFACE_NONE:
234 case RR_SURFACE_PLANAR:
235 RrPlanarMinSize(sur, w, h);
237 case RR_SURFACE_NONPLANAR:
243 for (i = 0; i < sur->ntextures; ++i) {
244 switch (sur->texture[i].type) {
245 case RR_TEXTURE_NONE:
249 case RR_TEXTURE_TEXT:
250 /* XXX MEASUER STRING PLS */
251 minw = MAX(minw, 100 /*MEASURESTRING*/);
252 minh = MAX(minh, 10 /*HEIGHTOFFONT*/);
254 case RR_TEXTURE_RGBA:
255 minw = MAX(minw, (sur->texture[i].data.rgba.x +
256 sur->texture[i].data.rgba.w));
257 minh = MAX(minw, (sur->texture[i].data.rgba.y +
258 sur->texture[i].data.rgba.h));
270 void RrSurfaceShow(struct RrSurface *sur)
274 XMapWindow(RrDisplay(sur->inst), sur->win);
277 void RrSurfaceHide(struct RrSurface *sur)
281 XUnmapWindow(RrDisplay(sur->inst), sur->win);
284 int RrSurfaceVisible(struct RrSurface *sur)
290 void RrSurfaceShapeSetBase(struct RrSurface *sur, Window base, int x, int y)
293 sur->shape_base = base;
294 sur->shape_base_x = x;
295 sur->shape_base_y = y;
298 void RrSurfaceShape(struct RrSurface *sur)
305 XResizeWindow(RrDisplay(sur->inst), RrShapeWindow(sur->inst),
307 XShapeCombineShape(RrDisplay(sur->inst), RrShapeWindow(sur->inst),
309 sur->shape_base_x, sur->shape_base_y,
310 sur->shape_base, ShapeBounding, ShapeSet);
311 /* include the shape of the children */
312 for (it = sur->children; it; it = g_slist_next(it)) {
313 struct RrSurface *ch = it->data;
315 XShapeCombineShape(RrDisplay(sur->inst),
316 RrShapeWindow(sur->inst),
317 ShapeBounding, ch->x, ch->y, ch->win,
318 ShapeBounding, ShapeUnion);
321 case RR_SURFACE_NONE:
323 case RR_SURFACE_PLANAR:
324 /* XXX shape me based on something! an alpha mask? */
326 case RR_SURFACE_NONPLANAR:
327 /* XXX shape me based on my GL form! */
332 /* apply the final shape */
333 XShapeCombineShape(RrDisplay(sur->inst), sur->win, ShapeBounding, 0, 0,
334 RrShapeWindow(sur->inst), ShapeBounding, ShapeSet);