]> icculus.org git repositories - dana/openbox.git/blob - render2/paint.c
fix a seg, fix the loop for rendering a string
[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 struct ExposeArea {
10     struct RrSurface *sur;
11     int x;
12     int y;
13     int w;
14     int h;
15 };
16
17 #define MERGE_AREA(a, x, y, w, h) \
18             a->w = MAX(a->x + a->w - 1, x + w - 1) - MIN(a->x, x), \
19             a->h = MAX(a->y + a->h - 1, y + h - 1) - MIN(a->y, y), \
20             a->x = MIN(a->x, x), \
21             a->y = MIN(a->y, y)
22
23
24 void RrExpose(struct RrInstance *inst, XExposeEvent *e)
25 {
26     XEvent e2;
27     struct RrSurface *sur;
28     Window win;
29
30     win = e->window;
31
32     if ((sur = RrInstaceLookupSurface(inst, win))) {
33         while (XCheckTypedWindowEvent(RrDisplay(inst), Expose, win, &e2));
34         while (sur->parent && RrSurfaceType(sur->parent) != RR_SURFACE_NONE)
35             sur = sur->parent;
36         RrPaint(sur);
37     } else
38         RrDebug("Unable to find surface for window 0x%lx\n", win);
39 }
40
41 /*! Paints the surface, and all its children */
42 void RrPaint(struct RrSurface *sur)
43 {
44     struct RrInstance *inst;
45     struct RrSurface *p;
46     int ok;
47     int surx, sury;
48     GSList *it;
49
50     inst = RrSurfaceInstance(sur);
51
52     /* can't paint a prototype! */
53     assert(inst);
54     if (!inst) return;
55
56     if (!RrSurfaceVisible(sur)) return;
57
58     /* recurse and paint children */
59     for (it = RrSurfaceChildren(sur); it; it = g_slist_next(it))
60         RrPaint(it->data);
61
62     RrDebug("making %p, %p, %p current\n",
63             RrDisplay(inst), RrSurfaceWindow(sur), RrContext(inst));
64
65     ok = glXMakeCurrent(RrDisplay(inst), RrSurfaceWindow(sur),RrContext(inst));
66     assert(ok);
67
68     glMatrixMode(GL_MODELVIEW);
69     glLoadIdentity();
70     glMatrixMode(GL_PROJECTION);
71     glLoadIdentity();
72
73     glOrtho(0, RrScreenWidth(inst), RrScreenHeight(inst), 0, 0, 10);
74     glViewport(0, 0, RrScreenWidth(inst), RrScreenHeight(inst));
75     glMatrixMode(GL_MODELVIEW);
76     glTranslatef(-RrSurfaceX(sur),
77                  RrScreenHeight(inst)-RrSurfaceHeight(sur)-RrSurfaceY(sur), 0);
78     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
79
80     p = sur;
81     surx = sury = 0;
82     while (p) {
83         surx += RrSurfaceX(p);
84         sury += RrSurfaceY(p);
85         p = p->parent;
86     }
87
88     switch (RrSurfaceType(sur)) {
89     case RR_SURFACE_PLANAR:
90         RrPlanarPaint(sur, surx, sury);
91         break;
92     case RR_SURFACE_NONPLANAR:
93         assert(0);
94         break;
95     case RR_SURFACE_NONE:
96         break;
97     }
98
99     glXSwapBuffers(RrDisplay(inst), RrSurfaceWindow(sur));
100 }