Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor

  • Loading branch information...
commit 734cedd419293c1983bfa168c458e94268f3d22c 1 parent a623120
Han Lin Yap authored
6 Battery Time Remaining.xcodeproj/project.pbxproj
View
@@ -13,6 +13,7 @@
2841C7F115C91CC100F4F15F /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 2841C7EF15C91CC100F4F15F /* Credits.rtf */; };
2841C7F415C91CC100F4F15F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2841C7F315C91CC100F4F15F /* AppDelegate.m */; };
2841C7FE15C91CEF00F4F15F /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2841C7FD15C91CEF00F4F15F /* IOKit.framework */; };
+ 28527E581622E8A800EE3644 /* ImageFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 28527E571622E8A800EE3644 /* ImageFilter.m */; };
28833BAE15D7B90B00741727 /* HttpGet.m in Sources */ = {isa = PBXBuildFile; fileRef = 28833BAD15D7B90B00741727 /* HttpGet.m */; };
28833BB215D7D4FF00741727 /* Readme.md in Resources */ = {isa = PBXBuildFile; fileRef = 28833BB115D7D4FF00741727 /* Readme.md */; };
28833BB415D7D61100741727 /* build_version in Resources */ = {isa = PBXBuildFile; fileRef = 28833BB315D7D61100741727 /* build_version */; };
@@ -69,6 +70,8 @@
2841C7F215C91CC100F4F15F /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
2841C7F315C91CC100F4F15F /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
2841C7FD15C91CEF00F4F15F /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
+ 28527E561622E8A800EE3644 /* ImageFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageFilter.h; sourceTree = "<group>"; };
+ 28527E571622E8A800EE3644 /* ImageFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageFilter.m; sourceTree = "<group>"; };
28563BBE1621A34500960191 /* it */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/Localizable.strings; sourceTree = "<group>"; };
288305DF15DD005C0064D457 /* sv */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/Localizable.strings; sourceTree = "<group>"; };
28833BAC15D7B90B00741727 /* HttpGet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HttpGet.h; sourceTree = "<group>"; };
@@ -152,6 +155,8 @@
28FEDA6315DA5EB200320B72 /* LLManager.m */,
28FEDA6415DA5EB200320B72 /* LLStrings.h */,
2841C7F215C91CC100F4F15F /* AppDelegate.h */,
+ 28527E561622E8A800EE3644 /* ImageFilter.h */,
+ 28527E571622E8A800EE3644 /* ImageFilter.m */,
2841C7F315C91CC100F4F15F /* AppDelegate.m */,
28833BAC15D7B90B00741727 /* HttpGet.h */,
28833BAD15D7B90B00741727 /* HttpGet.m */,
@@ -280,6 +285,7 @@
2841C7ED15C91CC100F4F15F /* main.m in Sources */,
2841C7F415C91CC100F4F15F /* AppDelegate.m in Sources */,
28833BAE15D7B90B00741727 /* HttpGet.m in Sources */,
+ 28527E581622E8A800EE3644 /* ImageFilter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
61 Battery Time Remaining/AppDelegate.m
View
@@ -8,12 +8,12 @@
#import "AppDelegate.h"
#import "HttpGet.h"
+#import "ImageFilter.h"
#import "LLManager.h"
#import <IOKit/ps/IOPowerSources.h>
#import <IOKit/ps/IOPSKeys.h>
#import <IOKit/pwr_mgt/IOPM.h>
#import <IOKit/pwr_mgt/IOPMLib.h>
-#import <QuartzCore/QuartzCore.h>
//#define DEBUG_BATTERY_PERCENT
#define CHECK_FOR_UPDATE
@@ -360,7 +360,7 @@ - (void)setStatusBarImage:(NSImage *)image title:(NSString *)title
// Image
[image setTemplate:( ! isCapacityWarning)];
[self.statusItem setImage:image];
- [self.statusItem setAlternateImage:[self imageInvertColor:image]];
+ [self.statusItem setAlternateImage:[ImageFilter invertColor:image]];
// Title
NSDictionary *attributedStyle = [NSDictionary dictionaryWithObjectsAndKeys:
@@ -460,12 +460,12 @@ - (NSImage *)loadBatteryIconNamed:(NSString *)iconName
- (void)cacheBatteryIcon {
// special treatment for the BatteryCharging, BatteryCharged, and BatteryEmpty images
// they need to be shifted down by 2points to be in the same position as Apple's
- NSImage *imgCharging = [self imageOffset:[self loadBatteryIconNamed:@"BatteryCharging"] top:EXTRA_TOP_OFFSET];
- NSImage *imgCharged = [self imageOffset:[self loadBatteryIconNamed:@"BatteryCharged"] top:EXTRA_TOP_OFFSET];
- NSImage *imgEmpty = [self imageOffset:[self loadBatteryIconNamed:@"BatteryEmpty"] top:EXTRA_TOP_OFFSET];
+ NSImage *imgCharging = [ImageFilter offset:[self loadBatteryIconNamed:@"BatteryCharging"] top:EXTRA_TOP_OFFSET];
+ NSImage *imgCharged = [ImageFilter offset:[self loadBatteryIconNamed:@"BatteryCharged"] top:EXTRA_TOP_OFFSET];
+ NSImage *imgEmpty = [ImageFilter offset:[self loadBatteryIconNamed:@"BatteryEmpty"] top:EXTRA_TOP_OFFSET];
// Make the image black and white
- imgCharged = [self imageBW:[self imageBW:imgCharged]];
+ imgCharged = [ImageFilter blackWhite:[ImageFilter blackWhite:imgCharged]];
// finally construct the dictionary from which we will retrieve the images at runtime
batteryIcons = [NSDictionary dictionaryWithObjectsAndKeys:
@@ -481,55 +481,6 @@ - (void)cacheBatteryIcon {
nil];
}
-- (NSImage *)imageBW:(NSImage *)_image
-{
- NSImage *image = [_image copy];
- [image lockFocus];
-
- // http://stackoverflow.com/a/10033772/304894
- CIImage *beginImage = [[CIImage alloc] initWithData:[image TIFFRepresentation]];
- CIImage *blackAndWhite = [[CIFilter filterWithName:@"CIColorControls" keysAndValues:kCIInputImageKey, beginImage, @"inputBrightness", [NSNumber numberWithFloat:0.0], @"inputContrast", [NSNumber numberWithFloat:1.1], @"inputSaturation", [NSNumber numberWithFloat:0.0], nil] valueForKey:@"outputImage"];
- CIImage *output = [[CIFilter filterWithName:@"CIExposureAdjust" keysAndValues:kCIInputImageKey, blackAndWhite, @"inputEV", [NSNumber numberWithFloat:0.7], nil] valueForKey:@"outputImage"];
- [output drawInRect:NSMakeRect(0, 0, [_image size].width, [_image size].height) fromRect:NSRectFromCGRect([output extent]) operation:NSCompositeSourceOver fraction:1.0];
-
- [image unlockFocus];
-
- return image;
-}
-
-- (NSImage *)imageOffset:(NSImage *)_image top:(CGFloat)top
-{
- NSImage *newImage = [[NSImage alloc] initWithSize:NSMakeSize(_image.size.width, _image.size.height + top)];
- [newImage lockFocus];
-
- [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
- [_image drawInRect:NSMakeRect(0, 0, _image.size.width, _image.size.height)
- fromRect:NSMakeRect(0, 0, _image.size.width, _image.size.height)
- operation:NSCompositeSourceOver
- fraction:1.0];
-
- [newImage unlockFocus];
-
- return newImage;
-}
-
-- (NSImage *)imageInvertColor:(NSImage *)_image
-{
- NSImage *image = [_image copy];
- [image lockFocus];
-
- CIImage *ciImage = [[CIImage alloc] initWithData:[image TIFFRepresentation]];
- CIFilter *filter = [CIFilter filterWithName:@"CIColorInvert"];
- [filter setDefaults];
- [filter setValue:ciImage forKey:@"inputImage"];
- CIImage *output = [filter valueForKey:@"outputImage"];
- [output drawInRect:NSMakeRect(0, 0, [_image size].width, [_image size].height) fromRect:NSRectFromCGRect([output extent]) operation:NSCompositeSourceOver fraction:1.0];
-
- [image unlockFocus];
-
- return image;
-}
-
- (void)openEnergySaverPreference:(id)sender
{
[[NSWorkspace sharedWorkspace] openFile:@"/System/Library/PreferencePanes/EnergySaver.prefPane"];
17 Battery Time Remaining/ImageFilter.h
View
@@ -0,0 +1,17 @@
+//
+// ImageFilter.h
+// Battery Time Remaining
+//
+// Created by Han Lin Yap on 2012-10-08.
+// Copyright (c) 2012 Han Lin Yap. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface ImageFilter : NSObject
+
++ (NSImage *)blackWhite:(NSImage *)_image;
++ (NSImage *)offset:(NSImage *)_image top:(CGFloat)top;
++ (NSImage *)invertColor:(NSImage *)_image;
+
+@end
63 Battery Time Remaining/ImageFilter.m
View
@@ -0,0 +1,63 @@
+//
+// ImageFilter.m
+// Battery Time Remaining
+//
+// Created by Han Lin Yap on 2012-10-08.
+// Copyright (c) 2012 Han Lin Yap. All rights reserved.
+//
+
+#import "ImageFilter.h"
+#import <QuartzCore/QuartzCore.h>
+
+@implementation ImageFilter
+
++ (NSImage *)blackWhite:(NSImage *)_image
+{
+ NSImage *image = [_image copy];
+ [image lockFocus];
+
+ // http://stackoverflow.com/a/10033772/304894
+ CIImage *beginImage = [[CIImage alloc] initWithData:[image TIFFRepresentation]];
+ CIImage *blackAndWhite = [[CIFilter filterWithName:@"CIColorControls" keysAndValues:kCIInputImageKey, beginImage, @"inputBrightness", [NSNumber numberWithFloat:0.0], @"inputContrast", [NSNumber numberWithFloat:1.1], @"inputSaturation", [NSNumber numberWithFloat:0.0], nil] valueForKey:@"outputImage"];
+ CIImage *output = [[CIFilter filterWithName:@"CIExposureAdjust" keysAndValues:kCIInputImageKey, blackAndWhite, @"inputEV", [NSNumber numberWithFloat:0.7], nil] valueForKey:@"outputImage"];
+ [output drawInRect:NSMakeRect(0, 0, [_image size].width, [_image size].height) fromRect:NSRectFromCGRect([output extent]) operation:NSCompositeSourceOver fraction:1.0];
+
+ [image unlockFocus];
+
+ return image;
+}
+
++ (NSImage *)offset:(NSImage *)_image top:(CGFloat)top
+{
+ NSImage *newImage = [[NSImage alloc] initWithSize:NSMakeSize(_image.size.width, _image.size.height + top)];
+ [newImage lockFocus];
+
+ [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
+ [_image drawInRect:NSMakeRect(0, 0, _image.size.width, _image.size.height)
+ fromRect:NSMakeRect(0, 0, _image.size.width, _image.size.height)
+ operation:NSCompositeSourceOver
+ fraction:1.0];
+
+ [newImage unlockFocus];
+
+ return newImage;
+}
+
++ (NSImage *)invertColor:(NSImage *)_image
+{
+ NSImage *image = [_image copy];
+ [image lockFocus];
+
+ CIImage *ciImage = [[CIImage alloc] initWithData:[image TIFFRepresentation]];
+ CIFilter *filter = [CIFilter filterWithName:@"CIColorInvert"];
+ [filter setDefaults];
+ [filter setValue:ciImage forKey:@"inputImage"];
+ CIImage *output = [filter valueForKey:@"outputImage"];
+ [output drawInRect:NSMakeRect(0, 0, [_image size].width, [_image size].height) fromRect:NSRectFromCGRect([output extent]) operation:NSCompositeSourceOver fraction:1.0];
+
+ [image unlockFocus];
+
+ return image;
+}
+
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.