Revision: 12452 http://sourceforge.net/p/skim-app/code/12452 Author: hofman Date: 2021-10-04 14:51:57 +0000 (Mon, 04 Oct 2021) Log Message: ----------- Add a hidden preference for a sepia tone effect. Always add filters to pdfviews and page displays. Rename function to get color effect filters.
Modified Paths: -------------- trunk/NSGraphics_SKExtensions.h trunk/NSGraphics_SKExtensions.m trunk/SKBasePDFView.m trunk/SKImageToolTipWindow.m trunk/SKPDFView.m trunk/SKThumbnailImageView.m trunk/SKTransitionController.m Modified: trunk/NSGraphics_SKExtensions.h =================================================================== --- trunk/NSGraphics_SKExtensions.h 2021-10-04 09:47:12 UTC (rev 12451) +++ trunk/NSGraphics_SKExtensions.h 2021-10-04 14:51:57 UTC (rev 12452) @@ -57,4 +57,4 @@ #pragma mark - -extern NSArray *SKColorInvertFilters(void); +extern NSArray *SKColorEffectFilters(void); Modified: trunk/NSGraphics_SKExtensions.m =================================================================== --- trunk/NSGraphics_SKExtensions.m 2021-10-04 09:47:12 UTC (rev 12451) +++ trunk/NSGraphics_SKExtensions.m 2021-10-04 14:51:57 UTC (rev 12452) @@ -40,6 +40,7 @@ #import "NSGeometry_SKExtensions.h" #import "NSColor_SKExtensions.h" #import <Quartz/Quartz.h> +#import "SKStringConstants.h" #if SDK_BEFORE(10_14) @@ -183,9 +184,19 @@ #pragma mark - -extern NSArray *SKColorInvertFilters(void) { - if (SKHasDarkAppearance(NSApp)) +extern NSArray *SKColorEffectFilters(void) { + CGFloat sepia = [[NSUserDefaults standardUserDefaults] doubleForKey:@"SKSepiaTone"]; + BOOL invert = SKHasDarkAppearance(NSApp) && [[NSUserDefaults standardUserDefaults] boolForKey:SKInvertColorsInDarkModeKey]; + if (sepia > 0.0) { + if (sepia > 1.0) + sepia = 1.0; + if (invert) + return [NSArray arrayWithObjects:[CIFilter filterWithName:@"CISepiaTone" keysAndValues:@"inputIntensity", [NSNumber numberWithDouble:sepia], nil], [CIFilter filterWithName:@"CIColorInvert"], [CIFilter filterWithName:@"CIHueAdjust" keysAndValues:kCIInputAngleKey, [NSNumber numberWithDouble:M_PI], nil], nil]; + else + return [NSArray arrayWithObjects:[CIFilter filterWithName:@"CISepiaTone" keysAndValues:@"inputIntensity", [NSNumber numberWithDouble:sepia], nil], nil]; + } else if (invert) { return [NSArray arrayWithObjects:[CIFilter filterWithName:@"CIColorInvert"], [CIFilter filterWithName:@"CIHueAdjust" keysAndValues:kCIInputAngleKey, [NSNumber numberWithDouble:M_PI], nil], nil]; - else + } else { return [NSArray array]; + } } Modified: trunk/SKBasePDFView.m =================================================================== --- trunk/SKBasePDFView.m 2021-10-04 09:47:12 UTC (rev 12451) +++ trunk/SKBasePDFView.m 2021-10-04 14:51:57 UTC (rev 12452) @@ -75,10 +75,9 @@ if (RUNNING_AFTER(10_13)) { SKSetHasDefaultAppearance(self); SKSetHasLightAppearance([[self scrollView] contentView]); - if ([[NSUserDefaults standardUserDefaults] boolForKey:SKInvertColorsInDarkModeKey]) { + if ([[NSUserDefaults standardUserDefaults] boolForKey:SKInvertColorsInDarkModeKey]) SKSetHasLightAppearance([self scrollView]); - [[self scrollView] setContentFilters:SKColorInvertFilters()]; - } + [[self scrollView] setContentFilters:SKColorEffectFilters()]; [self handleScrollerStyleChangedNotification:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleScrollerStyleChangedNotification:) @@ -123,11 +122,10 @@ - (void)invertColorsInDarkModeDidChange { if ([[NSUserDefaults standardUserDefaults] boolForKey:SKInvertColorsInDarkModeKey]) { SKSetHasLightAppearance([self scrollView]); - [[self scrollView] setContentFilters:SKColorInvertFilters()]; } else { SKSetHasDefaultAppearance([self scrollView]); - [[self scrollView] setContentFilters:[NSArray array]]; } + [[self scrollView] setContentFilters:SKColorEffectFilters()]; } - (void)viewDidChangeEffectiveAppearance { @@ -135,8 +133,7 @@ #pragma clang diagnostic ignored "-Wpartial-availability" [super viewDidChangeEffectiveAppearance]; #pragma clang diagnostic pop - if ([[NSUserDefaults standardUserDefaults] boolForKey:SKInvertColorsInDarkModeKey]) - [[self scrollView] setContentFilters:SKColorInvertFilters()]; + [[self scrollView] setContentFilters:SKColorEffectFilters()]; } - (void)handleScrollerStyleChangedNotification:(NSNotification *)notification { Modified: trunk/SKImageToolTipWindow.m =================================================================== --- trunk/SKImageToolTipWindow.m 2021-10-04 09:47:12 UTC (rev 12451) +++ trunk/SKImageToolTipWindow.m 2021-10-04 14:51:57 UTC (rev 12452) @@ -95,6 +95,8 @@ [backgroundView setState:NSVisualEffectStateActive]; [backgroundView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [self setContentView:backgroundView]; + } else { + [self setBackgroundColor:[NSColor colorWithGenericGamma22White:0.97 alpha:1.0]]; } } @@ -123,19 +125,7 @@ if (image) { [self setBackgroundImage:image]; - if (RUNNING_AFTER(10_13)) { - if (isOpaque && [[NSUserDefaults standardUserDefaults] boolForKey:SKInvertColorsInDarkModeKey]) - [[self contentView] setContentFilters:SKColorInvertFilters()]; - else - [[self contentView] setContentFilters:[NSArray array]]; - } else if (isOpaque) { - [self setBackgroundColor:[NSColor whiteColor]]; - } else { - static NSColor *backgroundColor = nil; - if (backgroundColor == nil) - backgroundColor = [[NSColor colorWithGenericGamma22White:0.97 alpha:1.0] retain]; - [self setBackgroundColor:backgroundColor]; - } + [[self contentView] setContentFilters:isOpaque ? SKColorEffectFilters() : [NSArray array]]; contentRect.size = [image size]; contentRect.origin.x = fmin(thePoint.x, NSMaxX(screenRect) - NSWidth(contentRect)); Modified: trunk/SKPDFView.m =================================================================== --- trunk/SKPDFView.m 2021-10-04 09:47:12 UTC (rev 12451) +++ trunk/SKPDFView.m 2021-10-04 14:51:57 UTC (rev 12452) @@ -3073,8 +3073,7 @@ [super viewDidChangeEffectiveAppearance]; #pragma clang diagnostic pop if (loupeWindow) { - if ([[NSUserDefaults standardUserDefaults] boolForKey:SKInvertColorsInDarkModeKey]) - [[loupeWindow contentView] setContentFilters:SKColorInvertFilters()]; + [[loupeWindow contentView] setContentFilters:SKColorEffectFilters()]; [self updateLoupeBackgroundColor]; } } @@ -3082,13 +3081,11 @@ - (void)invertColorsInDarkModeDidChange { [super invertColorsInDarkModeDidChange]; if (loupeWindow) { - if ([[NSUserDefaults standardUserDefaults] boolForKey:SKInvertColorsInDarkModeKey]) { + [[loupeWindow contentView] setContentFilters:SKColorEffectFilters()]; + if ([[NSUserDefaults standardUserDefaults] boolForKey:SKInvertColorsInDarkModeKey]) SKSetHasLightAppearance(loupeWindow); - [[loupeWindow contentView] setContentFilters:SKColorInvertFilters()]; - } else { + else SKSetHasDefaultAppearance(loupeWindow); - [[loupeWindow contentView] setContentFilters:[NSArray array]]; - } [self updateLoupeBackgroundColor]; } } @@ -3241,14 +3238,12 @@ [layer setContentsScale:[[self layer] contentsScale]]; if (wantsAdded && [self wantsLayer]) { [[self layer] addSublayer:layer]; - if ([[NSUserDefaults standardUserDefaults] boolForKey:SKInvertColorsInDarkModeKey]) - [layer setFilters:SKColorInvertFilters()]; + [layer setFilters:SKColorEffectFilters()]; } else { overlay = [[SKAnimatedBorderlessWindow alloc] initWithContentRect:[self convertRectToScreen:[self bounds]]]; [[overlay contentView] setWantsLayer:YES]; [[[overlay contentView] layer] addSublayer:layer]; - if ([[NSUserDefaults standardUserDefaults] boolForKey:SKInvertColorsInDarkModeKey]) - [[overlay contentView] setContentFilters:SKColorInvertFilters()]; + [[overlay contentView] setContentFilters:SKColorEffectFilters()]; if (wantsAdded) [[self window] addChildWindow:overlay ordered:NSWindowAbove]; } @@ -4851,8 +4846,7 @@ [loupeLayer setBackgroundColor:cgColor]; if (hasBackgroundView) { [loupeWindow setContentView:loupeView]; - if ([[NSUserDefaults standardUserDefaults] boolForKey:SKInvertColorsInDarkModeKey]) - [loupeView setContentFilters:SKColorInvertFilters()]; + [loupeView setContentFilters:SKColorEffectFilters()]; } } else if (hasBackgroundView) { [(NSVisualEffectView *)[loupeWindow contentView] setMaterial:material]; @@ -4864,10 +4858,8 @@ [loupeView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [loupeWindow setContentView:view]; [view addSubview:loupeView]; - if ([[NSUserDefaults standardUserDefaults] boolForKey:SKInvertColorsInDarkModeKey]) { - [view setContentFilters:SKColorInvertFilters()]; - [loupeView setContentFilters:[NSArray array]]; - } + [view setContentFilters:SKColorEffectFilters()]; + [loupeView setContentFilters:[NSArray array]]; [loupeView release]; if (NSIsEmptyRect([view bounds]) == NO) [view setMaskImage:[NSImage maskImageWithSize:[view bounds].size cornerRadius:LOUPE_RADIUS]]; Modified: trunk/SKThumbnailImageView.m =================================================================== --- trunk/SKThumbnailImageView.m 2021-10-04 09:47:12 UTC (rev 12451) +++ trunk/SKThumbnailImageView.m 2021-10-04 14:51:57 UTC (rev 12452) @@ -46,11 +46,9 @@ @implementation SKThumbnailImageView - (void)commonInit { + [self setWantsLayer:YES]; + [self setContentFilters:SKColorEffectFilters()]; if (RUNNING_AFTER(10_13)) { - if ([[NSUserDefaults standardUserDefaults] boolForKey:SKInvertColorsInDarkModeKey]) { - [self setWantsLayer:YES]; - [self setContentFilters:SKColorInvertFilters()]; - } [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKey:SKInvertColorsInDarkModeKey context:&SKThumbnailImageViewDefaultsObservationContext]; } } @@ -84,7 +82,7 @@ [super viewDidChangeEffectiveAppearance]; #pragma clang diagnostic pop if ([[NSUserDefaults standardUserDefaults] boolForKey:SKInvertColorsInDarkModeKey]) - [self setContentFilters:SKColorInvertFilters()]; + [self setContentFilters:SKColorEffectFilters()]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { @@ -91,7 +89,7 @@ if (context == &SKThumbnailImageViewDefaultsObservationContext) { if (SKHasDarkAppearance(NSApp)) { if ([[NSUserDefaults standardUserDefaults] boolForKey:SKInvertColorsInDarkModeKey]) - [self setContentFilters:SKColorInvertFilters()]; + [self setContentFilters:SKColorEffectFilters()]; else [self setContentFilters:[NSArray array]]; } Modified: trunk/SKTransitionController.m =================================================================== --- trunk/SKTransitionController.m 2021-10-04 09:47:12 UTC (rev 12451) +++ trunk/SKTransitionController.m 2021-10-04 14:51:57 UTC (rev 12452) @@ -394,9 +394,9 @@ CGFloat scale = CGRectGetWidth([tmpImage extent]) / NSWidth(bounds); CIImage *image = [tmpImage imageByCroppingToRect:CGRectIntegral(scaleRect(NSIntersectionRect(rect, bounds), scale))]; [tmpImage release]; - if ([[NSUserDefaults standardUserDefaults] boolForKey:SKInvertColorsInDarkModeKey]) { - NSArray *invertFilters = SKColorInvertFilters(); - for (CIFilter *filter in invertFilters) { + NSArray *colorFilters = SKColorEffectFilters(); + if ([colorFilters count] > 0) { + for (CIFilter *filter in colorFilters) { [filter setValue:image forKey:kCIInputImageKey]; image = [filter outputImage]; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Skim-app-commit mailing list Skim-app-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/skim-app-commit