summaryrefslogtreecommitdiffstats
path: root/macosx/HBDockTile.m
diff options
context:
space:
mode:
authorritsuka <[email protected]>2014-08-20 07:29:18 +0000
committerritsuka <[email protected]>2014-08-20 07:29:18 +0000
commitd1897978424444696eda51313f41feffc4112c78 (patch)
tree2094bb1f44c9a4a2eaafad7cc16adce4c6c26744 /macosx/HBDockTile.m
parentda33f7120c66115d506be98d6cfb08bd2c267ea5 (diff)
MacGui: added a HBDockTile class to manage the dock tile.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6324 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/HBDockTile.m')
-rw-r--r--macosx/HBDockTile.m77
1 files changed, 77 insertions, 0 deletions
diff --git a/macosx/HBDockTile.m b/macosx/HBDockTile.m
new file mode 100644
index 000000000..bfbed37b7
--- /dev/null
+++ b/macosx/HBDockTile.m
@@ -0,0 +1,77 @@
+//
+// HBDockTile.m
+// HandBrake
+//
+// Created by Damiano Galassi on 20/08/14.
+//
+//
+
+#import "HBDockTile.h"
+#import "DockTextField.h"
+
+NSString *dockTilePercentFormat = @"%2.1f%%";
+
+@interface HBDockTile ()
+
+@property (nonatomic, retain) NSDockTile *dockTile;
+@property (nonatomic, retain) NSImage *image;
+@property (nonatomic, retain) DockTextField * percentField;
+@property (nonatomic, retain) DockTextField * timeField;
+
+@end
+
+@implementation HBDockTile
+
+- (instancetype)initWithDockTile:(NSDockTile *)dockTile image:(NSImage *)image
+{
+ self = [super init];
+ if (self)
+ {
+ _dockTile = [dockTile retain];
+ _image = [image retain];
+
+ NSImageView *iv = [[NSImageView alloc] init];
+ [iv setImage:_image];
+ [dockTile setContentView:iv];
+
+ _percentField = [[DockTextField alloc] initWithFrame:NSMakeRect(0.0f, 32.0f, [dockTile size].width, 30.0f)];
+ [_percentField changeGradientColors:[NSColor colorWithDeviceRed:0.4f green:0.6f blue:0.4f alpha:1.0f] endColor:[NSColor colorWithDeviceRed:0.2f green:0.4f blue:0.2f alpha:1.0f]];
+ [iv addSubview:_percentField];
+
+ _timeField = [[DockTextField alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, [dockTile size].width, 30.0f)];
+ [_timeField changeGradientColors:[NSColor colorWithDeviceRed:0.6f green:0.4f blue:0.4f alpha:1.0f] endColor:[NSColor colorWithDeviceRed:0.4f green:0.2f blue:0.2f alpha:1.0f]];
+ [iv addSubview:_timeField];
+ [iv release];
+ }
+ return self;
+}
+
+- (void)dealloc
+{
+ [_dockTile release];
+ [_image release];
+ [_percentField release];
+ [_timeField release];
+
+ [super dealloc];
+}
+
+- (void)updateDockIcon:(double)progress withETA:(NSString *)etaStr
+{
+ if (progress < 0.0 || progress > 1.0)
+ {
+ [_percentField setHidden:YES];
+ [_timeField setHidden:YES];
+ }
+ else
+ {
+ [_percentField setTextToDisplay:[NSString stringWithFormat:dockTilePercentFormat, progress * 100]];
+ [_percentField setHidden:NO];
+ [_timeField setTextToDisplay:etaStr];
+ [_timeField setHidden:NO];
+ }
+
+ [_dockTile display];
+}
+
+@end