]> git.sesse.net Git - vlc/blob - modules/gui/macosx/fspanel.m
macosx: unify and modernize coding style
[vlc] / modules / gui / macosx / fspanel.m
1 /*****************************************************************************
2  * fspanel.m: MacOS X full screen panel
3  *****************************************************************************
4  * Copyright (C) 2006-2012 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  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #import "intf.h"
29 #import "CoreInteraction.h"
30 #import "MainWindow.h"
31 #import "misc.h"
32 #import "fspanel.h"
33 #import "CompatibilityFixes.h"
34 #import <vlc_aout_intf.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     [self setFadeTimer:nil];
112     [super dealloc];
113 }
114
115 -(void)center
116 {
117     /* centre the panel in the lower third of the screen */
118     NSPoint theCoordinate;
119     NSRect theScreensFrame;
120     NSRect theWindowsFrame;
121     NSScreen *screen;
122
123     /* user-defined screen */
124     screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
125
126     if (!screen)
127         /* invalid preferences or none specified, using main screen */
128         screen = [NSScreen mainScreen];
129
130     theScreensFrame = [screen frame];
131     theWindowsFrame = [self frame];
132
133     theCoordinate.x = (theScreensFrame.size.width - theWindowsFrame.size.width) / 2 + theScreensFrame.origin.x;
134     theCoordinate.y = (theScreensFrame.size.height / 3) - theWindowsFrame.size.height + theScreensFrame.origin.y;
135     [self setFrameTopLeftPoint: theCoordinate];
136 }
137
138 - (void)setPlay
139 {
140     [[self contentView] setPlay];
141 }
142
143 - (void)setPause
144 {
145     [[self contentView] setPause];
146 }
147
148 - (void)setStreamTitle:(NSString *)o_title
149 {
150     [[self contentView] setStreamTitle: o_title];
151 }
152
153 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
154 {
155     [[self contentView] setStreamPos:f_pos andTime: o_time];
156 }
157
158 - (void)setSeekable:(BOOL) b_seekable
159 {
160     [[self contentView] setSeekable: b_seekable];
161 }
162
163 - (void)setVolumeLevel: (int)i_volumeLevel
164 {
165     [[self contentView] setVolumeLevel: i_volumeLevel];
166 }
167
168 - (void)setNonActive:(id)noData
169 {
170     b_nonActive = YES;
171     [self orderOut: self];
172
173     /* here's fadeOut, just without visibly fading */
174     b_displayed = NO;
175     [self setAlphaValue:0.0];
176     [self setFadeTimer:nil];
177     b_fadeQueued = NO;
178 }
179
180 - (void)setActive:(id)noData
181 {
182     b_nonActive = NO;
183     [[VLCMain sharedInstance] showFullscreenController];
184 }
185
186 /* This routine is called repeatedly to fade in the window */
187 - (void)focus:(NSTimer *)timer
188 {
189     /* we need to push ourselves to front if the vout window was closed since our last display */
190     if(b_voutWasUpdated) {
191         [self orderFront: self];
192         b_voutWasUpdated = NO;
193     }
194
195     if([self alphaValue] < 1.0)
196         [self setAlphaValue:[self alphaValue]+0.1];
197     if([self alphaValue] >= 1.0) {
198         b_displayed = YES;
199         [self setAlphaValue: 1.0];
200         [self setFadeTimer:nil];
201         if(b_fadeQueued) {
202             b_fadeQueued=NO;
203             [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];
204         }
205     }
206 }
207
208 /* This routine is called repeatedly to hide the window */
209 - (void)unfocus:(NSTimer *)timer
210 {
211     if(b_keptVisible) {
212         b_keptVisible = NO;
213         b_fadeQueued = NO;
214         [self setFadeTimer: NULL];
215         [self fadeIn];
216         return;
217     }
218     if([self alphaValue] > 0.0)
219         [self setAlphaValue:[self alphaValue]-0.05];
220     if([self alphaValue] <= 0.05) {
221         b_displayed = NO;
222         [self setAlphaValue:0.0];
223         [self setFadeTimer:nil];
224         if(b_fadeQueued) {
225             b_fadeQueued=NO;
226             [self setFadeTimer:
227                 [NSTimer scheduledTimerWithTimeInterval:0.1
228                                                  target:self
229                                                selector:@selector(focus:)
230                                                userInfo:NULL
231                                                 repeats:YES]];
232         }
233     }
234 }
235
236 - (void)mouseExited:(NSEvent *)theEvent
237 {
238     /* give up our focus, so the vout may show us again without letting the user clicking it */
239     vout_thread_t *p_vout = getVout();
240     if (p_vout) {
241         if (var_GetBool(p_vout, "fullscreen"))
242             [[[[VLCMainWindow sharedInstance] videoView] window] makeKeyWindow];
243         vlc_object_release(p_vout);
244     }
245 }
246
247 - (void)hideMouse
248 {
249     [NSCursor setHiddenUntilMouseMoves: YES];
250 }
251
252 - (void)fadeIn
253 {
254     /* in case that the user don't want us to appear, make sure we hide the mouse */
255
256     if(!config_GetInt(VLCIntf, "macosx-fspanel")) {
257         float time = (float)var_CreateGetInteger(VLCIntf, "mouse-hide-timeout") / 1000.;
258         [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:time target:self selector:@selector(hideMouse) userInfo:nil repeats:NO]];
259         return;
260     }
261
262     if(b_nonActive)
263         return;
264
265     [self orderFront: nil];
266
267     if([self alphaValue] < 1.0 || b_displayed != YES) {
268         if (![self fadeTimer])
269             [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];
270         else if ([[[self fadeTimer] userInfo] shortValue]==0)
271             b_fadeQueued=YES;
272     }
273     [self autoHide];
274 }
275
276 - (void)fadeOut
277 {
278     if(NSPointInRect([NSEvent mouseLocation],[self frame]))
279         return;
280
281     if(([self alphaValue] > 0.0)) {
282         if (![self fadeTimer])
283             [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];
284         else if ([[[self fadeTimer] userInfo] shortValue]==1)
285             b_fadeQueued=YES;
286     }
287 }
288
289 /* triggers a timer to autoHide us again after some seconds of no activity */
290 - (void)autoHide
291 {
292     /* this will tell the timer to start over again or to start at all */
293     b_keptVisible = YES;
294
295     /* get us a valid timer */
296     if(! b_alreadyCounting) {
297         i_timeToKeepVisibleInSec = var_CreateGetInteger(VLCIntf, "mouse-hide-timeout") / 500;
298         if(hideAgainTimer) {
299             [hideAgainTimer invalidate];
300             [hideAgainTimer autorelease];
301         }
302         /* released in -autoHide and -dealloc */
303         hideAgainTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.5
304                                                           target: self
305                                                         selector: @selector(keepVisible:)
306                                                         userInfo: nil
307                                                          repeats: YES] retain];
308         b_alreadyCounting = YES;
309     }
310 }
311
312 - (void)keepVisible:(NSTimer *)timer
313 {
314     /* if the user triggered an action, start over again */
315     if(b_keptVisible)
316         b_keptVisible = NO;
317
318     /* count down until we hide ourselfes again and do so if necessary */
319     if(--i_timeToKeepVisibleInSec < 1) {
320         [self hideMouse];
321         [self fadeOut];
322         [hideAgainTimer invalidate]; /* released in -autoHide and -dealloc */
323         b_alreadyCounting = NO;
324     }
325 }
326
327 /* A getter and setter for our main timer that handles window fading */
328 - (NSTimer *)fadeTimer
329 {
330     return fadeTimer;
331 }
332
333 - (void)setFadeTimer:(NSTimer *)timer
334 {
335     [timer retain];
336     [fadeTimer invalidate];
337     [fadeTimer autorelease];
338     fadeTimer=timer;
339 }
340
341 - (void)mouseDown:(NSEvent *)theEvent
342 {
343     mouseClic = [theEvent locationInWindow];
344 }
345
346 - (void)mouseDragged:(NSEvent *)theEvent
347 {
348     NSPoint point = [NSEvent mouseLocation];
349     point.x -= mouseClic.x;
350     point.y -= mouseClic.y;
351     [self setFrameOrigin:point];
352 }
353
354 - (void)setVoutWasUpdated: (int)i_newdevice;
355 {
356     b_voutWasUpdated = YES;
357     if(i_newdevice != i_device) {
358         i_device = i_newdevice;
359         [self center];
360     }
361 }
362 @end
363
364 /*****************************************************************************
365  * FSPanelView
366  *****************************************************************************/
367 @implementation VLCFSPanelView
368
369 #define addButton(o_button, imageOff, imageOn, _x, _y, action, AXDesc, ToolTip)               \
370     s_rc.origin.x = _x;                                                                         \
371     s_rc.origin.y = _y;                                                                         \
372     o_button = [[NSButton alloc] initWithFrame: s_rc];                                 \
373     [o_button setButtonType: NSMomentaryChangeButton];                                          \
374     [o_button setBezelStyle: NSRegularSquareBezelStyle];                                        \
375     [o_button setBordered: NO];                                                                 \
376     [o_button setFont:[NSFont systemFontOfSize:0]];                                             \
377     [o_button setImage:[NSImage imageNamed:imageOff]];                                 \
378     [o_button setAlternateImage:[NSImage imageNamed:imageOn]];                         \
379     [o_button sizeToFit];                                                                       \
380     [o_button setTarget: self];                                                                 \
381     [o_button setAction: @selector(action:)];                                                   \
382     [[o_button cell] accessibilitySetOverrideValue:AXDesc forAttribute:NSAccessibilityDescriptionAttribute]; \
383     [[o_button cell] accessibilitySetOverrideValue:ToolTip forAttribute:NSAccessibilityTitleAttribute]; \
384     [o_button setToolTip: ToolTip]; \
385     [self addSubview:o_button];
386
387 #define addTextfield(class, o_text, align, font, color)                                    \
388     o_text = [[class alloc] initWithFrame: s_rc];                            \
389     [o_text setDrawsBackground: NO];                                                        \
390     [o_text setBordered: NO];                                                               \
391     [o_text setEditable: NO];                                                               \
392     [o_text setSelectable: NO];                                                             \
393     [o_text setStringValue: _NS("(no item is being played)")];                                                    \
394     [o_text setAlignment: align];                                                           \
395     [o_text setTextColor: [NSColor color]];                                                 \
396     [o_text setFont:[NSFont font:[NSFont smallSystemFontSize]]];                     \
397     [self addSubview:o_text];
398
399 - (id)initWithFrame:(NSRect)frameRect
400 {
401     id view = [super initWithFrame:frameRect];
402     fillColor = [[NSColor clearColor] retain];
403     NSRect s_rc = [self frame];
404     addButton(o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev, _NS("Click to go to the previous playlist item."), _NS("Previous"));
405     addButton(o_bwd, @"fs_rewind"        , @"fs_rewind_highlight"       , 211, 14, backward, _NS("Click and hold to skip backward through the current media."), _NS("Backward"));
406     addButton(o_play, @"fs_play"          , @"fs_play_highlight"         , 267, 10, play, _NS("Click to play or pause the current media."), _NS("Play/Pause"));
407     addButton(o_fwd, @"fs_forward"       , @"fs_forward_highlight"      , 313, 14, forward, _NS("Click and hold to skip forward through the current media."), _NS("Forward"));
408     addButton(o_next, @"fs_skip_next"     , @"fs_skip_next_highlight"    , 365, 15, next, _NS("Click to go to the next playlist item."), _NS("Next"));
409     addButton(o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, toggleFullscreen, _NS("Click to exit fullscreen playback."), _NS("Toggle Fullscreen mode"));
410 /*
411     addButton(o_button, @"image (off state)", @"image (on state)", 38, 51, something, accessibility help string, usual tool tip);
412  */
413     [o_fwd setContinuous:YES];
414     [o_bwd setContinuous:YES];
415
416     /* time slider */
417     s_rc = [self frame];
418     s_rc.origin.x = 15;
419     s_rc.origin.y = 55;
420     s_rc.size.width = 518;
421     s_rc.size.height = 9;
422     o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];
423     [o_fs_timeSlider setMinValue:0];
424     [o_fs_timeSlider setMaxValue:10000];
425     [o_fs_timeSlider setFloatValue: 0];
426     [o_fs_timeSlider setContinuous: YES];
427     [o_fs_timeSlider setTarget: self];
428     [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];
429     [[o_fs_volumeSlider cell] accessibilitySetOverrideValue:_NS("Position") forAttribute:NSAccessibilityTitleAttribute];
430     [[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];
431     [self addSubview: o_fs_timeSlider];
432
433     /* volume slider */
434     s_rc = [self frame];
435     s_rc.origin.x = 26;
436     s_rc.origin.y = 20;
437     s_rc.size.width = 95;
438     s_rc.size.height = 10;
439     o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];
440     [o_fs_volumeSlider setMinValue:0];
441     [o_fs_volumeSlider setMaxValue:AOUT_VOLUME_MAX];
442     [o_fs_volumeSlider setIntValue:AOUT_VOLUME_DEFAULT];
443     [o_fs_volumeSlider setContinuous: YES];
444     [o_fs_volumeSlider setTarget: self];
445     [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];
446     [[o_fs_volumeSlider cell] accessibilitySetOverrideValue:_NS("Volume") forAttribute:NSAccessibilityTitleAttribute];
447     [[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];
448     [self addSubview: o_fs_volumeSlider];
449
450     /* time counter and stream title output fields */
451     s_rc = [self frame];
452     s_rc.origin.x = 98;
453     s_rc.origin.y = 64;
454     s_rc.size.width = 352;
455     s_rc.size.height = 14;
456     addTextfield(NSTextField, o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor);
457     s_rc.origin.x = 471;
458     s_rc.origin.y = 64;
459     s_rc.size.width = 65;
460     addTextfield(VLCTimeField, o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor);
461
462     o_background_img = [[NSImage imageNamed:@"fs_background"] retain];
463     o_vol_sld_img = [[NSImage imageNamed:@"fs_volume_slider_bar"] retain];
464     o_vol_mute_img = [[NSImage imageNamed:@"fs_volume_mute"] retain];
465     o_vol_max_img = [[NSImage imageNamed:@"fs_volume_max"] retain];
466     o_time_sld_img = [[NSImage imageNamed:@"fs_time_slider"] retain];
467
468     return view;
469 }
470
471 - (void)dealloc
472 {
473     [o_background_img release];
474     [o_vol_sld_img release];
475     [o_vol_mute_img release];
476     [o_vol_max_img release];
477     [o_time_sld_img release];
478     [o_fs_timeSlider release];
479     [o_fs_volumeSlider release];
480     [o_prev release];
481     [o_next release];
482     [o_bwd release];
483     [o_play release];
484     [o_fwd release];
485     [o_fullscreen release];
486     [o_streamTitle_txt release];
487     [o_streamPosition_txt release];
488     [super dealloc];
489 }
490
491 - (void)setPlay
492 {
493     [o_play setImage:[NSImage imageNamed:@"fs_play"]];
494     [o_play setAlternateImage: [NSImage imageNamed:@"fs_play_highlight"]];
495 }
496
497 - (void)setPause
498 {
499     [o_play setImage: [NSImage imageNamed:@"fs_pause"]];
500     [o_play setAlternateImage: [NSImage imageNamed:@"fs_pause_highlight"]];
501 }
502
503 - (void)setStreamTitle:(NSString *)o_title
504 {
505     [o_streamTitle_txt setStringValue: o_title];
506 }
507
508 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
509 {
510     [o_streamPosition_txt setStringValue: o_time];
511     [o_fs_timeSlider setFloatValue: f_pos];
512 }
513
514 - (void)setSeekable:(BOOL)b_seekable
515 {
516     [o_bwd setEnabled: b_seekable];
517     [o_fwd setEnabled: b_seekable];
518     [o_fs_timeSlider setEnabled: b_seekable];
519 }
520
521 - (void)setVolumeLevel: (int)i_volumeLevel
522 {
523     [o_fs_volumeSlider setIntValue: i_volumeLevel];
524 }
525
526 - (IBAction)play:(id)sender
527 {
528     [[VLCCoreInteraction sharedInstance] play];
529 }
530
531 - (IBAction)forward:(id)sender
532 {
533     if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) > 0.16) {
534         // we just skipped 4 "continous" events, otherwise we are too fast
535         [[VLCCoreInteraction sharedInstance] forwardExtraShort];
536         last_fwd_event = [NSDate timeIntervalSinceReferenceDate];
537     }
538 }
539
540 - (IBAction)backward:(id)sender
541 {
542     if (([NSDate timeIntervalSinceReferenceDate] - last_bwd_event) > 0.16) {
543         // we just skipped 4 "continous" events, otherwise we are too fast
544         [[VLCCoreInteraction sharedInstance] backwardExtraShort];
545         last_bwd_event = [NSDate timeIntervalSinceReferenceDate];
546     }
547 }
548
549 - (IBAction)prev:(id)sender
550 {
551     [[VLCCoreInteraction sharedInstance] previous];
552 }
553
554 - (IBAction)next:(id)sender
555 {
556     [[VLCCoreInteraction sharedInstance] next];
557 }
558
559 - (IBAction)toggleFullscreen:(id)sender
560 {
561     [[VLCCoreInteraction sharedInstance] toggleFullscreen];
562 }
563
564 - (IBAction)fsTimeSliderUpdate:(id)sender
565 {
566     input_thread_t * p_input;
567     p_input = pl_CurrentInput(VLCIntf);
568     if(p_input != NULL) {
569         vlc_value_t pos;
570
571         pos.f_float = [o_fs_timeSlider floatValue] / 10000.;
572         var_Set(p_input, "position", pos);
573         vlc_object_release(p_input);
574     }
575     [[VLCMain sharedInstance] updatePlaybackPosition];
576 }
577
578 - (IBAction)fsVolumeSliderUpdate:(id)sender
579 {
580     [[VLCCoreInteraction sharedInstance] setVolume: [sender intValue]];
581 }
582
583 #define addImage(image, _x, _y, mode)                                                       \
584     image_size = [image size];                                                              \
585     image_rect.size = image_size;                                                           \
586     image_rect.origin.x = 0;                                                                \
587     image_rect.origin.y = 0;                                                                \
588     frame.origin.x = _x;                                                                    \
589     frame.origin.y = _y;                                                                    \
590     frame.size = image_size;                                                                \
591     [image drawInRect:frame fromRect:image_rect operation:mode fraction:1];
592
593 - (void)drawRect:(NSRect)rect
594 {
595     NSRect frame = [self frame];
596     NSRect image_rect;
597     NSSize image_size;
598     NSImage *img;
599     addImage(o_background_img, 0, 0, NSCompositeCopy);
600     addImage(o_vol_sld_img, 26, 23, NSCompositeSourceOver);
601     addImage(o_vol_mute_img, 16, 18, NSCompositeSourceOver);
602     addImage(o_vol_max_img, 124, 18, NSCompositeSourceOver);
603     addImage(o_time_sld_img, 15, 53, NSCompositeSourceOver);
604 }
605
606 @end
607
608 /*****************************************************************************
609  * VLCFSTimeSlider
610  *****************************************************************************/
611 @implementation VLCFSTimeSlider
612 - (void)drawKnobInRect:(NSRect)knobRect
613 {
614     NSRect image_rect;
615     NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];
616     image_rect.size = [img size];
617     image_rect.origin.x = 0;
618     image_rect.origin.y = 0;
619     knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
620     knobRect.size.width = image_rect.size.width;
621     knobRect.size.height = image_rect.size.height;
622     [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
623 }
624
625 - (void)drawRect:(NSRect)rect
626 {
627     /* Draw default to make sure the slider behaves correctly */
628     [[NSGraphicsContext currentContext] saveGraphicsState];
629     NSRectClip(NSZeroRect);
630     [super drawRect:rect];
631     [[NSGraphicsContext currentContext] restoreGraphicsState];
632
633     NSRect knobRect = [[self cell] knobRectFlipped:NO];
634     knobRect.origin.y+=7.5;
635     [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
636     [self drawKnobInRect: knobRect];
637 }
638
639 @end
640
641 /*****************************************************************************
642 * VLCFSVolumeSlider
643 *****************************************************************************/
644 @implementation VLCFSVolumeSlider
645 - (void)drawKnobInRect:(NSRect) knobRect
646 {
647     NSRect image_rect;
648     NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];
649     image_rect.size = [img size];
650     image_rect.origin.x = 0;
651     image_rect.origin.y = 0;
652     knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
653     knobRect.size.width = image_rect.size.width;
654     knobRect.size.height = image_rect.size.height;
655     [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
656 }
657
658 - (void)drawRect:(NSRect)rect
659 {
660     /* Draw default to make sure the slider behaves correctly */
661     [[NSGraphicsContext currentContext] saveGraphicsState];
662     NSRectClip(NSZeroRect);
663     [super drawRect:rect];
664     [[NSGraphicsContext currentContext] restoreGraphicsState];
665
666     NSRect knobRect = [[self cell] knobRectFlipped:NO];
667     knobRect.origin.y+=6;
668     [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
669     [self drawKnobInRect: knobRect];
670 }
671
672 @end
673