aboutsummaryrefslogtreecommitdiff
path: root/generic/Draw.c
diff options
context:
space:
mode:
authorlecoanet2002-03-15 13:35:04 +0000
committerlecoanet2002-03-15 13:35:04 +0000
commit3e9bbe9c8e6d4f0de9ad8af2a9363c4781b6473e (patch)
treef6546e1b448aa9714ed8852d82a00fc55305d907 /generic/Draw.c
parent3d5eed1096262e5fdfcfe0c5c6f6f426d2d02ea6 (diff)
downloadtkzinc-3e9bbe9c8e6d4f0de9ad8af2a9363c4781b6473e.zip
tkzinc-3e9bbe9c8e6d4f0de9ad8af2a9363c4781b6473e.tar.gz
tkzinc-3e9bbe9c8e6d4f0de9ad8af2a9363c4781b6473e.tar.bz2
tkzinc-3e9bbe9c8e6d4f0de9ad8af2a9363c4781b6473e.tar.xz
Traitement des nouveaux reliefs.
Diffstat (limited to 'generic/Draw.c')
-rw-r--r--generic/Draw.c257
1 files changed, 163 insertions, 94 deletions
diff --git a/generic/Draw.c b/generic/Draw.c
index b019bb7..73e3bfb 100644
--- a/generic/Draw.c
+++ b/generic/Draw.c
@@ -332,7 +332,7 @@ DrawLineShape(WidgetInfo *wi,
/*
- * ReliefIndexOfSegment --
+ * ReliefColorOfSegment --
*/
static XColor *
ReliefColorOfSegment(ZnReal x1,
@@ -349,7 +349,7 @@ ReliefColorOfSegment(ZnReal x1,
num_colors = RELIEF_STEPS*2+1;
angle_step = M_PI / (num_colors-1);
origin = -(DegreesToRadian(wi->light_angle))-(angle_step/2.0);
- if (relief == RELIEF_BEVEL_IN) {
+ if (relief == RELIEF_SUNKEN) {
origin += M_PI;
}
@@ -421,7 +421,7 @@ DrawRectangleRelief(WidgetInfo *wi,
new_line_width = line_width/2;
offset = line_width - new_line_width;
DrawRectangleRelief(wi,
- (relief==RELIEF_GROOVE)?RELIEF_BEVEL_IN:RELIEF_BEVEL_OUT,
+ (relief==RELIEF_GROOVE)?RELIEF_SUNKEN:RELIEF_RAISED,
gradient, bbox, new_line_width);
internal_bbox = *bbox;
internal_bbox.x +=offset;
@@ -429,7 +429,7 @@ DrawRectangleRelief(WidgetInfo *wi,
internal_bbox.width -= offset*2;
internal_bbox.height -= offset*2;
DrawRectangleRelief(wi,
- (relief==RELIEF_GROOVE)?RELIEF_BEVEL_OUT:RELIEF_BEVEL_IN,
+ (relief==RELIEF_GROOVE)?RELIEF_RAISED:RELIEF_SUNKEN,
gradient, &internal_bbox, new_line_width);
return;
}
@@ -478,12 +478,28 @@ DrawRectangleRelief(WidgetInfo *wi,
}
+typedef struct {
+ WidgetInfo *wi;
+ ZnPoint *pp;
+ ZnPoint *p0;
+ ZnPoint *p1;
+ double dist;
+ ZnBBox *bbox;
+ ReliefStyle relief;
+ ZnGradient *gradient;
+ int alpha;
+ ZnBool smooth;
+ int result;
+ int count;
+ ZnBool toggle;
+} PolygonData;
+
static void
DoPolygon(ZnPoint *p,
int num_points,
int line_width,
- ZnBool (*cb)(ZnPoint *bevels, int proc_points, void *closure),
- void *closure)
+ ZnBool (*cb)(ZnPoint *bevels, PolygonData *pd),
+ PolygonData *pd)
{
int i, processed_points;
ZnPoint *p1, *p11=NULL, *p2;
@@ -566,6 +582,7 @@ DoPolygon(ZnPoint *p,
i = -2;
p1 = &p[num_points-2];
}
+
for (p2 = p1+1; i < num_points; i++, p2++) {
/*
* When it is time to wrap, do it
@@ -639,7 +656,14 @@ DoPolygon(ZnPoint *p,
}
if ((processed_points >= 2) || (!closed && (processed_points == 1))) {
- if ((*cb)(bevel_points, processed_points, closure)) {
+ if ((processed_points == num_points-1) && !closed) {
+ pd->p0 = pd->p1 = NULL;
+ }
+ else {
+ pd->p0 = p1;
+ pd->p1 = p2;
+ }
+ if ((*cb)(bevel_points, pd)) {
return;
}
}
@@ -660,18 +684,6 @@ DoPolygon(ZnPoint *p,
}
}
-typedef struct {
- WidgetInfo *wi;
- ZnPoint *pp;
- double dist;
- ZnBBox *bbox;
- ReliefStyle relief;
- ZnGradient *gradient;
- int alpha;
- ZnBool smooth;
- int result;
- ZnBool toggle;
-} PolygonData;
/*
**********************************************************************************
@@ -682,15 +694,13 @@ typedef struct {
**********************************************************************************
*/
static ZnBool
-PolygonBBoxCB(ZnPoint *bevels,
- int proc_points,
- void *closure)
+PolygonBBoxCB(ZnPoint *bevels,
+ PolygonData *pd)
{
- ZnBBox *bbox = closure;
int i;
for (i = 0; i < 4; i++) {
- AddPointToBBox(bbox, bevels[i].x, bevels[i].y);
+ AddPointToBBox(pd->bbox, bevels[i].x, bevels[i].y);
}
return 0;
}
@@ -701,8 +711,11 @@ GetPolygonReliefBBox(ZnPoint *points,
int line_width,
ZnBBox *bbox)
{
+ PolygonData pd;
+
+ pd.bbox = bbox;
ResetBBox(bbox);
- DoPolygon(points, num_points, line_width, PolygonBBoxCB, bbox);
+ DoPolygon(points, num_points, line_width, PolygonBBoxCB, &pd);
}
@@ -716,13 +729,11 @@ GetPolygonReliefBBox(ZnPoint *points,
**********************************************************************************
*/
static ZnBool
-PolygonInBBoxCB(ZnPoint *bevels,
- int proc_points,
- void *closure)
+PolygonInBBoxCB(ZnPoint *bevels,
+ PolygonData *pd)
{
- PolygonData *pd = closure;
-
- if (proc_points <= 2) {
+ if (pd->count == 0) {
+ pd->count++;
pd->result = PolygonInBBox(bevels, 4, pd->bbox, NULL);
if (pd->result == 0) {
return 1;
@@ -746,6 +757,8 @@ PolygonReliefInBBox(ZnPoint *points,
PolygonData pd;
pd.bbox = area;
+ pd.count = 0;
+
DoPolygon(points, num_points, line_width, PolygonInBBoxCB, &pd);
return pd.result;
@@ -762,11 +775,9 @@ PolygonReliefInBBox(ZnPoint *points,
**********************************************************************************
*/
static ZnBool
-PolygonDistCB(ZnPoint *bevels,
- int proc_points,
- void *closure)
+PolygonDistCB(ZnPoint *bevels,
+ PolygonData *pd)
{
- PolygonData *pd = closure;
double new_dist;
new_dist = PolygonToPointDist(bevels, 4, pd->pp);
@@ -804,29 +815,18 @@ PolygonReliefToPointDist(ZnPoint *points,
**********************************************************************************
*/
static ZnBool
-PolygonDrawCB(ZnPoint *bevels,
- int proc_points,
- void *closure)
+PolygonDrawCB(ZnPoint *bevels,
+ PolygonData *pd)
{
- PolygonData *pd = closure;
WidgetInfo *wi = pd->wi;
XPoint bevel_xpoints[5];
XGCValues values;
int j;
-#if 1
+
values.foreground = ZnPixel(ReliefColorOfSegment(bevels[0].x, bevels[0].y,
bevels[3].x, bevels[3].y,
pd->relief, pd->gradient, pd->wi));
-#endif
-#if 0
- values.foreground = toggle ? WhitePixelOfScreen(wi->screen):BlackPixelOfScreen(wi->screen);
-#endif
-#if 0
- values.foreground = colinear ? WhitePixelOfScreen(wi->screen):BlackPixelOfScreen(wi->screen);
-#endif
-#if 0
- toggle = !toggle;
-#endif
+
values.fill_style = FillSolid;
XChangeGC(wi->dpy, wi->gc, GCFillStyle|GCForeground, &values);
@@ -834,16 +834,10 @@ PolygonDrawCB(ZnPoint *bevels,
bevel_xpoints[j].x = REAL_TO_INT(bevels[j].x);
bevel_xpoints[j].y = REAL_TO_INT(bevels[j].y);
}
-#if 1
+
XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, bevel_xpoints, 4,
Convex, CoordModeOrigin);
-#endif
-#if 0
- bevel_xpoints[4] = bevel_xpoints[0];
- values.line_width = 0;
- XChangeGC(wi->dpy, wi->gc, GCLineWidth, &values);
- XDrawLines(wi->dpy, wi->draw_buffer, wi->gc, bevel_xpoints, 5, CoordModeOrigin);
-#endif
+
return 0;
}
@@ -859,14 +853,15 @@ DrawPolygonRelief(WidgetInfo *wi,
pd.wi = wi;
pd.gradient = gradient;
+
/*
* Grooves and ridges are drawn with two calls. The first
* with the original width, the second with half the width.
*/
if ((relief == RELIEF_RIDGE) || (relief == RELIEF_GROOVE)) {
- pd.relief = (relief==RELIEF_GROOVE)?RELIEF_BEVEL_OUT:RELIEF_BEVEL_IN;
+ pd.relief = (relief==RELIEF_GROOVE)?RELIEF_RAISED:RELIEF_SUNKEN;
DoPolygon(points, num_points, line_width, PolygonDrawCB, &pd);
- pd.relief = (relief==RELIEF_GROOVE)?RELIEF_BEVEL_IN:RELIEF_BEVEL_OUT;
+ pd.relief = (relief==RELIEF_GROOVE)?RELIEF_SUNKEN:RELIEF_RAISED;
DoPolygon(points, num_points, line_width/2, PolygonDrawCB, &pd);
}
else {
@@ -885,24 +880,108 @@ DrawPolygonRelief(WidgetInfo *wi,
*/
#ifdef GLX
static ZnBool
-PolygonRenderCB(ZnPoint *bevels,
- int proc_points,
- void *closure)
+PolygonRenderCB(ZnPoint *bevels,
+ PolygonData *pd)
{
- PolygonData *pd = closure;
- int i, a, b;
- XColor *color = ReliefColorOfSegment(bevels[0].x, bevels[0].y,
- bevels[3].x, bevels[3].y,
- pd->relief, pd->gradient, pd->wi);
-
- glColor4us(color->red, color->green, color->blue, pd->alpha);
- glBegin(GL_QUADS);
+ int i;
+ ZnPoint p[6];
+ XColor *c[8];
+ XColor *color = ZnGetGradientColor(pd->gradient, 51, NULL);
+ ReliefStyle relief, int_relief;
+ ZnBool two_faces, round, rule;
+
+ rule = pd->relief & RELIEF_RULE;
+ round = pd->relief & RELIEF_ROUND;
+ two_faces = pd->relief & RELIEF_TWO_FACES;
+ relief = pd->relief & RELIEF_MASK;
for (i = 0; i < 4; i++) {
- a = REAL_TO_INT(bevels[i].x);
- b = REAL_TO_INT(bevels[i].y);
- glVertex2f(a, b);
+ p[i].x = REAL_TO_INT(bevels[i].x);
+ p[i].y = REAL_TO_INT(bevels[i].y);
+ }
+
+ if (two_faces) {
+ p[4].x = (p[0].x+p[1].x)/2;
+ p[4].y = (p[0].y+p[1].y)/2;
+ p[5].x = (p[2].x+p[3].x)/2;
+ p[5].y = (p[2].y+p[3].y)/2;
+
+ if (relief == RELIEF_SUNKEN) {
+ int_relief = RELIEF_RAISED;
+ }
+ else {
+ int_relief = RELIEF_SUNKEN;
+ }
+ c[0]=c[1]=c[2]=c[3] = ReliefColorOfSegment(bevels[0].x, bevels[0].y,
+ bevels[3].x, bevels[3].y,
+ relief, pd->gradient, pd->wi);
+ c[4]=c[5]=c[6]=c[7] = ReliefColorOfSegment(bevels[0].x, bevels[0].y,
+ bevels[3].x, bevels[3].y,
+ int_relief, pd->gradient, pd->wi);
+ if (pd->smooth && pd->p0) {
+ c[2]=c[3] = ReliefColorOfSegment(pd->p0->x, pd->p0->y,
+ pd->p1->x, pd->p1->y,
+ relief, pd->gradient, pd->wi);
+ c[6]=c[7] = ReliefColorOfSegment(pd->p0->x, pd->p0->y,
+ pd->p1->x, pd->p1->y,
+ int_relief, pd->gradient, pd->wi);
+ }
+ if (round) {
+ if (!rule) {
+ c[0]=c[3]=c[5]=c[6]=color;
+ }
+ else {
+ c[1]=c[2]=c[4]=c[7]=color;
+ }
+ }
+ glBegin(GL_QUADS);
+ glColor4us(c[0]->red, c[0]->green, c[0]->blue, pd->alpha);
+ glVertex2f(p[0].x, p[0].y);
+
+ glColor4us(c[1]->red, c[1]->green, c[1]->blue, pd->alpha);
+ glVertex2f(p[4].x, p[4].y);
+
+ glColor4us(c[2]->red, c[2]->green, c[2]->blue, pd->alpha);
+ glVertex2f(p[5].x, p[5].y);
+
+ glColor4us(c[3]->red, c[3]->green, c[3]->blue, pd->alpha);
+ glVertex2f(p[3].x, p[3].y);
+
+ glColor4us(c[4]->red, c[4]->green, c[4]->blue, pd->alpha);
+ glVertex2f(p[4].x, p[4].y);
+
+ glColor4us(c[5]->red, c[5]->green, c[5]->blue, pd->alpha);
+ glVertex2f(p[1].x, p[1].y);
+
+ glColor4us(c[6]->red, c[6]->green, c[6]->blue, pd->alpha);
+ glVertex2f(p[2].x, p[2].y);
+
+ glColor4us(c[7]->red, c[7]->green, c[7]->blue, pd->alpha);
+ glVertex2f(p[5].x, p[5].y);
+ glEnd();
+ }
+ else { /* Single face */
+ c[0]=c[1]=c[2]=c[3] = ReliefColorOfSegment(bevels[0].x, bevels[0].y,
+ bevels[3].x, bevels[3].y,
+ relief, pd->gradient, pd->wi);
+ if (pd->smooth && pd->p0) {
+ c[2]=c[3] = ReliefColorOfSegment(pd->p0->x, pd->p0->y,
+ pd->p1->x, pd->p1->y,
+ relief, pd->gradient, pd->wi);
+ }
+ if (round) {
+ c[1]=c[2] = color;
+ }
+ glBegin(GL_QUADS);
+ glColor4us(c[0]->red, c[0]->green, c[0]->blue, pd->alpha);
+ glVertex2f(p[0].x, p[0].y);
+ glColor4us(c[1]->red, c[1]->green, c[1]->blue, pd->alpha);
+ glVertex2f(p[1].x, p[1].y);
+ glColor4us(c[2]->red, c[2]->green, c[2]->blue, pd->alpha);
+ glVertex2f(p[2].x, p[2].y);
+ glColor4us(c[3]->red, c[3]->green, c[3]->blue, pd->alpha);
+ glVertex2f(p[3].x, p[3].y);
+ glEnd();
}
- glEnd();
return 0;
}
@@ -911,7 +990,6 @@ void
RenderPolygonRelief(WidgetInfo *wi,
ReliefStyle relief,
ZnGradient *gradient,
- int alpha,
ZnBool smooth,
ZnPoint *points,
int num_points,
@@ -921,24 +999,14 @@ RenderPolygonRelief(WidgetInfo *wi,
pd.wi = wi;
pd.gradient = gradient;
- pd.alpha = ZnComposeAlpha(alpha, wi->alpha);
+ ZnGetGradientColor(gradient, 0, &pd.alpha);
+ pd.alpha = ZnComposeAlpha(pd.alpha, wi->alpha);
pd.smooth = smooth;
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ pd.relief = relief;
+ pd.count = 0;
- /*
- * Grooves and ridges are drawn with two calls. The first
- * with the original width, the second with half the width.
- */
- if ((relief == RELIEF_RIDGE) || (relief == RELIEF_GROOVE)) {
- pd.relief = (relief==RELIEF_GROOVE)?RELIEF_BEVEL_OUT:RELIEF_BEVEL_IN;
- DoPolygon(points, num_points, line_width, PolygonRenderCB, &pd);
- pd.relief = (relief==RELIEF_GROOVE)?RELIEF_BEVEL_IN:RELIEF_BEVEL_OUT;
- DoPolygon(points, num_points, line_width/2, PolygonRenderCB, &pd);
- }
- else {
- pd.relief = relief;
- DoPolygon(points, num_points, line_width, PolygonRenderCB, &pd);
- }
+ DoPolygon(points, num_points, line_width, PolygonRenderCB, &pd);
}
void
@@ -964,7 +1032,7 @@ RenderPolyline(WidgetInfo *wi,
/*
* The code below draws curves thiner than the min
- * of GL_ALIASED_LINE_WIDTH_RANGE and GL_ALIASED_POINT_SIZE_RANGE
+ * of GL_SMOOTH_LINE_WIDTH_RANGE and GL_SMOOTH_POINT_SIZE_RANGE
* with a mix of anti-aliased lines and points. The curves that
* are thicker are drawn using regular polygons.
* The joints are drawn only rounded, the caps can be either round
@@ -1587,8 +1655,9 @@ getTCVI(TexFont *txf,
}
}
}
- /* ZnWarning("Tried to access unavailable texture font character");*/
- printf("Tried to access unavailable texture font character '%c'(\\0%o)\n", c, c);
+ fprintf(stderr,
+ "Tried to access unavailable texture font character '%c'(\\0%o)\n",
+ c, c);
return txf->lut[(int)'!' - txf->min_glyph];
}