Revision: 27837 http://sourceforge.net/p/bibdesk/svn/27837 Author: hofman Date: 2022-08-24 16:44:20 +0000 (Wed, 24 Aug 2022) Log Message: ----------- Let background view of zoomable pdfview popup draw itself with color depending on global parameters.
Modified Paths: -------------- trunk/bibdesk/BDSKZoomablePDFView.h trunk/bibdesk/BDSKZoomablePDFView.m Modified: trunk/bibdesk/BDSKZoomablePDFView.h =================================================================== --- trunk/bibdesk/BDSKZoomablePDFView.h 2022-08-24 14:34:37 UTC (rev 27836) +++ trunk/bibdesk/BDSKZoomablePDFView.h 2022-08-24 16:44:20 UTC (rev 27837) @@ -43,7 +43,6 @@ @interface BDSKZoomablePDFView : PDFView { NSPopUpButton *scalePopUpButton; - BDSKBackgroundView *backgroundView; CGFloat startScale; } Modified: trunk/bibdesk/BDSKZoomablePDFView.m =================================================================== --- trunk/bibdesk/BDSKZoomablePDFView.m 2022-08-24 14:34:37 UTC (rev 27836) +++ trunk/bibdesk/BDSKZoomablePDFView.m 2022-08-24 16:44:20 UTC (rev 27837) @@ -52,12 +52,7 @@ #endif -@interface BDSKBackgroundView : NSView { - NSColor *backgroundColor; - NSColor *edgeColor; -} -@property (nonatomic, retain) NSColor *backgroundColor; -@property (nonatomic, retain) NSColor *edgeColor; +@interface BDSKBackgroundView : NSView @end @@ -83,9 +78,7 @@ #pragma mark Instance methods - (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; BDSKDESTROY(scalePopUpButton); - BDSKDESTROY(backgroundView); [super dealloc]; } @@ -221,25 +214,11 @@ - (void)updateColorFilters { if (BDSKHasDarkAppearance(NSApp)) { [[self scrollView] setContentFilters:[NSArray arrayWithObjects: [CIFilter filterWithName:@"CIColorMatrix" keysAndValues:@"inputRVector", [CIVector vectorWithX:1.0-LR Y:-LG Z:-LB W:0.0], @"inputGVector", [CIVector vectorWithX:-LR Y:1.0-LG Z:-LB W:0.0], @"inputBVector", [CIVector vectorWithX:-LR Y:-LG Z:1.0-LB W:0.0], @"inputBiasVector", [CIVector vectorWithX:1.0 Y:1.0 Z:1.0 W:0.0], nil], nil]]; - [backgroundView setContentFilters:[NSArray arrayWithObjects: [CIFilter filterWithName:@"CIColorMatrix" keysAndValues:@"inputRVector", [CIVector vectorWithX:1.0-LR Y:-LG Z:-LB W:0.0], @"inputGVector", [CIVector vectorWithX:-LR Y:1.0-LG Z:-LB W:0.0], @"inputBVector", [CIVector vectorWithX:-LR Y:-LG Z:1.0-LB W:0.0], @"inputAVector", [CIVector vectorWithX:0.0 Y:0.0 Z:0.0 W:1.0], @"inputBiasVector", [CIVector vectorWithX:1.0 Y:1.0 Z:1.0 W:0.0], nil], nil]]; } else { [[self scrollView] setContentFilters:[NSArray array]]; - [backgroundView setContentFilters:[NSArray array]]; } } -- (void)handleScrollerStyleDidChange:(NSNotification *)notification { - if ([NSScroller preferredScrollerStyle] == NSScrollerStyleLegacy) { - [backgroundView setBackgroundColor:[NSColor colorWithGenericGamma22White:0.98 alpha:1.0]]; - [backgroundView setEdgeColor:[NSColor colorWithGenericGamma22White:0.905 alpha:1.0]]; - } else { - [backgroundView setBackgroundColor:[NSColor whiteColor]]; - [backgroundView setEdgeColor:nil]; - } - [self updateColorFilters]; - [backgroundView setNeedsDisplay:YES]; -} - - (void)viewDidChangeEffectiveAppearance { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wpartial-availability" @@ -293,27 +272,25 @@ [scalePopUpButton setTarget:self]; [scalePopUpButton setAction:@selector(scalePopUpAction:)]; - backgroundView = [[BDSKBackgroundView alloc] initWithFrame:[scalePopUpButton frame]]; + NSView *backgroundView = [[[BDSKBackgroundView alloc] initWithFrame:[scalePopUpButton frame]] autorelease]; [backgroundView setTranslatesAutoresizingMaskIntoConstraints:NO]; [self addSubview:backgroundView]; [scalePopUpButton setTranslatesAutoresizingMaskIntoConstraints:NO]; - [self addSubview:scalePopUpButton]; + [backgroundView addSubview:scalePopUpButton]; - NSArray *constraints = [NSMutableArray arrayWithObjects: + [self addConstraints:[NSArray arrayWithObjects: [NSLayoutConstraint constraintWithLeadingMargin:0.0 forItem:backgroundView toItem:self], - [NSLayoutConstraint constraintWithBottomMargin:0.0 forItem:backgroundView toItem:self], - [NSLayoutConstraint constraintWithLeadingMargin:2.0 forItem:scalePopUpButton toItem:self], + [NSLayoutConstraint constraintWithBottomMargin:0.0 forItem:backgroundView toItem:self], nil]]; + [backgroundView addConstraints:[NSArray arrayWithObjects: + [NSLayoutConstraint constraintWithLeadingMargin:2.0 forItem:scalePopUpButton toItem:backgroundView], [NSLayoutConstraint constraintWithTrailingMargin:1.0 forItem:scalePopUpButton toItem:backgroundView], [NSLayoutConstraint constraintWithTopMargin:1.0 forItem:scalePopUpButton toItem:backgroundView], - [NSLayoutConstraint constraintWithBottomMargin:1.0 forItem:scalePopUpButton toItem:self], nil]; - [self addConstraints:constraints]; + [NSLayoutConstraint constraintWithBottomMargin:1.0 forItem:scalePopUpButton toItem:backgroundView], nil]]; [self updateScrollerInsets]; BDSKSetHasDefaultAppearance(self); BDSKSetHasLightAppearance([self scrollView]); - [self handleScrollerStyleDidChange:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleScrollerStyleDidChange:) name:NSPreferredScrollerStyleDidChangeNotification object:nil]; } } @@ -484,33 +461,36 @@ @implementation BDSKBackgroundView -@synthesize backgroundColor, edgeColor; +- (void)handleScrollerStyleDidChange:(NSNotification *)notification { + [self setNeedsDisplay:YES]; +} - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) { - backgroundColor = nil; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleScrollerStyleDidChange:) name:NSPreferredScrollerStyleDidChangeNotification object:nil]; } return self; } - (void)dealloc { - BDSKDESTROY(backgroundColor); + [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc]; } - (void)drawRect:(NSRect)rect { - if ([self backgroundColor]) { - [NSGraphicsContext saveGraphicsState]; - [[self backgroundColor] setFill]; + BOOL isDark = BDSKHasDarkAppearance(nil); + [NSGraphicsContext saveGraphicsState]; + if ([NSScroller preferredScrollerStyle] == NSScrollerStyleLegacy) { + [[NSColor colorWithGenericGamma22White:isDark ? 0.262 : 0.981 alpha:1.0] setFill]; [NSBezierPath fillRect:rect]; - if (edgeColor) { - [[self edgeColor] setFill]; - [NSBezierPath fillRect:BDSKSliceRect(rect, 1.0, NSMaxYEdge)]; - } - [NSGraphicsContext restoreGraphicsState]; + [[NSColor colorWithGenericGamma22White:isDark ? 0.499 : 0.905 alpha:1.0] setFill]; + [NSBezierPath fillRect:BDSKSliceRect([self bounds], 1.0, NSMaxYEdge)]; + } else { + [[NSColor colorWithGenericGamma22White:isDark ? 0.118 : 1.0 alpha:1.0] setFill]; + [NSBezierPath fillRect:rect]; } - [super drawRect:rect]; + [NSGraphicsContext restoreGraphicsState]; } @end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit