mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-04 05:20:42 +00:00
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:
parent
958681e979
commit
667ad46abe
2 changed files with 36 additions and 15 deletions
|
@ -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>
|
2010-06-18 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||||
|
|
||||||
* Source/NSAttributedString.m
|
* Source/NSAttributedString.m
|
||||||
|
|
|
@ -665,10 +665,12 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
|
||||||
|
|
||||||
- (double) closestTickMarkValueToValue: (double)aValue
|
- (double) closestTickMarkValueToValue: (double)aValue
|
||||||
{
|
{
|
||||||
double f;
|
double d, f;
|
||||||
|
|
||||||
if (_numberOfTickMarks == 0)
|
if (_numberOfTickMarks == 0)
|
||||||
return aValue;
|
return aValue;
|
||||||
|
else if (_numberOfTickMarks == 1)
|
||||||
|
return (_maxValue + _minValue) / 2;
|
||||||
|
|
||||||
if (aValue < _minValue)
|
if (aValue < _minValue)
|
||||||
{
|
{
|
||||||
|
@ -679,8 +681,9 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
|
||||||
aValue = _maxValue;
|
aValue = _maxValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
f = ((aValue - _minValue) * _numberOfTickMarks) / (_maxValue - _minValue);
|
d = _maxValue - _minValue;
|
||||||
f = ((rint(f) * (_maxValue - _minValue)) / _numberOfTickMarks) + _minValue;
|
f = ((aValue - _minValue) * (_numberOfTickMarks - 1)) / d;
|
||||||
|
f = ((rint(f) * d) / (_numberOfTickMarks - 1)) + _minValue;
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
@ -713,21 +716,24 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
|
||||||
if ((index < 0) || (index >= _numberOfTickMarks))
|
if ((index < 0) || (index >= _numberOfTickMarks))
|
||||||
{
|
{
|
||||||
[NSException raise: NSRangeException
|
[NSException raise: NSRangeException
|
||||||
format: @"Index of tick mark out of bound."];
|
format: @"Index of tick mark out of bounds."];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_numberOfTickMarks > 1)
|
||||||
|
{
|
||||||
if (_isVertical)
|
if (_isVertical)
|
||||||
{
|
{
|
||||||
d = NSHeight(rect) / _numberOfTickMarks;
|
d = NSHeight(rect) / (_numberOfTickMarks - 1);
|
||||||
rect.size.height = d;
|
rect.size.height = d;
|
||||||
rect.origin.y += d * index;
|
rect.origin.y += d * index;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
d = NSWidth(rect) / _numberOfTickMarks;
|
d = NSWidth(rect) / (_numberOfTickMarks - 1);
|
||||||
rect.size.width = d;
|
rect.size.width = d;
|
||||||
rect.origin.x += d * index;
|
rect.origin.x += d * index;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
@ -764,12 +770,20 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
|
||||||
|
|
||||||
- (double) tickMarkValueAtIndex: (int)index
|
- (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)
|
if (index >= _numberOfTickMarks)
|
||||||
return _maxValue;
|
return _maxValue;
|
||||||
if (index <= 0)
|
if (index <= 0)
|
||||||
return _minValue;
|
return _minValue;
|
||||||
|
|
||||||
return _minValue + index * (_maxValue - _minValue) / _numberOfTickMarks;
|
return _minValue + index * (_maxValue - _minValue) / (_numberOfTickMarks - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) trackMouse: (NSEvent*)theEvent
|
- (BOOL) trackMouse: (NSEvent*)theEvent
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue