mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 11:11:05 +00:00
Implement ticks for level indicator. Code by Christopher Elsmore
<elsmorian@gmail.com>. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25378 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8b5ef317f7
commit
c463685ee7
4 changed files with 283 additions and 168 deletions
|
@ -1,3 +1,11 @@
|
|||
2007-08-03 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSView.m (-displayIfNeededInRectIgnoringOpacity:):
|
||||
Correct spelling in comment.
|
||||
* Headers/AppKit/NSLevelIndicatorCell.h: Add ivar for cell frame.
|
||||
* Source/NSLevelIndicator.m (-rectOfTickMarkAtIndex:, -cellSize): Implement.
|
||||
Patch by Christopher Elsmore <elsmorian@gmail.com>.
|
||||
|
||||
2007-08-03 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Headers/AppKit/NSDocumentController.h,
|
||||
|
|
|
@ -53,6 +53,7 @@ typedef enum _NSLevelIndicatorStyle
|
|||
int _numberOfTickMarks;
|
||||
NSLevelIndicatorStyle _style;
|
||||
NSTickMarkPosition _tickMarkPosition;
|
||||
NSRect _cellFrame;
|
||||
}
|
||||
|
||||
- (id)initWithLevelIndicatorStyle:(NSLevelIndicatorStyle)style;
|
||||
|
|
|
@ -64,14 +64,14 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
- (id) copyWithZone:(NSZone *) zone;
|
||||
- (id) copyWithZone:(NSZone *) zone
|
||||
{
|
||||
NSLevelIndicatorCell *c = [super copyWithZone: zone];
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
- (void) dealloc;
|
||||
- (void) dealloc
|
||||
{
|
||||
[super dealloc];
|
||||
}
|
||||
|
@ -159,7 +159,7 @@
|
|||
|
||||
- (double) tickMarkValueAtIndex: (int)index
|
||||
{
|
||||
if ((index < 0) || (index > _numberOfTickMarks))
|
||||
if ((index < 0) || (index >= _numberOfTickMarks))
|
||||
{
|
||||
[NSException raise: NSRangeException
|
||||
format: @"tick mark index invalid"];
|
||||
|
@ -168,22 +168,123 @@
|
|||
return _minValue + index * (_maxValue - _minValue) / _numberOfTickMarks;
|
||||
}
|
||||
|
||||
- (NSRect) rectOfTickMarkAtIndex: (int)index;
|
||||
- (NSRect) rectOfTickMarkAtIndex: (int)index
|
||||
{
|
||||
if ((index < 0) || (index > _numberOfTickMarks))
|
||||
NSRect cellRect = NSZeroRect;
|
||||
float frameWidth = _cellFrame.size.width;
|
||||
|
||||
if ((index < 0) || (index >= _numberOfTickMarks))
|
||||
{
|
||||
[NSException raise: NSRangeException
|
||||
format: @"tick mark index invalid"];
|
||||
}
|
||||
|
||||
// FIXME: Need to cache the cell frame for this
|
||||
return NSZeroRect;
|
||||
// Create default minor tickmark size in cellRect
|
||||
cellRect.size.width = 1;
|
||||
cellRect.size.height = 4;
|
||||
|
||||
// If all tick marks are major:
|
||||
if (_numberOfTickMarks <= _numberOfMajorTickMarks)
|
||||
{
|
||||
// Use major tick mark size
|
||||
cellRect.size.width = 3;
|
||||
cellRect.size.height = 7;
|
||||
}
|
||||
// If major tick marks fit with even spacing
|
||||
else if ((_numberOfTickMarks -1) % (_numberOfMajorTickMarks - 1) == 0)
|
||||
{
|
||||
int minorTicksPerMajor = (_numberOfTickMarks - 1) / (_numberOfMajorTickMarks - 1);
|
||||
|
||||
// If index is a major tick mark
|
||||
if (index % minorTicksPerMajor == 0)
|
||||
{
|
||||
// Use major tick mark size
|
||||
cellRect.size.width = 3;
|
||||
cellRect.size.height = 7;
|
||||
}
|
||||
}
|
||||
// FIXME: Extra tick mark code, when all major tick marks don't fit but a lesser amount will
|
||||
|
||||
// Last tick mark
|
||||
if (index == (_numberOfTickMarks - 1))
|
||||
{
|
||||
cellRect.origin.x = (frameWidth - cellRect.size.width);
|
||||
}
|
||||
// Not the first tick mark. (First tick mark will use 0,0 default values already set)
|
||||
else if (index != 0)
|
||||
{
|
||||
float spacing = (frameWidth / (_numberOfTickMarks - 1)) * index;
|
||||
cellRect.origin.x = spacing - (cellRect.size.width / 2);
|
||||
}
|
||||
|
||||
- (NSSize) cellSize;
|
||||
// Set origins if tick marks are above the indicator
|
||||
if (_tickMarkPosition == NSTickMarkAbove)
|
||||
{
|
||||
// FIXME: sum up all widths and use default height for controlSize
|
||||
return [super cellSize];
|
||||
switch (_style)
|
||||
{
|
||||
case NSContinuousCapacityLevelIndicatorStyle:
|
||||
{
|
||||
cellRect.origin.y = 16;
|
||||
break;
|
||||
}
|
||||
case NSRelevancyLevelIndicatorStyle:
|
||||
{
|
||||
cellRect.origin.y = 12;
|
||||
break;
|
||||
}
|
||||
case NSRatingLevelIndicatorStyle:
|
||||
{
|
||||
cellRect.origin.y = 13;
|
||||
break;
|
||||
}
|
||||
case NSDiscreteCapacityLevelIndicatorStyle:
|
||||
{
|
||||
cellRect.origin.y = 18;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// If tick mark is minor and below indicator, use y origin of 3. If not, default value of 0 is used
|
||||
else if (cellRect.size.width == 1)
|
||||
{
|
||||
cellRect.origin.y = 3;
|
||||
}
|
||||
|
||||
return NSIntegralRect(cellRect);
|
||||
}
|
||||
|
||||
- (NSSize) cellSize
|
||||
{
|
||||
// Sizes are the same as those from OSX
|
||||
NSSize cellSize = NSMakeSize(400000, 25);
|
||||
|
||||
// Change cellSize to the correct size:
|
||||
switch (_style)
|
||||
{
|
||||
case NSContinuousCapacityLevelIndicatorStyle:
|
||||
{
|
||||
cellSize.height = 23;
|
||||
break;
|
||||
}
|
||||
case NSRelevancyLevelIndicatorStyle:
|
||||
{
|
||||
cellSize.height = 19;
|
||||
break;
|
||||
}
|
||||
case NSRatingLevelIndicatorStyle:
|
||||
{
|
||||
cellSize.height = 20;
|
||||
cellSize.width = 13 * _maxValue;
|
||||
break;
|
||||
}
|
||||
case NSDiscreteCapacityLevelIndicatorStyle:
|
||||
{
|
||||
cellSize.height = 25;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return cellSize;
|
||||
}
|
||||
|
||||
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||
|
@ -193,6 +294,7 @@
|
|||
double val = (value -_minValue) / (_maxValue -_minValue);
|
||||
BOOL vertical = (cellFrame.size.height > cellFrame.size.width);
|
||||
|
||||
_cellFrame = cellFrame;
|
||||
if (value < _warningValue)
|
||||
fillColor = [NSColor greenColor];
|
||||
else if (value < _criticalValue)
|
||||
|
@ -205,7 +307,9 @@
|
|||
// FIXME: this code only works for horizontal frames
|
||||
float x;
|
||||
float y0, y1;
|
||||
float step = _numberOfTickMarks > 1 ? (cellFrame.size.width - 1.0) / (_numberOfTickMarks - 1) : 1.0;
|
||||
float step = _numberOfTickMarks > 1 ?
|
||||
(cellFrame.size.width - 1.0) / (_numberOfTickMarks - 1) :
|
||||
1.0;
|
||||
int tick;
|
||||
|
||||
if (_tickMarkPosition == NSTickMarkBelow)
|
||||
|
@ -236,7 +340,9 @@
|
|||
{
|
||||
int segments = (int)(_maxValue - _minValue);
|
||||
// width of one segment
|
||||
float step = (segments > 0) ? ((vertical ? cellFrame.size.height : cellFrame.size.width) / segments) : 10.0;
|
||||
float step = (segments > 0) ?
|
||||
((vertical ? cellFrame.size.height : cellFrame.size.width) / segments) :
|
||||
10.0;
|
||||
int i;
|
||||
int ifill = val * segments + 0.5;
|
||||
|
||||
|
|
|
@ -2254,8 +2254,8 @@ convert_rect_using_matrices(NSRect aRect, NSAffineTransform *matrix1,
|
|||
|
||||
/*
|
||||
* If we still need display after displaying the invalid rectangle,
|
||||
* this means, some subviews still need to display. For opaque subviews
|
||||
* there invalid rectangle may even overlap the original aRect.
|
||||
* this means that some subviews still need to display. For opaque subviews
|
||||
* their invalid rectangle may even overlap the original aRect.
|
||||
* Display any subview that need display.
|
||||
*/
|
||||
if (_rFlags.needs_display == YES)
|
||||
|
|
Loading…
Reference in a new issue