From c5878804de67b7a18cbe3e4e6296f70b6491af37 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Thu, 16 May 2002 08:52:36 +0000 Subject: Correction des param�tres angulaires de GetCirclePoints. Adaptation suite � la modification du code des images, bitmap, fontes. --- generic/Draw.c | 337 +++++++++++++++++++++++++-------------------------------- 1 file changed, 150 insertions(+), 187 deletions(-) (limited to 'generic/Draw.c') diff --git a/generic/Draw.c b/generic/Draw.c index 078439e..ea93823 100644 --- a/generic/Draw.c +++ b/generic/Draw.c @@ -70,13 +70,13 @@ /* ********************************************************************************** * - * SetLineStyle -- + * ZnSetLineStyle -- * ********************************************************************************** */ void -SetLineStyle(WidgetInfo *wi, - LineStyle line_style) +ZnSetLineStyle(WidgetInfo *wi, + LineStyle line_style) { if (wi->render) { #ifdef GLX @@ -127,7 +127,7 @@ SetLineStyle(WidgetInfo *wi, /* ********************************************************************************** * - * GetLineShape -- + * ZnGetLineShape -- * Compute the points describing the given line shape between point p1 and p2. * If bbox is non null, it is filled with the bounding box of the shape. * @@ -162,12 +162,12 @@ SetLineStyle(WidgetInfo *wi, ********************************************************************************** */ void -GetLineShape(ZnPoint *p1, - ZnPoint *p2, - unsigned int line_width, - LineShape shape, - ZnBBox *bbox, - ZnList to_points) +ZnGetLineShape(ZnPoint *p1, + ZnPoint *p2, + unsigned int line_width, + LineShape shape, + ZnBBox *bbox, + ZnList to_points) { ZnPoint *points; int num_points, i; @@ -288,7 +288,7 @@ GetLineShape(ZnPoint *p1, /* ********************************************************************************** * - * DrawLineShape -- + * ZnDrawLineShape -- * Draw a line given the points describing its path. It is designed to work * with GetLineShape albeit it does fairly trivial things. In the future some * shapes might need cooperation between the two and the clients will be ready @@ -298,13 +298,13 @@ GetLineShape(ZnPoint *p1, ********************************************************************************** */ void -DrawLineShape(WidgetInfo *wi, - ZnPoint *p, - int num_p, - LineStyle line_style, - ZnColor foreground, - unsigned int line_width, - LineShape shape) +ZnDrawLineShape(WidgetInfo *wi, + ZnPoint *p, + int num_p, + LineStyle line_style, + ZnColor foreground, + unsigned int line_width, + LineShape shape) { XPoint *xpoints; int i; @@ -313,7 +313,7 @@ DrawLineShape(WidgetInfo *wi, /* * Setup GC. */ - SetLineStyle(wi, line_style); + ZnSetLineStyle(wi, line_style); values.foreground = ZnPixel(foreground); values.line_width = (line_width == 1) ? 0 : line_width; values.fill_style = FillSolid; @@ -388,17 +388,17 @@ ReliefColorOfSegment(ZnReal x1, /* ********************************************************************************** * - * DrawRectangleRelief -- + * ZnDrawRectangleRelief -- * Draw the bevels inside bbox. * ********************************************************************************** */ void -DrawRectangleRelief(WidgetInfo *wi, - ReliefStyle relief, - ZnGradient *gradient, - XRectangle *bbox, - unsigned int line_width) +ZnDrawRectangleRelief(WidgetInfo *wi, + ReliefStyle relief, + ZnGradient *gradient, + XRectangle *bbox, + unsigned int line_width) { XPoint bevel[4]; @@ -420,17 +420,17 @@ DrawRectangleRelief(WidgetInfo *wi, new_line_width = line_width/2; offset = line_width - new_line_width; - DrawRectangleRelief(wi, - (relief==RELIEF_GROOVE)?RELIEF_SUNKEN:RELIEF_RAISED, - gradient, bbox, new_line_width); + ZnDrawRectangleRelief(wi, + (relief==RELIEF_GROOVE)?RELIEF_SUNKEN:RELIEF_RAISED, + gradient, bbox, new_line_width); internal_bbox = *bbox; internal_bbox.x +=offset; internal_bbox.y += offset; internal_bbox.width -= offset*2; internal_bbox.height -= offset*2; - DrawRectangleRelief(wi, - (relief==RELIEF_GROOVE)?RELIEF_RAISED:RELIEF_SUNKEN, - gradient, &internal_bbox, new_line_width); + ZnDrawRectangleRelief(wi, + (relief==RELIEF_GROOVE)?RELIEF_RAISED:RELIEF_SUNKEN, + gradient, &internal_bbox, new_line_width); return; } @@ -688,7 +688,7 @@ DoPolygon(ZnPoint *p, /* ********************************************************************************** * - * GetPolygonReliefBBox -- + * ZnGetPolygonReliefBBox -- * Returns the bevelled polygon bounding box. * ********************************************************************************** @@ -706,10 +706,10 @@ PolygonBBoxCB(ZnPoint *bevels, } void -GetPolygonReliefBBox(ZnPoint *points, - int num_points, - int line_width, - ZnBBox *bbox) +ZnGetPolygonReliefBBox(ZnPoint *points, + int num_points, + int line_width, + ZnBBox *bbox) { PolygonData pd; @@ -722,7 +722,7 @@ GetPolygonReliefBBox(ZnPoint *points, /* ********************************************************************************** * - * PolygonReliefInBBox -- + * ZnPolygonReliefInBBox -- * Returns (-1) if the relief is entirely outside the bbox, (1) if it is * entirely inside or (0) if in between * @@ -749,10 +749,10 @@ PolygonInBBoxCB(ZnPoint *bevels, } int -PolygonReliefInBBox(ZnPoint *points, - int num_points, - int line_width, - ZnBBox *area) +ZnPolygonReliefInBBox(ZnPoint *points, + int num_points, + int line_width, + ZnBBox *area) { PolygonData pd; @@ -768,7 +768,7 @@ PolygonReliefInBBox(ZnPoint *points, /* ********************************************************************************** * - * PolygonReliefToPointDist -- + * ZnPolygonReliefToPointDist -- * Returns the distance between the given point and * the bevelled polygon. * @@ -791,10 +791,10 @@ PolygonDistCB(ZnPoint *bevels, } double -PolygonReliefToPointDist(ZnPoint *points, - int num_points, - int line_width, - ZnPoint *pp) +ZnPolygonReliefToPointDist(ZnPoint *points, + int num_points, + int line_width, + ZnPoint *pp) { PolygonData pd; @@ -809,7 +809,7 @@ PolygonReliefToPointDist(ZnPoint *points, /* ********************************************************************************** * - * DrawPolygonRelief -- + * ZnDrawPolygonRelief -- * Draw the bevels around path. * ********************************************************************************** @@ -842,12 +842,12 @@ PolygonDrawCB(ZnPoint *bevels, } void -DrawPolygonRelief(WidgetInfo *wi, - ReliefStyle relief, - ZnGradient *gradient, - ZnPoint *points, - int num_points, - int line_width) +ZnDrawPolygonRelief(WidgetInfo *wi, + ReliefStyle relief, + ZnGradient *gradient, + ZnPoint *points, + int num_points, + int line_width) { PolygonData pd; @@ -873,7 +873,7 @@ DrawPolygonRelief(WidgetInfo *wi, /* ********************************************************************************** * - * RenderPolygonRelief -- + * ZnRenderPolygonRelief -- * Draw the bevels around path using alpha enabled rendering. * ********************************************************************************** @@ -987,13 +987,13 @@ PolygonRenderCB(ZnPoint *bevels, } void -RenderPolygonRelief(WidgetInfo *wi, - ReliefStyle relief, - ZnGradient *gradient, - ZnBool smooth, - ZnPoint *points, - int num_points, - int line_width) +ZnRenderPolygonRelief(WidgetInfo *wi, + ReliefStyle relief, + ZnGradient *gradient, + ZnBool smooth, + ZnPoint *points, + int num_points, + int line_width) { PolygonData pd; @@ -1010,16 +1010,16 @@ RenderPolygonRelief(WidgetInfo *wi, } void -RenderPolyline(WidgetInfo *wi, - ZnPoint *points, - int num_points, - int line_width, - LineStyle line_style, - int cap_style, - int join_style, - ZnLineEnd first_end, - ZnLineEnd last_end, - ZnGradient *gradient) +ZnRenderPolyline(WidgetInfo *wi, + ZnPoint *points, + int num_points, + int line_width, + LineStyle line_style, + int cap_style, + int join_style, + ZnLineEnd first_end, + ZnLineEnd last_end, + ZnGradient *gradient) { int num_clips = ZnListSize(wi->clip_stack); ZnPoint end_points[LINE_END_POINTS]; @@ -1043,7 +1043,7 @@ RenderPolyline(WidgetInfo *wi, color = ZnGetGradientColor(gradient, 0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); - SetLineStyle(wi, line_style); + ZnSetLineStyle(wi, line_style); glLineWidth(line_width); glPointSize(line_width); @@ -1122,7 +1122,7 @@ RenderPolyline(WidgetInfo *wi, int num_cpoints; ZnReal lw_2 = line_width / 2.0; ZnPoint *cpoints = GetCirclePoints(3, ZN_CIRCLE_COARSE, - 0, 360, &num_cpoints, NULL); + 0, 2*M_PI, &num_cpoints, NULL); for ( ; i < k; i++) { glBegin(GL_TRIANGLE_FAN); @@ -1139,24 +1139,28 @@ RenderPolyline(WidgetInfo *wi, void -RenderImage(WidgetInfo *wi, - ImageBits *image, /* ImageBits or BitmapBits */ - ZnGradient *gradient, - ZnPoint *origin, - ZnBool modulate) +ZnRenderImage(WidgetInfo *wi, + ZnImage image, + ZnGradient *gradient, + ZnPoint *origin, + ZnBool modulate) { ZnReal nx, ny; XColor *color; - int alpha; - + int alpha, width, height; + ZnReal t, s; + GLuint texobj; + color = ZnGetGradientColor(gradient, 0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); - nx = origin->x + image->width; - ny = origin->y + image->height; + ZnSizeOfImage(image, &width, &height); + texobj = ZnImageTex(image, &t, &s); + nx = origin->x + width; + ny = origin->y + height; glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, image->texture); + glBindTexture(GL_TEXTURE_2D, texobj); if (modulate) { glColor4us(color->red, color->green, color->blue, alpha); } @@ -1166,26 +1170,27 @@ RenderImage(WidgetInfo *wi, glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex2f(origin->x, origin->y); - glTexCoord2f(0.0, image->t); + glTexCoord2f(0.0, t); glVertex2f(origin->x, ny); - glTexCoord2f(image->s, image->t); + glTexCoord2f(s, t); glVertex2f(nx, ny); - glTexCoord2f(image->s, 0.0); + glTexCoord2f(s, 0.0); glVertex2f(nx, origin->y); glEnd(); glDisable(GL_TEXTURE_2D); } void -RenderTile(struct _WidgetInfo *wi, - ImageBits *tile, - ZnGradient *gradient, - void cb(void *), - void *closure, - ZnPoint *quad) /* Right now it's a ZnBBox */ +ZnRenderTile(WidgetInfo *wi, + ZnImage tile, + ZnGradient *gradient, + void cb(void *), + void *closure, + ZnPoint *quad) /* Right now it's a ZnBBox */ { - ZnReal x, y, nx, ny, lx, ly, s, t; - int alpha, num_clips = ZnListSize(wi->clip_stack); + ZnReal x, y, nx, ny, lx, ly, s, t, tiles, tilet; + int width, height, alpha, num_clips = ZnListSize(wi->clip_stack); + GLuint texobj; if (gradient) { ZnGetGradientColor(gradient, 0.0, &alpha); @@ -1210,10 +1215,12 @@ RenderTile(struct _WidgetInfo *wi, * The rectangle is drawn using quads, each * quad matching the size of the texture tile. */ + ZnSizeOfImage(tile, &width, &height); + texobj = ZnImageTex(tile, &tilet, &tiles); glEnable(GL_TEXTURE_2D); glColor4us(65535, 65535, 65535, alpha); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glBindTexture(GL_TEXTURE_2D, tile->texture); + glBindTexture(GL_TEXTURE_2D, texobj); y = quad[0].y; lx = quad[1].x; @@ -1222,20 +1229,20 @@ RenderTile(struct _WidgetInfo *wi, do { x = quad[0].x; t = 1.0; - ny = y + tile->height; + ny = y + height; if (ny > ly) { ny = ly; - t = (ly - y) / (ZnReal) tile->height; + t = (ly - y) / (ZnReal) height; } - t *= tile->t; + t *= tilet; do { s = 1.0; - nx = x + tile->width; + nx = x + width; if (nx > lx) { nx = lx; - s = (lx - x) / (ZnReal) tile->width; + s = (lx - x) / (ZnReal) width; } - s *= tile->s; + s *= tiles; glTexCoord2f(0.0, 0.0); glVertex2f(x, y); glTexCoord2f(0.0, t); @@ -1259,10 +1266,10 @@ RenderTile(struct _WidgetInfo *wi, } void -ComputeAxialGradient(WidgetInfo *wi, - ZnPoly *shape, - int angle, - ZnPoint *grad_geo) +ZnComputeAxialGradient(WidgetInfo *wi, + ZnPoly *shape, + int angle, + ZnPoint *grad_geo) { ZnTransfo *transfo1, *transfo2; ZnBool *holes; @@ -1301,11 +1308,11 @@ ComputeAxialGradient(WidgetInfo *wi, } void -ComputeRadialGradient(WidgetInfo *wi, - ZnPoly *shape, - ZnBBox *bbox, - ZnPoint *center, - ZnPoint *grad_geo) +ZnComputeRadialGradient(WidgetInfo *wi, + ZnPoly *shape, + ZnBBox *bbox, + ZnPoint *center, + ZnPoint *grad_geo) { ZnReal dist, new, x, y, fact; ZnBool *holes; @@ -1344,16 +1351,16 @@ ComputeRadialGradient(WidgetInfo *wi, } void -RenderGradient(struct _WidgetInfo *wi, - ZnGradient *gradient, /* The grdient to be drawn (static - * parameters). */ - void cb(void *), /* A callback called to clip the shape - * containing the gradient. */ - void *closure, /* The callback parameter. */ - ZnPoint *quad, /* The gradient geometric parameters - * (dynamic). */ - ZnPoly *poly /* Used only by ZN_PATH_GRADIENT */ - ) +ZnRenderGradient(WidgetInfo *wi, + ZnGradient *gradient, /* The grdient to be drawn (static + * parameters). */ + void cb(void *), /* A callback called to clip the shape + * containing the gradient. */ + void *closure, /* The callback parameter. */ + ZnPoint *quad, /* The gradient geometric parameters + * (dynamic). */ + ZnPoly *poly /* Used only by ZN_PATH_GRADIENT */ + ) { int alpha, angle, i, j; int type = gradient->type; @@ -1466,7 +1473,7 @@ RenderGradient(struct _WidgetInfo *wi, ZnPoint *genarc; XColor *color2; - genarc = GetCirclePoints(3, ZN_CIRCLE_FINE, 0, 360, &num_p, NULL); + genarc = GetCirclePoints(3, ZN_CIRCLE_FINE, 0, 2*M_PI, &num_p, NULL); radiusx = 0; radiusy = 0; color = gradient->colors[0].rgb; @@ -1589,9 +1596,9 @@ RenderGradient(struct _WidgetInfo *wi, void -RenderHollowDot(struct _WidgetInfo *wi, - ZnPoint *p, - ZnReal size) +ZnRenderHollowDot(WidgetInfo *wi, + ZnPoint *p, + ZnReal size) { int num_clips = ZnListSize(wi->clip_stack); @@ -1629,46 +1636,13 @@ RenderHollowDot(struct _WidgetInfo *wi, #include -static TexGlyphVertexInfo * -getTCVI(TexFont *txf, - int c) -{ - TexGlyphVertexInfo *tgvi; - - /* Automatically substitute uppercase letters with lowercase if not - uppercase available (and vice versa). */ - if ((c >= txf->min_glyph) && (c < txf->min_glyph + txf->range)) { - tgvi = txf->lut[c - txf->min_glyph]; - if (tgvi) { - return tgvi; - } - if (islower(c)) { - c = toupper(c); - if ((c >= txf->min_glyph) && (c < txf->min_glyph + txf->range)) { - return txf->lut[c - txf->min_glyph]; - } - } - if (isupper(c)) { - c = tolower(c); - if ((c >= txf->min_glyph) && (c < txf->min_glyph + txf->range)) { - return txf->lut[c - txf->min_glyph]; - } - } - } - fprintf(stderr, - "Tried to access unavailable texture font character '%c'(\\0%o)\n", - c, c); - return txf->lut[(int)'!' - txf->min_glyph]; -} - - void -txfRenderGlyph(TexFont *txf, - int c) +ZnRenderGlyph(ZnTexFontInfo *tfi, + int c) { - TexGlyphVertexInfo *tgvi; + ZnTexGVI *tgvi; - tgvi = getTCVI(txf, c); + tgvi = ZnTexFontGVI(tfi, c); glBegin(GL_QUADS); glTexCoord2fv(tgvi->t0); @@ -1684,14 +1658,14 @@ txfRenderGlyph(TexFont *txf, } void -txfRenderString(TexFont *txf, - unsigned char *string, - int len) +ZnRenderString(ZnTexFontInfo *tfi, + unsigned char *string, + int len) { int i; for (i = 0; i < len; i++) { - txfRenderGlyph(txf, string[i]); + ZnRenderGlyph(tfi, string[i]); } } @@ -1700,14 +1674,14 @@ enum { }; void -txfRenderFancyString(TexFont *txf, - unsigned char *string, - int len) +ZnRenderFancyString(ZnTexFontInfo *tfi, + unsigned char *string, + int len) { - TexGlyphVertexInfo *tgvi; - GLubyte c[4][3]; - int mode = MONO; - int i; + ZnTexGVI *tgvi; + GLubyte c[4][3]; + int mode = MONO; + int i; for (i = 0; i < len; i++) { if (string[i] == 27) { @@ -1736,10 +1710,10 @@ txfRenderFancyString(TexFont *txf, } else { switch (mode) { case MONO: - txfRenderGlyph(txf, string[i]); + ZnRenderGlyph(tfi, string[i]); break; case TOP_BOTTOM: - tgvi = getTCVI(txf, string[i]); + tgvi = ZnTexFontGVI(tfi, string[i]); glBegin(GL_QUADS); glColor3ubv(c[0]); glTexCoord2fv(tgvi->t0); @@ -1755,7 +1729,7 @@ txfRenderFancyString(TexFont *txf, glTranslatef(tgvi->advance, 0.0, 0.0); break; case LEFT_RIGHT: - tgvi = getTCVI(txf, string[i]); + tgvi = ZnTexFontGVI(tfi, string[i]); glBegin(GL_QUADS); glColor3ubv(c[0]); glTexCoord2fv(tgvi->t0); @@ -1773,7 +1747,7 @@ txfRenderFancyString(TexFont *txf, glTranslatef(tgvi->advance, 0.0, 0.0); break; case FOUR: - tgvi = getTCVI(txf, string[i]); + tgvi = ZnTexFontGVI(tfi, string[i]); glBegin(GL_QUADS); glColor3ubv(c[0]); glTexCoord2fv(tgvi->t0); @@ -1795,15 +1769,4 @@ txfRenderFancyString(TexFont *txf, } } -int -txfInFont(TexFont * txf, int c) -{ - /* NOTE: No uppercase/lowercase substituion. */ - if ((c >= txf->min_glyph) && (c < txf->min_glyph + txf->range)) { - if (txf->lut[c - txf->min_glyph]) { - return 1; - } - } - return 0; -} #endif -- cgit v1.1