Browse Source

Added ifdef option to color status bar icon

Thomas Buck 9 years ago
parent
commit
a8dfc8885e
2 changed files with 29 additions and 2 deletions
  1. 28
    1
      CaseLights/AppDelegate.m
  2. 1
    1
      CaseLights/Info.plist

+ 28
- 1
CaseLights/AppDelegate.m View File

62
 #define MENU_ITEM_TAG_NOTHING -1
62
 #define MENU_ITEM_TAG_NOTHING -1
63
 #define MENU_ITEM_TAG_AUDIO -2
63
 #define MENU_ITEM_TAG_AUDIO -2
64
 
64
 
65
+#define COLORED_MENU_BAR_ICON
66
+
65
 @interface AppDelegate ()
67
 @interface AppDelegate ()
66
 
68
 
67
 @property (weak) IBOutlet NSMenu *statusMenu;
69
 @property (weak) IBOutlet NSMenu *statusMenu;
109
 @synthesize serial, lastLEDMode, microphone;
111
 @synthesize serial, lastLEDMode, microphone;
110
 @synthesize menuItemColor;
112
 @synthesize menuItemColor;
111
 
113
 
114
++ (NSImage *)tintedImage:(NSImage *)image WithColor:(NSColor *)tint {
115
+    NSSize size = [image size];
116
+    NSRect imageBounds = NSMakeRect(0, 0, size.width, size.height);
117
+    
118
+    NSImage *copiedImage = [image copy];
119
+    
120
+    [copiedImage lockFocus];
121
+    
122
+    [tint set];
123
+    NSRectFillUsingOperation(imageBounds, NSCompositeSourceAtop);
124
+    
125
+    [copiedImage unlockFocus];
126
+    
127
+    return copiedImage;
128
+}
129
+
112
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
130
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
113
     srand((unsigned)time(NULL));
131
     srand((unsigned)time(NULL));
114
     [AudioVisualizer setDelegate:self];
132
     [AudioVisualizer setDelegate:self];
120
     
138
     
121
     // Prepare status bar menu
139
     // Prepare status bar menu
122
     statusImage = [NSImage imageNamed:@"MenuIcon"];
140
     statusImage = [NSImage imageNamed:@"MenuIcon"];
123
-    [statusImage setTemplate:YES];
124
     statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
141
     statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
142
+#ifdef COLORED_MENU_BAR_ICON
143
+    [statusImage setTemplate:NO];
144
+    [statusItem setImage:[AppDelegate tintedImage:statusImage WithColor:[NSColor blackColor]]];
145
+#else
146
+    [statusImage setTemplate:YES];
125
     [statusItem setImage:statusImage];
147
     [statusItem setImage:statusImage];
148
+#endif
126
     [statusItem setMenu:statusMenu];
149
     [statusItem setMenu:statusMenu];
127
     
150
     
128
     // Set default configuration values, load existing ones
151
     // Set default configuration values, load existing ones
461
         NSLog(@"Trying to send RGB without opened port!\n");
484
         NSLog(@"Trying to send RGB without opened port!\n");
462
 #endif
485
 #endif
463
     }
486
     }
487
+    
488
+#ifdef COLORED_MENU_BAR_ICON
489
+    [statusItem setImage:[AppDelegate tintedImage:statusImage WithColor:[NSColor colorWithCalibratedRed:r / 255.0f green:g / 255.0f blue:b / 255.0f alpha:1.0f]]];
490
+#endif
464
 }
491
 }
465
 
492
 
466
 - (IBAction)relistSerialPorts:(id)sender {
493
 - (IBAction)relistSerialPorts:(id)sender {

+ 1
- 1
CaseLights/Info.plist View File

21
 	<key>CFBundleSignature</key>
21
 	<key>CFBundleSignature</key>
22
 	<string>????</string>
22
 	<string>????</string>
23
 	<key>CFBundleVersion</key>
23
 	<key>CFBundleVersion</key>
24
-	<string>397</string>
24
+	<string>402</string>
25
 	<key>LSApplicationCategoryType</key>
25
 	<key>LSApplicationCategoryType</key>
26
 	<string>public.app-category.utilities</string>
26
 	<string>public.app-category.utilities</string>
27
 	<key>LSMinimumSystemVersion</key>
27
 	<key>LSMinimumSystemVersion</key>

Loading…
Cancel
Save