From ad607bc22b6e635990c31991c34281aec469abad Mon Sep 17 00:00:00 2001 From: relikd Date: Sun, 15 Sep 2019 23:14:36 +0200 Subject: [PATCH] rename NS_INLINE --- baRSS/Helper/DrawImage.m | 43 ++++++++++--------- baRSS/Helper/NSString+Ext.m | 4 +- baRSS/Helper/NSView+Ext.h | 6 +-- baRSS/Helper/NSView+Ext.m | 23 +++++----- .../Feeds Tab/RefreshStatisticsView.m | 2 +- baRSS/Preferences/Preferences.m | 2 +- 6 files changed, 41 insertions(+), 39 deletions(-) diff --git a/baRSS/Helper/DrawImage.m b/baRSS/Helper/DrawImage.m index 931c1a7..7887157 100644 --- a/baRSS/Helper/DrawImage.m +++ b/baRSS/Helper/DrawImage.m @@ -53,7 +53,7 @@ /// @return @c MIN(s.width,s.height) -NS_INLINE const CGFloat ShorterSide(NSSize s) { +static inline const CGFloat ShorterSide(NSSize s) { return (s.width < s.height ? s.width : s.height); } @@ -69,18 +69,18 @@ NS_INLINE const CGFloat ShorterSide(NSSize s) { /// Add circle with @c radius -NS_INLINE void PathAddCircle(CGMutablePathRef path, CGFloat radius) { +static inline void PathAddCircle(CGMutablePathRef path, CGFloat radius) { CGPathAddArc(path, NULL, radius, radius, radius, 0, M_PI * 2, YES); } /// Add ring with @c radius and @c innerRadius -NS_INLINE void PathAddRing(CGMutablePathRef path, CGFloat radius, CGFloat innerRadius) { +static inline void PathAddRing(CGMutablePathRef path, CGFloat radius, CGFloat innerRadius) { CGPathAddArc(path, NULL, radius, radius, radius, 0, M_PI * 2, YES); CGPathAddArc(path, NULL, radius, radius, innerRadius, 0, M_PI * -2, YES); } /// Add a single RSS icon radio wave -NS_INLINE void PathAddRSSArc(CGMutablePathRef path, CGFloat radius, CGFloat thickness) { +static inline void PathAddRSSArc(CGMutablePathRef path, CGFloat radius, CGFloat thickness) { CGPathMoveToPoint(path, NULL, 0, radius + thickness); CGPathAddArc(path, NULL, 0, 0, radius + thickness, M_PI_2, 0, YES); CGPathAddLineToPoint(path, NULL, radius, 0); @@ -89,7 +89,7 @@ NS_INLINE void PathAddRSSArc(CGMutablePathRef path, CGFloat radius, CGFloat thic } /// Add two vertical bars representing a pause icon -NS_INLINE void PathAddPauseIcon(CGMutablePathRef path, CGAffineTransform at, CGFloat size, CGFloat thickness) { +static inline void PathAddPauseIcon(CGMutablePathRef path, CGAffineTransform at, CGFloat size, CGFloat thickness) { const CGFloat off = (size - 2 * thickness) / 4; CGPathAddRect(path, &at, CGRectMake(off, 0, thickness, size)); CGPathAddRect(path, &at, CGRectMake(size/2 + off, 0, thickness, size)); @@ -109,7 +109,7 @@ NS_INLINE void PathAddPauseIcon(CGMutablePathRef path, CGAffineTransform at, CGF /// Create @c CGPath for global icon; a menu bar and an open menu below -NS_INLINE void AddGlobalIconPath(CGContextRef c, CGFloat size) { +static inline void AddGlobalIconPath(CGContextRef c, CGFloat size) { CGMutablePathRef menu = CGPathCreateMutable(); CGPathAddRect(menu, NULL, CGRectMake(0, 0.8 * size, size, 0.2 * size)); CGPathAddRect(menu, NULL, CGRectMake(0.3 * size, 0, 0.55 * size, 0.75 * size)); @@ -125,7 +125,7 @@ NS_INLINE void AddGlobalIconPath(CGContextRef c, CGFloat size) { } /// Create @c CGPath for group icon; a folder symbol -NS_INLINE void AddGroupIconPath(CGContextRef c, CGFloat size, BOOL showBackground) { +static inline void AddGroupIconPath(CGContextRef c, CGFloat size, BOOL showBackground) { const CGFloat r1 = size * 0.05; // corners const CGFloat r2 = size * 0.08; // upper part, name tag const CGFloat r3 = size * 0.15; // lower part, corners inside @@ -162,10 +162,10 @@ NS_INLINE void AddGroupIconPath(CGContextRef c, CGFloat size, BOOL showBackgroun /** -NS_INLINE Create @c CGPath for RSS icon; a circle in the lower left bottom and two radio waves going outwards. -NS_INLINE @param connection If @c NO, draw only one radio wave and a pause icon in the upper right -NS_INLINE */ -NS_INLINE void AddRSSIconPath(CGContextRef c, CGFloat size, BOOL connection) { + Create @c CGPath for RSS icon; a circle in the lower left bottom and two radio waves going outwards. + @param connection If @c NO, draw only one radio wave and a pause icon in the upper right + */ +static inline void AddRSSIconPath(CGContextRef c, CGFloat size, BOOL connection) { CGMutablePathRef bars = CGPathCreateMutable(); // the rss bars PathAddCircle(bars, size * 0.125); PathAddRSSArc(bars, size * 0.45, size * 0.2); @@ -185,7 +185,7 @@ NS_INLINE void AddRSSIconPath(CGContextRef c, CGFloat size, BOOL connection) { /// Create @c CGPath with rounded corners (optional). @param roundness Value between @c 0.0 and @c 1.0 -NS_INLINE void AddRoundedBackgroundPath(CGContextRef c, CGRect r, CGFloat roundness) { +static void AddRoundedBackgroundPath(CGContextRef c, CGRect r, CGFloat roundness) { const CGFloat corner = ShorterSide(r.size) * (roundness / 2.0); if (corner > 0) { CGMutablePathRef pth = CGPathCreateMutable(); @@ -198,7 +198,7 @@ NS_INLINE void AddRoundedBackgroundPath(CGContextRef c, CGRect r, CGFloat roundn } /// Insert and draw linear gradient with @c color saturation @c ±0.3 -NS_INLINE void DrawGradient(CGContextRef c, CGFloat size, NSColor *color) { +static void DrawGradient(CGContextRef c, CGFloat size, NSColor *color) { CGFloat h = 0, s = 1, b = 1, a = 1; @try { NSColor *rgbColor = [color colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]]; @@ -226,7 +226,7 @@ NS_INLINE void DrawGradient(CGContextRef c, CGFloat size, NSColor *color) { /// Scale and translate context to the center with respect to the new scale. If @c width @c != @c length align top left. -NS_INLINE void SetContentScale(CGContextRef c, CGSize size, CGFloat scale) { +static void SetContentScale(CGContextRef c, CGSize size, CGFloat scale) { const CGFloat s = ShorterSide(size); CGFloat offset = s * (1 - scale) / 2; CGContextTranslateCTM(c, offset, size.height - s + offset); // top left alignment @@ -234,7 +234,7 @@ NS_INLINE void SetContentScale(CGContextRef c, CGSize size, CGFloat scale) { } /// Helper method; set drawing color, add rounded background and prepare content scale -NS_INLINE void DrawRoundedFrame(CGContextRef c, CGRect r, CGColorRef color, BOOL background, CGFloat corner, CGFloat defaultScale, CGFloat scaling) { +static void DrawRoundedFrame(CGContextRef c, CGRect r, CGColorRef color, BOOL background, CGFloat corner, CGFloat defaultScale, CGFloat scaling) { CGContextSetFillColorWithColor(c, color); CGContextSetStrokeColorWithColor(c, color); CGFloat contentScale = defaultScale; @@ -251,7 +251,7 @@ NS_INLINE void DrawRoundedFrame(CGContextRef c, CGRect r, CGColorRef color, BOOL /// Draw global icon (menu bar) -NS_INLINE void DrawGlobalIcon(CGRect r, CGColorRef color, BOOL background) { +static void DrawGlobalIcon(CGRect r, CGColorRef color, BOOL background) { CGContextRef c = NSGraphicsContext.currentContext.CGContext; DrawRoundedFrame(c, r, color, background, 0.4, 1.0, 0.7); AddGlobalIconPath(c, ShorterSide(r.size)); @@ -259,7 +259,7 @@ NS_INLINE void DrawGlobalIcon(CGRect r, CGColorRef color, BOOL background) { } /// Draw group icon (folder) -NS_INLINE void DrawGroupIcon(CGRect r, CGColorRef color, BOOL background) { +static void DrawGroupIcon(CGRect r, CGColorRef color, BOOL background) { CGContextRef c = NSGraphicsContext.currentContext.CGContext; const CGFloat s = ShorterSide(r.size); const CGFloat l = s * 0.08; // line width @@ -270,7 +270,7 @@ NS_INLINE void DrawGroupIcon(CGRect r, CGColorRef color, BOOL background) { } /// Draw RSS icon (flat without gradient) -NS_INLINE void DrawRSSIcon(CGRect r, CGColorRef color, BOOL background, BOOL connection) { +static void DrawRSSIcon(CGRect r, CGColorRef color, BOOL background, BOOL connection) { CGContextRef c = NSGraphicsContext.currentContext.CGContext; DrawRoundedFrame(c, r, color, background, 0.4, 1.0, 0.7); AddRSSIconPath(c, ShorterSide(r.size), connection); @@ -278,7 +278,7 @@ NS_INLINE void DrawRSSIcon(CGRect r, CGColorRef color, BOOL background, BOOL con } /// Draw RSS icon (with orange gradient, corner @c 0.4, white radio waves) -NS_INLINE void DrawRSSGradientIcon(CGRect r) { +static void DrawRSSGradientIcon(CGRect r) { const CGFloat size = ShorterSide(r.size); CGContextRef c = NSGraphicsContext.currentContext.CGContext; DrawRoundedFrame(c, r, NSColor.whiteColor.CGColor, YES, 0.4, 1.0, 0.7); @@ -293,7 +293,7 @@ NS_INLINE void DrawRSSGradientIcon(CGRect r) { } /// Draw unread icon (blue dot for unread menu item) -NS_INLINE void DrawUnreadIcon(CGRect r, NSColor *color) { +static void DrawUnreadIcon(CGRect r, NSColor *color) { CGFloat size = ShorterSide(r.size) / 2.0; CGContextRef c = NSGraphicsContext.currentContext.CGContext; CGMutablePathRef path = CGPathCreateMutable(); @@ -316,7 +316,7 @@ NS_INLINE void DrawUnreadIcon(CGRect r, NSColor *color) { /// Add single image to @c ImageNamed cache and set accessibility description -NS_INLINE void Register(CGFloat size, NSImageName name, NSString *description, BOOL (^draw)(NSRect r)) { +static void Register(CGFloat size, NSImageName name, NSString *description, BOOL (^draw)(NSRect r)) { NSImage *img = [NSImage imageWithSize: NSMakeSize(size, size) flipped:NO drawingHandler:draw]; img.accessibilityDescription = description; img.name = name; @@ -332,4 +332,5 @@ void RegisterImageViewNames(void) { Register(16, RSSImageMenuBarIconActive, NSLocalizedString(@"RSS menu bar icon", nil), ^(NSRect r) { DrawRSSIcon(r, [NSColor rssOrange].CGColor, YES, YES); return YES; }); Register(16, RSSImageMenuBarIconPaused, NSLocalizedString(@"RSS menu bar icon, paused", nil), ^(NSRect r) { DrawRSSIcon(r, [NSColor rssOrange].CGColor, YES, NO); return YES; }); Register(12, RSSImageMenuItemUnread, NSLocalizedString(@"Unread icon", nil), ^(NSRect r) { DrawUnreadIcon(r, [NSColor systemBlueColor]); return YES; }); + // TODO: user selected color for rss bar icon & unread dot } diff --git a/baRSS/Helper/NSString+Ext.m b/baRSS/Helper/NSString+Ext.m index 46a2606..4555752 100644 --- a/baRSS/Helper/NSString+Ext.m +++ b/baRSS/Helper/NSString+Ext.m @@ -103,11 +103,11 @@ #pragma mark - Helper methods -NS_INLINE BOOL OPEN(NSString *tag, NSString *match) { +static inline BOOL OPEN(NSString *tag, NSString *match) { return ([tag isEqualToString:match] || [tag hasPrefix:[match stringByAppendingString:@" "]]); } -NS_INLINE BOOL CLOSE(NSString *tag, NSString *match) { +static inline BOOL CLOSE(NSString *tag, NSString *match) { return [tag isEqualToString:match]; } diff --git a/baRSS/Helper/NSView+Ext.h b/baRSS/Helper/NSView+Ext.h index 29696c1..06b9293 100644 --- a/baRSS/Helper/NSView+Ext.h +++ b/baRSS/Helper/NSView+Ext.h @@ -41,11 +41,11 @@ static CGFloat const CENTER = -0.015625; /// Calculate @c origin.y going down from the top border of its @c superview -NS_INLINE CGFloat YFromTop(NSView *view) { return NSHeight(view.superview.frame) - NSMinY(view.frame) - view.alignmentRectInsets.bottom; } +static inline CGFloat YFromTop(NSView *view) { return NSHeight(view.superview.frame) - NSMinY(view.frame) - view.alignmentRectInsets.bottom; } /// @c MAX() -NS_INLINE CGFloat Max(CGFloat a, CGFloat b) { return a < b ? b : a; } +static inline CGFloat Max(CGFloat a, CGFloat b) { return a < b ? b : a; } /// @c Max(NSWidth(a.frame),NSWidth(b.frame)) -NS_INLINE CGFloat NSMaxWidth(NSView *a, NSView *b) { return Max(NSWidth(a.frame), NSWidth(b.frame)); } +static inline CGFloat NSMaxWidth(NSView *a, NSView *b) { return Max(NSWidth(a.frame), NSWidth(b.frame)); } /* diff --git a/baRSS/Helper/NSView+Ext.m b/baRSS/Helper/NSView+Ext.m index 3c76769..c86a40c 100644 --- a/baRSS/Helper/NSView+Ext.m +++ b/baRSS/Helper/NSView+Ext.m @@ -221,9 +221,15 @@ The @c autoresizingMask will be set accordingly. */ - (instancetype)placeIn:(NSView*)parent x:(CGFloat)x y:(CGFloat)y { - SetCenterableOrigin(self, parent, x, y); - if (x == CENTER) self.autoresizingMask |= NSViewMinXMargin | NSViewMaxXMargin; - if (y == CENTER) self.autoresizingMask |= NSViewMinYMargin | NSViewMaxYMargin; + if (x == CENTER) { + x = (NSWidth(parent.frame) - NSWidth(self.frame)) / 2; + self.autoresizingMask |= NSViewMinXMargin | NSViewMaxXMargin; + } + if (y == CENTER) { + y = (NSHeight(parent.frame) - NSHeight(self.frame)) / 2; + self.autoresizingMask |= NSViewMinYMargin | NSViewMaxYMargin; + } + [self setFrameOrigin: NSMakePoint(x, y)]; self.frame = [self frameForAlignmentRect:self.frame]; [parent addSubview:self]; return self; @@ -291,15 +297,10 @@ return self; } -/// Helper method to get y origin point (from top) while respecting @c alignmentRectInsets and view sizes -NS_INLINE void SetCenterableOrigin(NSView *view, NSView *parent, CGFloat x, CGFloat y) { - if (x == CENTER) x = (NSWidth(parent.frame) - NSWidth(view.frame)) / 2; - if (y == CENTER) y = (NSHeight(parent.frame) - NSHeight(view.frame)) / 2; - [view setFrameOrigin: NSMakePoint(x, y)]; -} + /// Helper method to set frame width and keep same height -NS_INLINE void SetFrameWidth(NSView *view, CGFloat w) { +static inline void SetFrameWidth(NSView *view, CGFloat w) { [view setFrameSize: NSMakeSize(w, NSHeight(view.frame))]; } @@ -352,7 +353,7 @@ NS_INLINE void SetFrameWidth(NSView *view, CGFloat w) { - (instancetype)textCenter { self.alignment = NSTextAlignmentCenter; return self; } /// Helper method to set new font, subsequently run @c sizeToFit -NS_INLINE void SetFontAndResize(NSControl *control, NSFont *font) { +static inline void SetFontAndResize(NSControl *control, NSFont *font) { control.font = font; [control sizeToFit]; } diff --git a/baRSS/Preferences/Feeds Tab/RefreshStatisticsView.m b/baRSS/Preferences/Feeds Tab/RefreshStatisticsView.m index 26ca608..15679e5 100644 --- a/baRSS/Preferences/Feeds Tab/RefreshStatisticsView.m +++ b/baRSS/Preferences/Feeds Tab/RefreshStatisticsView.m @@ -79,7 +79,7 @@ } /// Label with smaller gray text, non-editable. @c 13px height. -NS_INLINE NSTextField* GrayLabel(NSString *text) { +static inline NSTextField* GrayLabel(NSString *text) { return [[[NSView label:text] tiny] gray]; } diff --git a/baRSS/Preferences/Preferences.m b/baRSS/Preferences/Preferences.m index 36d9b57..5504c6b 100644 --- a/baRSS/Preferences/Preferences.m +++ b/baRSS/Preferences/Preferences.m @@ -55,7 +55,7 @@ } /// Helper method to generate tab item with image, label, and controller. -NS_INLINE NSTabViewItem* TabItem(NSImageName imageName, NSString *text, Class class) { +static NSTabViewItem* TabItem(NSImageName imageName, NSString *text, Class class) { NSTabViewItem *item = [NSTabViewItem tabViewItemWithViewController: [class new]]; item.image = [NSImage imageNamed:imageName]; item.label = text;