]> git.sesse.net Git - vlc/blob - modules/gui/macosx/fspanel.m
macosx: switch fspanel icon set to use the brighter 'highlight' graphics in idle...
[vlc] / modules / gui / macosx / fspanel.m
1 /*****************************************************************************
2  * fspanel.m: MacOS X full screen panel
3  *****************************************************************************
4  * Copyright (C) 2006-2013 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Jérôme Decoodt <djc at videolan dot org>
8  *          Felix Paul Kühne <fkuehne at videolan dot org>
9  *          David Fuhrmann <david dot fuhrmann at googlemail dot com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #import "intf.h"
30 #import "CoreInteraction.h"
31 #import "MainWindow.h"
32 #import "misc.h"
33 #import "fspanel.h"
34 #import "CompatibilityFixes.h"
35
36 @interface VLCFSPanel ()
37 - (void)hideMouse;
38 @end
39
40 /*****************************************************************************
41  * VLCFSPanel
42  *****************************************************************************/
43 @implementation VLCFSPanel
44 /* We override this initializer so we can set the NSBorderlessWindowMask styleMask, and set a few other important settings */
45 - (id)initWithContentRect:(NSRect)contentRect
46                 styleMask:(NSUInteger)aStyle
47                   backing:(NSBackingStoreType)bufferingType
48                     defer:(BOOL)flag
49 {
50     id win = [super initWithContentRect:contentRect styleMask:NSTexturedBackgroundWindowMask backing:bufferingType defer:flag];
51     [win setOpaque:NO];
52     [win setHasShadow: NO];
53     [win setBackgroundColor:[NSColor clearColor]];
54     if (!OSX_SNOW_LEOPARD)
55         [win setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
56
57     /* let the window sit on top of everything else and start out completely transparent */
58     [win setLevel:NSModalPanelWindowLevel];
59     i_device = 0;
60     hideAgainTimer = fadeTimer = nil;
61     [self setNonActive:nil];
62     return win;
63 }
64
65 - (void)awakeFromNib
66 {
67     [self setContentView:[[VLCFSPanelView alloc] initWithFrame: [self frame]]];
68     BOOL isInside = (NSPointInRect([NSEvent mouseLocation],[self frame]));
69     [[self contentView] addTrackingRect:[[self contentView] bounds] owner:self userData:nil assumeInside:isInside];
70     if (isInside)
71         [self mouseEntered:NULL];
72     if (!isInside)
73         [self mouseExited:NULL];
74
75     [self center];
76
77     /* get a notification if VLC isn't the active app anymore */
78     [[NSNotificationCenter defaultCenter]
79     addObserver: self
80        selector: @selector(setNonActive:)
81            name: NSApplicationDidResignActiveNotification
82          object: NSApp];
83
84     /* get a notification if VLC is the active app again */
85     [[NSNotificationCenter defaultCenter]
86     addObserver: self
87        selector: @selector(setActive:)
88            name: NSApplicationDidBecomeActiveNotification
89          object: NSApp];
90 }
91
92 /* make sure that we don't become key, since we can't handle hotkeys */
93 - (BOOL)canBecomeKeyWindow
94 {
95     return NO;
96 }
97
98 - (BOOL)mouseDownCanMoveWindow
99 {
100     return YES;
101 }
102
103 -(void)dealloc
104 {
105     [[NSNotificationCenter defaultCenter] removeObserver: self];
106
107     if (hideAgainTimer) {
108         [hideAgainTimer invalidate];
109         [hideAgainTimer release];
110     }
111
112     if (o_vout_window)
113         [o_vout_window release];
114
115     [self setFadeTimer:nil];
116     [super dealloc];
117 }
118
119 -(void)center
120 {
121     /* centre the panel in the lower third of the screen */
122     NSPoint theCoordinate;
123     NSRect theScreensFrame;
124     NSRect theWindowsFrame;
125     NSScreen *screen;
126
127     /* user-defined screen */
128     screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
129
130     if (!screen)
131         /* invalid preferences or none specified, using main screen */
132         screen = [NSScreen mainScreen];
133
134     theScreensFrame = [screen frame];
135     theWindowsFrame = [self frame];
136
137     theCoordinate.x = (theScreensFrame.size.width - theWindowsFrame.size.width) / 2 + theScreensFrame.origin.x;
138     theCoordinate.y = (theScreensFrame.size.height / 3) - theWindowsFrame.size.height + theScreensFrame.origin.y;
139     [self setFrameTopLeftPoint: theCoordinate];
140 }
141
142 - (void)setPlay
143 {
144     [[self contentView] setPlay];
145 }
146
147 - (void)setPause
148 {
149     [[self contentView] setPause];
150 }
151
152 - (void)setStreamTitle:(NSString *)o_title
153 {
154     [[self contentView] setStreamTitle: o_title];
155 }
156
157 - (void)updatePositionAndTime
158 {
159     [[self contentView] updatePositionAndTime];
160 }
161
162 - (void)setSeekable:(BOOL) b_seekable
163 {
164     [[self contentView] setSeekable: b_seekable];
165 }
166
167 - (void)setVolumeLevel: (int)i_volumeLevel
168 {
169     [[self contentView] setVolumeLevel: i_volumeLevel];
170 }
171
172 - (void)setNonActive:(id)noData
173 {
174     b_nonActive = YES;
175     [self orderOut: self];
176
177     /* here's fadeOut, just without visibly fading */
178     b_displayed = NO;
179     [self setAlphaValue:0.0];
180     [self setFadeTimer:nil];
181     b_fadeQueued = NO;
182 }
183
184 - (void)setActive:(id)noData
185 {
186     b_nonActive = NO;
187
188     [[VLCMain sharedInstance] showFullscreenController];
189 }
190
191 /* This routine is called repeatedly to fade in the window */
192 - (void)focus:(NSTimer *)timer
193 {
194     /* we need to push ourselves to front if the vout window was closed since our last display */
195     if (b_voutWasUpdated) {
196         [self orderFront: self];
197         b_voutWasUpdated = NO;
198     }
199
200     if ([self alphaValue] < 1.0)
201         [self setAlphaValue:[self alphaValue]+0.1];
202     if ([self alphaValue] >= 1.0) {
203         b_displayed = YES;
204         [self setAlphaValue: 1.0];
205         [self setFadeTimer:nil];
206         if (b_fadeQueued) {
207             b_fadeQueued=NO;
208             [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];
209         }
210     }
211 }
212
213 /* This routine is called repeatedly to hide the window */
214 - (void)unfocus:(NSTimer *)timer
215 {
216     if (b_keptVisible) {
217         b_keptVisible = NO;
218         b_fadeQueued = NO;
219         [self setFadeTimer: NULL];
220         [self fadeIn];
221         return;
222     }
223     if ([self alphaValue] > 0.0)
224         [self setAlphaValue:[self alphaValue]-0.05];
225     if ([self alphaValue] <= 0.05) {
226         b_displayed = NO;
227         [self setAlphaValue:0.0];
228         [self setFadeTimer:nil];
229         if (b_fadeQueued) {
230             b_fadeQueued=NO;
231             [self setFadeTimer:
232                 [NSTimer scheduledTimerWithTimeInterval:0.1
233                                                  target:self
234                                                selector:@selector(focus:)
235                                                userInfo:NULL
236                                                 repeats:YES]];
237         }
238     }
239 }
240
241 - (void)mouseExited:(NSEvent *)theEvent
242 {
243     /* give up our focus, so the vout may show us again without letting the user clicking it */
244     if (o_vout_window && var_GetBool(pl_Get(VLCIntf), "fullscreen"))
245         [o_vout_window makeKeyWindow];
246 }
247
248 - (void)hideMouse
249 {
250     [NSCursor setHiddenUntilMouseMoves: YES];
251 }
252
253 - (void)fadeIn
254 {
255     /* in case that the user don't want us to appear, make sure we hide the mouse */
256
257     if (!config_GetInt(VLCIntf, "macosx-fspanel")) {
258         float time = (float)var_CreateGetInteger(VLCIntf, "mouse-hide-timeout") / 1000.;
259         [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:time target:self selector:@selector(hideMouse) userInfo:nil repeats:NO]];
260         return;
261     }
262
263     if (b_nonActive)
264         return;
265
266     [self orderFront: nil];
267
268     if ([self alphaValue] < 1.0 || b_displayed != YES) {
269         if (![self fadeTimer])
270             [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];
271         else if ([[[self fadeTimer] userInfo] shortValue]==0)
272             b_fadeQueued=YES;
273     }
274     [self autoHide];
275 }
276
277 - (void)fadeOut
278 {
279     if (NSPointInRect([NSEvent mouseLocation],[self frame]))
280         return;
281
282     if (([self alphaValue] > 0.0)) {
283         if (![self fadeTimer])
284             [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];
285         else if ([[[self fadeTimer] userInfo] shortValue]==1)
286             b_fadeQueued=YES;
287     }
288 }
289
290 /* triggers a timer to autoHide us again after some seconds of no activity */
291 - (void)autoHide
292 {
293     /* this will tell the timer to start over again or to start at all */
294     b_keptVisible = YES;
295
296     /* get us a valid timer */
297     if (! b_alreadyCounting) {
298         i_timeToKeepVisibleInSec = var_CreateGetInteger(VLCIntf, "mouse-hide-timeout") / 500;
299         if (hideAgainTimer) {
300             [hideAgainTimer invalidate];
301             [hideAgainTimer autorelease];
302         }
303         /* released in -autoHide and -dealloc */
304         hideAgainTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.5
305                                                           target: self
306                                                         selector: @selector(keepVisible:)
307                                                         userInfo: nil
308                                                          repeats: YES] retain];
309         b_alreadyCounting = YES;
310     }
311 }
312
313 - (void)keepVisible:(NSTimer *)timer
314 {
315     /* if the user triggered an action, start over again */
316     if (b_keptVisible)
317         b_keptVisible = NO;
318
319     /* count down until we hide ourselfes again and do so if necessary */
320     if (--i_timeToKeepVisibleInSec < 1) {
321         [self hideMouse];
322         [self fadeOut];
323         [hideAgainTimer invalidate]; /* released in -autoHide and -dealloc */
324         b_alreadyCounting = NO;
325     }
326 }
327
328 /* A getter and setter for our main timer that handles window fading */
329 - (NSTimer *)fadeTimer
330 {
331     return fadeTimer;
332 }
333
334 - (void)setFadeTimer:(NSTimer *)timer
335 {
336     [timer retain];
337     [fadeTimer invalidate];
338     [fadeTimer autorelease];
339     fadeTimer=timer;
340 }
341
342 - (void)mouseDown:(NSEvent *)theEvent
343 {
344     mouseClic = [theEvent locationInWindow];
345 }
346
347 - (void)mouseDragged:(NSEvent *)theEvent
348 {
349     NSPoint point = [NSEvent mouseLocation];
350     point.x -= mouseClic.x;
351     point.y -= mouseClic.y;
352     [self setFrameOrigin:point];
353 }
354
355 - (void)setVoutWasUpdated: (VLCWindow *)o_window
356 {
357     b_voutWasUpdated = YES;
358     if (o_vout_window)
359         [o_vout_window release];
360     o_vout_window = [o_window retain];
361     int i_newdevice = (int)[[o_vout_window screen] displayID];
362     if (i_newdevice != i_device) {
363         i_device = i_newdevice;
364         [self center];
365     }
366 }
367 @end
368
369 /*****************************************************************************
370  * FSPanelView
371  *****************************************************************************/
372 @implementation VLCFSPanelView
373
374 #define addButton(o_button, imageOff, imageOn, _x, _y, action, AXDesc, ToolTip)               \
375     s_rc.origin.x = _x;                                                                         \
376     s_rc.origin.y = _y;                                                                         \
377     o_button = [[NSButton alloc] initWithFrame: s_rc];                                 \
378     [o_button setButtonType: NSMomentaryChangeButton];                                          \
379     [o_button setBezelStyle: NSRegularSquareBezelStyle];                                        \
380     [o_button setBordered: NO];                                                                 \
381     [o_button setFont:[NSFont systemFontOfSize:0]];                                             \
382     [o_button setImage:[NSImage imageNamed:imageOff]];                                 \
383     [o_button setAlternateImage:[NSImage imageNamed:imageOn]];                         \
384     [o_button sizeToFit];                                                                       \
385     [o_button setTarget: self];                                                                 \
386     [o_button setAction: @selector(action:)];                                                   \
387     [[o_button cell] accessibilitySetOverrideValue:AXDesc forAttribute:NSAccessibilityDescriptionAttribute]; \
388     [[o_button cell] accessibilitySetOverrideValue:ToolTip forAttribute:NSAccessibilityTitleAttribute]; \
389     [o_button setToolTip: ToolTip]; \
390     [self addSubview:o_button];
391
392 #define addTextfield(class, o_text, align, font, color)                                    \
393     o_text = [[class alloc] initWithFrame: s_rc];                            \
394     [o_text setDrawsBackground: NO];                                                        \
395     [o_text setBordered: NO];                                                               \
396     [o_text setEditable: NO];                                                               \
397     [o_text setSelectable: NO];                                                             \
398     [o_text setStringValue: _NS("(no item is being played)")];                                                    \
399     [o_text setAlignment: align];                                                           \
400     [o_text setTextColor: [NSColor color]];                                                 \
401     [o_text setFont:[NSFont font:[NSFont smallSystemFontSize]]];                     \
402     [self addSubview:o_text];
403
404 - (id)initWithFrame:(NSRect)frameRect
405 {
406     id view = [super initWithFrame:frameRect];
407     fillColor = [[NSColor clearColor] retain];
408     NSRect s_rc = [self frame];
409     addButton(o_prev, @"fs_skip_previous_highlight" , @"fs_skip_previous", 174, 15, prev, _NS("Click to go to the previous playlist item."), _NS("Previous"));
410     addButton(o_bwd, @"fs_rewind_highlight"        , @"fs_rewind"       , 211, 14, backward, _NS("Click and hold to skip backward through the current media."), _NS("Backward"));
411     addButton(o_play, @"fs_play_highlight"          , @"fs_play"         , 265, 10, play, _NS("Click to play or pause the current media."), _NS("Play/Pause"));
412     addButton(o_fwd, @"fs_forward_highlight"       , @"fs_forward"      , 313, 14, forward, _NS("Click and hold to skip forward through the current media."), _NS("Forward"));
413     addButton(o_next, @"fs_skip_next_highlight"     , @"fs_skip_next"    , 365, 15, next, _NS("Click to go to the next playlist item."), _NS("Next"));
414     addButton(o_fullscreen, @"fs_exit_fullscreen_highlight", @"fs_exit_fullscreen", 507, 13, toggleFullscreen, _NS("Click to exit fullscreen playback."), _NS("Toggle Fullscreen mode"));
415 /*
416     addButton(o_button, @"image (off state)", @"image (on state)", 38, 51, something, accessibility help string, usual tool tip);
417  */
418     [o_fwd setContinuous:YES];
419     [o_bwd setContinuous:YES];
420
421     /* time slider */
422     // (surrounding progress view for swipe behaviour)
423     s_rc.origin.x = 15;
424     s_rc.origin.y = 45;
425     s_rc.size.width = 518;
426     s_rc.size.height = 13;
427     o_progress_view = [[VLCProgressView alloc] initWithFrame: s_rc];
428     s_rc.origin.x = 0;
429     s_rc.origin.y = 0;
430     o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];
431     [o_fs_timeSlider setMinValue:0];
432     [o_fs_timeSlider setMaxValue:10000];
433     [o_fs_timeSlider setFloatValue: 0];
434     [o_fs_timeSlider setContinuous: YES];
435     [o_fs_timeSlider setTarget: self];
436     [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];
437     [[o_fs_volumeSlider cell] accessibilitySetOverrideValue:_NS("Position") forAttribute:NSAccessibilityTitleAttribute];
438     [[o_fs_timeSlider cell] accessibilitySetOverrideValue:_NS("Click and move the mouse while keeping the button pressed to use this slider to change current playback position.") forAttribute:NSAccessibilityDescriptionAttribute];
439     [self addSubview: o_progress_view];
440     [o_progress_view addSubview: o_fs_timeSlider];
441
442     /* volume slider */
443     s_rc = [self frame];
444     s_rc.origin.x = 26;
445     s_rc.origin.y = 21;
446     s_rc.size.width = 95;
447     s_rc.size.height = 10;
448     o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];
449     [o_fs_volumeSlider setMinValue:0];
450     [o_fs_volumeSlider setMaxValue:AOUT_VOLUME_MAX];
451     [o_fs_volumeSlider setIntValue:AOUT_VOLUME_DEFAULT];
452     [o_fs_volumeSlider setContinuous: YES];
453     [o_fs_volumeSlider setTarget: self];
454     [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];
455     [[o_fs_volumeSlider cell] accessibilitySetOverrideValue:_NS("Volume") forAttribute:NSAccessibilityTitleAttribute];
456     [[o_fs_volumeSlider cell] accessibilitySetOverrideValue:_NS("Click and move the mouse while keeping the button pressed to use this slider to change the volume.") forAttribute:NSAccessibilityDescriptionAttribute];
457     [self addSubview: o_fs_volumeSlider];
458
459     /* time counter and stream title output fields */
460     s_rc = [self frame];
461     // 10 px gap between time fields
462     s_rc.origin.x = 90;
463     s_rc.origin.y = 64;
464     s_rc.size.width = 361;
465     s_rc.size.height = 14;
466     addTextfield(NSTextField, o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor);
467     s_rc.origin.x = 15;
468     s_rc.origin.y = 64;
469     s_rc.size.width = 65;
470     addTextfield(VLCTimeField, o_streamPosition_txt, NSLeftTextAlignment, systemFontOfSize, whiteColor);
471     s_rc.origin.x = 471;
472     s_rc.origin.y = 64;
473     s_rc.size.width = 65;
474     addTextfield(VLCTimeField, o_streamLength_txt, NSRightTextAlignment, systemFontOfSize, whiteColor);
475     [o_streamLength_txt setRemainingIdentifier: @"DisplayFullscreenTimeAsTimeRemaining"];
476
477     o_background_img = [[NSImage imageNamed:@"fs_background"] retain];
478     o_vol_sld_img = [[NSImage imageNamed:@"fs_volume_slider_bar"] retain];
479     o_vol_mute_img = [[NSImage imageNamed:@"fs_volume_mute_highlight"] retain];
480     o_vol_max_img = [[NSImage imageNamed:@"fs_volume_max_highlight"] retain];
481     o_time_sld_img = [[NSImage imageNamed:@"fs_time_slider"] retain];
482
483     return view;
484 }
485
486 - (void)dealloc
487 {
488     [o_background_img release];
489     [o_vol_sld_img release];
490     [o_vol_mute_img release];
491     [o_vol_max_img release];
492     [o_time_sld_img release];
493     [o_fs_timeSlider release];
494     [o_fs_volumeSlider release];
495     [o_prev release];
496     [o_next release];
497     [o_bwd release];
498     [o_play release];
499     [o_fwd release];
500     [o_fullscreen release];
501     [o_streamTitle_txt release];
502     [o_streamPosition_txt release];
503     [super dealloc];
504 }
505
506 - (void)setPlay
507 {
508     [o_play setImage:[NSImage imageNamed:@"fs_play_highlight"]];
509     [o_play setAlternateImage: [NSImage imageNamed:@"fs_play"]];
510 }
511
512 - (void)setPause
513 {
514     [o_play setImage: [NSImage imageNamed:@"fs_pause_highlight"]];
515     [o_play setAlternateImage: [NSImage imageNamed:@"fs_pause"]];
516 }
517
518 - (void)setStreamTitle:(NSString *)o_title
519 {
520     [o_streamTitle_txt setStringValue: o_title];
521 }
522
523 - (void)updatePositionAndTime
524 {
525     input_thread_t * p_input;
526     p_input = pl_CurrentInput(VLCIntf);
527     if (p_input) {
528         
529         vlc_value_t pos;
530         float f_updated;
531
532         var_Get(p_input, "position", &pos);
533         f_updated = 10000. * pos.f_float;
534         [o_fs_timeSlider setFloatValue: f_updated];
535
536         vlc_value_t time;
537         char psz_time[MSTRTIME_MAX_SIZE];
538
539         var_Get(p_input, "time", &time);
540         mtime_t dur = input_item_GetDuration(input_GetItem(p_input));
541
542         // update total duration (right field)
543         if(dur <= 0) {
544             [o_streamLength_txt setHidden: YES];
545         } else {
546             [o_streamLength_txt setHidden: NO];
547
548             NSString *o_total_time;
549             if ([o_streamLength_txt timeRemaining]) {
550                 mtime_t remaining = 0;
551                 if (dur > time.i_time)
552                     remaining = dur - time.i_time;
553                 o_total_time = [NSString stringWithFormat: @"-%s", secstotimestr(psz_time, (remaining / 1000000))];
554             } else
555                 o_total_time = [NSString stringWithUTF8String: secstotimestr(psz_time, (dur / 1000000))];
556
557             [o_streamLength_txt setStringValue: o_total_time];
558         }
559
560         // update current position (left field)
561         NSString *o_playback_pos = [NSString stringWithUTF8String: secstotimestr(psz_time, (time.i_time / 1000000))];
562                
563         [o_streamPosition_txt setStringValue: o_playback_pos];
564         vlc_object_release(p_input);
565     } else {
566         [o_fs_timeSlider setFloatValue: 0.0];
567         [o_streamPosition_txt setStringValue: @"00:00"];
568         [o_streamLength_txt setHidden: YES];
569     }
570
571 }
572
573 - (void)setSeekable:(BOOL)b_seekable
574 {
575     [o_bwd setEnabled: b_seekable];
576     [o_fwd setEnabled: b_seekable];
577     [o_fs_timeSlider setEnabled: b_seekable];
578 }
579
580 - (void)setVolumeLevel: (int)i_volumeLevel
581 {
582     [o_fs_volumeSlider setIntValue: i_volumeLevel];
583 }
584
585 - (IBAction)play:(id)sender
586 {
587     [[VLCCoreInteraction sharedInstance] playOrPause];
588 }
589
590 - (IBAction)forward:(id)sender
591 {
592     if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) > 0.16) {
593         // we just skipped 4 "continous" events, otherwise we are too fast
594         [[VLCCoreInteraction sharedInstance] forwardExtraShort];
595         last_fwd_event = [NSDate timeIntervalSinceReferenceDate];
596     }
597 }
598
599 - (IBAction)backward:(id)sender
600 {
601     if (([NSDate timeIntervalSinceReferenceDate] - last_bwd_event) > 0.16) {
602         // we just skipped 4 "continous" events, otherwise we are too fast
603         [[VLCCoreInteraction sharedInstance] backwardExtraShort];
604         last_bwd_event = [NSDate timeIntervalSinceReferenceDate];
605     }
606 }
607
608 - (IBAction)prev:(id)sender
609 {
610     [[VLCCoreInteraction sharedInstance] previous];
611 }
612
613 - (IBAction)next:(id)sender
614 {
615     [[VLCCoreInteraction sharedInstance] next];
616 }
617
618 - (IBAction)toggleFullscreen:(id)sender
619 {
620     [[VLCCoreInteraction sharedInstance] toggleFullscreen];
621 }
622
623 - (IBAction)fsTimeSliderUpdate:(id)sender
624 {
625     input_thread_t * p_input;
626     p_input = pl_CurrentInput(VLCIntf);
627     if (p_input != NULL) {
628         vlc_value_t pos;
629
630         pos.f_float = [o_fs_timeSlider floatValue] / 10000.;
631         var_Set(p_input, "position", pos);
632         vlc_object_release(p_input);
633     }
634     [[VLCMain sharedInstance] updatePlaybackPosition];
635 }
636
637 - (IBAction)fsVolumeSliderUpdate:(id)sender
638 {
639     [[VLCCoreInteraction sharedInstance] setVolume: [sender intValue]];
640 }
641
642 #define addImage(image, _x, _y, mode)                                                       \
643     image_size = [image size];                                                              \
644     image_rect.size = image_size;                                                           \
645     image_rect.origin.x = 0;                                                                \
646     image_rect.origin.y = 0;                                                                \
647     frame.origin.x = _x;                                                                    \
648     frame.origin.y = _y;                                                                    \
649     frame.size = image_size;                                                                \
650     [image drawInRect:frame fromRect:image_rect operation:mode fraction:1];
651
652 - (void)drawRect:(NSRect)rect
653 {
654     NSRect frame = [self frame];
655     NSRect image_rect;
656     NSSize image_size;
657     NSImage *img;
658     addImage(o_background_img, 0, 0, NSCompositeCopy);
659     addImage(o_vol_sld_img, 26, 23, NSCompositeSourceOver);
660     addImage(o_vol_mute_img, 16, 18, NSCompositeSourceOver);
661     addImage(o_vol_max_img, 124, 18, NSCompositeSourceOver);
662     addImage(o_time_sld_img, 15, 45, NSCompositeSourceOver);
663 }
664
665 @end
666
667 /*****************************************************************************
668  * VLCFSTimeSlider
669  *****************************************************************************/
670 @implementation VLCFSTimeSlider
671 - (void)drawKnobInRect:(NSRect)knobRect
672 {
673     NSRect image_rect;
674     NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];
675     image_rect.size = [img size];
676     image_rect.origin.x = 0;
677     image_rect.origin.y = 0;
678     knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
679     knobRect.size.width = image_rect.size.width;
680     knobRect.size.height = image_rect.size.height;
681     [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
682 }
683
684 - (void)drawRect:(NSRect)rect
685 {
686     /* Draw default to make sure the slider behaves correctly */
687     [[NSGraphicsContext currentContext] saveGraphicsState];
688     NSRectClip(NSZeroRect);
689     [super drawRect:rect];
690     [[NSGraphicsContext currentContext] restoreGraphicsState];
691
692     NSRect knobRect = [[self cell] knobRectFlipped:NO];
693     knobRect.origin.y+=4;
694     [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
695     [self drawKnobInRect: knobRect];
696 }
697
698 @end
699
700 /*****************************************************************************
701 * VLCFSVolumeSlider
702 *****************************************************************************/
703 @implementation VLCFSVolumeSlider
704 - (void)drawKnobInRect:(NSRect) knobRect
705 {
706     NSRect image_rect;
707     NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob_highlight"];
708     image_rect.size = [img size];
709     image_rect.origin.x = 0;
710     image_rect.origin.y = 0;
711     knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
712     knobRect.size.width = image_rect.size.width;
713     knobRect.size.height = image_rect.size.height;
714     [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
715 }
716
717 - (void)drawRect:(NSRect)rect
718 {
719     /* Draw default to make sure the slider behaves correctly */
720     [[NSGraphicsContext currentContext] saveGraphicsState];
721     NSRectClip(NSZeroRect);
722     [super drawRect:rect];
723     [[NSGraphicsContext currentContext] restoreGraphicsState];
724
725     NSRect knobRect = [[self cell] knobRectFlipped:NO];
726     knobRect.origin.y+=7.5;
727     [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
728     [self drawKnobInRect: knobRect];
729 }
730
731 @end
732