Overlay windows now can be display floating on the screen.

This commit is contained in:
michael starke
2014-12-12 22:13:35 +01:00
parent 0b4a35c6d4
commit 3bff2a4f73
3 changed files with 57 additions and 20 deletions

View File

@@ -57,11 +57,17 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey";
toObject:[NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyGlobalAutotypeKeyDataKey]
options:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_applicationWillBecomeActive:)
name:NSApplicationWillBecomeActiveNotification
object:[NSApplication sharedApplication]];
}
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self unbind:NSStringFromSelector(@selector(enabled))];
[self unbind:NSStringFromSelector(@selector(hotKeyData))];
}
@@ -259,6 +265,13 @@ NSString *const kMPProcessIdentifierKey = @"kMPProcessIdentifierKey";
[self _performAutotypeUsingCurrentWindowAndApplication:NO];
}
#pragma mark -
#pragma mark NSApplication Notifications
- (void)_applicationWillBecomeActive:(NSNotification *)notification {
//[self _updateTargetApplicationAndWindow];
//NSLog(@"_applicaiontWillBecomActive");
}
#pragma mark -
#pragma mark Application information

View File

@@ -12,9 +12,15 @@
+ (MPOverlayWindowController *)sharedController;
/*
Displays an overlay centered at the given view. The Windows is added as a childwindow to the view window
/**
* Displays an overlay HUD style image with the given text, image centerd at the given view.
* There are two use cases. Either displaying information over a view by providing on,
* or displaying information on the main screen by using nil for the view.
*
* @param imageOrNil Image to be displayed. If nil, no image will be shown.
* @param labelOrNil Text to be displayed. If nil, no text will be rendered
* @param viewOrNil View to center the Overlay in. If nil, the window will be center and displayed on the main screen
*/
- (void)displayOverlayImage:(NSImage *)imageOrNil label:(NSString *)labelOrNil atView:(NSView *)view;
- (void)displayOverlayImage:(NSImage *)imageOrNil label:(NSString *)labelOrNil atView:(NSView *)viewOrNil;
@end

View File

@@ -45,13 +45,17 @@
[self.window setStyleMask:NSBorderlessWindowMask];
[self.window setAlphaValue:0];
[self.window setOpaque:NO];
[self.window setHasShadow:NO];
[self.window setHasShadow:YES];
[[self.textField cell] setBackgroundStyle:NSBackgroundStyleLowered];
[[self.imageView cell] setBackgroundStyle:NSBackgroundStyleDark];
[[self.imageView cell] setImageAlignment:NSImageAlignCenter];
}
- (void)displayOverlayImage:(NSImage *)imageOrNil label:(NSString *)labelOrNil atView:(NSView *)view {
if(self.isAnimating) {
return;
}
self.isAnimating = YES;
/* make window transparent */
[self.window setAlphaValue:0];
@@ -70,22 +74,36 @@
Center in view
*/
if(view) {
NSWindow *parentWindow = [view window];
NSRect parentFrame = [parentWindow frame];
NSRect myFrame = [self.window frame];
self.window.level = NSNormalWindowLevel;
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];
}
else {
self.window.level = NSStatusWindowLevel;
NSRect parentFrame = [NSScreen mainScreen].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];
}
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
context.duration = 0.2;
[[self.window animator]setAlphaValue:1];
} completionHandler:^{
[self.window performSelector:@selector(close) withObject:nil afterDelay:0.5];
[self performSelector:@selector(_didEndAnimation) withObject:nil afterDelay:0.5];
}];
}
}
- (void)_didEndAnimation {
self.isAnimating = NO;
[self.window close];
}
@end