26 @
typedef CPTickMarkPosition
32 @
typedef CPLevelIndicatorStyle
49 double _criticalValue;
50 CPTickMarkPosition _tickMarkPosition;
51 int _numberOfTickMarks;
52 int _numberOfMajorTickMarks;
61 return "level-indicator";
76 - (id)initWithFrame:(CGRect)aFrame
91 - (void)layoutSubviews
97 [bezelView setBackgroundColor:[
self valueForThemeAttribute:@"bezel-color"]];
99 var segmentCount = _maxValue - _minValue;
101 if (segmentCount <= 0)
104 var filledColor = [
self valueForThemeAttribute:@"color-normal"],
107 if (_warningValue < _criticalValue)
109 if (value >= _criticalValue)
110 filledColor = [
self valueForThemeAttribute:@"color-critical"];
111 else if (value >= _warningValue)
112 filledColor = [
self valueForThemeAttribute:@"color-warning"];
116 if (value <= _criticalValue)
117 filledColor = [
self valueForThemeAttribute:@"color-critical"];
118 else if (value <= _warningValue)
119 filledColor = [
self valueForThemeAttribute:@"color-warning"];
123 for (var i = 0; i < segmentCount; i++)
129 [segmentView setBackgroundColor:(_minValue + i) < value ? filledColor : [
self valueForThemeAttribute:@"color-empty"]];
135 return [[
CPView alloc] initWithFrame:CGRectMakeZero()];
138 - (CGRect)rectForEphemeralSubviewNamed:(
CPString)aViewName
141 var bezelHeight = 18,
145 if (aViewName ==
"bezel")
147 bounds.origin.y = (CGRectGetHeight(
bounds) - bezelHeight) / 2.0;
148 bounds.size.height = bezelHeight;
151 else if (aViewName.indexOf(
"segment-bezel") === 0)
153 var segment = parseInt(aViewName.substring(
"segment-bezel-".length), 10),
154 segmentCount = _maxValue - _minValue;
156 if (segment >= segmentCount)
157 return CGRectMakeZero();
159 var basicSegmentWidth =
bounds.size.width / segmentCount,
160 segmentFrame = CGRectCreateCopy([
self bounds]),
161 spacing = [
self valueForThemeAttribute:@"spacing"];
163 segmentFrame.origin.y = (CGRectGetHeight(
bounds) - bezelHeight) / 2.0;
164 segmentFrame.origin.x = FLOOR(segment * basicSegmentWidth);
165 segmentFrame.size.width = (segment == segmentCount - 1) ?
bounds.size.width - segmentFrame.origin.x : FLOOR(((segment + 1) * basicSegmentWidth)) - FLOOR((segment * basicSegmentWidth)) - spacing;
166 segmentFrame.size.height = segmentHeight;
171 return CGRectMakeZero();
177 - (void)setEditable:(BOOL)shouldBeEditable
179 if (_isEditable === shouldBeEditable)
182 _isEditable = shouldBeEditable;
196 if (![
self isEditable])
204 if (![
self isEditable] || ![
self isEnabled])
207 [
self _trackMouse:anEvent];
210 - (void)_trackMouse:(
CPEvent)anEvent
212 var type = [anEvent
type];
216 var segmentCount = _maxValue - _minValue;
218 if (segmentCount <= 0)
223 oldValue = [
self doubleValue],
231 newValue = _minValue;
235 newValue = _maxValue;
239 for (var i = 0; i < segmentCount; i++)
241 var rect = [
self rectForEphemeralSubviewNamed:"segment-bezel-" + i];
244 if (location.x >= CGRectGetMinX(rect) && location.x < CGRectGetMaxX(rect))
246 newValue = (_minValue + i + 1);
252 if (newValue != oldValue)
253 [
self setDoubleValue:newValue];
257 [CPApp setTarget:self selector:@selector(_trackMouse:) forNextEventMatchingMask:CPLeftMouseDraggedMask | CPLeftMouseUpMask untilDate:nil inMode:nil dequeue:YES];
259 if ([
self isContinuous])
260 [
self sendAction:[
self action] to:[
self target]];
262 else if (_isTracking)
265 [
self sendAction:[
self action] to:[
self target]];
274 - (void)setMinValue:(
double)minValue
276 if (_minValue === minValue)
278 _minValue = minValue;
283 - (void)setMaxValue:(
double)maxValue
285 if (_maxValue === maxValue)
287 _maxValue = maxValue;
292 - (void)setWarningValue:(
double)warningValue
294 if (_warningValue === warningValue)
296 _warningValue = warningValue;
301 - (void)setCriticalValue:(
double)criticalValue
303 if (_criticalValue === criticalValue)
305 _criticalValue = criticalValue;
344 _levelIndicatorStyle = [aCoder decodeIntForKey:CPLevelIndicatorStyleKey];
345 _minValue = [aCoder decodeDoubleForKey:CPLevelIndicatorMinValueKey];
346 _maxValue = [aCoder decodeDoubleForKey:CPLevelIndicatorMaxValueKey];
347 _warningValue = [aCoder decodeDoubleForKey:CPLevelIndicatorWarningValueKey];
348 _criticalValue = [aCoder decodeDoubleForKey:CPLevelIndicatorCriticalValueKey];
349 _tickMarkPosition = [aCoder decodeIntForKey:CPLevelIndicatorTickMarkPositionKey];
350 _numberOfTickMarks = [aCoder decodeIntForKey:CPLevelIndicatorNumberOfTickMarksKey];
351 _numberOfMajorTickMarks = [aCoder decodeIntForKey:CPLevelIndicatorNumberOfMajorTickMarksKey];
353 _isEditable = [aCoder decodeBoolForKey:CPLevelIndicatorIsEditableKey];
366 [aCoder encodeInt:_levelIndicatorStyle forKey:CPLevelIndicatorStyleKey];
367 [aCoder encodeDouble:_minValue forKey:CPLevelIndicatorMinValueKey];
368 [aCoder encodeDouble:_maxValue forKey:CPLevelIndicatorMaxValueKey];
369 [aCoder encodeDouble:_warningValue forKey:CPLevelIndicatorWarningValueKey];
370 [aCoder encodeDouble:_criticalValue forKey:CPLevelIndicatorCriticalValueKey];
371 [aCoder encodeInt:_tickMarkPosition forKey:CPLevelIndicatorTickMarkPositionKey];
372 [aCoder encodeInt:_numberOfTickMarks forKey:CPLevelIndicatorNumberOfTickMarksKey];
373 [aCoder encodeInt:_numberOfMajorTickMarks forKey:CPLevelIndicatorNumberOfMajorTickMarksKey];
374 [aCoder encodeBool:_isEditable forKey:CPLevelIndicatorIsEditableKey];
386 return _levelIndicatorStyle;
394 _levelIndicatorStyle = aValue;
408 - (void)setMinValue:(
double)aValue
424 - (void)setMaxValue:(
double)aValue
432 - (double)warningValue
434 return _warningValue;
440 - (void)setWarningValue:(
double)aValue
442 _warningValue = aValue;
448 - (double)criticalValue
450 return _criticalValue;
456 - (void)setCriticalValue:(
double)aValue
458 _criticalValue = aValue;
464 - (CPTickMarkPosition)tickMarkPosition
466 return _tickMarkPosition;
472 - (void)setTickMarkPosition:(CPTickMarkPosition)aValue
474 _tickMarkPosition = aValue;
480 - (int)numberOfTickMarks
482 return _numberOfTickMarks;
488 - (void)setNumberOfTickMarks:(
int)aValue
490 _numberOfTickMarks = aValue;
496 - (int)numberOfMajorTickMarks
498 return _numberOfMajorTickMarks;
504 - (void)setNumberOfMajorTickMarks:(
int)aValue
506 _numberOfMajorTickMarks = aValue;
var CPLevelIndicatorNumberOfTickMarksKey
CPRatingLevelIndicatorStyle
var CPLevelIndicatorMaxValueKey
An object representation of nil.
CGPoint locationInWindow()
CPDiscreteCapacityLevelIndicatorStyle
id initWithFrame:(CGRect aFrame)
global CPApp typedef CPTickMarkPosition CPTickMarkBelow
CPView hitTest:(CGPoint aPoint)
CPContinuousCapacityLevelIndicatorStyle
A mutable key-value pair collection.
var CPLevelIndicatorCriticalValueKey
var CPLevelIndicatorTickMarkPositionKey
An immutable string (collection of characters).
id initWithCoder:(CPCoder aCoder)
void setNeedsDisplay:(BOOL aFlag)
var CPLevelIndicatorStyleKey
var CPLevelIndicatorMinValueKey
var CPLevelIndicatorNumberOfMajorTickMarksKey
Defines methods for use when archiving & restoring (enc/decoding).
var CPLevelIndicatorIsEditableKey
CPLevelIndicatorStyle CPRelevancyLevelIndicatorStyle
void encodeWithCoder:(CPCoder aCoder)
CPView layoutEphemeralSubviewNamed:positioned:relativeToEphemeralSubviewNamed:(CPString aViewName, [positioned] CPWindowOrderingMode anOrderingMode, [relativeToEphemeralSubviewNamed] CPString relativeToViewName)
var CPLevelIndicatorWarningValueKey