mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-15 03:33:52 +00:00
Added simple hud overlay on double-click actions
This commit is contained in:
87
MacPass/MPOverlayWindowController.m
Normal file
87
MacPass/MPOverlayWindowController.m
Normal file
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// MPOverlayWindowController.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 03.03.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPOverlayWindowController.h"
|
||||
#import "MPOverlayView.h"
|
||||
|
||||
@interface MPOverlayWindowController ()
|
||||
|
||||
@property (assign) BOOL isAnimating;
|
||||
@property (assign) IBOutlet NSImageView *imageView;
|
||||
@property (assign) IBOutlet NSTextField *textField;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPOverlayWindowController
|
||||
|
||||
+ (MPOverlayWindowController *)sharedController {
|
||||
static MPOverlayWindowController *sharedInstance;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
sharedInstance = [[MPOverlayWindowController alloc] initWithWindowNibName:@"OverlayWindow"];
|
||||
});
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
- (id)initWithWindow:(NSWindow *)window {
|
||||
self = [super initWithWindow:window];
|
||||
if (self) {
|
||||
// Initialization code here.
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)windowDidLoad {
|
||||
[super windowDidLoad];
|
||||
[self.window setStyleMask:NSBorderlessWindowMask];
|
||||
[self.window setAlphaValue:0];
|
||||
[self.window setOpaque:NO];
|
||||
[self.window setHasShadow:NO];
|
||||
[[self.textField cell] setBackgroundStyle:NSBackgroundStyleLowered];
|
||||
[[self.imageView cell] setBackgroundStyle:NSBackgroundStyleLowered];
|
||||
[[self.imageView cell] setImageAlignment:NSImageAlignCenter];
|
||||
}
|
||||
|
||||
- (void)displayOverlayImage:(NSImage *)imageOrNil label:(NSString *)labelOrNil atView:(NSView *)view {
|
||||
/* make window transparent */
|
||||
|
||||
[self.window setAlphaValue:0];
|
||||
[self.window setIsVisible:YES];
|
||||
|
||||
/* setup any provided images and labels*/
|
||||
[self.imageView setImage:imageOrNil];
|
||||
if(labelOrNil) {
|
||||
[self.textField setStringValue:labelOrNil];
|
||||
}
|
||||
else {
|
||||
[self.textField setStringValue:@""];
|
||||
}
|
||||
[self.textField sizeToFit];
|
||||
/*
|
||||
Center in view
|
||||
*/
|
||||
if(view) {
|
||||
NSWindow *parentWindow = [view window];
|
||||
NSRect parentFrame = [parentWindow frame];
|
||||
NSRect myFrame = [self.window frame];
|
||||
NSPoint newOrigin = parentFrame.origin;
|
||||
newOrigin.x += 0.5 * (parentFrame.size.width - myFrame.size.width);
|
||||
newOrigin.y += 0.5 * (parentFrame.size.height - myFrame.size.height);
|
||||
[self.window setFrameOrigin:newOrigin];
|
||||
[parentWindow addChildWindow:self.window ordered:NSWindowAbove];
|
||||
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
|
||||
context.duration = 0.2;
|
||||
[[self.window animator]setAlphaValue:1];
|
||||
} completionHandler:^{
|
||||
[self.window performSelector:@selector(close) withObject:nil afterDelay:0.5];
|
||||
}];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user