Selaa lähdekoodia

Added ifdef option to color status bar icon

Thomas Buck 9 vuotta sitten
vanhempi
commit
a8dfc8885e
2 muutettua tiedostoa jossa 29 lisäystä ja 2 poistoa
  1. 28
    1
      CaseLights/AppDelegate.m
  2. 1
    1
      CaseLights/Info.plist

+ 28
- 1
CaseLights/AppDelegate.m Näytä tiedosto

@@ -62,6 +62,8 @@
62 62
 #define MENU_ITEM_TAG_NOTHING -1
63 63
 #define MENU_ITEM_TAG_AUDIO -2
64 64
 
65
+#define COLORED_MENU_BAR_ICON
66
+
65 67
 @interface AppDelegate ()
66 68
 
67 69
 @property (weak) IBOutlet NSMenu *statusMenu;
@@ -109,6 +111,22 @@
109 111
 @synthesize serial, lastLEDMode, microphone;
110 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 130
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
113 131
     srand((unsigned)time(NULL));
114 132
     [AudioVisualizer setDelegate:self];
@@ -120,9 +138,14 @@
120 138
     
121 139
     // Prepare status bar menu
122 140
     statusImage = [NSImage imageNamed:@"MenuIcon"];
123
-    [statusImage setTemplate:YES];
124 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 147
     [statusItem setImage:statusImage];
148
+#endif
126 149
     [statusItem setMenu:statusMenu];
127 150
     
128 151
     // Set default configuration values, load existing ones
@@ -461,6 +484,10 @@
461 484
         NSLog(@"Trying to send RGB without opened port!\n");
462 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 493
 - (IBAction)relistSerialPorts:(id)sender {

+ 1
- 1
CaseLights/Info.plist Näytä tiedosto

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

Loading…
Peruuta
Tallenna