Fix tick mark related calculations of NSSliderCell to correctly take

into account that the first and last tick marks conincide with the
minimum and maximum values of the slider.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@30804 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Wolfgang Lux 2010-06-21 19:42:08 +00:00
parent 081fc4e701
commit 3b077dae8a
2 changed files with 36 additions and 15 deletions

View file

@ -1,3 +1,10 @@
2010-06-21 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/NSSliderCell.m (-closestTickMarkValueToValue:,
-rectOfTickMarkAtIndex:, -tickMarkValueAtIndex:): Fix tick mark
related calculations to correctly take into account that the first
and last tick marks conincide with the minimum and maximum values.
2010-06-18 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/NSAttributedString.m

View file

@ -665,10 +665,12 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
- (double) closestTickMarkValueToValue: (double)aValue
{
double f;
double d, f;
if (_numberOfTickMarks == 0)
return aValue;
else if (_numberOfTickMarks == 1)
return (_maxValue + _minValue) / 2;
if (aValue < _minValue)
{
@ -679,8 +681,9 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
aValue = _maxValue;
}
f = ((aValue - _minValue) * _numberOfTickMarks) / (_maxValue - _minValue);
f = ((rint(f) * (_maxValue - _minValue)) / _numberOfTickMarks) + _minValue;
d = _maxValue - _minValue;
f = ((aValue - _minValue) * (_numberOfTickMarks - 1)) / d;
f = ((rint(f) * d) / (_numberOfTickMarks - 1)) + _minValue;
return f;
}
@ -713,20 +716,23 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
if ((index < 0) || (index >= _numberOfTickMarks))
{
[NSException raise: NSRangeException
format: @"Index of tick mark out of bound."];
format: @"Index of tick mark out of bounds."];
}
if (_isVertical)
if (_numberOfTickMarks > 1)
{
d = NSHeight(rect) / _numberOfTickMarks;
rect.size.height = d;
rect.origin.y += d * index;
}
else
{
d = NSWidth(rect) / _numberOfTickMarks;
rect.size.width = d;
rect.origin.x += d * index;
if (_isVertical)
{
d = NSHeight(rect) / (_numberOfTickMarks - 1);
rect.size.height = d;
rect.origin.y += d * index;
}
else
{
d = NSWidth(rect) / (_numberOfTickMarks - 1);
rect.size.width = d;
rect.origin.x += d * index;
}
}
return rect;
@ -764,12 +770,20 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
- (double) tickMarkValueAtIndex: (int)index
{
if ((index < 0) || (index >= _numberOfTickMarks))
{
[NSException raise: NSRangeException
format: @"Index of tick mark out of bounds."];
}
if (_numberOfTickMarks == 1)
return (_maxValue + _minValue) / 2;
if (index >= _numberOfTickMarks)
return _maxValue;
if (index <= 0)
return _minValue;
return _minValue + index * (_maxValue - _minValue) / _numberOfTickMarks;
return _minValue + index * (_maxValue - _minValue) / (_numberOfTickMarks - 1);
}
- (BOOL) trackMouse: (NSEvent*)theEvent