Revision: 13578
          http://sourceforge.net/p/skim-app/code/13578
Author:   hofman
Date:     2023-08-15 14:58:49 +0000 (Tue, 15 Aug 2023)
Log Message:
-----------
Allow changing the color for temporary ink notes in presentation using menu on 
drawing button

Modified Paths:
--------------
    trunk/SKNavigationWindow.m
    trunk/SKPDFView.m
    trunk/SKStringConstants.h
    trunk/SKStringConstants.m

Modified: trunk/SKNavigationWindow.m
===================================================================
--- trunk/SKNavigationWindow.m  2023-08-14 15:33:18 UTC (rev 13577)
+++ trunk/SKNavigationWindow.m  2023-08-15 14:58:49 UTC (rev 13578)
@@ -48,6 +48,10 @@
 #import "NSView_SKExtensions.h"
 #import "NSImage_SKExtensions.h"
 #import "NSString_SKExtensions.h"
+#import "NSColor_SKExtensions.h"
+#import "NSMenu_SKExtensions.h"
+#import "NSUserDefaults_SKExtensions.h"
+#import "SKStringConstants.h"
 #import <SkimNotes/SkimNotes.h>
 
 #define BUTTON_WIDTH 50.0
@@ -62,7 +66,6 @@
 
 #define CORNER_RADIUS 10.0
 
-
 static inline NSBezierPath *nextButtonPath(NSSize size);
 static inline NSBezierPath *previousButtonPath(NSSize size);
 static inline NSBezierPath *zoomButtonPath(NSSize size);
@@ -254,6 +257,9 @@
 
 #pragma mark -
 
+@interface SKCursorStyleWindow () <NSMenuDelegate>
+@end
+
 @implementation SKCursorStyleWindow
 
 - (id)initWithPDFView:(SKPDFView *)pdfView {
@@ -327,6 +333,10 @@
         rect.size.width = NSWidth([drawButton frame]);
         [[self contentView] addSubview:drawButton];
         
+        NSMenu *menu = [[[NSMenu alloc] init] autorelease];
+        [menu setDelegate:self];
+        [drawButton setMenu:menu forSegment:0];
+
         rect.origin.x = NSMaxX(rect);
         rect.size.width = SMALL_SEP_WIDTH;
         [[self contentView] addSubview:[[[SKNavigationSeparator alloc] 
initWithFrame:rect] autorelease]];
@@ -371,6 +381,42 @@
     [removeShadowButton setSelected:removeShadow forSegment:0];
 }
 
+- (void)chooseColor:(id)sender {
+    NSColor *color = [sender representedObject];
+    if ([color isEqual:[[NSUserDefaults standardUserDefaults] 
colorForKey:SKInkNoteColorKey]])
+        [[NSUserDefaults standardUserDefaults] 
removeObjectForKey:SKPresentationInkNoteColorKey];
+    else
+        [[NSUserDefaults standardUserDefaults] setColor:color 
forKey:SKPresentationInkNoteColorKey];
+}
+
+- (void)menuNeedsUpdate:(NSMenu *)menu {
+    [menu removeAllItems];
+    
+    NSMutableArray *colors = [[[NSColor favoriteColors] mutableCopy] 
autorelease];
+    NSColor *inkColor = [[NSUserDefaults standardUserDefaults] 
colorForKey:SKInkNoteColorKey];
+    NSColor *tmpColor = [[NSUserDefaults standardUserDefaults] 
colorForKey:SKPresentationInkNoteColorKey];
+    if ([colors containsObject:inkColor] == NO)
+        [colors insertObject:inkColor atIndex:0];
+    if (tmpColor && [colors containsObject:tmpColor] == NO)
+        [colors insertObject:tmpColor atIndex:0];
+    
+    NSSize size = NSMakeSize(16.0, 16.0);
+    
+    for (NSColor *color in colors) {
+        NSMenuItem *item = [menu addItemWithTitle:@"" 
action:@selector(chooseColor:) target:self];
+        
+        NSImage *image = [NSImage imageWithSize:size flipped:NO 
drawingHandler:^(NSRect rect){
+                [color drawSwatchInRoundedRect:rect];
+                return YES;
+            }];
+        [image setAccessibilityDescription:[color accessibilityValue]];
+        [item setRepresentedObject:color];
+        [item setImage:image];
+        if ([color isEqual:tmpColor ?: inkColor])
+            [item setState:NSOnState];
+    }
+}
+
 @end
 
 #pragma mark -

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2023-08-14 15:33:18 UTC (rev 13577)
+++ trunk/SKPDFView.m   2023-08-15 14:58:49 UTC (rev 13578)
@@ -4514,6 +4514,7 @@
     NSRect boxBounds = NSIntersectionRect([page boundsForBox:[self 
displayBox]], [self convertRect:[self visibleContentRect] toPage:page]);
     CGAffineTransform t = 
CGAffineTransformRotate(CGAffineTransformMakeScale([self scaleFactor], [self 
scaleFactor]), -M_PI_2 * [page rotation] / 90.0);
     CGFloat r = fmin(2.0, 2.0 * [self scaleFactor]);
+    NSColor *tmpColor = interactionMode == SKPresentationMode ? 
[[NSUserDefaults standardUserDefaults] 
colorForKey:SKPresentationInkNoteColorKey] : nil;
     layer = [CAShapeLayer layer];
     // transform and place so that the path is in page coordinates
     [layer setBounds:NSRectToCGRect(boxBounds)];
@@ -4538,7 +4539,7 @@
     } else {
         [self setCurrentAnnotation:nil];
         NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
-        [layer setStrokeColor:[[sud colorForKey:SKInkNoteColorKey] CGColor]];
+        [layer setStrokeColor:[tmpColor ?: [sud colorForKey:SKInkNoteColorKey] 
CGColor]];
         [layer setLineWidth:[sud floatForKey:SKInkNoteLineWidthKey]];
         if ((PDFBorderStyle)[sud integerForKey:SKInkNoteLineStyleKey] == 
kPDFBorderStyleDashed) {
             [layer setLineDashPattern:[sud 
arrayForKey:SKInkNoteDashPatternKey]];
@@ -4620,6 +4621,8 @@
             [self addAnnotation:annotation toPage:page];
             [[self undoManager] setActionName:NSLocalizedString(@"Add Note", 
@"Undo action name")];
         } else {
+            if (tmpColor)
+                [annotation setColor:tmpColor];
             [self addTemporaryAnnotation:annotation toPage:page];
         }
         

Modified: trunk/SKStringConstants.h
===================================================================
--- trunk/SKStringConstants.h   2023-08-14 15:33:18 UTC (rev 13577)
+++ trunk/SKStringConstants.h   2023-08-15 14:58:49 UTC (rev 13578)
@@ -147,3 +147,4 @@
 extern NSString *SKInvertColorsInDarkModeKey;
 extern NSString *SKSepiaToneKey;
 extern NSString *SKWhitePointKey;
+extern NSString *SKPresentationInkNoteColorKey;

Modified: trunk/SKStringConstants.m
===================================================================
--- trunk/SKStringConstants.m   2023-08-14 15:33:18 UTC (rev 13577)
+++ trunk/SKStringConstants.m   2023-08-15 14:58:49 UTC (rev 13578)
@@ -148,3 +148,4 @@
 NSString *SKInvertColorsInDarkModeKey = @"SKInvertColorsInDarkMode";
 NSString *SKSepiaToneKey = @"SKSepiaTone";
 NSString *SKWhitePointKey = @"SKWhitePoint";
+NSString *SKPresentationInkNoteColorKey = @"SKPresentationInkNoteColor";

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to