Attachment "tkScale.c.diff" to
ticket [3003895f]
added by
ttischler
2010-05-19 14:41:28.
--- tkScale.c 2007-12-13 09:24:16.000000000 +0100
+++ tkScale.c 2010-05-19 09:14:35.781250000 +0200
@@ -621,7 +621,7 @@
scalePtr->fromValue = TkRoundToResolution(scalePtr,
scalePtr->fromValue);
scalePtr->toValue = TkRoundToResolution(scalePtr, scalePtr->toValue);
- scalePtr->tickInterval = TkRoundToResolution(scalePtr,
+ scalePtr->tickInterval = TkRoundTickToResolution(scalePtr,
scalePtr->tickInterval);
/*
@@ -1126,27 +1126,43 @@
double
TkRoundToResolution(
- TkScale *scalePtr, /* Information about scale widget. */
- double value) /* Value to round. */
+ TkScale *scalePtr, /* Information about scale widget. */
+ double value) /* Value to round. */
{
- double rem, rounded, tick;
+ double rem, new, start;
- if (scalePtr->resolution <= 0) {
- return value;
- }
- tick = floor(value/scalePtr->resolution);
- rounded = scalePtr->resolution * tick;
- rem = value - rounded;
- if (rem < 0) {
- if (rem <= -scalePtr->resolution/2) {
- rounded = (tick - 1.0) * scalePtr->resolution;
+ if (scalePtr->resolution <= 0) {
+ return value;
}
- } else {
- if (rem >= scalePtr->resolution/2) {
- rounded = (tick + 1.0) * scalePtr->resolution;
+
+ start = fmod(scalePtr->fromValue, scalePtr->resolution);
+ rem = fmod(value - start + scalePtr->resolution/2, scalePtr->resolution);
+ if (rem < 0) {
+ rem = rem + scalePtr->resolution;
}
- }
- return rounded;
+ new = value + scalePtr->resolution/2 - rem;
+
+ return new;
+}
+
+double
+TkRoundTickToResolution(
+ TkScale *scalePtr, /* Information about scale widget. */
+ double value) /* Value to round. */
+{
+ double rem, new;
+
+ if (scalePtr->resolution <= 0) {
+ return value;
+ }
+
+ rem = fmod(value + scalePtr->resolution/2, scalePtr->resolution);
+ if (rem < 0) {
+ rem = rem + scalePtr->resolution;
+ }
+ new = value + scalePtr->resolution/2 - rem;
+
+ return new;
}
/*