Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Specific Delegate Methods #103

Merged
merged 8 commits into from
Mar 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions Project/Vision/PBJViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,34 @@ - (void)visionSessionDidStop:(PBJVision *)vision
[_previewView removeFromSuperview];
}

- (void)visionModeWillChange:(PBJVision *)vision
- (void)visionCameraModeWillChange:(PBJVision *)vision
{
NSLog(@"Camera mode will change");
}

- (void)visionModeDidChange:(PBJVision *)vision
- (void)visionCameraModeDidChange:(PBJVision *)vision
{
NSLog(@"Camera mode did change");
}

- (void)visionCameraDeviceWillChange:(PBJVision *)vision
{
NSLog(@"Camera device will change");
}

- (void)visionCameraDeviceDidChange:(PBJVision *)vision
{
NSLog(@"Camera device did change");
}

- (void)visionOutputFormatWillChange:(PBJVision *)vision
{
NSLog(@"Output format will change");
}

- (void)visionOutputFormatDidChange:(PBJVision *)vision
{
NSLog(@"Output format did change");
}

- (void)vision:(PBJVision *)vision didChangeCleanAperture:(CGRect)cleanAperture
Expand Down
10 changes: 8 additions & 2 deletions Source/PBJVision.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,14 @@ extern NSString * const PBJVisionVideoThumbnailKey;
- (void)visionSessionDidStart:(PBJVision *)vision;
- (void)visionSessionDidStop:(PBJVision *)vision;

- (void)visionModeWillChange:(PBJVision *)vision;
- (void)visionModeDidChange:(PBJVision *)vision;
- (void)visionCameraDeviceWillChange:(PBJVision*)vision;
- (void)visionCameraDeviceDidChange:(PBJVision*)vision;

- (void)visionCameraModeWillChange:(PBJVision*)vision;
- (void)visionCameraModeDidChange:(PBJVision*)vision;

- (void)visionOutputFormatWillChange:(PBJVision*)vision;
- (void)visionOutputFormatDidChange:(PBJVision*)vision;

- (void)vision:(PBJVision *)vision didChangeCleanAperture:(CGRect)cleanAperture;

Expand Down
49 changes: 43 additions & 6 deletions Source/PBJVision.m
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,31 @@ - (void)_setCameraMode:(PBJCameraMode)cameraMode cameraDevice:(PBJCameraDevice)c
if (!changeMode && !changeDevice && !changeOutputFormat)
return;

if ([_delegate respondsToSelector:@selector(visionModeWillChange:)])
[_delegate visionModeWillChange:self];
SEL targetDelegateMethodBeforeChange;
SEL targetDelegateMethodAfterChange;

if (changeDevice) {
targetDelegateMethodBeforeChange = @selector(visionCameraDeviceWillChange:);
targetDelegateMethodAfterChange = @selector(visionCameraDeviceDidChange:);
}
else if (changeMode) {
targetDelegateMethodBeforeChange = @selector(visionCameraModeWillChange:);
targetDelegateMethodAfterChange = @selector(visionCameraModeDidChange:);
}
else {
targetDelegateMethodBeforeChange = @selector(visionOutputFormatWillChange:);
targetDelegateMethodAfterChange = @selector(visionOutputFormatDidChange:);
}

if ([_delegate respondsToSelector:targetDelegateMethodBeforeChange]) {
// At this point, `targetDelegateMethodBeforeChange` will always refer to a valid selector, as
// from the sequence of conditionals above. Also the enclosing `if` statement ensures
// that the delegate responds to it, thus safely ignore this compiler warning.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[_delegate performSelector:targetDelegateMethodBeforeChange withObject:self];
#pragma clang diagnostic pop
}

_flags.changingModes = YES;

Expand All @@ -294,8 +317,15 @@ - (void)_setCameraMode:(PBJCameraMode)cameraMode cameraDevice:(PBJCameraDevice)c
if (!_captureSession) {
_flags.changingModes = NO;

if ([_delegate respondsToSelector:@selector(visionModeDidChange:)])
[_delegate visionModeDidChange:self];
if ([_delegate respondsToSelector:targetDelegateMethodAfterChange]) {
// At this point, `targetDelegateMethodAfterChange` will always refer to a valid selector, as
// from the sequence of conditionals above. Also the enclosing `if` statement ensures
// that the delegate responds to it, thus safely ignore this compiler warning.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[_delegate performSelector:targetDelegateMethodAfterChange withObject:self];
#pragma clang diagnostic pop
}

return;
}
Expand All @@ -305,8 +335,15 @@ - (void)_setCameraMode:(PBJCameraMode)cameraMode cameraDevice:(PBJCameraDevice)c
[self _enqueueBlockOnMainQueue:^{
_flags.changingModes = NO;

if ([_delegate respondsToSelector:@selector(visionModeDidChange:)])
[_delegate visionModeDidChange:self];
if ([_delegate respondsToSelector:targetDelegateMethodAfterChange]) {
// At this point, `targetDelegateMethodAfterChange` will always refer to a valid selector, as
// from the sequence of conditionals above. Also the enclosing `if` statement ensures
// that the delegate responds to it, thus safely ignore this compiler warning.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[_delegate performSelector:targetDelegateMethodAfterChange withObject:self];
#pragma clang diagnostic pop
}
}];
}];
}
Expand Down