* be more accurate when fading in and out (refs #913 and hopefully fixes it)
[vlc.git] / modules / gui / macosx / fspanel.m
1 /*****************************************************************************\r
2  * fspanel.m: MacOS X full screen panel\r
3  *****************************************************************************\r
4  * Copyright (C) 2006 the VideoLAN team\r
5  * $Id$\r
6  *\r
7  * Authors: J\8er\99me Decoodt <djc at videolan dot org>\r
8  *          Felix K\9fhne <fkuehne at videolan dot org>\r
9  *\r
10  * This program is free software; you can redistribute it and/or modify\r
11  * it under the terms of the GNU General Public License as published by\r
12  * the Free Software Foundation; either version 2 of the License, or\r
13  * (at your option) any later version.\r
14  * \r
15  * This program is distributed in the hope that it will be useful,\r
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
18  * GNU General Public License for more details.\r
19  *\r
20  * You should have received a copy of the GNU General Public License\r
21  * along with this program; if not, write to the Free Software\r
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.\r
23  *****************************************************************************/\r
24 \r
25 /*****************************************************************************\r
26  * Preamble\r
27  *****************************************************************************/\r
28 #import "intf.h"\r
29 #import "controls.h"\r
30 #import "vout.h"\r
31 #import "fspanel.h"\r
32 \r
33 #define KEEP_VISIBLE_AFTER_ACTION 4 /* time in half-sec until this panel will hide again after an user's action */\r
34 \r
35 /*****************************************************************************\r
36  * VLCFSPanel\r
37  *****************************************************************************/\r
38 @implementation VLCFSPanel\r
39 /* We override this initializer so we can set the NSBorderlessWindowMask styleMask, and set a few other important settings */\r
40 - (id)initWithContentRect:(NSRect)contentRect \r
41                 styleMask:(unsigned int)aStyle \r
42                   backing:(NSBackingStoreType)bufferingType \r
43                     defer:(BOOL)flag\r
44 {\r
45     id win = [super initWithContentRect:contentRect styleMask:NSTexturedBackgroundWindowMask backing:bufferingType defer:flag];\r
46     [win setOpaque:NO];\r
47     [win setHasShadow: NO];\r
48     [win setBackgroundColor:[NSColor clearColor]];\r
49     \r
50     /* let the window sit on top of everything else and start out completely transparent */\r
51     [win setLevel:NSFloatingWindowLevel];\r
52     [win setAlphaValue:0.0];\r
53     i_device = 0;\r
54 \r
55     [win center];\r
56     return win;\r
57 }\r
58 \r
59 - (void)awakeFromNib\r
60 {\r
61     [self setContentView:[[VLCFSPanelView alloc] initWithFrame: [self frame]]];\r
62     BOOL isInside = (NSPointInRect([NSEvent mouseLocation],[self frame]));\r
63     [[self contentView] addTrackingRect:[[self contentView] bounds] owner:self userData:nil assumeInside:isInside];\r
64     if (isInside)\r
65         [self mouseEntered:NULL];\r
66     if (!isInside)\r
67         [self mouseExited:NULL];\r
68     \r
69     /* get a notification if VLC isn't the active app anymore */\r
70     [[NSNotificationCenter defaultCenter]\r
71     addObserver: self\r
72        selector: @selector(setNonActive:)\r
73            name: NSApplicationDidResignActiveNotification\r
74          object: NSApp];\r
75     \r
76     /* get a notification if VLC is the active app again */\r
77     [[NSNotificationCenter defaultCenter]\r
78     addObserver: self\r
79        selector: @selector(setActive:)\r
80            name: NSApplicationDidBecomeActiveNotification\r
81          object: NSApp];\r
82 }\r
83 \r
84 /* Windows created with NSBorderlessWindowMask normally can't be key, but we want ours to be */\r
85 - (BOOL)canBecomeKeyWindow\r
86 {\r
87     return YES;\r
88 }\r
89 \r
90 - (BOOL)mouseDownCanMoveWindow\r
91 {\r
92     return YES;\r
93 }\r
94 \r
95 -(void)dealloc\r
96 {\r
97     [[NSNotificationCenter defaultCenter] removeObserver: self];\r
98     \r
99     if( hideAgainTimer )\r
100         [hideAgainTimer release];\r
101     [self setFadeTimer:nil];\r
102     [super dealloc];\r
103 }\r
104 \r
105 -(void)center\r
106 {\r
107     /* centre the panel in the lower third of the screen */\r
108     NSPoint theCoordinate;\r
109     NSRect theScreensFrame;\r
110     NSRect theWindowsFrame;\r
111 \r
112     if( i_device < 0 || i_device >= (signed int)[[NSScreen screens] count] )\r
113         /* invalid preferences or none specified, using main screen */\r
114         theScreensFrame = [[NSScreen mainScreen] frame];\r
115     else\r
116         /* user-defined screen */\r
117         theScreensFrame = [[[NSScreen screens] objectAtIndex: i_device] frame];\r
118 \r
119     theWindowsFrame = [self frame];\r
120     \r
121     theCoordinate.x = (theScreensFrame.size.width - theWindowsFrame.size.width) / 2 + theScreensFrame.origin.x;\r
122     theCoordinate.y = (theScreensFrame.size.height / 3) - theWindowsFrame.size.height + theScreensFrame.origin.y;\r
123     [self setFrameTopLeftPoint: theCoordinate];\r
124 }\r
125 \r
126 - (void)setPlay\r
127 {\r
128     [[self contentView] setPlay];\r
129 }\r
130 \r
131 - (void)setPause\r
132 {\r
133     [[self contentView] setPause];\r
134 }\r
135 \r
136 - (void)setStreamTitle:(NSString *)o_title\r
137 {\r
138     [[self contentView] setStreamTitle: o_title];\r
139 }\r
140 \r
141 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time\r
142 {\r
143     [[self contentView] setStreamPos:f_pos andTime: o_time];\r
144 }\r
145 \r
146 - (void)setSeekable:(BOOL) b_seekable\r
147 {\r
148     [[self contentView] setSeekable: b_seekable];\r
149 }\r
150 \r
151 - (void)setVolumeLevel: (float)f_volumeLevel\r
152 {\r
153     [[self contentView] setVolumeLevel: f_volumeLevel];\r
154 }\r
155 \r
156 - (void)setNonActive:(id)noData\r
157 {\r
158     b_nonActive = YES;\r
159     [self orderOut: self];\r
160     \r
161     /* here's fadeOut, just without visibly fading */\r
162     b_displayed = NO;\r
163     [self setAlphaValue:0.0];\r
164     [self setFadeTimer:nil];\r
165     b_fadeQueued = NO;\r
166 }\r
167 \r
168 - (void)setActive:(id)noData\r
169 {\r
170     if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )\r
171     {\r
172         b_nonActive = NO;\r
173         [self fadeIn];\r
174     }\r
175 }\r
176 \r
177 /* This routine is called repeatedly to fade in the window */\r
178 - (void)focus:(NSTimer *)timer\r
179 {\r
180     /* we need to push ourselves to front if the vout window was closed since our last display */\r
181     if( b_voutWasUpdated )\r
182     {\r
183         [self orderFront: self];\r
184         b_voutWasUpdated = NO;\r
185     }\r
186 \r
187     if( [self alphaValue] < 1.0 )\r
188         [self setAlphaValue:[self alphaValue]+0.1];\r
189     if( [self alphaValue] >= 1.0 )\r
190     {\r
191         b_displayed = YES;\r
192         [self setAlphaValue: 1.0];\r
193         [self setFadeTimer:nil];\r
194         if( b_fadeQueued )\r
195         {\r
196             b_fadeQueued=NO;\r
197             [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];\r
198         }\r
199     }\r
200 }\r
201 \r
202 /* This routine is called repeatedly to hide the window */\r
203 - (void)unfocus:(NSTimer *)timer\r
204 {\r
205     if( b_keptVisible )\r
206     {\r
207         b_keptVisible = NO;\r
208         b_fadeQueued = NO;\r
209         [[self fadeTimer] release];\r
210         [self setFadeTimer: NULL];\r
211         [self fadeIn];\r
212         return;\r
213     }\r
214     if( [self alphaValue] > 0.0 )\r
215         [self setAlphaValue:[self alphaValue]-0.1];\r
216     if( [self alphaValue] <= 0.1 )\r
217     {\r
218         b_displayed = NO;\r
219         [self setAlphaValue:0.0];\r
220         [self setFadeTimer:nil];\r
221         if( b_fadeQueued )\r
222         {\r
223             b_fadeQueued=NO;\r
224             [self setFadeTimer:\r
225                 [NSTimer scheduledTimerWithTimeInterval:0.1 \r
226                                                  target:self \r
227                                                selector:@selector(focus:) \r
228                                                userInfo:NULL \r
229                                                 repeats:YES]];\r
230         }\r
231     }\r
232 }\r
233 \r
234 - (void)mouseExited:(NSEvent *)theEvent\r
235 {\r
236     /* give up our focus, so the vout may show us again without letting the user clicking it */\r
237     if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )\r
238         [[[[[VLCMain sharedInstance] getControls] getVoutView] window] makeKeyWindow];\r
239 }\r
240 \r
241 - (void)fadeIn\r
242 {\r
243     /* in case that the user don't want us to appear, just return here */\r
244     if(! config_GetInt( VLCIntf, "macosx-fspanel" ) || b_nonActive )\r
245         return;\r
246     \r
247     [self orderFront: nil];\r
248     \r
249     if( [self alphaValue] < 1.0 || b_displayed != YES )\r
250     {\r
251         if (![self fadeTimer])\r
252             [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];\r
253         else if ([[[self fadeTimer] userInfo] shortValue]==0)\r
254             b_fadeQueued=YES;\r
255     }\r
256     [self autoHide];\r
257 }\r
258 \r
259 - (void)fadeOut\r
260 {\r
261     if( NSPointInRect([NSEvent mouseLocation],[self frame]))\r
262         return;\r
263 \r
264     if( ( [self alphaValue] > 0.0 ) )\r
265     {\r
266         if (![self fadeTimer])\r
267             [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];\r
268         else if ([[[self fadeTimer] userInfo] shortValue]==1)\r
269             b_fadeQueued=YES;\r
270     }\r
271 }\r
272 \r
273 /* triggers a timer to autoHide us again after some seconds of no activity */\r
274 - (void)autoHide\r
275 {\r
276     /* this will tell the timer to start over again or to start at all */\r
277     b_keptVisible = YES;\r
278     \r
279     /* get us a valid timer */\r
280     if(! b_alreadyCounting )\r
281     {\r
282         hideAgainTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5\r
283                                                           target: self \r
284                                                         selector: @selector(keepVisible:)\r
285                                                         userInfo: nil \r
286                                                          repeats: YES];\r
287         [hideAgainTimer fire];\r
288         [hideAgainTimer retain];\r
289         b_alreadyCounting = YES;\r
290     }\r
291 }\r
292 \r
293 - (void)keepVisible:(NSTimer *)timer\r
294 {\r
295     /* if the user triggered an action, start over again */\r
296     if( b_keptVisible )\r
297     {\r
298         i_timeToKeepVisibleInSec = KEEP_VISIBLE_AFTER_ACTION;\r
299         b_keptVisible = NO;\r
300     }\r
301     \r
302     /* count down until we hide ourselfes again and do so if necessary */\r
303     i_timeToKeepVisibleInSec -= 1;\r
304     if( i_timeToKeepVisibleInSec < 1 )\r
305     {\r
306         [self fadeOut];\r
307         [timer invalidate];\r
308         [timer release];\r
309         b_alreadyCounting = NO;\r
310         timer = NULL;\r
311     }\r
312 }\r
313 \r
314 /* A getter and setter for our main timer that handles window fading */\r
315 - (NSTimer *)fadeTimer\r
316 {\r
317     return fadeTimer;\r
318 }\r
319 \r
320 - (void)setFadeTimer:(NSTimer *)timer\r
321 {\r
322     [timer retain];\r
323     [fadeTimer invalidate];\r
324     [fadeTimer release];\r
325     fadeTimer=timer;\r
326 }\r
327 \r
328 - (void)mouseDown:(NSEvent *)theEvent\r
329 {\r
330     mouseClic = [theEvent locationInWindow];\r
331 }\r
332 \r
333 - (void)mouseDragged:(NSEvent *)theEvent\r
334 {\r
335     NSPoint point = [NSEvent mouseLocation];\r
336     point.x -= mouseClic.x;\r
337     point.y -= mouseClic.y;\r
338     [self setFrameOrigin:point];\r
339 }\r
340 \r
341 - (BOOL)isDisplayed\r
342 {\r
343     return b_displayed;\r
344 }\r
345 \r
346 - (void)setVoutWasUpdated: (int)i_newdevice;\r
347 {\r
348     b_voutWasUpdated = YES;\r
349     if( i_newdevice != i_device )\r
350     {\r
351         i_device = i_newdevice;\r
352         [self center];\r
353     }\r
354 }\r
355 @end\r
356 \r
357 /*****************************************************************************\r
358  * FSPanelView\r
359  *****************************************************************************/\r
360 @implementation VLCFSPanelView\r
361 \r
362 #define addButton( o_button, imageOff, imageOn, _x, _y, action )                                \\r
363     s_rc.origin.x = _x;                                                                         \\r
364     s_rc.origin.y = _y;                                                                         \\r
365     o_button = [[NSButton alloc] initWithFrame: s_rc];                                 \\r
366     [o_button setButtonType: NSMomentaryChangeButton];                                          \\r
367     [o_button setBezelStyle: NSRegularSquareBezelStyle];                                        \\r
368     [o_button setBordered: NO];                                                                 \\r
369     [o_button setFont:[NSFont systemFontOfSize:0]];                                             \\r
370     [o_button setImage:[NSImage imageNamed:imageOff]];                                 \\r
371     [o_button setAlternateImage:[NSImage imageNamed:imageOn]];                         \\r
372     [o_button sizeToFit];                                                                       \\r
373     [o_button setTarget: self];                                                                 \\r
374     [o_button setAction: @selector(action:)];                                                   \\r
375     [self addSubview:o_button];\r
376 \r
377 #define addTextfield( o_text, align, font, color, size )                                    \\r
378     o_text = [[NSTextField alloc] initWithFrame: s_rc];                            \\r
379     [o_text setDrawsBackground: NO];                                                        \\r
380     [o_text setBordered: NO];                                                               \\r
381     [o_text setEditable: NO];                                                               \\r
382     [o_text setSelectable: NO];                                                             \\r
383     [o_text setStringValue: _NS("(no item is being played)")];                                                    \\r
384     [o_text setAlignment: align];                                                           \\r
385     [o_text setTextColor: [NSColor color]];                                                 \\r
386     [o_text setFont:[NSFont font:[NSFont smallSystemFontSize] - size]];                     \\r
387     [self addSubview:o_text];\r
388 \r
389 - (id)initWithFrame:(NSRect)frameRect\r
390 {\r
391     id view = [super initWithFrame:frameRect];\r
392     fillColor = [[NSColor clearColor] retain];\r
393     NSRect s_rc = [self frame];\r
394     addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev );\r
395     addButton( o_bwd, @"fs_rewind"        , @"fs_rewind_highlight"       , 211, 14, backward );\r
396     addButton( o_play, @"fs_play"          , @"fs_play_highlight"         , 267, 10, play );\r
397     addButton( o_fwd, @"fs_forward"       , @"fs_forward_highlight"      , 313, 14, forward );\r
398     addButton( o_next, @"fs_skip_next"     , @"fs_skip_next_highlight"    , 365, 15, next );\r
399     addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, windowAction );\r
400 /*\r
401     addButton( o_button, @"image (off state)", @"image (on state)", 38, 51, something );\r
402  */\r
403 \r
404     /* time slider */\r
405     s_rc = [self frame];\r
406     s_rc.origin.x = 15;\r
407     s_rc.origin.y = 53;\r
408     s_rc.size.width = 518;\r
409     s_rc.size.height = 9;\r
410     o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];\r
411     [o_fs_timeSlider setMinValue:0];\r
412     [o_fs_timeSlider setMaxValue:10000];\r
413     [o_fs_timeSlider setFloatValue: 0];\r
414     [o_fs_timeSlider setContinuous: YES];\r
415     [o_fs_timeSlider setTarget: self];\r
416     [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];\r
417     [self addSubview: o_fs_timeSlider];\r
418 \r
419     /* volume slider */\r
420     s_rc = [self frame];\r
421     s_rc.origin.x = 26;\r
422     s_rc.origin.y = 17.5;\r
423     s_rc.size.width = 95;\r
424     s_rc.size.height = 10;\r
425     o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];\r
426     [o_fs_volumeSlider setMinValue:0];\r
427     [o_fs_volumeSlider setMaxValue:32];\r
428     [o_fs_volumeSlider setFloatValue: 0];\r
429     [o_fs_volumeSlider setContinuous: YES];\r
430     [o_fs_volumeSlider setTarget: self];\r
431     [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];\r
432     [self addSubview: o_fs_volumeSlider];\r
433     \r
434     /* time counter and stream title output fields */\r
435     s_rc = [self frame];\r
436     s_rc.origin.x = 98;\r
437     s_rc.origin.y = 64;\r
438     s_rc.size.width = 352;\r
439     s_rc.size.height = 14;\r
440     addTextfield( o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );\r
441     s_rc.origin.x = 486;\r
442     s_rc.origin.y = 64;\r
443     s_rc.size.width = 50;\r
444     addTextfield( o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor, 0 );\r
445 \r
446     return view;\r
447 }\r
448 \r
449 - (void)dealloc\r
450 {\r
451     [o_fs_timeSlider release];\r
452     [o_fs_volumeSlider release];\r
453     [o_prev release];\r
454     [o_next release];\r
455     [o_bwd release];\r
456     [o_play release];\r
457     [o_fwd release];\r
458     [o_fullscreen release];\r
459     [o_streamTitle_txt release];\r
460     [o_streamPosition_txt release];\r
461     [super dealloc];\r
462 }\r
463 \r
464 - (void)setPlay\r
465 {\r
466     [o_play setImage:[NSImage imageNamed:@"fs_play"]];\r
467     [o_play setAlternateImage: [NSImage imageNamed:@"fs_play_highlight"]];\r
468 }\r
469 \r
470 - (void)setPause\r
471 {\r
472     [o_play setImage: [NSImage imageNamed:@"fs_pause"]];\r
473     [o_play setAlternateImage: [NSImage imageNamed:@"fs_pause_highlight"]];\r
474 }\r
475 \r
476 - (void)setStreamTitle:(NSString *)o_title\r
477 {\r
478     [o_streamTitle_txt setStringValue: o_title];\r
479 }\r
480 \r
481 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time\r
482 {\r
483     [o_streamPosition_txt setStringValue: o_time];\r
484     [o_fs_timeSlider setFloatValue: f_pos];\r
485 }\r
486 \r
487 - (void)setSeekable:(BOOL)b_seekable\r
488 {\r
489     [o_bwd setEnabled: b_seekable];\r
490     [o_fwd setEnabled: b_seekable];\r
491     [o_fs_timeSlider setEnabled: b_seekable];\r
492 }\r
493 \r
494 - (void)setVolumeLevel: (float)f_volumeLevel\r
495 {\r
496     [o_fs_volumeSlider setFloatValue: f_volumeLevel];\r
497 }\r
498 \r
499 - (IBAction)play:(id)sender\r
500 {\r
501     [[[VLCMain sharedInstance] getControls] play: sender];\r
502 }\r
503 \r
504 - (IBAction)forward:(id)sender\r
505 {\r
506     [[[VLCMain sharedInstance] getControls] forward: sender];\r
507 }\r
508 \r
509 - (IBAction)backward:(id)sender\r
510 {\r
511     [[[VLCMain sharedInstance] getControls] backward: sender];\r
512 }\r
513 \r
514 - (IBAction)prev:(id)sender\r
515 {\r
516     [[[VLCMain sharedInstance] getControls] prev: sender];\r
517 }\r
518 \r
519 - (IBAction)next:(id)sender\r
520 {\r
521     [[[VLCMain sharedInstance] getControls] next: sender];\r
522 }\r
523 \r
524 - (IBAction)windowAction:(id)sender\r
525 {\r
526     [[[VLCMain sharedInstance] getControls] windowAction: sender];\r
527 }\r
528 \r
529 - (IBAction)fsTimeSliderUpdate:(id)sender\r
530 {\r
531     [[VLCMain sharedInstance] timesliderUpdate: sender];\r
532 }\r
533 \r
534 - (IBAction)fsVolumeSliderUpdate:(id)sender\r
535 {\r
536     [[[VLCMain sharedInstance] getControls] volumeSliderUpdated: sender];\r
537 }\r
538 \r
539 #define addImage(image, _x, _y, mode, _width)                                               \\r
540     img = [NSImage imageNamed:image];                                              \\r
541     image_rect.size = [img size];                                                           \\r
542     image_rect.origin.x = 0;                                                                \\r
543     image_rect.origin.y = 0;                                                                \\r
544     frame.origin.x = _x;                                                                    \\r
545     frame.origin.y = _y;                                                                    \\r
546     frame.size = [img size];                                                                \\r
547     if( _width ) frame.size.width = _width;                                                 \\r
548     [img drawInRect:frame fromRect:image_rect operation:mode fraction:1];\r
549 \r
550 - (void)drawRect:(NSRect)rect\r
551 {\r
552         NSRect frame = [self frame];\r
553     NSRect image_rect;\r
554     NSImage *img;\r
555     addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 );\r
556     addImage( @"fs_volume_slider_bar", 26, 22, NSCompositeSourceOver, 0 );\r
557     addImage( @"fs_volume_mute", 16, 18, NSCompositeSourceOver, 0 );\r
558     addImage( @"fs_volume_max", 124, 17, NSCompositeSourceOver, 0 );\r
559     addImage( @"fs_time_slider", 15, 53, NSCompositeSourceOver, 0);\r
560 }\r
561 \r
562 @end\r
563 \r
564 /*****************************************************************************\r
565  * VLCFSTimeSlider\r
566  *****************************************************************************/\r
567 @implementation VLCFSTimeSlider\r
568 - (void)drawKnobInRect:(NSRect)knobRect\r
569 {\r
570     NSRect image_rect;\r
571     NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];\r
572     image_rect.size = [img size];\r
573     image_rect.origin.x = 0;\r
574     image_rect.origin.y = 0;\r
575     knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;\r
576     knobRect.size.width = image_rect.size.width;\r
577     knobRect.size.height = image_rect.size.height;\r
578     [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];\r
579 }\r
580 \r
581 - (void)drawRect:(NSRect)rect\r
582 {\r
583     /* Draw default to make sure the slider behaves correctly */\r
584     [[NSGraphicsContext currentContext] saveGraphicsState];\r
585     NSRectClip(NSZeroRect);\r
586     [super drawRect:rect];\r
587     [[NSGraphicsContext currentContext] restoreGraphicsState];\r
588     \r
589     NSRect knobRect = [[self cell] knobRectFlipped:NO];\r
590     knobRect.origin.y+=7.5;\r
591     [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];\r
592     [self drawKnobInRect: knobRect];\r
593 }\r
594 \r
595 @end\r
596 \r
597 /*****************************************************************************\r
598 * VLCFSVolumeSlider\r
599 *****************************************************************************/\r
600 @implementation VLCFSVolumeSlider\r
601 - (void)drawKnobInRect:(NSRect) knobRect\r
602 {\r
603     NSRect image_rect;\r
604     NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];\r
605     image_rect.size = [img size];\r
606     image_rect.origin.x = 0;\r
607     image_rect.origin.y = 0;\r
608     knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;\r
609     knobRect.size.width = image_rect.size.width;\r
610     knobRect.size.height = image_rect.size.height;\r
611     [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];\r
612 }\r
613 \r
614 - (void)drawRect:(NSRect)rect\r
615 {\r
616     /* Draw default to make sure the slider behaves correctly */\r
617     [[NSGraphicsContext currentContext] saveGraphicsState];\r
618     NSRectClip(NSZeroRect);\r
619     [super drawRect:rect];\r
620     [[NSGraphicsContext currentContext] restoreGraphicsState];\r
621     \r
622     NSRect knobRect = [[self cell] knobRectFlipped:NO];\r
623     knobRect.origin.y+=6;\r
624     [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];\r
625     [self drawKnobInRect: knobRect];\r
626 }\r
627 \r
628 @end\r
629 \r