From 70a2ab3d50a9858fabada6e9ee19a2b1768dfbce Mon Sep 17 00:00:00 2001 From: Mike Piatek-Jimenez Date: Mon, 18 May 2020 17:23:46 -0400 Subject: [PATCH] Fix expanding/contracting the graph window on mouseover. --- Graph Views/XRGBackgroundView.h | 5 +---- Graph Views/XRGBackgroundView.m | 38 +++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Graph Views/XRGBackgroundView.h b/Graph Views/XRGBackgroundView.h index 638144a..58663f9 100644 --- a/Graph Views/XRGBackgroundView.h +++ b/Graph Views/XRGBackgroundView.h @@ -44,15 +44,12 @@ NSRect unminimizedRect; NSPoint viewPointClicked; - - NSTrackingRectTag trackingRect; } @property NSString *hostname; @property NSArray *resizeRects; -@property NSBezierPath *outerPath; -@property NSBezierPath *innerPath; +@property NSTrackingArea *trackingArea; @property BOOL clickedMinimized; diff --git a/Graph Views/XRGBackgroundView.m b/Graph Views/XRGBackgroundView.m index d2f92b0..0fd70d6 100644 --- a/Graph Views/XRGBackgroundView.m +++ b/Graph Views/XRGBackgroundView.m @@ -60,8 +60,6 @@ - (void)awakeFromNib { - (void)setFrame:(NSRect)frame { [super setFrame:frame]; - - [self updatePaths]; [parentWindow.moduleManager windowChangedToSize:self.frame.size]; } @@ -69,20 +67,21 @@ - (void)offsetDrawingOrigin:(NSSize)offset { [self translateOriginToPoint: NSMakePoint(offset.width, offset.height)]; } -- (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { - [self updatePaths]; +- (NSBezierPath *)outerPath { + int borderWidth = [parentWindow borderWidth]; + + return [NSBezierPath bezierPathWithRoundedRect:self.bounds xRadius:borderWidth yRadius:borderWidth]; } -- (void)updatePaths { +- (NSBezierPath *)innerPath { int borderWidth = [parentWindow borderWidth]; NSRect tmpRect = [self bounds]; tmpRect.origin.x += borderWidth; tmpRect.origin.y = tmpRect.size.height - borderWidth - [appSettings textRectHeight]; tmpRect.size.width -= borderWidth * 2; tmpRect.size.height = [appSettings textRectHeight]; - - self.outerPath = [NSBezierPath bezierPathWithRoundedRect:self.bounds xRadius:borderWidth yRadius:borderWidth]; - self.innerPath = [NSBezierPath bezierPathWithRoundedRect:tmpRect xRadius:borderWidth yRadius:borderWidth]; + + return [NSBezierPath bezierPathWithRoundedRect:tmpRect xRadius:borderWidth yRadius:borderWidth]; } - (void)drawRect:(NSRect)rect{ @@ -97,8 +96,6 @@ - (void)drawRect:(NSRect)rect{ [self translateOriginToPoint: NSMakePoint(0, 0 - [self frame].size.width)]; isVertical = NO; lastWidth = [self frame].size.width; - - [self updatePaths]; } if ([moduleManager graphOrientationVertical] && !isVertical) { // first update our size: @@ -110,8 +107,6 @@ - (void)drawRect:(NSRect)rect{ [self setBoundsRotation: 0]; [self setAutoresizesSubviews:YES]; isVertical = YES; - - [self updatePaths]; } if (!isVertical) { @@ -132,10 +127,10 @@ - (void)drawRect:(NSRect)rect{ tmpRect.size.height = [appSettings textRectHeight]; [[appSettings borderColor] set]; - [self.outerPath fill]; + [[self outerPath] fill]; [[appSettings backgroundColor] set]; - [self.innerPath fill]; + [[self innerPath] fill]; NSRect titleRect; if (isVertical) { @@ -490,6 +485,21 @@ - (BOOL)performDragOperation:(id )sender { return YES; } +- (void)updateTrackingAreas { + [super updateTrackingAreas]; + + if (self.trackingArea) { + [self removeTrackingArea:self.trackingArea]; + self.trackingArea = nil; + } + + self.trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds + options:(NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways) + owner:self + userInfo:nil]; + [self addTrackingArea:self.trackingArea]; +} + - (void)mouseEntered:(NSEvent *)theEvent { // NSLog(@"mouseEntered start\n"); if (self.clickedMinimized && [appSettings autoExpandGraph]) {