forked from rentzsch/Blitz
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SpeakerSlidesView.m
143 lines (114 loc) · 3.11 KB
/
SpeakerSlidesView.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//
// SpeakerSlidesView.m
// Blitz
//
// Created by Timothy J. Wood on 9/20/09.
// Copyright 2009 The Omni Group. All rights reserved.
//
#import "SpeakerSlidesView.h"
#import <Quartz/Quartz.h>
@implementation SpeakerSlidePDFView
- (void)drawPagePost:(PDFPage *)page;
{
// Draw a border around the page so that if it has black edges it doesn't fade into the black background.
[[NSColor colorWithCalibratedHue:215.0f/360.0f saturation:0.75f brightness:0.75f alpha:1.0f] set];
NSFrameRect([self bounds]);
}
@end
@interface SpeakerSlidesView (/*Private*/)
- (id)_speakerSlidesViewInit;
- (void)_layoutSlides;
- (void)_updatePages;
@end
@implementation SpeakerSlidesView
- initWithFrame:(NSRect)frame;
{
if (!(self = [super initWithFrame:frame]))
return nil;
return [self _speakerSlidesViewInit];
}
- initWithCoder:(NSCoder *)coder;
{
if (!(self = [super initWithCoder:coder]))
return nil;
return [self _speakerSlidesViewInit];
}
- (id)_speakerSlidesViewInit;
{
// Nothing, oops.
return self;
}
- (void)awakeFromNib;
{
[self _layoutSlides];
[_currentSlideView setBackgroundColor:[NSColor blackColor]];
[_nextSlideView setBackgroundColor:[NSColor blackColor]];
}
- (void)dealloc;
{
[_pdfDocument release];
[_currentSlideView release];
[_nextSlideView release];
[super dealloc];
}
#pragma mark -
#pragma mark NSView subclass
- (BOOL)isOpaque
{
return YES;
}
- (void)resizeSubviewsWithOldSize:(NSSize)oldSize;
{
[super resizeSubviewsWithOldSize:oldSize];
[self _layoutSlides];
}
- (void)drawRect:(NSRect)rect;
{
[[NSColor blackColor] set];
NSRectFill(self.bounds);
}
#pragma mark -
#pragma mark KVC
@synthesize currentSlideView = _currentSlideView;
@synthesize nextSlideView = _nextSlideView;
@synthesize pageIndex = _pageIndex;
- (void)setPageIndex:(NSUInteger)pageIndex;
{
if (_pageIndex == pageIndex)
return;
_pageIndex = pageIndex;
[self _updatePages];
}
@synthesize pdfDocument = _pdfDocument;
- (void)setPdfDocument:(PDFDocument *)pdfDocument;
{
if (_pdfDocument == pdfDocument)
return;
[_pdfDocument release];
_pdfDocument = [pdfDocument retain];
[_currentSlideView setDocument:_pdfDocument];
[_nextSlideView setDocument:_pdfDocument];
[self _updatePages];
}
#pragma mark -
#pragma mark Private
- (void)_updatePages;
{
NSUInteger pageCount = [_pdfDocument pageCount];
PDFPage *page;
page = (_pageIndex < pageCount) ? [_pdfDocument pageAtIndex:_pageIndex] : nil;
[_currentSlideView goToPage:page];
page = (_pageIndex + 1 < pageCount) ? [_pdfDocument pageAtIndex:_pageIndex + 1] : nil;
[_nextSlideView goToPage:page];
}
- (void)_layoutSlides;
{
NSRect bounds = self.bounds;
NSRect leftSlideRect, rightSlideRect;
NSDivideRect(bounds, &leftSlideRect, &rightSlideRect, bounds.size.width / 2, NSMinXEdge);
leftSlideRect = NSIntegralRect(NSInsetRect(leftSlideRect, 16, 16));
rightSlideRect = NSIntegralRect(NSInsetRect(rightSlideRect, 16, 16));
[_currentSlideView setFrame:leftSlideRect];
[_nextSlideView setFrame:rightSlideRect];
}
@end