Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Commit

Permalink
fullscreen behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
HBehrens committed Jan 31, 2012
1 parent 704fac1 commit ac0dd4b
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 89 deletions.
2 changes: 2 additions & 0 deletions CamHolderApp/CHDocument.h
Expand Up @@ -34,7 +34,9 @@ extern NSArray* CHCachedCaptureDevices;
-(void)resetZoom;

@property (nonatomic, assign) BOOL showsInspector;
@property (nonatomic, assign) NSSize contentSize;

-(void)toggleInspector:(id)sender;


@end
7 changes: 5 additions & 2 deletions CamHolderApp/CHDocument.m
Expand Up @@ -13,7 +13,7 @@ @implementation CHDocument

@synthesize isAutoExposureActive, exposureTimeFactor, isAutoFocusActive, focusFactor, activeCaptureDevice,
normalizedCroppingRect, isMirroredHorizontally, isMirroredVertically, rotation,
showsInspector;
showsInspector, contentSize;

- (id)init
{
Expand Down Expand Up @@ -196,7 +196,10 @@ -(IBAction)toggleInspector:(id)sender {
self.showsInspector = !self.showsInspector;
}


-(void)setContentSize:(NSSize)contentSize_ {
contentSize = contentSize_;
NSLog(@"setContentSize: %@", NSStringFromSize(contentSize));
}



Expand Down
9 changes: 9 additions & 0 deletions CamHolderApp/CHWindowController.h
Expand Up @@ -17,12 +17,16 @@
QTCaptureDeviceInput *_videoInput;

NSUInteger _originalWindowMask;
NSRect _nonFullScreenFrame;
NSRect _fullscreenFrame;
BOOL _ignoreWindowDidResize;

IBOutlet NSComboBox *captureDevicesCombobox;
IBOutlet NSSlider *exposureSlider;
IBOutlet CroppingQTCaptureView *captureView;
IBOutlet NSView* zoomRectView;
IBOutlet NSView* inspectorView;

}

- (IBAction)captureDeviceChanged:(id)sender;
Expand All @@ -32,4 +36,9 @@

-(void)setShowsInspector:(BOOL)value;

@property (nonatomic, assign) BOOL isFullscreen;

-(IBAction)toggleFullscreen:(id)sender;
-(void)setContentSize:(NSSize)size;

@end
79 changes: 77 additions & 2 deletions CamHolderApp/CHWindowController.m
Expand Up @@ -11,6 +11,8 @@

@implementation CHWindowController

@synthesize isFullscreen;

- (id)initWithWindow:(NSWindow *)window
{
self = [super initWithWindow:window];
Expand Down Expand Up @@ -162,6 +164,9 @@ -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NS
if(object == self.document && [@"showsInspector" isEqualToString:keyPath]) {
[self setShowsInspector:self.document.showsInspector];
} else
if(object == self.document && [@"contentSize" isEqualToString:keyPath]) {
[self setContentSize:self.document.contentSize];
} else

[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
Expand All @@ -174,10 +179,12 @@ -(CHDocument *)document {
-(void)setDocument:(CHDocument *)document {
[self.document removeObserver:self forKeyPath:@"activeCaptureDevice"];
[self.document removeObserver:self forKeyPath:@"showsInspector"];
[self.document removeObserver:self forKeyPath:@"contentSize"];

[super setDocument:document];
[self.document addObserver:self forKeyPath:@"activeCaptureDevice" options:NSKeyValueObservingOptionNew context:nil];
[self.document addObserver:self forKeyPath:@"showsInspector" options:NSKeyValueObservingOptionNew context:nil];
[self.document addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];
}

-(void)captureDeviceChanged:(id)sender {
Expand All @@ -194,7 +201,30 @@ -(void)setWindow:(CHDraggableWindow *)window {

#pragma mark - view options

-(void)windowDidResize:(NSNotification *)notification {
//- (void)windowDidEndLiveResize:(NSNotification *)notification {
// TODO: listen to property
if(self.isFullscreen || _ignoreWindowDidResize)
return;

_ignoreWindowDidResize = YES;
self.document.contentSize = captureView.frame.size;
_ignoreWindowDidResize = NO;
}

-(void)setContentSize:(NSSize)size {
if(NSEqualSizes(size, captureView.frame.size))
return;

NSRect r = self.window.frame;
r.size.width += size.width - captureView.frame.size.width;
r.size.height += size.height - captureView.frame.size.height;
[self.window setFrame:r display:YES animate:YES];
}

-(void)setShowsInspector:(BOOL)value {
BOOL oldIgnoreWindowDidResize = _ignoreWindowDidResize;
_ignoreWindowDidResize = YES;
self.window.styleMask = value ? _originalWindowMask : NSBorderlessWindowMask;
NSRect r = self.window.frame;
float widthDelta = inspectorView.frame.size.width * (value ? 1 : -1);
Expand All @@ -204,8 +234,53 @@ -(void)setShowsInspector:(BOOL)value {
r = [(NSView*)self.window.contentView frame];
if(value)r.size.width -= widthDelta;
captureView.frame = r;
self.window.isDraggable = !value;
captureView.canSelectRect = value;
self.window.isDraggable = !value && !self.isFullscreen;
captureView.canSelectRect = value && !self.isFullscreen;
_ignoreWindowDidResize = oldIgnoreWindowDidResize;;
}

-(void)displayAsFullScreenInRect:(NSRect)frame {
if(self.document.showsInspector)
[self setShowsInspector:NO];

_nonFullScreenFrame = self.window.frame;

[[NSApplication sharedApplication] setPresentationOptions:(NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar)];

// workaround to animate zoom (needs another even in main loop since setting styleMask prevents animation otherwise)
_fullscreenFrame = frame;

self.window.isDraggable = NO;
[self performSelector:@selector(delayedZoom) withObject:nil afterDelay:0];
}

-(void)delayedZoom {
[self.window setFrame:_fullscreenFrame display:YES animate:YES];
}

-(void)clearIgnoreWindowDidResize {
_ignoreWindowDidResize = NO;
}

-(void)setIsFullscreen:(BOOL)isFullscreen_ {
isFullscreen = isFullscreen_;
if(isFullscreen) {
[self displayAsFullScreenInRect: self.window.screen.frame];
} else {
_ignoreWindowDidResize = YES;
[self performSelector:@selector(clearIgnoreWindowDidResize) withObject:nil afterDelay:1];
[self.window setFrame:_nonFullScreenFrame display:YES animate:YES];
[[NSApplication sharedApplication] setPresentationOptions:NSApplicationPresentationDefault];
if(self.document.showsInspector)
[self setShowsInspector:self.document.showsInspector];
self.window.isDraggable = YES;
}

}

-(IBAction)toggleFullscreen:(id)sender {
self.isFullscreen = !self.isFullscreen;
}


@end

0 comments on commit ac0dd4b

Please sign in to comment.