]> icculus.org git repositories - dana/openbox.git/blob - render2/paint.c
larger default font, fits snugglier now
[dana/openbox.git] / render2 / paint.c
1 #include "render.h"
2 #include "surface.h"
3 #include "instance.h"
4 #include "debug.h"
5 #include <assert.h>
6 #include <stdlib.h>
7 #include <GL/glx.h>
8
9 void steal_children_exposes(struct RrInstance *inst, struct RrSurface *sur)
10 {
11     GSList *it;
12     XEvent e2;
13
14     for (it = sur->children; it; it = g_slist_next(it)) {
15         switch (RrSurfaceType(((struct RrSurface*)it->data))) {
16         case RR_SURFACE_NONE:
17             break;
18         case RR_SURFACE_PLANAR:
19             if (RrPlanarHasAlpha(((struct RrSurface*)it->data))) {
20                 while (XCheckTypedWindowEvent
21                        (RrDisplay(inst), Expose,
22                         ((struct RrSurface*)it->data)->win, &e2));
23                 steal_children_exposes(inst, it->data);
24             }
25             break;
26         case RR_SURFACE_NONPLANAR:
27             assert(0);
28         }
29     }
30 }
31
32 void RrExpose(struct RrInstance *inst, XExposeEvent *e)
33 {
34     XEvent e2;
35     struct RrSurface *sur;
36
37     g_message("Expose on %lx", e->window);
38
39     if ((sur = RrInstaceLookupSurface(inst, e->window))) {
40         while (1) {
41             struct RrSurface *p = NULL;
42
43             /* steal events along the way */
44             while (XCheckTypedWindowEvent(RrDisplay(inst), Expose,
45                                           sur->win, &e2));
46
47             switch (RrSurfaceType(sur)) {
48             case RR_SURFACE_NONE:
49                 break;
50             case RR_SURFACE_PLANAR:
51                 if (RrPlanarHasAlpha(sur))
52                     p = RrSurfaceParent(sur);
53                 break;
54             case RR_SURFACE_NONPLANAR:
55                 assert(0);
56             }
57
58             if (p) sur = p;
59             else break;
60         }
61         /* also do this for transparent children */
62         steal_children_exposes(inst, sur);
63         RrPaint(sur, 0);
64     } else
65         RrDebug("Unable to find surface for window 0x%lx\n", e->window);
66 }
67
68 /*! Paints the surface, and all its children */
69 void RrPaint(struct RrSurface *sur, int recurse_always)
70 {
71     struct RrInstance *inst;
72     struct RrSurface *p;
73     int ok, i;
74     int surx, sury;
75     int x, y, w, h, e;
76     GSList *it;
77
78     inst = RrSurfaceInstance(sur);
79
80     /* can't paint a prototype! */
81     assert(inst);
82     if (!inst) return;
83
84     if (!RrSurfaceVisible(sur)) return;
85
86     ok = glXMakeCurrent(RrDisplay(inst), RrSurfaceWindow(sur),RrContext(inst));
87     assert(ok);
88
89     glViewport(0, 0, RrScreenWidth(inst), RrScreenHeight(inst));
90 /*
91     glMatrixMode(GL_PROJECTION);
92     glLoadIdentity();
93     glOrtho(RrSurfaceX(sur), RrSurfaceX(sur) + RrSurfaceWidth(sur),
94             RrSurfaceY(sur), RrSurfaceY(sur) + RrSurfaceHeight(sur),
95             0, 10);
96     glMatrixMode(GL_MODELVIEW);
97     glViewport(0, 0, RrSurfaceWidth(sur), RrSurfaceHeight(sur));
98 */
99
100     glPushMatrix();
101     glTranslatef(-RrSurfaceX(sur), -RrSurfaceY(sur), 0);
102     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
103
104     p = sur;
105     surx = sury = 0;
106     while (p) {
107         surx += RrSurfaceX(p);
108         sury += RrSurfaceY(p);
109         p = p->parent;
110     }
111
112     switch (RrSurfaceType(sur)) {
113     case RR_SURFACE_PLANAR:
114         RrPlanarPaint(sur, surx, sury);
115         e = RrPlanarEdgeWidth(sur);
116         x = RrSurfaceX(sur) + e;
117         y = RrSurfaceY(sur) + e;
118         w = RrSurfaceWidth(sur) - e * 2;
119         h = RrSurfaceHeight(sur) - e * 2;
120         break;
121     case RR_SURFACE_NONPLANAR:
122         assert(0);
123         break;
124     case RR_SURFACE_NONE:
125         x = RrSurfaceX(sur);
126         y = RrSurfaceY(sur);
127         w = RrSurfaceWidth(sur);
128         h = RrSurfaceHeight(sur);
129         break;
130     }
131
132     for (i = 0; i < sur->ntextures; ++i)
133         RrTexturePaint(sur, &sur->texture[i], x, y, w, h);
134
135     glPopMatrix();
136
137     glXSwapBuffers(RrDisplay(inst), RrSurfaceWindow(sur));
138
139     /* recurse and paint children */
140     for (it = RrSurfaceChildren(sur); it; it = g_slist_next(it)) {
141         if (recurse_always)
142             RrPaint(it->data, 1);
143         else {
144             switch (RrSurfaceType(((struct RrSurface*)it->data))) {
145             case RR_SURFACE_NONE:
146                 break;
147             case RR_SURFACE_PLANAR:
148                 if (RrPlanarHasAlpha(it->data))
149                     RrPaint(it->data, 0);
150                 break;
151             case RR_SURFACE_NONPLANAR:
152                 assert(0);
153                 break;
154             }
155         }
156     }
157 }