Skip to content

Commit c9f43d1

Browse files
Improvements to the menubar icon
the code is a lot simpler and it draws the icon crisper. also changed the selected icon to white.
1 parent d830847 commit c9f43d1

File tree

6 files changed

+68
-81
lines changed

6 files changed

+68
-81
lines changed

AppController.m

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,14 +1138,12 @@ - (void)applicationDidBecomeActive:(NSNotification *)aNotification {
11381138

11391139
if ([notationController currentNoteStorageFormat] != SingleDatabaseFormat)
11401140
[notationController performSelector:@selector(synchronizeNotesFromDirectory) withObject:nil afterDelay:0.0];
1141-
[cView setActiveIcon:self];
11421141
[notationController updateDateStringsIfNecessary];
11431142
}
11441143

11451144
- (void)applicationWillResignActive:(NSNotification *)aNotification {
11461145
//sync note files when switching apps so user doesn't have to guess when they'll be updated
11471146
[notationController synchronizeNoteChanges:nil];
1148-
[cView setInactiveIcon:self];
11491147
[[NSNotificationCenter defaultCenter] postNotificationName:@"ModTimersShouldReset" object:nil];
11501148

11511149
}
@@ -2814,9 +2812,11 @@ - (IBAction)setLCColorScheme:(id)sender{
28142812
userScheme=1;
28152813
[[NSUserDefaults standardUserDefaults] setInteger:userScheme forKey:@"ColorScheme"];
28162814
// [self setForegrndColor:[NSColor colorWithDeviceRed:0.405 green:0.405 blue:0.405 alpha:1.0]];
2817-
[self setForegrndColor:[NSColor colorWithDeviceWhite:0.2430 alpha:1.0]];
2815+
[self setForegrndColor:[NSColor colorWithCalibratedRed:0.2430 green:0.2430 blue:0.2430 alpha:1.0]];
2816+
28182817
//[self setBackgrndColor:[NSColor colorWithDeviceWhite:0.970 alpha:1.0]];
2819-
[self setBackgrndColor:[NSColor colorWithDeviceWhite:0.902 alpha:1.0]];
2818+
// [NSColor colorWithCalibratedRed:0.902 green:0.902 blue:0.902 alpha:1.0]
2819+
[self setBackgrndColor:[NSColor colorWithCalibratedRed:0.902 green:0.902 blue:0.902 alpha:1.0]];
28202820
NSMenu *mainM = [NSApp mainMenu];
28212821
NSMenu *viewM = [[mainM itemWithTitle:@"View"] submenu];
28222822
mainM = [[viewM itemWithTitle:@"Color Schemes"] submenu];
@@ -3301,15 +3301,15 @@ - (void)hideDockIconAfterDelay{
33013301
[self performSelector:@selector(hideDockIcon) withObject:nil afterDelay:0.22];
33023302
}
33033303

3304-
- (void)setUpStatusBarItem{
3305-
float width = 25.0f;
3306-
CGFloat height = [[NSStatusBar systemStatusBar] thickness];
3307-
NSRect viewFrame = NSMakeRect(0.0f, 0.0f, width, height);
3308-
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:width] retain];
3309-
cView = [[[StatusItemView alloc] initWithFrame:viewFrame controller:self] autorelease];
3310-
[statusItem setView:cView];
3311-
}
3304+
- (void)setUpStatusBarItem{
3305+
NSRect viewFrame = NSMakeRect(0.0f, 0.0f, 24.0f,[[NSStatusBar systemStatusBar] thickness]);
3306+
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:24.0f] retain];
3307+
cView = [[[StatusItemView alloc] initWithFrame:viewFrame] autorelease];
3308+
[statusItem setView:cView];
33123309

3310+
[[NSNotificationCenter defaultCenter]postNotificationName:@"StatusBarMenuIsAwake" object:statBarMenu];
3311+
}
3312+
33133313
- (void)toggleStatusItem:(NSNotification *)notification{
33143314
if (!statusItem) {
33153315
[self setUpStatusBarItem];

LinkingEditor.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ - (NSColor*)_linkColorForForegroundColor:(NSColor*)fgColor backgroundColor:(NSCo
332332
- (NSColor*)_selectionColorForForegroundColor:(NSColor*)fgColor backgroundColor:(NSColor*)bgColor {
333333
fgColor = [fgColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
334334
bgColor = [bgColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
335-
335+
336336
NSColor *proposedBlend = [fgColor blendedColorWithFraction:0.5 ofColor:bgColor];
337337
NSColor *defaultColor = [[NSColor selectedTextBackgroundColor] colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
338338

@@ -343,12 +343,11 @@ - (NSColor*)_selectionColorForForegroundColor:(NSColor*)fgColor backgroundColor:
343343
//but the selection-color-difference from the foreground text needs to be great enough as well,
344344
//and the proposed-color-difference from the foreground can't be too poor
345345
//this heuristic chooses all the system-highlight colors in default fg/bg combinations and fg/bg blends in all others
346-
347-
// NSLog(@"fg diff of proposed: %g fg diff of sel: %g", fgDiff, fgSelDiff);
348-
if ((_perceptualDarkness(fgColor) > _perceptualDarkness(defaultColor) &&
349-
_perceptualDarkness(defaultColor) > _perceptualDarkness(bgColor) && fgSelDiff > 300.0) || fgDiff < 170.0)
346+
347+
if ((_perceptualDarkness(fgColor) > _perceptualDarkness(defaultColor) &&
348+
_perceptualDarkness(defaultColor) > (_perceptualDarkness(bgColor)+0.22) && fgSelDiff > 300.0) || fgDiff < 160.0){
350349
return defaultColor;
351-
350+
}
352351
//amplify the background balance after testing
353352
return [fgColor blendedColorWithFraction:0.69 ofColor:bgColor];
354353
}

Notation.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
5C4B35421307220E00014119 /* TransparentScrollerSlotVerticalFill.tif in Resources */ = {isa = PBXBuildFile; fileRef = 5C4B353A1307220E00014119 /* TransparentScrollerSlotVerticalFill.tif */; };
141141
5C4B356A1307225000014119 /* ETTransparentScroller.m in Sources */ = {isa = PBXBuildFile; fileRef = 5C4B35691307225000014119 /* ETTransparentScroller.m */; };
142142
5C84319114229D810020E5A7 /* PassphraseRetriever.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5C84319314229D810020E5A7 /* PassphraseRetriever.xib */; };
143+
5C91A1861723079B006BF757 /* nvMenuW.png in Resources */ = {isa = PBXBuildFile; fileRef = 5C91A1851723079B006BF757 /* nvMenuW.png */; };
143144
5C94376F132A0C9E00B08B80 /* greyscrollervertbottom3.tif in Resources */ = {isa = PBXBuildFile; fileRef = 5C94376C132A0C9D00B08B80 /* greyscrollervertbottom3.tif */; };
144145
5C943771132A0C9E00B08B80 /* greyscrollerverttop3.tif in Resources */ = {isa = PBXBuildFile; fileRef = 5C94376E132A0C9D00B08B80 /* greyscrollerverttop3.tif */; };
145146
5C96F4FF131C2F9500A2E4AC /* TabClose_Front_Pressed.tif in Resources */ = {isa = PBXBuildFile; fileRef = 5C96F4FC131C2F9500A2E4AC /* TabClose_Front_Pressed.tif */; };
@@ -629,6 +630,7 @@
629630
5C84319814229D940020E5A7 /* it */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = it; path = it.lproj/PassphraseRetriever.xib; sourceTree = "<group>"; };
630631
5C84319914229D940020E5A7 /* zh */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = zh; path = zh.lproj/PassphraseRetriever.xib; sourceTree = "<group>"; };
631632
5C8FA1F416F8A91800A2C6D7 /* SimperiumConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimperiumConfig.h; sourceTree = "<group>"; };
633+
5C91A1851723079B006BF757 /* nvMenuW.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = nvMenuW.png; sourceTree = "<group>"; };
632634
5C94376C132A0C9D00B08B80 /* greyscrollervertbottom3.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = greyscrollervertbottom3.tif; sourceTree = "<group>"; };
633635
5C94376D132A0C9D00B08B80 /* greyscrollervertfill3.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = greyscrollervertfill3.tif; sourceTree = "<group>"; };
634636
5C94376E132A0C9D00B08B80 /* greyscrollerverttop3.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = greyscrollerverttop3.tif; sourceTree = "<group>"; };
@@ -1138,6 +1140,7 @@
11381140
5C2CC189134989D7006FFE56 /* nvMenuDark.png */,
11391141
5C2CC182134989A8006FFE56 /* nvMenu.png */,
11401142
5C2CC183134989A8006FFE56 /* nvMenuC.png */,
1143+
5C91A1851723079B006BF757 /* nvMenuW.png */,
11411144
93A158BD133C497400E1E7DA /* Notality.icns */,
11421145
5C94376C132A0C9D00B08B80 /* greyscrollervertbottom3.tif */,
11431146
5C94376D132A0C9D00B08B80 /* greyscrollervertfill3.tif */,
@@ -1652,6 +1655,7 @@
16521655
B683A0DC16F1CDA600564A1D /* [email protected] in Resources */,
16531656
B683A0DD16F1CDA600564A1D /* [email protected] in Resources */,
16541657
B683A0DE16F1CDA600564A1D /* [email protected] in Resources */,
1658+
5C91A1861723079B006BF757 /* nvMenuW.png in Resources */,
16551659
);
16561660
runOnlyForDeploymentPostprocessing = 0;
16571661
};

StatusItemView.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@
88

99
#import <Cocoa/Cocoa.h>
1010

11-
@class AppController;
11+
12+
typedef enum { DarkMenuIcon, SelectedMenuIcon } StatusIconType;
13+
1214
@interface StatusItemView : NSView {
13-
__weak AppController *controller;
14-
BOOL clicked;
15+
// BOOL clicked;
16+
StatusIconType sbIconType;
1517
}
1618

17-
//@property (nonatomic,readwrite,assign) BOOL clicked;
1819

19-
- (id)initWithFrame:(NSRect)frame controller:(AppController *)ctrlr;
20-
//- (void)setClicked:(BOOL)inBool;
21-
- (void)setInactiveIcon:(id)sender;
22-
- (void)setActiveIcon:(id)sender;
20+
@property(readwrite,nonatomic)StatusIconType sbIconType;
2321

2422
@end

StatusItemView.m

Lines changed: 41 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,92 +7,78 @@
77
//
88

99
#import "StatusItemView.h"
10-
#import "AppController.h"
1110

1211
NSString *imageName = @"nvMenuDark";
12+
static NSRect itemRect;
1313

14-
@implementation StatusItemView
1514

15+
@implementation StatusItemView
1616

17-
- (id)initWithFrame:(NSRect)frame controller:(AppController *)ctrlr
18-
{
19-
if (self = [super initWithFrame:frame]) {
20-
controller = ctrlr; // deliberately weak reference.
21-
}
22-
return self;
23-
}
17+
@synthesize sbIconType;
2418

2519

26-
- (void)dealloc
27-
{
28-
controller = nil;
29-
[super dealloc];
20+
- (id)initWithFrame:(NSRect)frameRect{
21+
if ((self=[super initWithFrame:frameRect])) {
22+
itemRect=NSMakeRect(4.0, 3.0, 16.0, 16.0);
23+
self.sbIconType=DarkMenuIcon;
24+
}
25+
return self;
3026
}
3127

3228
- (void)drawRect:(NSRect)rect {
33-
if (clicked) {
34-
imageName=@"nvMenuC";
35-
[[NSColor selectedMenuItemColor] set];
36-
NSRectFill(rect);
29+
CGFloat fract=1.0;
30+
if (sbIconType==SelectedMenuIcon) {
31+
fract=0.87;
32+
[[NSColor selectedMenuItemColor] setFill];
3733
}else {
38-
if ([NSApp isActive]) {
39-
imageName = @"nvMenuDark";
40-
}else{
41-
imageName = @"nvMenuDark";
42-
}
43-
[[NSColor clearColor] set];
44-
NSRectFill(rect);
34+
[[NSColor clearColor] setFill];
4535
}
46-
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
47-
NSString *path = [bundle pathForResource:imageName ofType:@"png"];
48-
NSImage *menuIcon = [[NSImage alloc] initWithContentsOfFile:path];
49-
NSSize msgSize = [menuIcon size];
50-
NSRect msgRect = NSMakeRect(0, 0, msgSize.width, msgSize.height);
51-
msgRect.origin.x = ([self frame].size.width - msgSize.width)/2;
52-
msgRect.origin.y = ([self frame].size.height - msgSize.height)/2;
53-
[menuIcon drawInRect:msgRect fromRect:NSZeroRect operation: NSCompositeSourceOver fraction:1.0];
54-
[menuIcon autorelease];
36+
NSRectFill(rect);
37+
38+
[[NSImage imageNamed:imageName] drawInRect:itemRect fromRect:NSZeroRect operation: NSCompositeSourceOver fraction:fract];
5539
}
5640

41+
5742
- (void)mouseDown:(NSEvent *)event
5843
{
59-
clicked = YES;
60-
[self setNeedsDisplay:YES];
44+
self.sbIconType=SelectedMenuIcon;
6145
NSUInteger flags=[event modifierFlags];
6246
if (((flags&NSDeviceIndependentModifierFlagsMask)==(flags&NSControlKeyMask))&&((flags&NSDeviceIndependentModifierFlagsMask)>0)) {
6347
[[NSNotificationCenter defaultCenter]postNotificationName:@"StatusItemMenuShouldDrop" object:nil];
64-
clicked = NO;
65-
[self setNeedsDisplay:YES];
48+
self.sbIconType=DarkMenuIcon;
6649
}else{
6750
[[NSNotificationCenter defaultCenter]postNotificationName:@"NVShouldActivate" object:self];
6851
}
6952
}
7053

7154
- (void)mouseUp:(NSEvent *)event {
72-
73-
// [[NSNotificationCenter defaultCenter] postNotificationName:@"ModTimersShouldReset" object:nil];
74-
clicked = NO;
75-
[self setNeedsDisplay:YES];
76-
[self viewWillDraw];
55+
self.sbIconType=DarkMenuIcon;
56+
// [self viewWillDraw];
7757
}
7858

7959
- (void)rightMouseDown:(NSEvent *)event {
80-
clicked = YES;
81-
[self setNeedsDisplay:YES];
60+
self.sbIconType=SelectedMenuIcon;
8261
[[NSNotificationCenter defaultCenter]postNotificationName:@"StatusItemMenuShouldDrop" object:nil];
83-
// [controller toggleAttachedMenu:self];
84-
clicked = NO;
85-
[self setNeedsDisplay:YES];
62+
self.sbIconType=DarkMenuIcon;
8663
}
8764

88-
- (void)setInactiveIcon:(id)sender{
89-
imageName = @"nvMenuDark";
90-
[self setNeedsDisplay:YES];
91-
}
92-
93-
- (void)setActiveIcon:(id)sender{
94-
imageName=@"nvMenuDark";;
95-
[self setNeedsDisplay:YES];
65+
- (void)setSbIconType:(StatusIconType)type{
66+
if (sbIconType!=type) {
67+
switch (type) {
68+
case DarkMenuIcon:
69+
imageName=@"nvMenuDark";
70+
break;
71+
case SelectedMenuIcon:
72+
imageName=@"nvMenuW";
73+
break;
74+
75+
default:
76+
imageName=@"nvMenuDark";
77+
break;
78+
}
79+
sbIconType=type;
80+
[self setNeedsDisplay:YES];
81+
}
9682
}
9783

9884
@end

nvMenuW.png

3.74 KB
Loading

0 commit comments

Comments
 (0)