From d353bed451f1d1b68c441c51b36ed358130fb67f Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Tue, 3 Jun 2003 19:58:09 +0000 Subject: [PATCH] rendering fixes for gl --- render2/instance.c | 7 ++++--- render2/paint.c | 50 +++++++++++++++++++++++++++++++++++++--------- render2/planar.c | 18 +++++++++-------- render2/planar.h | 2 ++ render2/render.h | 4 ++-- render2/surface.c | 23 ++++++++++++++++----- render2/test.c | 2 +- render2/theme.c | 11 +++++++++- render2/theme.h | 3 +++ 9 files changed, 91 insertions(+), 29 deletions(-) diff --git a/render2/instance.c b/render2/instance.c index 311a86e0..996344f6 100644 --- a/render2/instance.c +++ b/render2/instance.c @@ -97,9 +97,10 @@ struct RrInstance *RrInstanceNew(Display *display, int screen) RrVisual(inst), AllocNone); inst->glx_context = glXCreateContext(display, &vilist[best], NULL, True); - inst->shape_window = XCreateSimpleWindow(display, - RootWindow(display, screen), - 0, 0, 1, 1, 0, 0, 0); + inst->shape_window = XCreateWindow(display,RootWindow(display, screen), + 0, 0, 1, 1, 0, + RrInstanceDepth(inst), InputOutput, + RrInstanceVisual(inst), 0, NULL); /* make the context current on anything we can so we can dl textures */ diff --git a/render2/paint.c b/render2/paint.c index 135ae79e..dbdff140 100644 --- a/render2/paint.c +++ b/render2/paint.c @@ -30,16 +30,33 @@ void RrExpose(struct RrInstance *inst, XExposeEvent *e) win = e->window; if ((sur = RrInstaceLookupSurface(inst, win))) { - while (XCheckTypedWindowEvent(RrDisplay(inst), Expose, win, &e2)); - while (sur->parent && RrSurfaceType(sur->parent) != RR_SURFACE_NONE) - sur = sur->parent; - RrPaint(sur); + while (1) { + struct RrSurface *p = NULL; + + while (XCheckTypedWindowEvent(RrDisplay(inst), Expose, + sur->win, &e2)); + + switch (RrSurfaceType(sur)) { + case RR_SURFACE_NONE: + break; + case RR_SURFACE_PLANAR: + if (RrPlanarHasAlpha(sur)) + p = RrSurfaceParent(sur); + break; + case RR_SURFACE_NONPLANAR: + assert(0); + } + + if (p) sur = p; + else break; + } + RrPaint(sur, 0); } else RrDebug("Unable to find surface for window 0x%lx\n", win); } /*! Paints the surface, and all its children */ -void RrPaint(struct RrSurface *sur) +void RrPaint(struct RrSurface *sur, int recurse_always) { struct RrInstance *inst; struct RrSurface *p; @@ -55,10 +72,6 @@ void RrPaint(struct RrSurface *sur) if (!RrSurfaceVisible(sur)) return; - /* recurse and paint children */ - for (it = RrSurfaceChildren(sur); it; it = g_slist_next(it)) - RrPaint(it->data); - ok = glXMakeCurrent(RrDisplay(inst), RrSurfaceWindow(sur),RrContext(inst)); assert(ok); @@ -103,4 +116,23 @@ void RrPaint(struct RrSurface *sur) glPopMatrix(); glXSwapBuffers(RrDisplay(inst), RrSurfaceWindow(sur)); + + /* recurse and paint children */ + for (it = RrSurfaceChildren(sur); it; it = g_slist_next(it)) { + if (recurse_always) + RrPaint(it->data, 1); + else { + switch (RrSurfaceType(((struct RrSurface*)it->data))) { + case RR_SURFACE_NONE: + break; + case RR_SURFACE_PLANAR: + if (RrPlanarHasAlpha(it->data)) + RrPaint(it->data, 0); + break; + case RR_SURFACE_NONPLANAR: + assert(0); + break; + } + } + } } diff --git a/render2/planar.c b/render2/planar.c index bc36e205..ba6ef899 100644 --- a/render2/planar.c +++ b/render2/planar.c @@ -27,6 +27,15 @@ void RrPlanarSet(struct RrSurface *sur, sur->data.planar.border = *border; } +int RrPlanarHasAlpha(struct RrSurface *sur) +{ + if (RrColorHasAlpha(RrPlanarPrimaryColor(sur))) return 1; + if (!(RrPlanarColorType(sur) == RR_PLANAR_NONE || + RrPlanarColorType(sur) == RR_PLANAR_SOLID)) + if (RrColorHasAlpha(RrPlanarSecondaryColor(sur))) return 1; + return 0; +} + static void copy_parent(struct RrSurface *sur) { int ncols; @@ -115,19 +124,12 @@ static void RrBorderPaint(int x, int y, int w, int h, int bwidth, RrColor4f(color); - glBegin(GL_LINES); + glBegin(GL_LINE_LOOP); glLineWidth(bwidth); glVertex2i(x + offset, y + offset); - glVertex2i(x + offset, y + h - offset); - glVertex2i(x + offset, y + h - offset); glVertex2i(x + w - offset, y + h - offset); - - glVertex2i(x + w - offset, y + h - offset); - glVertex2i(x + w - offset, y + offset); - glVertex2i(x + w - offset, y + offset); - glVertex2i(x + offset, y + offset); glLineWidth(1.0); /* XXX is this needed? */ glEnd(); } diff --git a/render2/planar.h b/render2/planar.h index e1009a4f..acaae812 100644 --- a/render2/planar.h +++ b/render2/planar.h @@ -21,6 +21,8 @@ struct RrPlanarSurface { #define RrPlanarBorderWidth(sur) ((sur)->data.planar.borderwidth) #define RrPlanarBorderColor(sur) ((sur)->data.planar.border) +int RrPlanarHasAlpha(struct RrSurface *sur); + void RrPlanarPaint(struct RrSurface *sur, int absx, int absy); void RrPlanarMinSize(struct RrSurface *sur, int *w, int *h); diff --git a/render2/render.h b/render2/render.h index 701b712a..57def775 100644 --- a/render2/render.h +++ b/render2/render.h @@ -222,8 +222,8 @@ void RrTextureSetNone(struct RrSurface *sur, /* drawing */ -/*! Paints the surface, and all its children */ -void RrPaint(struct RrSurface *sur); +/*! Paints the surface, and optionally all its children */ +void RrPaint(struct RrSurface *sur, int recurse_always); void RrExpose(struct RrInstance *inst, XExposeEvent *e); diff --git a/render2/surface.c b/render2/surface.c index 2ead9fb9..b1da3158 100644 --- a/render2/surface.c +++ b/render2/surface.c @@ -155,15 +155,26 @@ void RrSurfaceSetArea(struct RrSurface *sur, int w, int h) { + int m, r; + assert(w > 0 && h > 0); if (!(w > 0 && h > 0)) return; + m = sur->x != x || sur->y != y; + r = sur->w != w || sur->h != h; + sur->x = x; sur->y = y; sur->w = w; sur->h = h; - if (sur->win) - XMoveResizeWindow(RrDisplay(sur->inst), sur->win, x, y, w, h); + if (sur->win) { + if (m && r) + XMoveResizeWindow(RrDisplay(sur->inst), sur->win, x, y, w, h); + else if (m) + XMoveWindow(RrDisplay(sur->inst), sur->win, x, y); + else if (r) + XResizeWindow(RrDisplay(sur->inst), sur->win, w, h); + } } Window RrSurfaceWindow(struct RrSurface *sur) @@ -206,9 +217,11 @@ void RrSurfaceMinSize(struct RrSurface *sur, int *w, int *h) minh = MAX(minh, 0); break; case RR_TEXTURE_TEXT: - /* XXX MEASUER STRING PLS */ - minw = MAX(minw, 100 /*MEASURESTRING*/); - minh = MAX(minh, 10 /*HEIGHTOFFONT*/); + minw = + MAX(minw, + RrFontMeasureString(sur->texture[i].data.text.font, + sur->texture[i].data.text.string)); + minh = MAX(minh, RrFontHeight(sur->texture[i].data.text.font)); break; case RR_TEXTURE_RGBA: minw = MAX(minw, (sur->texture[i].data.rgba.x + diff --git a/render2/test.c b/render2/test.c index eb76e5c9..a96a95db 100644 --- a/render2/test.c +++ b/render2/test.c @@ -86,7 +86,7 @@ int main() /* fall through ... */ } else { while (XCheckTypedWindowEvent(display, win, Expose, &report)); - RrPaint(sur); + RrPaint(sur, 0); break; } case ConfigureNotify: diff --git a/render2/theme.c b/render2/theme.c index be961bd2..9539902c 100644 --- a/render2/theme.c +++ b/render2/theme.c @@ -22,7 +22,7 @@ struct RrTheme *RrThemeLoad(struct RrInstance *inst, const char *name) theme->title_font = RrFontOpen(inst, "arial:bold:pixelsize=10:" - "shadow:shadowoffset=1:shadowtint=0.1"); + "shadow=true:shadowoffset=1:shadowtint=0.1"); theme->title_justify = RR_CENTER; RrColorSet(&theme->b_color, 0, 0, 0, 1); @@ -135,6 +135,15 @@ struct RrTheme *RrThemeLoad(struct RrInstance *inst, const char *name) RrPlanarSet(theme->title_f, RR_PLANAR_SOLID, RR_BEVEL_NONE, &pri, NULL, 1, &bor); + theme->plate = RrSurfaceNewProto(RR_SURFACE_PLANAR, 0); + theme->plate_f = RrSurfaceNewProto(RR_SURFACE_PLANAR, 0); + + RrColorSet(&pri, 0, 0, 0, 1); + RrPlanarSet(theme->plate, RR_PLANAR_SOLID, RR_BEVEL_NONE, + &pri, NULL, 0, NULL); + RrPlanarSet(theme->plate_f, RR_PLANAR_SOLID, RR_BEVEL_NONE, + &pri, NULL, 0, NULL); + theme->label = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1); theme->label_f = RrSurfaceNewProto(RR_SURFACE_PLANAR, 1); diff --git a/render2/theme.h b/render2/theme.h index 3d309e2e..6637b948 100644 --- a/render2/theme.h +++ b/render2/theme.h @@ -62,6 +62,9 @@ struct RrTheme { struct RrSurface *frame; + struct RrSurface *plate; + struct RrSurface *plate_f; /* focused */ + struct RrSurface *title; struct RrSurface *title_f; /* focused */ -- 2.39.2