From 79d484a0a3b5eaffe1ae5fdf61e189df2194a0d4 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Wed, 14 Mar 2001 16:28:58 +0000 Subject: Integration du code de test GLX. Am�lioration du remplissage lorsque le rectangle est align� sur les axes (tuiles et stipples). --- generic/Rectangle.c | 193 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 164 insertions(+), 29 deletions(-) (limited to 'generic/Rectangle.c') diff --git a/generic/Rectangle.c b/generic/Rectangle.c index 6723631..2779e80 100644 --- a/generic/Rectangle.c +++ b/generic/Rectangle.c @@ -45,6 +45,7 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " * Bit offset of flags. */ #define FILLED_BIT 1 /* If the rectangle is filled with color/pattern */ +#define ALIGNED_BIT 2 /* @@ -399,6 +400,8 @@ ComputeCoordinates(Item item, RectangleItem rect = (RectangleItem) item; ZnPoint p[4]; int i; + ZnBool aligned; + ZnDim delta; ResetBBox(&item->item_bounding_box); if (!rect->line_width && ISCLEAR(rect->flags, FILLED_BIT)) { @@ -433,6 +436,14 @@ ComputeCoordinates(Item item, item->item_bounding_box.corner.x += 1; item->item_bounding_box.corner.y += 1; + delta = rect->dev[0].y - rect->dev[1].y; + delta = ABS(delta); + aligned = delta < X_PRECISION_LIMIT; + delta = rect->dev[0].x - rect->dev[1].x; + delta = ABS(delta); + aligned |= delta < X_PRECISION_LIMIT; + ASSIGN(rect->flags, ALIGNED_BIT, aligned); + if (wi->render) { #ifdef LIBART ArtVpath vpath[6]; @@ -531,19 +542,10 @@ Draw(Item item) RectangleItem rect = (RectangleItem) item; XGCValues values; int i, gc_mask; - ZnBool aligned; - ZnDim delta; XRectangle r; XPoint xp[5]; - delta = rect->dev[0].y - rect->dev[1].y; - delta = ABS(delta); - aligned = delta < X_PRECISION_LIMIT; - delta = rect->dev[0].x - rect->dev[1].x; - delta = ABS(delta); - aligned |= delta < X_PRECISION_LIMIT; - - if (aligned) { + if (ISSET(rect->flags, ALIGNED_BIT)) { if (rect->dev[0].x < rect->dev[2].x) { r.x = rect->dev[0].x; r.width = rect->dev[2].x - r.x; @@ -574,7 +576,7 @@ Draw(Item item) */ if (ISSET(rect->flags, FILLED_BIT)) { if (rect->grad_geom) { - if (aligned) { + if (ISSET(rect->flags, ALIGNED_BIT)) { DrawRectangleGradient(wi, rect->grad_geom, rect->fill_color, &r); } else { @@ -590,7 +592,7 @@ Draw(Item item) Pixmap pmap = GetImagePixmap(wi->win, rect->tile_name, rect->tile, NULL); values.fill_style = FillTiled; values.tile = pmap; - if (aligned) { + if (ISSET(rect->flags, ALIGNED_BIT)) { values.ts_x_origin = (int) r.x; values.ts_y_origin = (int) r.y; } @@ -604,7 +606,7 @@ Draw(Item item) else if (rect->fill_pattern != ZnUnspecifiedPattern) { /* Fill stippled */ values.fill_style = FillStippled; values.stipple = rect->fill_pattern; - if (aligned) { + if (ISSET(rect->flags, ALIGNED_BIT)) { values.ts_x_origin = (int) r.x; values.ts_y_origin = (int) r.y; } @@ -620,7 +622,7 @@ Draw(Item item) values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCForeground | GCFillStyle, &values); } - if (aligned) { + if (ISSET(rect->flags, ALIGNED_BIT)) { XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc, r.x, r.y, r.width, r.height); } @@ -633,7 +635,7 @@ Draw(Item item) /* Draw the outline */ if (rect->line_width) { if (rect->relief != RELIEF_FLAT) { - if (aligned) { + if (ISSET(rect->flags, ALIGNED_BIT)) { DrawRectangleRelief(wi, rect->relief, rect->gradient, &r, rect->line_width); } @@ -654,7 +656,7 @@ Draw(Item item) values.foreground = ZnPixel(rect->line_color); values.line_width = (rect->line_width == 1) ? 0 : rect->line_width; values.join_style = JoinMiter; - if (!aligned) { + if (ISCLEAR(rect->flags, ALIGNED_BIT)) { gc_mask |= GCCapStyle; values.cap_style = CapProjecting; } @@ -668,7 +670,7 @@ Draw(Item item) gc_mask |= GCStipple; XChangeGC(wi->dpy, wi->gc, gc_mask, &values); } - if (aligned) { + if (ISSET(rect->flags, ALIGNED_BIT)) { XDrawRectangle(wi->dpy, wi->draw_buffer, wi->gc, r.x, r.y, r.width, r.height); } @@ -690,10 +692,10 @@ Draw(Item item) static void Render(Item item) { -#ifdef LIBART WidgetInfo *wi = item->wi; RectangleItem rect = (RectangleItem) item; XColor *color = ZnColorGradientMidColor(wi->win, rect->fill_color); +#ifdef LIBART ArtPixBuf *pixbuf = NULL; if (rect->fill_svp != NULL) { @@ -712,6 +714,148 @@ Render(Item item) rect->line_alpha & 0xff, 0, 0, NULL); } #endif +#ifdef GLX + int i; + + if (ISSET(rect->flags, FILLED_BIT)) { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + if (rect->grad_geom) { + } + else { + if (rect->tile != ZnUnspecifiedImage) { /* Fill tiled */ + ImageBits *im_bits = GetImageTexture(wi->win, rect->tile_name, rect->tile); + ZnReal x, y, nx, ny, lx, ly, s, t; + + /* + ZnReal dx, dy, width, height; + + if (ISSET(rect->flags, ALIGNED_BIT)) { + width = rect->dev[1].x - rect->dev[0].x; + if (width < 0) { + width = -width; + } + height = rect->dev[3].y - rect->dev[0].y; + if (height < 0) { + height = -height; + } + } + else { + dx = rect->dev[1].x - rect->dev[0].x; + dy = rect->dev[1].y - rect->dev[0].y; + width = sqrt(dx*dx + dy*dy); + dx = rect->dev[3].x - rect->dev[0].x; + dy = rect->dev[3].y - rect->dev[0].y; + height = sqrt(dx*dx + dy*dy); + } + dx = width/im_bits->width * im_bits->s; + dy = height/im_bits->height * im_bits->t; + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, im_bits->texture); + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); + glVertex2f(rect->dev[0].x, rect->dev[0].y); + glTexCoord2f(0.0, dy); + glVertex2f(rect->dev[3].x, rect->dev[3].y); + glTexCoord2f(dx, dy); + glVertex2f(rect->dev[2].x, rect->dev[2].y); + glTexCoord2f(dx, 0.0); + glVertex2f(rect->dev[1].x, rect->dev[1].y); + glEnd(); + glDisable(GL_TEXTURE_2D);*/ + + /* + * Setup the stencil buffer with the shape to be drawn. + */ + glClear(GL_STENCIL_BUFFER_BIT); + glEnable(GL_STENCIL_TEST); + glStencilFunc(GL_ALWAYS, 1, 1); + glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + glBegin(GL_QUADS); + glVertex2f(rect->dev[0].x, rect->dev[0].y); + glVertex2f(rect->dev[3].x, rect->dev[3].y); + glVertex2f(rect->dev[2].x, rect->dev[2].y); + glVertex2f(rect->dev[1].x, rect->dev[1].y); + glEnd(); + /* + * Then texture map the rectangle through the shape. + * The rectangle is drawn using quad-strips, each + * quad matching the size of the texture tile. + */ + /* glDisable(GL_STENCIL_TEST);*/ + glStencilFunc(GL_EQUAL, 1, 1); + glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, im_bits->texture); + y = item->item_bounding_box.orig.y; + lx = item->item_bounding_box.corner.x; + ly = item->item_bounding_box.corner.y; + glBegin(GL_QUADS); + do { + x = item->item_bounding_box.orig.x; + t = 1.0; + ny = y + im_bits->height; + if (ny > ly) { + ny = ly; + t = (ly - y) / (ZnReal) im_bits->height; + } + t *= im_bits->t; + do { + s = 1.0; + nx = x + im_bits->width; + if (nx > lx) { + nx = lx; + s = (lx - x) / (ZnReal) im_bits->width; + } + s *= im_bits->s; + glTexCoord2f(0.0, 0.0); + glVertex2f(x, y); + glTexCoord2f(0.0, t); + glVertex2f(x, ny); + glTexCoord2f(s, t); + glVertex2f(nx, ny); + glTexCoord2f(s, 0.0); + glVertex2f(nx, y); + x = nx; + } + while (x != lx); + y = ny; + } + while (y != ly); + glEnd(); + glDisable(GL_TEXTURE_2D); + glDisable(GL_STENCIL_TEST); + } + else if (rect->fill_pattern != ZnUnspecifiedPattern) { /* Fill stippled */ + } + else { /* Fill solid */ + glColor4us(color->red, color->green, color->blue, rect->fill_alpha*256); + glBegin(GL_QUADS); + for (i = 0; i < 4; i++) { + glVertex2f(rect->dev[i].x, rect->dev[i].y); + } + glEnd(); + } + } + } + + if (rect->line_width) { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + if (rect->relief != RELIEF_FLAT) { + } + else { + glColor4us(rect->line_color->red, rect->line_color->green, + rect->line_color->blue, rect->line_alpha*256); + glLineWidth(rect->line_width); + glBegin(GL_QUADS); + for (i = 0; i < 4; i++) { + glVertex2f(rect->dev[i].x, rect->dev[i].y); + } + glEnd(); + } + } +#endif } @@ -806,18 +950,9 @@ GetClipVertices(Item item, ZnPoly *poly) { RectangleItem rect = (RectangleItem) item; - double delta; - ZnBool aligned; ZnPoint *points; - delta = rect->dev[0].y - rect->dev[1].y; - delta = ABS(delta); - aligned = delta < PRECISION_LIMIT; - delta = rect->dev[0].x - rect->dev[1].x; - delta = ABS(delta); - aligned |= delta < PRECISION_LIMIT; - - if (aligned) { + if (ISSET(rect->flags, ALIGNED_BIT)) { ZnListAssertSize(item->wi->work_pts, 2); points = (ZnPoint *) ZnListArray(item->wi->work_pts); POLY_CONTOUR1(poly, points, 2); @@ -843,7 +978,7 @@ GetClipVertices(Item item, POLY_CONTOUR1(poly, rect->dev, 4); } - return aligned; + return ISSET(rect->flags, ALIGNED_BIT); } -- cgit v1.1