Commit 8aa0cd85 authored by Marvin Scholz's avatar Marvin Scholz

macosx: Fix DefaultValueSlider tickmark position in RTL layout

parent d6bf647e
......@@ -117,46 +117,39 @@
}
/*
* Adapted from GNUstep NSSliderCell
* - (NSRect)knobRectFlipped:(BOOL)flipped
*
* Calculates the knobRect for a given position
* This is later used to draw the default tick mark in the center of
* where the knob would be, when it is at the default value.
*/
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
- (NSRect)knobRectFlipped:(BOOL)flipped forValue:(double)doubleValue
{
NSRect superRect = [super knobRectFlipped:flipped];
NSPoint origin = _trackRect.origin;
NSSize size = superRect.size;
if ([self isVertical] && flipped) {
doubleValue = _maxValue + _minValue - doubleValue;
}
doubleValue = (doubleValue - _minValue) / (_maxValue - _minValue);
if ([self isVertical] == YES) {
origin.x = superRect.origin.x;
origin.y += (_trackRect.size.height - size.height) * doubleValue;
} else {
origin.x += ((_trackRect.size.width - size.width) * doubleValue);
origin.y = superRect.origin.y;
}
return NSMakeRect(origin.x, origin.y, size.width, size.height);
}
- (NSRect)knobRectFlipped:(BOOL)flipped forValue:(double)doubleValue
{
NSRect resultRect;
double val = [self normalizedValue:doubleValue] / 100;
if (self.isVertical) {
resultRect.origin.x = -1;
resultRect.origin.y = (NSHeight(_trackRect) - self.knobThickness) * val;
if (_isRTL)
resultRect.origin.y = (NSHeight(_trackRect) - self.knobThickness) - resultRect.origin.y;
} else {
resultRect.origin.x = (NSWidth(_trackRect) - self.knobThickness) * val;
resultRect.origin.y = -1;
if (_isRTL)
resultRect.origin.x = (NSWidth(_trackRect) - self.knobThickness) - resultRect.origin.x;
}
resultRect.size.height = self.knobThickness;
resultRect.size.width = self.knobThickness;
return [self.controlView backingAlignedRect:resultRect options:NSAlignAllEdgesNearest];
}
#pragma mark -
#pragma mark Overwritten super methods
- (NSRect)knobRectFlipped:(BOOL)flipped
{
return [self knobRectFlipped:flipped forValue:[self doubleValue]];
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
// Do all other drawing
......
......@@ -155,25 +155,6 @@
[NSGraphicsContext restoreGraphicsState];
}
- (double)myNormalizedDouble
{
double min = [self minValue];
double max = [self maxValue];
double current = [self doubleValue];
max -= min;
current -= min;
return current / max;
}
- (NSRect)knobRectFlipped:(BOOL)flipped
{
double val = [self myNormalizedDouble];
NSRect rect = NSMakeRect((NSWidth(_trackRect) - self.knobThickness) * val, -1, self.knobThickness, self.knobThickness);
return [[self controlView] backingAlignedRect:rect options:NSAlignAllEdgesNearest];
}
- (void)drawBarInside:(NSRect)rect flipped:(BOOL)flipped
{
// Inset rect
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment