Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Bart Louwers <bart@emeel.net>
38 lines
1.3 KiB
Objective-C
38 lines
1.3 KiB
Objective-C
#import "MLNCompassCell.h"
|
|
|
|
@implementation MLNCompassCell
|
|
|
|
- (instancetype)init {
|
|
if (self = [super init]) {
|
|
#pragma GCC diagnostic push
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
self.sliderType = NSCircularSlider;
|
|
#pragma GCC diagnostic pop
|
|
// A tick mark for each cardinal direction.
|
|
self.numberOfTickMarks = 4;
|
|
// This slider goes backwards!
|
|
self.minValue = -360;
|
|
self.maxValue = 0;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)drawKnob:(NSRect)knobRect {
|
|
// Draw a red triangle pointing whichever way the slider is facing.
|
|
NSBezierPath *trianglePath = [NSBezierPath bezierPath];
|
|
[trianglePath moveToPoint:NSMakePoint(NSMinX(knobRect), NSMaxY(knobRect))];
|
|
[trianglePath lineToPoint:NSMakePoint(NSMaxX(knobRect), NSMaxY(knobRect))];
|
|
[trianglePath lineToPoint:NSMakePoint(NSMidX(knobRect), NSMinY(knobRect))];
|
|
[trianglePath closePath];
|
|
NSAffineTransform *transform = [NSAffineTransform transform];
|
|
[transform translateXBy:NSMidX(knobRect) yBy:NSMidY(knobRect)];
|
|
[transform scaleBy:0.8];
|
|
[transform rotateByDegrees:self.doubleValue];
|
|
[transform translateXBy:-NSMidX(knobRect) yBy:-NSMidY(knobRect)];
|
|
[trianglePath transformUsingAffineTransform:transform];
|
|
[[NSColor redColor] setFill];
|
|
[trianglePath fill];
|
|
}
|
|
|
|
@end
|