2020-08-17
| | |
21:17 |
|
check-in: 2c6d9d34 user: fvogel tags: core-8-6-branch
|
21:15 |
|
Closed-Leaf
check-in: d4bc0b58 user: fvogel tags: bug-3003895fff, bug-1899040fff, bug-81c3ef9314
|
21:11 |
|
check-in: 76668172 user: fvogel tags: bug-3003895fff, bug-1899040fff, bug-81c3ef9314
|
2019-01-05
| | |
20:55 |
|
check-in: 4a9a1264 user: fvogel tags: bug-3003895fff, bug-1899040fff
|
2019-01-04
| | |
00:49 |
|
check-in: 6942f5af user: culler tags: core-8-6-branch
|
2019-01-03
| | |
21:30 |
|
check-in: a6e441b5 user: jan.nijtmans tags: trunk
|
21:17 |
|
Closed-Leaf
check-in: ab5d40e3 user: jan.nijtmans tags: bug-18a4ba19bd
|
21:14 |
|
check-in: 519cc259 user: jan.nijtmans tags: core-8-6-branch
|
21:09 |
|
check-in: 6ca933bc user: jan.nijtmans tags: core-8-6-branch
|
19:45 |
|
check-in: d49951e5 user: culler tags: bug-9e31fd9449-8-6
|
16:20 |
|
check-in: 1fcb165e user: culler tags: bug-9e31fd9449-8-6
|
| | |
Changes to generic/tkScale.c.
︙ | | |
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
|
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
|
-
+
-
-
-
-
+
+
+
+
-
-
-
-
+
+
|
double value;
Tcl_Obj *valuePtr;
valuePtr = Tcl_ObjGetVar2(interp, scalePtr->varNamePtr, NULL,
TCL_GLOBAL_ONLY);
if ((valuePtr != NULL) &&
(Tcl_GetDoubleFromObj(NULL, valuePtr, &value) == TCL_OK)) {
scalePtr->value = TkRoundToResolution(scalePtr, value);
scalePtr->value = TkRoundValueToResolution(scalePtr, value);
}
}
/*
* Several options need special processing, such as parsing the
* orientation and creating GCs.
*/
/*
* The fromValue shall not be rounded to the resolution, but the
* toValue and tickInterval do.
*/
scalePtr->fromValue = TkRoundToResolution(scalePtr,
scalePtr->fromValue);
scalePtr->toValue = TkRoundToResolution(scalePtr, scalePtr->toValue);
scalePtr->tickInterval = TkRoundToResolution(scalePtr,
scalePtr->toValue = TkRoundValueToResolution(scalePtr, scalePtr->toValue);
scalePtr->tickInterval = TkRoundIntervalToResolution(scalePtr,
scalePtr->tickInterval);
/*
* Make sure that the tick interval has the right sign so that
* addition moves from fromValue to toValue.
*/
|
︙ | | |
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
|
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
|
-
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
|
}
scalePtr->flags |= what;
}
/*
*--------------------------------------------------------------
*
* TkRoundToResolution --
* TkRoundValueToResolution, TkRoundIntervalToResolution --
*
* Round a given floating-point value to the nearest multiple of the
* scale's resolution.
* TkRoundValueToResolution rounds an absolute value based on the from
* value as a reference.
* TkRoundIntervalToResolution rounds a relative value without
* reference, i.e. it rounds an interval.
*
* Results:
* The return value is the rounded result.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
double
TkRoundToResolution(
TkRoundValueToResolution(
TkScale *scalePtr, /* Information about scale widget. */
double value) /* Value to round. */
{
return TkRoundIntervalToResolution(scalePtr, value - scalePtr->fromValue)
+ scalePtr->fromValue;
}
double
TkRoundIntervalToResolution(
TkScale *scalePtr, /* Information about scale widget. */
double value) /* Value to round. */
{
double rem, rounded, tick;
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 (rem <= -scalePtr->resolution/2) {
rounded = (tick - 1.0) * scalePtr->resolution;
}
} else {
if (rem >= scalePtr->resolution/2) {
rounded = (tick + 1.0) * scalePtr->resolution;
}
if (rem >= scalePtr->resolution/2) {
rounded = (tick + 1.0) * scalePtr->resolution;
}
}
return rounded;
}
/*
*----------------------------------------------------------------------
*
|
︙ | | |
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
|
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
|
-
+
|
valuePtr = Tcl_ObjGetVar2(interp, scalePtr->varNamePtr, NULL,
TCL_GLOBAL_ONLY);
result = Tcl_GetDoubleFromObj(interp, valuePtr, &value);
if (result != TCL_OK) {
resultStr = "can't assign non-numeric value to scale variable";
ScaleSetVariable(scalePtr);
} else {
scalePtr->value = TkRoundToResolution(scalePtr, value);
scalePtr->value = TkRoundValueToResolution(scalePtr, value);
/*
* This code is a bit tricky because it sets the scale's value before
* calling TkScaleSetValue. This way, TkScaleSetValue won't bother to
* set the variable again or to invoke the -command. However, it also
* won't redisplay the scale, so we have to ask for that explicitly.
*/
|
︙ | | |
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
|
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
|
-
+
|
double value, /* New value for scale. Gets adjusted if it's
* off the scale. */
int setVar, /* Non-zero means reflect new value through to
* associated variable, if any. */
int invokeCommand) /* Non-zero means invoked -command option to
* notify of new value, 0 means don't. */
{
value = TkRoundToResolution(scalePtr, value);
value = TkRoundValueToResolution(scalePtr, value);
if ((value < scalePtr->fromValue)
^ (scalePtr->toValue < scalePtr->fromValue)) {
value = scalePtr->fromValue;
}
if ((value > scalePtr->toValue)
^ (scalePtr->toValue < scalePtr->fromValue)) {
value = scalePtr->toValue;
|
︙ | | |
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
|
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
|
-
+
|
value = 0;
}
if (value > 1) {
value = 1;
}
value = scalePtr->fromValue +
value * (scalePtr->toValue - scalePtr->fromValue);
return TkRoundToResolution(scalePtr, value);
return TkRoundValueToResolution(scalePtr, value);
}
/*
*----------------------------------------------------------------------
*
* TkScaleValueToPixel --
*
|
︙ | | |
Changes to generic/tkScale.h.
︙ | | |
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
-
+
+
|
#define SPACING 2
/*
* Declaration of procedures used in the implementation of the scale widget.
*/
MODULE_SCOPE void TkEventuallyRedrawScale(TkScale *scalePtr, int what);
MODULE_SCOPE double TkRoundToResolution(TkScale *scalePtr, double value);
MODULE_SCOPE double TkRoundValueToResolution(TkScale *scalePtr, double value);
MODULE_SCOPE double TkRoundIntervalToResolution(TkScale *scalePtr, double value);
MODULE_SCOPE TkScale * TkpCreateScale(Tk_Window tkwin);
MODULE_SCOPE void TkpDestroyScale(TkScale *scalePtr);
MODULE_SCOPE void TkpDisplayScale(ClientData clientData);
MODULE_SCOPE int TkpScaleElement(TkScale *scalePtr, int x, int y);
MODULE_SCOPE void TkScaleSetValue(TkScale *scalePtr, double value,
int setVar, int invokeCommand);
MODULE_SCOPE double TkScalePixelToValue(TkScale *scalePtr, int x, int y);
|
︙ | | |
Changes to tests/scale.test.
︙ | | |
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
|
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
} -result {untouched empty}
# Widget used in 14.* tests
destroy .s
pack [scale .s]
update
test scale-14.1 {RoundToResolution procedure} -body {
test scale-14.1 {RoundValueToResolution procedure} -body {
.s configure -from 0 -to 100 -sliderlength 10 -length 114 -bd 2 \
-orient horizontal -resolution 4.0
update
.s get 84 152
} -result 72
test scale-14.2 {RoundToResolution procedure} -body {
test scale-14.2 {RoundValueToResolution procedure} -body {
.s configure -from 0 -to 100 -sliderlength 10 -length 114 -bd 2 \
-orient horizontal -resolution 4.0
update
.s get 86 152
} -result 76
test scale-14.3 {RoundToResolution procedure} -body {
test scale-14.3 {RoundValueToResolution procedure} -body {
.s configure -from 100 -to 0 -sliderlength 10 -length 114 -bd 2 \
-orient horizontal -resolution 4.0
update
.s get 84 152
} -result 28
test scale-14.4 {RoundToResolution procedure} -body {
test scale-14.4 {RoundValueToResolution procedure} -body {
.s configure -from 100 -to 0 -sliderlength 10 -length 114 -bd 2 \
-orient horizontal -resolution 4.0
update
.s get 86 152
} -result 24
test scale-14.5 {RoundToResolution procedure} -body {
test scale-14.5 {RoundValueToResolution procedure} -body {
.s configure -from -100 -to 0 -sliderlength 10 -length 114 -bd 2 \
-orient horizontal -resolution 4.0
update
.s get 84 152
} -result {-28}
test scale-14.6 {RoundToResolution procedure} -body {
test scale-14.6 {RoundValueToResolution procedure} -body {
.s configure -from -100 -to 0 -sliderlength 10 -length 114 -bd 2 \
-orient horizontal -resolution 4.0
update
.s get 86 152
} -result {-24}
test scale-14.7 {RoundToResolution procedure} -body {
test scale-14.7 {RoundValueToResolution procedure} -body {
.s configure -from 0 -to -100 -sliderlength 10 -length 114 -bd 2 \
-orient horizontal -resolution 4.0
update
.s get 84 152
} -result {-72}
test scale-14.8 {RoundToResolution procedure} -body {
test scale-14.8 {RoundValueToResolution procedure} -body {
.s configure -from 0 -to -100 -sliderlength 10 -length 114 -bd 2 \
-orient horizontal -resolution 4.0
update
.s get 86 152
} -result {-76}
test scale-14.9 {RoundToResolution procedure} -body {
test scale-14.9 {RoundValueToResolution procedure} -body {
.s configure -from 0 -to 2.25 -sliderlength 10 -length 114 -bd 2 \
-orient horizontal -resolution 0
update
.s get 84 152
} -result {1.64}
test scale-14.10 {RoundToResolution procedure} -body {
test scale-14.10 {RoundValueToResolution procedure} -body {
.s configure -from 0 -to 2.25 -sliderlength 10 -length 114 -bd 2 \
-orient horizontal -resolution 0
update
.s get 86 152
} -result {1.69}
test scale-14.11 {RoundToResolution procedure} -body {
test scale-14.11 {RoundValueToResolution procedure} -body {
.s configure -from 0 -to 225 -sliderlength 10 -length 114 -bd 2 \
-orient horizontal -resolution 0 -digits 5
update
.s get 84 152
} -result {164.25}
test scale-14.12 {RoundToResolution procedure} -body {
test scale-14.12 {RoundValueToResolution procedure} -body {
.s configure -from 0 -to 225 -sliderlength 10 -length 114 -bd 2 \
-orient horizontal -resolution 0 -digits 5
update
.s get 86 152
} -result {168.75}
destroy .s
test scale-14.13 {RoundValueToResolution procedure, round-off errors} -setup {
# see [220665ffff], and duplicates [220265ffff] and [779559ffff]
set x NotSet
pack [scale .s -orient horizontal -resolution .1 -from -180 -to 180 -command "set x"]
update
} -body {
.s configure -background red
update
set x
} -cleanup {
destroy .s
} -result {NotSet}
test scale-14a.1 {RoundValueToResolution, RoundIntervalToResolution procedures} -setup {
pack [scale .s -orient horizontal]
update
} -body {
.s configure -length 400 -bd 0 -from 1 -to 9 -resolution 2 -tickinterval 1
update
.s get 200 0
} -cleanup {
destroy .s
} -result {5}
test scale-14a.2 {RoundValueToResolution, RoundIntervalToResolution procedures} -setup {
pack [scale .s -orient horizontal]
update
} -body {
.s configure -length 400 -bd 0 -from -1.5 -to 1.5 -resolution 1 \
-tickinterval 1 -digits 2
update
.s get 250 0
} -cleanup {
destroy .s
} -result {0.5}
test scale-15.1 {ScaleVarProc procedure} -setup {
deleteWindows
} -body {
set y -130
scale .s -from 0 -to -200 -variable y -orient horizontal -length 150
|
︙ | | |
Changes to unix/tkUnixScale.c.
︙ | | |
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
-
+
-
+
|
/ (double) scalePtr->fontHeight;
if (ticks > maxTicks) {
tickInterval *= (ticks / maxTicks);
}
for (tickValue = scalePtr->fromValue; ;
tickValue += tickInterval) {
/*
* The TkRoundToResolution call gets rid of accumulated
* The TkRoundValueToResolution call gets rid of accumulated
* round-off errors, if any.
*/
tickValue = TkRoundToResolution(scalePtr, tickValue);
tickValue = TkRoundValueToResolution(scalePtr, tickValue);
if (scalePtr->toValue >= scalePtr->fromValue) {
if (tickValue > scalePtr->toValue) {
break;
}
} else {
if (tickValue < scalePtr->toValue) {
break;
|
︙ | | |
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
|
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
|
-
+
-
+
|
/ (double) Tk_TextWidth(scalePtr->tkfont, valueString, -1);
if (ticks > maxTicks) {
tickInterval *= (ticks / maxTicks);
}
for (tickValue = scalePtr->fromValue; ;
tickValue += tickInterval) {
/*
* The TkRoundToResolution call gets rid of accumulated
* The TkRoundValueToResolution call gets rid of accumulated
* round-off errors, if any.
*/
tickValue = TkRoundToResolution(scalePtr, tickValue);
tickValue = TkRoundValueToResolution(scalePtr, tickValue);
if (scalePtr->toValue >= scalePtr->fromValue) {
if (tickValue > scalePtr->toValue) {
break;
}
} else {
if (tickValue < scalePtr->toValue) {
break;
|
︙ | | |