Skip to content

Commit

Permalink
Merge pull request #28 from c-alpha/master
Browse files Browse the repository at this point in the history
Re-introduce white shadow using setTemplate:
  • Loading branch information
codler committed Aug 27, 2012
2 parents f1ad823 + ff6259d commit 73e8ada
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Battery Time Remaining/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ @interface AppDelegate ()
{
NSDictionary *batteryIcons;
BOOL showParenthesis;
BOOL isCapacityWarning;
}

- (void)cacheBatteryIcon;
Expand All @@ -47,6 +48,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
self.advancedSupported = ([self getAdvancedBatteryInfo] != nil);
[self cacheBatteryIcon];
isCapacityWarning = NO;

// Init notification
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
Expand Down Expand Up @@ -167,7 +169,10 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification

- (void)updateStatusItem
{
// Get the estimated time remaining
// reset warning state; new state will be calculated here anyway
isCapacityWarning = NO;

// Get the estimated time remaining
CFTimeInterval timeRemaining = IOPSGetTimeRemainingEstimate();

// Get list of power sources
Expand Down Expand Up @@ -278,6 +283,7 @@ - (void)updateStatusItem
- (void)setStatusBarImage:(NSImage *)image title:(NSString *)title
{
// Image
[image setTemplate:( ! isCapacityWarning)];
[self.statusItem setImage:image];
[self.statusItem setAlternateImage:[self imageInvertColor:image]];

Expand Down Expand Up @@ -327,13 +333,15 @@ - (NSImage *)getBatteryIconPercent:(NSInteger)percent

if (percent > 15)
{
isCapacityWarning = NO;
// draw black capacity bar
batteryLevelLeft = [self getBatteryIconNamed:@"BatteryLevelCapB-L"];
batteryLevelMiddle = [self getBatteryIconNamed:@"BatteryLevelCapB-M"];
batteryLevelRight = [self getBatteryIconNamed:@"BatteryLevelCapB-R"];
}
else
{
isCapacityWarning = YES;
// draw red capacity bar
batteryLevelLeft = [self getBatteryIconNamed:@"BatteryLevelCapR-L"];
batteryLevelMiddle = [self getBatteryIconNamed:@"BatteryLevelCapR-M"];
Expand All @@ -345,7 +353,7 @@ - (NSImage *)getBatteryIconPercent:(NSInteger)percent
CGFloat capBarHeight = [batteryLevelLeft size].height;
CGFloat capBarTopOffset = (([batteryOutline size].height - (EXTRA_TOP_OFFSET * drawingUnit)) - capBarHeight) / 2.0;
CGFloat capBarLength = ceil(percent / 8.0f) * drawingUnit; // max width is 13 units
if (capBarLength < (2 * drawingUnit + 0.1f)) { capBarLength = 2 * drawingUnit + 0.1f; }
if (capBarLength <= (2 * drawingUnit)) { capBarLength = (2 * drawingUnit) + 0.1f; } // must be _greater_than_ the end segments

[batteryOutline lockFocus];
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
Expand Down

0 comments on commit 73e8ada

Please sign in to comment.