Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tuned dynamic fill of the icon #2

Merged
merged 2 commits into from
Aug 5, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Battery Time Remaining.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
2841C7F415C91CC100F4F15F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2841C7F315C91CC100F4F15F /* AppDelegate.m */; };
2841C7F715C91CC200F4F15F /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2841C7F515C91CC200F4F15F /* MainMenu.xib */; };
2841C7FE15C91CEF00F4F15F /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2841C7FD15C91CEF00F4F15F /* IOKit.framework */; };
D570489C15CF1B9200E488C4 /* battery.icns in Resources */ = {isa = PBXBuildFile; fileRef = D570489B15CF1B9200E488C4 /* battery.icns */; };
D58C7EF815CD7C6100C07E0C /* StartAtLoginHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = D58C7EF715CD7C6100C07E0C /* StartAtLoginHelper.m */; };
/* End PBXBuildFile section */

Expand All @@ -32,6 +33,7 @@
2841C7F315C91CC100F4F15F /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
2841C7F615C91CC200F4F15F /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = "<group>"; };
2841C7FD15C91CEF00F4F15F /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
D570489B15CF1B9200E488C4 /* battery.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = battery.icns; sourceTree = "<group>"; };
D58C7EF615CD7C6100C07E0C /* StartAtLoginHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StartAtLoginHelper.h; sourceTree = "<group>"; };
D58C7EF715CD7C6100C07E0C /* StartAtLoginHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StartAtLoginHelper.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand All @@ -52,6 +54,7 @@
2841C7D115C91CC100F4F15F = {
isa = PBXGroup;
children = (
D570489B15CF1B9200E488C4 /* battery.icns */,
2841C7E615C91CC100F4F15F /* Battery Time Remaining */,
2841C7DF15C91CC100F4F15F /* Frameworks */,
2841C7DD15C91CC100F4F15F /* Products */,
Expand Down Expand Up @@ -165,6 +168,7 @@
2841C7EB15C91CC100F4F15F /* InfoPlist.strings in Resources */,
2841C7F115C91CC100F4F15F /* Credits.rtf in Resources */,
2841C7F715C91CC200F4F15F /* MainMenu.xib in Resources */,
D570489C15CF1B9200E488C4 /* battery.icns in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
14 changes: 7 additions & 7 deletions Battery Time Remaining/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,20 @@ - (void)updateStatusItem
NSInteger hour = (int)timeRemaining / 3600;
NSInteger minute = (int)timeRemaining % 3600 / 60;

// Make dynamic Battery icon
// Make dynamic battery icon
NSImage *batteryDynamic = [self getBatteryIconNamed:@"BatteryEmpty"];

[batteryDynamic lockFocus];

NSRect sourceRect;
sourceRect.origin = NSZeroPoint;
sourceRect.origin.x += [batteryDynamic size].width / 100 * 15;
sourceRect.origin.y += [batteryDynamic size].height / 50 * 10;
sourceRect.origin.y += [batteryDynamic size].height / 50 * 15;
sourceRect.size = [batteryDynamic size];
sourceRect.size.width -= [batteryDynamic size].width / 100 * 40;
sourceRect.size.height -= [batteryDynamic size].height / 50 * 20;
sourceRect.size.width -= [batteryDynamic size].width / 100 * 43;
sourceRect.size.height -= [batteryDynamic size].height / 50 * 30;

sourceRect.size.width -= [batteryDynamic size].width / 100 * (60.0f - (60.0f / 100.0f * percent));
sourceRect.size.width -= [batteryDynamic size].width / 100 * (60.f - (60.f / 100.f * percent));

if (percent > 15)
{
Expand All @@ -156,7 +156,7 @@ - (void)updateStatusItem
[[NSColor redColor] set];
}

NSRectFill (sourceRect);
NSRectFill(sourceRect);

[batteryDynamic unlockFocus];

Expand Down
2 changes: 1 addition & 1 deletion Battery Time Remaining/Battery Time Remaining-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<string>battery</string>
<key>CFBundleIdentifier</key>
<string>com.codler.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
Expand Down
Binary file added battery.icns
Binary file not shown.