mirror of
https://github.com/darlinghq/darling-rik-theme.git
synced 2025-02-22 18:40:51 +00:00
segmented cell
This commit is contained in:
parent
16c8e73806
commit
b6cd1813e8
@ -19,8 +19,10 @@ Rik_OBJC_FILES = \
|
||||
Rik+Scroller.m\
|
||||
Rik+ColorWell.m\
|
||||
Rik+Stepper.m\
|
||||
Rik+Segmented.m\
|
||||
GSStandardDecorationView+Rik.m\
|
||||
NSWindow+Rik.m\
|
||||
NSSegmentedCell+Rik.m\
|
||||
RikWindowButton.m\
|
||||
RikWindowButtonCell.m\
|
||||
RikScrollerKnobSlotCell.m
|
||||
|
61
NSSegmentedCell+Rik.m
Normal file
61
NSSegmentedCell+Rik.m
Normal file
@ -0,0 +1,61 @@
|
||||
#include "Rik.h"
|
||||
|
||||
@interface NSSegmentedCell(RikTheme)
|
||||
@end
|
||||
@implementation NSSegmentedCell(RikTheme)
|
||||
|
||||
|
||||
- (NSColor*) textColor
|
||||
{
|
||||
//IT DOES NOT WORKS
|
||||
if(_cell.state == GSThemeSelectedState)
|
||||
return [NSColor whiteColor];
|
||||
if (_cell.is_disabled)
|
||||
return [NSColor disabledControlTextColor];
|
||||
else
|
||||
return [NSColor controlTextColor];
|
||||
}
|
||||
- (void) _drawBorderAndBackgroundWithFrame: (NSRect)cellFrame
|
||||
inView: (NSView*)controlView
|
||||
{
|
||||
CGFloat radius = 4;
|
||||
cellFrame = NSInsetRect(cellFrame, 0.5, 0.5);
|
||||
NSColor* strokeColorButton = [Rik controlStrokeColor];
|
||||
NSBezierPath* roundedRectanglePath = [NSBezierPath bezierPathWithRoundedRect: cellFrame
|
||||
xRadius: radius
|
||||
yRadius: radius];
|
||||
[strokeColorButton setStroke];
|
||||
[roundedRectanglePath setLineWidth: 1];
|
||||
[roundedRectanglePath stroke];
|
||||
NSInteger i;
|
||||
NSUInteger count = [_items count];
|
||||
NSRect frame = cellFrame;
|
||||
NSRect controlFrame = [controlView frame];
|
||||
|
||||
NSBezierPath* linesPath = [NSBezierPath bezierPath];
|
||||
[linesPath setLineWidth: 1];
|
||||
CGFloat offsetX = 0;
|
||||
for (i = 0; i < count-1;i++)
|
||||
{
|
||||
frame.size.width = [[_items objectAtIndex: i] width];
|
||||
if(frame.size.width == 0.0)
|
||||
{
|
||||
frame.size.width = (controlFrame.size.width - frame.origin.x) / (count);
|
||||
}
|
||||
offsetX += frame.size.width;
|
||||
offsetX = floor(offsetX) + 0.5;
|
||||
[linesPath moveToPoint: NSMakePoint(offsetX, NSMinY(frame))];
|
||||
[linesPath lineToPoint: NSMakePoint(offsetX, NSMaxY(frame))];
|
||||
}
|
||||
[linesPath stroke];
|
||||
}
|
||||
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||
{
|
||||
if (NSIsEmptyRect(cellFrame))
|
||||
return;
|
||||
// i want to draw the border for last
|
||||
[self drawInteriorWithFrame: cellFrame inView: controlView];
|
||||
[self _drawBorderAndBackgroundWithFrame: cellFrame inView: controlView];
|
||||
//[self _drawFocusRingWithFrame: cellFrame inView: controlView];
|
||||
}
|
||||
@end
|
57
Rik+Segmented.m
Normal file
57
Rik+Segmented.m
Normal file
@ -0,0 +1,57 @@
|
||||
#import "Rik.h"
|
||||
|
||||
@implementation Rik(RikSegmented)
|
||||
|
||||
- (void) drawSegmentedControlSegment: (NSCell *)cell
|
||||
withFrame: (NSRect)cellFrame
|
||||
inView: (NSView *)controlView
|
||||
style: (NSSegmentStyle)style
|
||||
state: (GSThemeControlState)state
|
||||
roundedLeft: (BOOL)roundedLeft
|
||||
roundedRight: (BOOL)roundedRight
|
||||
{
|
||||
NSColor * c = [NSColor controlBackgroundColor];
|
||||
NSGradient* normalButtongradient = [self _bezelGradientWithColor: c];
|
||||
|
||||
NSColor* buttonStroke = [Rik controlStrokeColor];
|
||||
NSColor* buttonFill = [NSColor colorWithCalibratedRed: 0.58 green: 0.58 blue: 0.58 alpha: 1];
|
||||
NSColor* buttonFillLight = [NSColor colorWithCalibratedRed: 0.663 green: 0.663 blue: 0.663 alpha: 1];
|
||||
|
||||
NSGradient* buttonGradient = [[NSGradient alloc] initWithColorsAndLocations:
|
||||
buttonFill, 0.0,
|
||||
buttonFill, 0.64,
|
||||
buttonFillLight, 1.0, nil];
|
||||
|
||||
CGFloat button2CornerRadius = 4;
|
||||
NSRect button2Rect = cellFrame;
|
||||
NSRect button2InnerRect = NSInsetRect(button2Rect, button2CornerRadius, button2CornerRadius);
|
||||
NSBezierPath* buttonPath;
|
||||
if(roundedRight)
|
||||
{
|
||||
buttonPath = [NSBezierPath bezierPath];
|
||||
[buttonPath moveToPoint: NSMakePoint(NSMinX(button2Rect), NSMinY(button2Rect))];
|
||||
[buttonPath appendBezierPathWithArcWithCenter: NSMakePoint(NSMaxX(button2InnerRect), NSMinY(button2InnerRect)) radius: button2CornerRadius startAngle: 270 endAngle: 360];
|
||||
[buttonPath appendBezierPathWithArcWithCenter: NSMakePoint(NSMaxX(button2InnerRect), NSMaxY(button2InnerRect)) radius: button2CornerRadius startAngle: 0 endAngle: 90];
|
||||
[buttonPath lineToPoint: NSMakePoint(NSMinX(button2Rect), NSMaxY(button2Rect))];
|
||||
[buttonPath closePath];
|
||||
}
|
||||
else if(roundedLeft)
|
||||
{
|
||||
buttonPath = [NSBezierPath bezierPath];
|
||||
[buttonPath appendBezierPathWithArcWithCenter: NSMakePoint(NSMinX(button2InnerRect), NSMinY(button2InnerRect)) radius: button2CornerRadius startAngle: 180 endAngle: 270];
|
||||
[buttonPath lineToPoint: NSMakePoint(NSMaxX(button2Rect), NSMinY(button2Rect))];
|
||||
[buttonPath lineToPoint: NSMakePoint(NSMaxX(button2Rect), NSMaxY(button2Rect))];
|
||||
[buttonPath appendBezierPathWithArcWithCenter: NSMakePoint(NSMinX(button2InnerRect), NSMaxY(button2InnerRect)) radius: button2CornerRadius startAngle: 90 endAngle: 180];
|
||||
[buttonPath closePath];
|
||||
}
|
||||
else
|
||||
{
|
||||
buttonPath = [NSBezierPath bezierPathWithRect: button2Rect];
|
||||
}
|
||||
if(state == GSThemeSelectedState)
|
||||
[buttonGradient drawInBezierPath: buttonPath angle: -90];
|
||||
else
|
||||
[normalButtongradient drawInBezierPath: buttonPath angle: -90];
|
||||
|
||||
}
|
||||
@end
|
Loading…
x
Reference in New Issue
Block a user