Menu Bar Icon and Group Icon drawing. Fixed IBDesignable bug (framework search path)
This commit is contained in:
@@ -1 +1 @@
|
||||
github "relikd/RSXML" "c1b8eca0854aa4d1262dc5dfc054ec8dafb18609"
|
||||
github "relikd/RSXML" "6bf8f713596c1d3e253780cf7f6bd62843dc12a7"
|
||||
|
||||
@@ -457,6 +457,7 @@
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/../Frameworks",
|
||||
"$(FRAMEWORK_SEARCH_PATHS)",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.12;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = de.relikd.baRSS;
|
||||
@@ -507,6 +508,7 @@
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/../Frameworks",
|
||||
"$(FRAMEWORK_SEARCH_PATHS)",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.12;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = de.relikd.baRSS;
|
||||
|
||||
@@ -42,4 +42,21 @@ IB_DESIGNABLE
|
||||
@interface DrawSeparator : NSView
|
||||
@end
|
||||
|
||||
IB_DESIGNABLE
|
||||
@interface DrawImage : NSView
|
||||
@property (strong) IBInspectable NSColor *color;
|
||||
/** percentage value between 0 - 100 */
|
||||
@property (assign) IBInspectable CGFloat roundness;
|
||||
@property (strong, readonly) NSImageView *imageView;
|
||||
|
||||
- (NSImage*)drawnImage;
|
||||
@end
|
||||
|
||||
IB_DESIGNABLE
|
||||
@interface SettingsIconGlobal : DrawImage
|
||||
@end
|
||||
|
||||
IB_DESIGNABLE
|
||||
@interface SettingsIconGroup : DrawImage
|
||||
@end
|
||||
|
||||
|
||||
@@ -22,6 +22,16 @@
|
||||
|
||||
#import "DrawImage.h"
|
||||
|
||||
@implementation NSColor (RandomColor)
|
||||
+ (NSColor*)randomColor { // just for testing purposes
|
||||
return [NSColor colorWithRed:(arc4random()%50+20)/100.0
|
||||
green:(arc4random()%50+20)/100.0
|
||||
blue:(arc4random()%50+20)/100.0
|
||||
alpha:1];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation RSSIcon
|
||||
|
||||
+ (NSColor*)rssOrange {
|
||||
@@ -122,3 +132,133 @@
|
||||
[grdnt drawInBezierPath:rounded angle:0];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@implementation DrawImage
|
||||
@synthesize roundness = _roundness;
|
||||
|
||||
//#if !TARGET_INTERFACE_BUILDER #endif
|
||||
- (instancetype)initWithCoder:(NSCoder *)decoder {
|
||||
self = [super initWithCoder:decoder];
|
||||
_imageView = [NSImageView imageViewWithImage:[self drawnImage]];
|
||||
[_imageView setFrameSize:self.frame.size];
|
||||
_imageView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
||||
[self addSubview:_imageView];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSImage*)drawnImage {
|
||||
return [NSImage imageWithSize:self.frame.size flipped:NO drawingHandler:^BOOL(NSRect rect) {
|
||||
[self drawImageInRect:rect];
|
||||
return YES;
|
||||
}];
|
||||
}
|
||||
|
||||
- (CGFloat)roundness { return _roundness; }
|
||||
- (void)setRoundness:(CGFloat)roundness {
|
||||
if (roundness < 0) roundness = 0;
|
||||
else if (roundness > 100) roundness = 100;
|
||||
_roundness = roundness / 2;
|
||||
}
|
||||
|
||||
- (CGFloat)shorterSide {
|
||||
if (self.frame.size.width < self.frame.size.height)
|
||||
return self.frame.size.width;
|
||||
return self.frame.size.height;
|
||||
}
|
||||
|
||||
- (void)drawImageInRect:(NSRect)r {
|
||||
CGMutablePathRef pth = CGPathCreateMutable();
|
||||
CGFloat corner = (_roundness / 100.0);
|
||||
if (corner > 0) {
|
||||
corner *= [self shorterSide];
|
||||
CGPathAddRoundedRect(pth, NULL, r, corner, corner);
|
||||
} else {
|
||||
CGPathAddRect(pth, NULL, r);
|
||||
}
|
||||
CGContextRef c = [[NSGraphicsContext currentContext] CGContext];
|
||||
CGContextSetFillColorWithColor(c, [_color CGColor]);
|
||||
CGContextAddPath(c, pth);
|
||||
CGPathRelease(pth);
|
||||
if ([self isMemberOfClass:[DrawImage class]])
|
||||
CGContextFillPath(c); // fill only if not a subclass
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation SettingsIconGlobal
|
||||
- (void)drawImageInRect:(NSRect)r {
|
||||
CGFloat w = r.size.width;
|
||||
CGFloat h = r.size.height;
|
||||
|
||||
CGMutablePathRef menu = CGPathCreateMutable();
|
||||
// CGFloat s = (w < h ? w : h);
|
||||
CGAffineTransform at = CGAffineTransformIdentity;//CGAffineTransformMake(0.7, 0, 0, 0.7, s * 0.15, s * 0.15); // scale 0.7, translate 0.15
|
||||
CGPathAddRect(menu, &at, CGRectMake(0, 0.8 * h, w, 0.2 * h));
|
||||
CGPathAddRect(menu, &at, CGRectMake(0.3 * w, 0, 0.55 * w, 0.75 * h));
|
||||
CGPathAddRect(menu, &at, CGRectMake(0.35 * w, 0.05 * h, 0.45 * w, 0.75 * h));
|
||||
|
||||
CGFloat entryHeight = 0.1 * h; // 0.075
|
||||
for (int i = 0; i < 3; i++) { // 4
|
||||
//CGPathAddRect(menu, &at, CGRectMake(0.37 * w, (2 * i + 1) * entryHeight, 0.42 * w, entryHeight)); // uncomment path above
|
||||
CGPathAddRect(menu, &at, CGRectMake(0.35 * w, (2 * i + 1.5) * entryHeight, 0.4 * w, entryHeight * 0.8));
|
||||
}
|
||||
|
||||
CGContextRef c = [[NSGraphicsContext currentContext] CGContext];
|
||||
CGContextSetFillColorWithColor(c, [self.color CGColor]);
|
||||
|
||||
// [super drawImageInRect:r]; // add path of rounded rect
|
||||
CGContextAddPath(c, menu);
|
||||
CGPathRelease(menu);
|
||||
CGContextEOFillPath(c);
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation SettingsIconGroup
|
||||
- (void)drawImageInRect:(NSRect)r {
|
||||
CGFloat w = r.size.width;
|
||||
CGFloat h = r.size.height;
|
||||
CGFloat s = (w < h ? w : h); // shorter side
|
||||
CGFloat l = s * 0.04; // line size (half)
|
||||
CGFloat r1 = s * 0.05; // corners
|
||||
CGFloat r2 = s * 0.08; // upper part, name tag
|
||||
CGFloat r3 = s * 0.15; // lower part, corners inside
|
||||
CGFloat posTop = 0.85 * h - l;
|
||||
CGFloat posMiddle = 0.6 * h - l - r3;
|
||||
CGFloat posBottom = 0.15 * h + l + r1;
|
||||
CGFloat posNameTag = 0.3 * w - l;
|
||||
|
||||
CGContextRef c = [[NSGraphicsContext currentContext] CGContext];
|
||||
CGAffineTransform at = CGAffineTransformIdentity;//CGAffineTransformMake(0.7, 0, 0, 0.7, s * 0.15, s * 0.15); // scale 0.7, translate 0.15
|
||||
CGContextSetFillColorWithColor(c, [self.color CGColor]);
|
||||
CGContextSetStrokeColorWithColor(c, [self.color CGColor]);
|
||||
CGContextSetLineWidth(c, l * 2);
|
||||
|
||||
CGMutablePathRef upper = CGPathCreateMutable();
|
||||
CGPathMoveToPoint(upper, &at, l, 0.5 * h);
|
||||
CGPathAddLineToPoint(upper, &at, l, posTop - r1);
|
||||
CGPathAddArc(upper, &at, l + r1, posTop - r1, r1, M_PI, M_PI_2, YES);
|
||||
CGPathAddArc(upper, &at, posNameTag, posTop - r2, r2, M_PI_2, M_PI_4, YES);
|
||||
CGPathAddArc(upper, &at, posNameTag + 2 * r2, posTop, r2, M_PI + M_PI_4, -M_PI_2, NO);
|
||||
CGPathAddArc(upper, &at, w - l - r1, posTop - r1 - r2, r1, M_PI_2, 0, YES);
|
||||
CGPathAddArc(upper, &at, w - l - r1, posBottom, r1, 0, -M_PI_2, YES);
|
||||
CGPathAddArc(upper, &at, l + r1, posBottom, r1, -M_PI_2, M_PI, YES);
|
||||
CGPathCloseSubpath(upper);
|
||||
|
||||
CGMutablePathRef lower = CGPathCreateMutable();
|
||||
CGPathMoveToPoint(lower, &at, l, 0.5 * h);
|
||||
CGPathAddArc(lower, &at, l + r3, posMiddle, r3, M_PI, M_PI_2, YES);
|
||||
CGPathAddArc(lower, &at, w - l - r3, posMiddle, r3, M_PI_2, 0, YES);
|
||||
CGPathAddArc(lower, &at, w - l - r1, posBottom, r1, 0, -M_PI_2, YES);
|
||||
CGPathAddArc(lower, &at, l + r1, posBottom, r1, -M_PI_2, M_PI, YES);
|
||||
CGPathCloseSubpath(lower);
|
||||
|
||||
CGContextAddPath(c, upper);
|
||||
CGContextAddPath(c, lower);
|
||||
CGContextStrokePath(c);
|
||||
CGPathRelease(upper);
|
||||
CGPathRelease(lower);
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -107,19 +107,10 @@
|
||||
</binding>
|
||||
</connections>
|
||||
</button>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5s3-gS-ufH">
|
||||
<rect key="frame" x="18" y="161" width="284" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Show in global menu:" id="6rt-um-3x5">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Xbr-a8-v9X">
|
||||
<rect key="frame" x="28" y="137" width="274" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="check" title="Open all unread" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="FT6-me-ACu">
|
||||
<rect key="frame" x="18" y="117" width="22" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="check" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="FT6-me-ACu">
|
||||
<behavior key="behavior" pushIn="YES" changeContents="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
@@ -133,9 +124,9 @@
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Eyy-w7-79K">
|
||||
<rect key="frame" x="28" y="117" width="274" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="check" title="Update all feeds" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="Z56-ik-iHk">
|
||||
<rect key="frame" x="18" y="137" width="22" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="check" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="Z56-ik-iHk">
|
||||
<behavior key="behavior" pushIn="YES" changeContents="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
@@ -149,9 +140,9 @@
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="lAu-qx-vWl">
|
||||
<rect key="frame" x="28" y="97" width="274" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="check" title="Mark all read" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="8Ko-Cq-fCy">
|
||||
<rect key="frame" x="18" y="97" width="22" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="check" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="8Ko-Cq-fCy">
|
||||
<behavior key="behavior" pushIn="YES" changeContents="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
@@ -165,9 +156,9 @@
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="eKg-IL-v85">
|
||||
<rect key="frame" x="28" y="77" width="274" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="check" title="Mark all unread" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="K4h-ul-R6b">
|
||||
<rect key="frame" x="18" y="77" width="22" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="check" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="K4h-ul-R6b">
|
||||
<behavior key="behavior" pushIn="YES" changeContents="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
@@ -218,11 +209,83 @@
|
||||
</menu>
|
||||
</popUpButtonCell>
|
||||
</popUpButton>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Fey-RP-7wF">
|
||||
<rect key="frame" x="128" y="138" width="133" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Update all feeds" id="Yy6-xr-m0l">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="VhY-mw-Rej">
|
||||
<rect key="frame" x="128" y="118" width="133" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Open all unread" id="lVL-bb-uA6">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="qFU-En-OSw">
|
||||
<rect key="frame" x="128" y="98" width="133" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Mark all read" id="XD8-5a-Hlg">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="oFG-IQ-p9b">
|
||||
<rect key="frame" x="128" y="78" width="133" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Mark all unread" id="PJI-mv-AnH">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ZCI-pL-I3q">
|
||||
<rect key="frame" x="56" y="162" width="18" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="NSFolder" id="r1h-PL-XrL"/>
|
||||
</imageView>
|
||||
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="SKf-Y7-8xS" customClass="SettingsIconGroup">
|
||||
<rect key="frame" x="114" y="168" width="18" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<userDefinedRuntimeAttributes>
|
||||
<userDefinedRuntimeAttribute type="color" keyPath="color">
|
||||
<color key="value" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</userDefinedRuntimeAttribute>
|
||||
</userDefinedRuntimeAttributes>
|
||||
</customView>
|
||||
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="P4Y-i1-MGE" customClass="SettingsIconGlobal">
|
||||
<rect key="frame" x="20" y="162" width="18" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<userDefinedRuntimeAttributes>
|
||||
<userDefinedRuntimeAttribute type="color" keyPath="color">
|
||||
<color key="value" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</userDefinedRuntimeAttribute>
|
||||
</userDefinedRuntimeAttributes>
|
||||
</customView>
|
||||
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Q3s-d8-Nlf" customClass="SettingsIconGroup">
|
||||
<rect key="frame" x="174" y="119" width="121" height="121"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<userDefinedRuntimeAttributes>
|
||||
<userDefinedRuntimeAttribute type="color" keyPath="color">
|
||||
<color key="value" red="1" green="0.077124427349073099" blue="0.07612364338405142" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</userDefinedRuntimeAttribute>
|
||||
<userDefinedRuntimeAttribute type="number" keyPath="roundness">
|
||||
<real key="value" value="40"/>
|
||||
</userDefinedRuntimeAttribute>
|
||||
</userDefinedRuntimeAttributes>
|
||||
</customView>
|
||||
</subviews>
|
||||
<point key="canvasLocation" x="91" y="-163"/>
|
||||
<point key="canvasLocation" x="140" y="-155.5"/>
|
||||
</customView>
|
||||
</objects>
|
||||
<resources>
|
||||
<image name="NSBookmarksTemplate" width="17" height="18"/>
|
||||
<image name="NSFolder" width="32" height="32"/>
|
||||
</resources>
|
||||
</document>
|
||||
|
||||
Reference in New Issue
Block a user