mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-01 00:00:48 +00:00
Basic implementation of the tick mark methods. Added en-/decoding
for tick marks. [setKnobThickness:], [setNumberOfTickMarks:] and [setTickMarkPosition:] now update the control. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@16543 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
f3e456cd83
commit
2ff2caa7ec
1 changed files with 90 additions and 12 deletions
|
@ -24,7 +24,10 @@
|
||||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <math.h> // (float)rintf(float x)
|
||||||
|
#include <gnustep/gui/config.h>
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
|
#include <Foundation/NSException.h>
|
||||||
|
|
||||||
#include <AppKit/NSSliderCell.h>
|
#include <AppKit/NSSliderCell.h>
|
||||||
#include <AppKit/NSColor.h>
|
#include <AppKit/NSColor.h>
|
||||||
|
@ -33,6 +36,7 @@
|
||||||
#include <AppKit/NSImage.h>
|
#include <AppKit/NSImage.h>
|
||||||
#include <AppKit/NSTextFieldCell.h>
|
#include <AppKit/NSTextFieldCell.h>
|
||||||
|
|
||||||
|
DEFINE_RINT_IF_MISSING
|
||||||
|
|
||||||
/**
|
/**
|
||||||
<unit>
|
<unit>
|
||||||
|
@ -56,6 +60,16 @@
|
||||||
*/
|
*/
|
||||||
@implementation NSSliderCell
|
@implementation NSSliderCell
|
||||||
|
|
||||||
|
+ (void) initialize
|
||||||
|
{
|
||||||
|
if (self == [NSSliderCell class])
|
||||||
|
{
|
||||||
|
/* Set the class version to 2, as tick information is now
|
||||||
|
stored in the encoding */
|
||||||
|
[self setVersion: 2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (id) init
|
- (id) init
|
||||||
{
|
{
|
||||||
self = [self initImageCell: nil];
|
self = [self initImageCell: nil];
|
||||||
|
@ -96,7 +110,7 @@
|
||||||
only.</p> */
|
only.</p> */
|
||||||
- (void) drawBarInside: (NSRect)rect flipped: (BOOL)flipped
|
- (void) drawBarInside: (NSRect)rect flipped: (BOOL)flipped
|
||||||
{
|
{
|
||||||
[[NSColor scrollBarColor] set];
|
[[NSColor scrollBarColor] set];
|
||||||
NSRectFill(rect);
|
NSRectFill(rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,6 +251,12 @@
|
||||||
size.width = thickness;
|
size.width = thickness;
|
||||||
|
|
||||||
[image setSize: size];
|
[image setSize: size];
|
||||||
|
|
||||||
|
if ((_control_view != nil) &&
|
||||||
|
([_control_view isKindOfClass: [NSControl class]]))
|
||||||
|
{
|
||||||
|
[(NSControl*)_control_view updateCell: self];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets the value by which the slider will be be incremented when with the
|
/** Sets the value by which the slider will be be incremented when with the
|
||||||
|
@ -379,22 +399,39 @@
|
||||||
|
|
||||||
- (double) closestTickMarkValueToValue: (double)aValue
|
- (double) closestTickMarkValueToValue: (double)aValue
|
||||||
{
|
{
|
||||||
if (aValue < _minValue)
|
double f;
|
||||||
return _minValue;
|
|
||||||
else if (aValue > _maxValue)
|
|
||||||
return _maxValue;
|
|
||||||
|
|
||||||
if (_numberOfTickMarks == 0)
|
if (_numberOfTickMarks == 0)
|
||||||
return aValue;
|
return aValue;
|
||||||
|
|
||||||
// FIXME
|
if (aValue < _minValue)
|
||||||
return 0.0;
|
{
|
||||||
|
aValue = _minValue;
|
||||||
|
}
|
||||||
|
else if (aValue > _maxValue)
|
||||||
|
{
|
||||||
|
aValue = _maxValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
f = ((aValue - _minValue) * _numberOfTickMarks) / (_maxValue - _minValue);
|
||||||
|
f = ((rint(f) * (_maxValue - _minValue)) / _numberOfTickMarks) + _minValue;
|
||||||
|
|
||||||
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int) indexOfTickMarkAtPoint: (NSPoint)point
|
- (int) indexOfTickMarkAtPoint: (NSPoint)point
|
||||||
{
|
{
|
||||||
// FIXME
|
int i;
|
||||||
return 0;
|
|
||||||
|
for (i = 0; i < _numberOfTickMarks; i++)
|
||||||
|
{
|
||||||
|
if (NSPointInRect(point, [self rectOfTickMarkAtIndex: i]))
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NSNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int) numberOfTickMarks
|
- (int) numberOfTickMarks
|
||||||
|
@ -404,8 +441,29 @@
|
||||||
|
|
||||||
- (NSRect) rectOfTickMarkAtIndex: (int)index
|
- (NSRect) rectOfTickMarkAtIndex: (int)index
|
||||||
{
|
{
|
||||||
// FIXME
|
NSRect rect = _trackRect;
|
||||||
return NSZeroRect;
|
float d;
|
||||||
|
|
||||||
|
if ((index < 0) || (index >= _numberOfTickMarks))
|
||||||
|
{
|
||||||
|
[NSException raise: NSRangeException
|
||||||
|
format: @"Index of tick mark out of bound."];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_isVertical)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setAllowsTickMarkValuesOnly: (BOOL)flag
|
- (void) setAllowsTickMarkValuesOnly: (BOOL)flag
|
||||||
|
@ -416,11 +474,21 @@
|
||||||
- (void) setNumberOfTickMarks: (int)numberOfTickMarks
|
- (void) setNumberOfTickMarks: (int)numberOfTickMarks
|
||||||
{
|
{
|
||||||
_numberOfTickMarks = numberOfTickMarks;
|
_numberOfTickMarks = numberOfTickMarks;
|
||||||
|
if ((_control_view != nil) &&
|
||||||
|
([_control_view isKindOfClass: [NSControl class]]))
|
||||||
|
{
|
||||||
|
[(NSControl*)_control_view updateCell: self];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setTickMarkPosition: (NSTickMarkPosition)position
|
- (void) setTickMarkPosition: (NSTickMarkPosition)position
|
||||||
{
|
{
|
||||||
_tickMarkPosition = position;
|
_tickMarkPosition = position;
|
||||||
|
if ((_control_view != nil) &&
|
||||||
|
([_control_view isKindOfClass: [NSControl class]]))
|
||||||
|
{
|
||||||
|
[(NSControl*)_control_view updateCell: self];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSTickMarkPosition) tickMarkPosition
|
- (NSTickMarkPosition) tickMarkPosition
|
||||||
|
@ -445,6 +513,12 @@
|
||||||
&_minValue, &_maxValue, &_altIncrementValue, &_isVertical];
|
&_minValue, &_maxValue, &_altIncrementValue, &_isVertical];
|
||||||
[decoder decodeValueOfObjCType: @encode(id) at: &_titleCell];
|
[decoder decodeValueOfObjCType: @encode(id) at: &_titleCell];
|
||||||
[decoder decodeValueOfObjCType: @encode(id) at: &_knobCell];
|
[decoder decodeValueOfObjCType: @encode(id) at: &_knobCell];
|
||||||
|
if ([decoder versionForClassName: @"NSSliderCell"] >= 2)
|
||||||
|
{
|
||||||
|
[decoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsTickMarkValuesOnly];
|
||||||
|
[decoder decodeValueOfObjCType: @encode(int) at: &_numberOfTickMarks];
|
||||||
|
[decoder decodeValueOfObjCType: @encode(int) at: &_tickMarkPosition];
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,6 +529,10 @@
|
||||||
&_minValue, &_maxValue, &_altIncrementValue, &_isVertical];
|
&_minValue, &_maxValue, &_altIncrementValue, &_isVertical];
|
||||||
[coder encodeValueOfObjCType: @encode(id) at: &_titleCell];
|
[coder encodeValueOfObjCType: @encode(id) at: &_titleCell];
|
||||||
[coder encodeValueOfObjCType: @encode(id) at: &_knobCell];
|
[coder encodeValueOfObjCType: @encode(id) at: &_knobCell];
|
||||||
|
// New for version 2
|
||||||
|
[coder encodeValueOfObjCType: @encode(BOOL) at: &_allowsTickMarkValuesOnly];
|
||||||
|
[coder encodeValueOfObjCType: @encode(int) at: &_numberOfTickMarks];
|
||||||
|
[coder encodeValueOfObjCType: @encode(int) at: &_tickMarkPosition];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue