-
Notifications
You must be signed in to change notification settings - Fork 54
/
ControlPanel.m
275 lines (241 loc) · 9.16 KB
/
ControlPanel.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
//
// Movist
//
// Copyright 2006 ~ 2008 Yong-Hoe Kim. All rights reserved.
// Yong-Hoe Kim <[email protected]>
//
// This file is part of Movist.
//
// Movist is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Movist is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#import "ControlPanel.h"
#import "MMovieView.h"
#import "AppController.h"
#import "UserDefaults.h"
#import "MMovie_QuickTime.h"
#import "MMovie_FFMPEG.h"
@implementation ControlPanel
- (id)initWithContentRect:(NSRect)contentRect
styleMask:(NSWindowStyleMask)styleMask
backing:(NSBackingStoreType)bufferingType
defer:(BOOL)deferCreation
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
if (self = [super initWithContentRect:contentRect
styleMask:NSBorderlessWindowMask
backing:bufferingType
defer:deferCreation]) {
[self initHUDWindow];
[self setFloatingPanel:TRUE];
}
return self;
}
- (void)awakeFromNib
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
[self updateHUDBackground];
[self initHUDSubviews];
_initialDragPoint.x = -1;
_initialDragPoint.y = -1;
[_videoBrightnessSlider setMinValue:MIN_BRIGHTNESS];
[_videoBrightnessSlider setMaxValue:MAX_BRIGHTNESS];
[_videoBrightnessSlider setFloatValue:DEFAULT_BRIGHTNESS];
[_videoSaturationSlider setMinValue:MIN_SATURATION];
[_videoSaturationSlider setMaxValue:MAX_SATURATION];
[_videoSaturationSlider setFloatValue:DEFAULT_SATURATION];
[_videoContrastSlider setMinValue:MIN_CONTRAST];
[_videoContrastSlider setMaxValue:MAX_CONTRAST];
[_videoContrastSlider setFloatValue:DEFAULT_CONTRAST];
[_videoHueSlider setMinValue:MIN_HUE];
[_videoHueSlider setMaxValue:MAX_HUE];
[_videoHueSlider setFloatValue:DEFAULT_HUE];
[_playbackRateSlider setMinValue:MIN_PLAY_RATE];
[_playbackRateSlider setMaxValue:MAX_PLAY_RATE];
[self updatePlaybackRateSlider:DEFAULT_PLAY_RATE];
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSString* identifier = (NSString*)[defaults objectForKey:MControlTabKey];
if (NSNotFound == [_tabView indexOfTabViewItemWithIdentifier:identifier]) {
[_segmentedControl setSelectedSegment:0];
[_tabView selectFirstTabViewItem:self];
}
else {
int index = [_tabView indexOfTabViewItemWithIdentifier:identifier];
[_segmentedControl setSelectedSegment:index];
[_tabView selectTabViewItemWithIdentifier:identifier];
}
}
- (void)dealloc
{
[self cleanupHUDWindow];
[super dealloc];
}
- (void)orderOut:(id)sender
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSString* identifier = (NSString*)[[_tabView selectedTabViewItem] identifier];
[defaults setObject:identifier forKey:MControlTabKey];
[super orderOut:sender];
}
- (BOOL)canBecomeKeyWindow { return FALSE; }
////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark window-moving by dragging
- (void)mouseDown:(NSEvent*)event
{
NSRect frame = [self frame];
NSPoint loc = [event locationInWindow];
_initialDragPoint = [self convertRectToScreen:(NSRect){.origin=loc, .size=NSZeroSize}].origin;
_initialDragPoint.x -= frame.origin.x;
_initialDragPoint.y -= frame.origin.y;
}
- (void)mouseUp:(NSEvent*)event
{
_initialDragPoint.x = -1;
_initialDragPoint.y = -1;
}
- (void)mouseDragged:(NSEvent*)event
{
if (0 <= _initialDragPoint.x && 0 <= _initialDragPoint.y) {
NSPoint loc = [event locationInWindow];
NSPoint p = [self convertRectToScreen:(NSRect){.origin=loc, .size=NSZeroSize}].origin;
NSRect sr = [[self screen] frame];
NSRect wr = [self frame];
NSPoint origin;
origin.x = p.x - _initialDragPoint.x;
origin.y = p.y - _initialDragPoint.y;
if (NSMaxY(sr) < origin.y + wr.size.height) {
origin.y = sr.origin.y + (sr.size.height - wr.size.height);
}
[self setFrameOrigin:origin];
}
}
///////////////////////////////////////////////////////////////////////////////
#pragma mark -
- (void)showPanel { [self orderFront:self]; }
- (void)hidePanel { [self orderOut:self]; }
- (IBAction)segmentedControlAction:(id)sender
{
[_tabView selectTabViewItemAtIndex:[_segmentedControl selectedSegment]];
}
- (void)setMovieURL:(NSURL*)url
{
if (!url) {
[_movieFilenameTextField setStringValue:@""];
}
else if ([url isFileURL]) {
[_movieFilenameTextField setStringValue:[[url path] lastPathComponent]];
}
else {
[_movieFilenameTextField setStringValue:[[url absoluteString] lastPathComponent]];
}
}
////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark video
- (IBAction)videoColorControlsAction:(id)sender
{
//TRACE(@"%s %@", __PRETTY_FUNCTION__, sender);
if (sender == _videoBrightnessSlider) {
[_movieView setBrightness:normalizedFloat25([sender floatValue])];
[_movieView setMessage:[NSString localizedStringWithFormat:@"%@ %.2f",
NSLocalizedString(@"Brightness", nil), [_movieView brightness]]];
}
else if (sender == _videoSaturationSlider) {
[_movieView setSaturation:normalizedFloat25([sender floatValue])];
[_movieView setMessage:[NSString localizedStringWithFormat:@"%@ %.2f",
NSLocalizedString(@"Saturation", nil), [_movieView saturation]]];
}
else if (sender == _videoContrastSlider) {
[_movieView setContrast:normalizedFloat25([sender floatValue])];
[_movieView setMessage:[NSString localizedStringWithFormat:@"%@ %.2f",
NSLocalizedString(@"Contrast", nil), [_movieView contrast]]];
}
else if (sender == _videoHueSlider) {
[_movieView setHue:normalizedFloat25([sender floatValue])];
[_movieView setMessage:[NSString localizedStringWithFormat:@"%@ %.2f",
NSLocalizedString(@"Hue", nil), [_movieView hue]]];
}
}
- (IBAction)videoColorControlsDefaultsAction:(id)sender
{
//TRACE(@"%s %d", __PRETTY_FUNCTION__, [sender tag]);
switch ([sender tag]) {
case 0 :
[_videoBrightnessSlider setFloatValue:DEFAULT_BRIGHTNESS];
[self videoColorControlsAction:_videoBrightnessSlider];
break;
case 1 :
[_videoSaturationSlider setFloatValue:DEFAULT_SATURATION];
[self videoColorControlsAction:_videoSaturationSlider];
break;
case 2 :
[_videoContrastSlider setFloatValue:DEFAULT_CONTRAST];
[self videoColorControlsAction:_videoContrastSlider];
break;
case 3 :
[_videoHueSlider setFloatValue:DEFAULT_HUE];
[self videoColorControlsAction:_videoHueSlider];
break;
}
}
////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark audio
////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark subtitle
- (float)subtitleTrackLoadingTime { return _subtitleTrackLoadingTime; }
- (void)setSubtitleTrackLoadingTime:(float)t { _subtitleTrackLoadingTime = t; }
////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark playback
- (void)updatePlaybackRateSlider:(float)rate
{
float value;
const float dv = (3.0 - 0.5) / 6;
if (rate <= 1.0) {
value = (0.5 + dv * 0) + (2 * dv * (rate - 0.5)) / (1.0 - 0.5);
}
else if (rate <= 2.0) {
value = (0.5 + dv * 2) + (2 * dv * (rate - 1.0)) / (2.0 - 1.0);
}
else { // rate <= 3.0
value = (0.5 + dv * 4) + (2 * dv * (rate - 2.0)) / (3.0 - 2.0);
}
[_playbackRateSlider setFloatValue:value];
}
- (IBAction)playbackRateAction:(id)sender
{
const float dv = (3.0 - 0.5) / 6;
if (sender == _playbackRateSlider) {
float rate;
float value = [_playbackRateSlider floatValue];
if (value <= 0.5 + dv * 2) { // 0.5 ~ 1.0 (2: 0.5, 0.75, 1.0)
rate = 0.5 + (value - (0.5 + dv * 0)) * ((1.0 - 0.5) / 2) / dv;
}
else if (value <= 0.5 + dv * 5) { // 1.0 ~ 2.0 (3: 1.0, 1.3, 1.6, 2.0)
rate = 1.0 + (value - (0.5 + dv * 2)) * ((2.0 - 1.0) / 2) / dv;
}
else { // 2.0 ~ 3.0 (1: 2.0, 3.0)
rate = 2.0 + (value - (0.5 + dv * 4)) * ((3.0 - 2.0) / 2) / dv;
}
[_appController setPlayRate:rate];
}
else {
[_playbackRateSlider setFloatValue:0.5 + dv * 2];
[_appController setPlayRate:DEFAULT_PLAY_RATE];
}
}
@end