-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlipViewerController.m
115 lines (92 loc) · 2.37 KB
/
FlipViewerController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// FlipViewerController.m
// Kineo
//
// Created by Ben Yellin on 3/20/11.
// Copyright 2011 Been Yelling. All rights reserved.
//
#import "FlipViewerController.h"
#import "FlipSeries.h"
#import "PrintController.h"
@interface FlipViewerController (Private)
- (void)playUpdate:(NSTimer *)timer;
@end
@implementation FlipViewerController
@synthesize isPlaying;
- (id)initWithFlipSeries:(FlipSeries *)series {
if (self = [super initWithWindowNibName:@"FlipViewer"]) {
flipSeries = [series retain];
}
return self;
}
- (void)windowDidLoad {
[self.window setTitle:[flipSeries title]];
[titleField setStringValue:[flipSeries title]];
// Image View
currentImageIndex = 0;
[self displayImageAtIndex:currentImageIndex];
}
- (void)windowWillClose:(NSNotification *)notification {
[flipSeries release];
}
- (void)dealloc {
[flipSeries release];
[super dealloc];
}
- (IBAction)showPrevImage:(id)sender {
currentImageIndex--;
if (currentImageIndex < 0)
currentImageIndex = [flipSeries numberOfImages]-1;
[self displayImageAtIndex:currentImageIndex];
}
- (IBAction)showNextImage:(id)sender {
currentImageIndex++;
if (currentImageIndex >= [flipSeries numberOfImages])
currentImageIndex = 0;
[self displayImageAtIndex:currentImageIndex];
}
- (void)displayImageAtIndex:(NSInteger)index {
NSImage *flipImage = [flipSeries getImage:index];
if (flipImage) {
[imageView setImage:flipImage];
}
}
- (IBAction)playPause:(id)sender {
self.isPlaying = !isPlaying;
if ([sender isKindOfClass:[NSButton class]]) {
if (isPlaying)
[sender setTitle:@"Pause"];
else
[sender setTitle:@"Play"];
}
}
- (void)setIsPlaying:(BOOL)flag {
isPlaying = flag;
if (isPlaying) {
[NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(playUpdate:)
userInfo:nil
repeats:YES];
}
}
- (void)playUpdate:(NSTimer *)timer {
if (isPlaying) {
[self showNextImage:nil];
} else {
[timer invalidate];
}
}
- (IBAction)changeTitle:(id)sender {
NSString *newTitle = [titleField stringValue];
flipSeries.title = newTitle;
[self.window setTitle:newTitle];
}
- (IBAction)print:(id)sender {
flipSeries.title = [titleField stringValue];
PrintController *printController = [[PrintController alloc]
initWithFlipSeries:flipSeries];
[printController showWindow:nil];
[self.window setTitle:flipSeries.title];
}
@end