aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlecoanet2001-06-27 08:37:09 +0000
committerlecoanet2001-06-27 08:37:09 +0000
commit76e82090dd6eda66b6247bd6c5980e3b7a56c3ff (patch)
treee0fe884fa6ca62b0fc7ecdf61759c66af6c5353c
parentaf7f21c4c8676b8a66b2b1c22a847ae08817b34a (diff)
downloadtkzinc-76e82090dd6eda66b6247bd6c5980e3b7a56c3ff.zip
tkzinc-76e82090dd6eda66b6247bd6c5980e3b7a56c3ff.tar.gz
tkzinc-76e82090dd6eda66b6247bd6c5980e3b7a56c3ff.tar.bz2
tkzinc-76e82090dd6eda66b6247bd6c5980e3b7a56c3ff.tar.xz
correction de bugs sur les degrade reliefs
-rw-r--r--generic/Color.c30
-rw-r--r--generic/Draw.c31
2 files changed, 39 insertions, 22 deletions
diff --git a/generic/Color.c b/generic/Color.c
index 64707b5..57702c3 100644
--- a/generic/Color.c
+++ b/generic/Color.c
@@ -920,7 +920,7 @@ ZnGetGradientColor(Tk_Window tkwin,
{
int index, min, max;
ZnGradientColor *color, *next_color;
- XColor *shade;
+ XColor *shade=NULL;
ZnReal tt;
if (!grad->realized) {
@@ -949,11 +949,13 @@ ZnGetGradientColor(Tk_Window tkwin,
}
index = (max + min) / 2;
}
+ /*printf("color index %d ", index);*/
color = grad->colors[index];
next_color = grad->colors[index+1];
- tt = ((position - (ZnReal) color->position) /
- (ZnReal) ((next_color->position - color->position) / grad->num_shades));
- index = REAL_TO_INT(tt);
+ tt = (grad->num_shades * (position - (ZnReal) color->position) /
+ (ZnReal) (next_color->position - color->position));
+ index = (int) tt;
+ /*printf("shade index %d %g\n", index, tt);*/
shade = color->shades[index];
}
@@ -1040,37 +1042,37 @@ ZnGetReliefGradient(Tcl_Interp *interp,
*/
tmp1 = (30 * (int) base->red)/100;
tmp2 = ((int) base->red)/2;
- light_color.red = MIN(tmp1, tmp2);
+ dark_color.red = MIN(tmp1, tmp2);
tmp1 = (30 * (int) base->green)/100;
tmp2 = ((int) base->green)/2;
- light_color.green = MIN(tmp1, tmp2);
+ dark_color.green = MIN(tmp1, tmp2);
tmp1 = (30 * (int) base->blue)/100;
tmp2 = ((int) base->blue)/2;
- light_color.blue = MIN(tmp1, tmp2);
+ dark_color.blue = MIN(tmp1, tmp2);
tmp1 = MAX_INTENSITY;/*(170 * (int) base->red)/10;*/
if (tmp1 > MAX_INTENSITY) {
tmp1 = MAX_INTENSITY;
}
tmp2 = (MAX_INTENSITY + (int) base->red)/2;
- dark_color.red = MAX(tmp1, tmp2);
+ light_color.red = MAX(tmp1, tmp2);
tmp1 = MAX_INTENSITY;/*(170 * (int) base->green)/10;*/
if (tmp1 > MAX_INTENSITY) {
tmp1 = MAX_INTENSITY;
}
tmp2 = (MAX_INTENSITY + (int) base->green)/2;
- dark_color.green = MAX(tmp1, tmp2);
+ light_color.green = MAX(tmp1, tmp2);
tmp1 = MAX_INTENSITY;/*(170 * (int) base->blue)/10;*/
if (tmp1 > MAX_INTENSITY) {
tmp1 = MAX_INTENSITY;
}
tmp2 = (MAX_INTENSITY + (int) base->blue)/2;
- dark_color.blue = MAX(tmp1, tmp2);
+ light_color.blue = MAX(tmp1, tmp2);
- sprintf(color_name, "#%2d%2d%2d|#%2d%2d%2d|#%2d%2d%2d%%%d",
- light_color.red, light_color.green, light_color.blue,
- base->red, base->green, base->blue,
- dark_color.red, dark_color.green, dark_color.blue,
+ sprintf(color_name, "#%02x%02x%02x|#%02x%02x%02x 50|#%02x%02x%02x%%%d",
+ dark_color.red/256, dark_color.green/256, dark_color.blue/256,
+ base->red/256, base->green/256, base->blue/256,
+ light_color.red/256, light_color.green/256, light_color.blue/256,
RELIEF_STEPS);
return ZnGetGradient(interp, tkwin, color_name);
diff --git a/generic/Draw.c b/generic/Draw.c
index ce48b3d..cc5378c 100644
--- a/generic/Draw.c
+++ b/generic/Draw.c
@@ -321,27 +321,42 @@ ReliefColorOfSegment(ZnReal x1,
WidgetInfo *wi)
{
ZnReal angle, angle_step, origin, position;
- int num_colors;
+ int num_colors, color_index;
num_colors = RELIEF_STEPS*2+1;
- angle_step = 2*M_PI / num_colors;
+ angle_step = M_PI / (num_colors-1);
origin = -(DegreesToRadian(wi->light_angle))-(angle_step/2.0);
if (relief == RELIEF_BEVEL_IN) {
origin += M_PI;
}
- angle = (ProjectionToAngle(y1 - y2, x2 - x1) + M_PI - origin);
+ angle = ProjectionToAngle(y1 - y2, x2 - x1) + M_PI - origin;
while (angle < 0.0) {
angle += 2*M_PI;
}
while (angle > 2*M_PI) {
angle -= 2*M_PI;
}
- position = (angle/angle_step)*(100/num_colors);
- /*printf("position %g, angle %g, origin %g\n",
- position,
- RadianToDegrees(angle),
- RadianToDegrees(origin));*/
+
+ color_index = (int) (angle/angle_step);
+ if (color_index > num_colors-1) {
+ color_index = 2*(num_colors-1)-color_index;
+ }
+ if ((color_index < 0) || (color_index >= num_colors)) {
+ printf("Color index out of gradient (should not happen).\n");
+ if (color_index < 0) {
+ color_index = 0;
+ }
+ if (color_index >= num_colors) {
+ color_index = num_colors-1;
+ }
+ }
+ position = 100*color_index/num_colors;
+ /*printf("position %g, angle %g(%g), origin %g\n",
+ position,
+ RadianToDegrees(angle),
+ angle,
+ RadianToDegrees(origin));*/
return ZnPixel(ZnGetGradientColor(wi->win, gradient, position));
}