🎨 Minor formatting tweaks

This commit is contained in:
Kevin Sawicki 2017-06-05 11:08:05 -07:00
parent 96251e55de
commit 2880cfdc9c

View file

@ -57,12 +57,15 @@ BOOL mouseInside = NO;
- (id)initWithFrame:(NSRect)frame { - (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) {
if (self) {
// create buttons // create buttons
NSButton *closeButton = [NSWindow standardWindowButton:NSWindowCloseButton forStyleMask:NSTitledWindowMask]; NSButton* closeButton = [NSWindow standardWindowButton:NSWindowCloseButton
NSButton *minitButton = [NSWindow standardWindowButton:NSWindowMiniaturizeButton forStyleMask:NSTitledWindowMask]; forStyleMask:NSTitledWindowMask];
NSButton *fullScreenButton = [NSWindow standardWindowButton:NSWindowZoomButton forStyleMask:NSTitledWindowMask]; NSButton* minitButton = [NSWindow standardWindowButton:NSWindowMiniaturizeButton
forStyleMask:NSTitledWindowMask];
NSButton* fullScreenButton = [NSWindow standardWindowButton:NSWindowZoomButton
forStyleMask:NSTitledWindowMask];
// size view for buttons // size view for buttons
const int top = 3; const int top = 3;
@ -70,24 +73,26 @@ BOOL mouseInside = NO;
const int left = 7; const int left = 7;
const int between = 6; const int between = 6;
const int right = 6; const int right = 6;
auto buttonsSize = NSMakeRect(0, auto buttonsSize = NSMakeRect(0,
0, 0,
left + closeButton.frame.size.width + between + minitButton.frame.size.width + between + fullScreenButton.frame.size.width + right, left + closeButton.frame.size.width + between + minitButton.frame.size.width + between + fullScreenButton.frame.size.width + right,
top + closeButton.frame.size.height + bottom); top + closeButton.frame.size.height + bottom);
// NSView* buttons = [[SemaphoreView alloc] initWithFrame:buttonsSize];
[self setFrame:buttonsSize]; [self setFrame:buttonsSize];
//set their location //set their location
[closeButton setFrame:NSMakeRect(7, [closeButton setFrame:NSMakeRect(left,
buttonsSize.size.height - closeButton.frame.size.height - 3, buttonsSize.size.height - closeButton.frame.size.height - top,
closeButton.frame.size.width, closeButton.frame.size.width,
closeButton.frame.size.height)]; closeButton.frame.size.height)];
[minitButton setFrame:NSMakeRect(7 + closeButton.frame.size.width + 6, [minitButton setFrame:NSMakeRect(
buttonsSize.size.height - minitButton.frame.size.height - 3, left + closeButton.frame.size.width + between,
buttonsSize.size.height - minitButton.frame.size.height - top,
minitButton.frame.size.width, minitButton.frame.size.width,
minitButton.frame.size.height)]; minitButton.frame.size.height)];
[fullScreenButton setFrame:NSMakeRect(7 + closeButton.frame.size.width + 6 + minitButton.frame.size.width + 6, [fullScreenButton setFrame:NSMakeRect(
buttonsSize.size.height - fullScreenButton.frame.size.height - 3, left + closeButton.frame.size.width + between + minitButton.frame.size.width + between,
buttonsSize.size.height - fullScreenButton.frame.size.height - top,
fullScreenButton.frame.size.width, fullScreenButton.frame.size.width,
fullScreenButton.frame.size.height)]; fullScreenButton.frame.size.height)];
@ -102,32 +107,37 @@ BOOL mouseInside = NO;
// refresh for initial conditions // refresh for initial conditions
[self setNeedsDisplayForButtons]; [self setNeedsDisplayForButtons];
} }
return self; return self;
} }
- (BOOL)_mouseInGroup:(NSButton *)button { - (BOOL)_mouseInGroup:(NSButton*)button {
return mouseInside; return mouseInside;
} }
- (void)updateTrackingAreas { - (void)updateTrackingAreas {
NSTrackingArea *const trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:(NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect) owner:self userInfo:nil]; NSTrackingArea* const trackingArea =
[[NSTrackingArea alloc] initWithRect:NSZeroRect
options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect
owner:self
userInfo:nil];
[self addTrackingArea:trackingArea]; [self addTrackingArea:trackingArea];
} }
- (void)mouseEntered:(NSEvent *)event { - (void)mouseEntered:(NSEvent*)event {
[super mouseEntered:event]; [super mouseEntered:event];
mouseInside = YES; mouseInside = YES;
[self setNeedsDisplayForButtons]; [self setNeedsDisplayForButtons];
} }
- (void)mouseExited:(NSEvent *)event { - (void)mouseExited:(NSEvent*)event {
[super mouseExited:event]; [super mouseExited:event];
mouseInside = NO; mouseInside = NO;
[self setNeedsDisplayForButtons]; [self setNeedsDisplayForButtons];
} }
- (void)setNeedsDisplayForButtons { - (void)setNeedsDisplayForButtons {
for (NSView *subview in self.subviews) { for (NSView* subview in self.subviews) {
[subview setHidden:!mouseInside]; [subview setHidden:!mouseInside];
[subview setNeedsDisplay:YES]; [subview setNeedsDisplay:YES];
} }
@ -685,7 +695,9 @@ enum {
[[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFront:nil]; [[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFront:nil];
} }
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem { // Custom window button methods
- (BOOL)validateMenuItem:(NSMenuItem*)menuItem {
return ([menuItem action] == @selector(performClose:) || [menuItem action] == @selector(performMiniaturize:)) ? YES : [super validateMenuItem:menuItem]; return ([menuItem action] == @selector(performClose:) || [menuItem action] == @selector(performMiniaturize:)) ? YES : [super validateMenuItem:menuItem];
} }
@ -694,11 +706,10 @@ enum {
} }
- (void)performClose:(id)sender { - (void)performClose:(id)sender {
if([[self delegate] respondsToSelector:@selector(windowShouldClose:)]) { if ([[self delegate] respondsToSelector:@selector(windowShouldClose:)]) {
if(![[self delegate] windowShouldClose:self]) return; if (![[self delegate] windowShouldClose:self]) return;
} } else if ([self respondsToSelector:@selector(windowShouldClose:)]) {
else if([self respondsToSelector:@selector(windowShouldClose:)]) { if (![self windowShouldClose:self]) return;
if(![self windowShouldClose:self]) return;
} }
[self close]; [self close];
} }