* don't double free an object! Thanks to nivix for pointing me to the right direction...
[vlc.git] / modules / gui / macosx / fspanel.m
1 /*****************************************************************************\r
2  * fspanel.m: MacOS X full screen panel\r
3  *****************************************************************************\r
4  * Copyright (C) 2006-2007 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 a 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:NSModalPanelWindowLevel];\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 #if GC_ENABLED\r
96 - (void)finalize\r
97 {\r
98         /* dealloc isn't called on 10.5 in case that GC is enabled, so we need to provide the functionality here */\r
99         [[NSNotificationCenter defaultCenter] removeObserver: self];\r
100         [self setFadeTimer:nil];\r
101         \r
102         [super finalize];\r
103 }\r
104 #endif\r
105 \r
106 -(void)dealloc\r
107 {\r
108     [[NSNotificationCenter defaultCenter] removeObserver: self];\r
109     \r
110     if( hideAgainTimer )\r
111         [hideAgainTimer release];\r
112     [self setFadeTimer:nil];\r
113     [super dealloc];\r
114 }\r
115 \r
116 -(void)center\r
117 {\r
118     /* centre the panel in the lower third of the screen */\r
119     NSPoint theCoordinate;\r
120     NSRect theScreensFrame;\r
121     NSRect theWindowsFrame;\r
122 \r
123     if( i_device < 0 || i_device >= (signed int)[[NSScreen screens] count] )\r
124         /* invalid preferences or none specified, using main screen */\r
125         theScreensFrame = [[NSScreen mainScreen] frame];\r
126     else\r
127         /* user-defined screen */\r
128         theScreensFrame = [[[NSScreen screens] objectAtIndex: i_device] frame];\r
129 \r
130     theWindowsFrame = [self frame];\r
131     \r
132     theCoordinate.x = (theScreensFrame.size.width - theWindowsFrame.size.width) / 2 + theScreensFrame.origin.x;\r
133     theCoordinate.y = (theScreensFrame.size.height / 3) - theWindowsFrame.size.height + theScreensFrame.origin.y;\r
134     [self setFrameTopLeftPoint: theCoordinate];\r
135 }\r
136 \r
137 - (void)setPlay\r
138 {\r
139     [[self contentView] setPlay];\r
140 }\r
141 \r
142 - (void)setPause\r
143 {\r
144     [[self contentView] setPause];\r
145 }\r
146 \r
147 - (void)setStreamTitle:(NSString *)o_title\r
148 {\r
149     [[self contentView] setStreamTitle: o_title];\r
150 }\r
151 \r
152 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time\r
153 {\r
154     [[self contentView] setStreamPos:f_pos andTime: o_time];\r
155 }\r
156 \r
157 - (void)setSeekable:(BOOL) b_seekable\r
158 {\r
159     [[self contentView] setSeekable: b_seekable];\r
160 }\r
161 \r
162 - (void)setVolumeLevel: (float)f_volumeLevel\r
163 {\r
164     [[self contentView] setVolumeLevel: f_volumeLevel];\r
165 }\r
166 \r
167 - (void)setNonActive:(id)noData\r
168 {\r
169     b_nonActive = YES;\r
170     [self orderOut: self];\r
171     \r
172     /* here's fadeOut, just without visibly fading */\r
173     b_displayed = NO;\r
174     [self setAlphaValue:0.0];\r
175     [self setFadeTimer:nil];\r
176     b_fadeQueued = NO;\r
177 }\r
178 \r
179 - (void)setActive:(id)noData\r
180 {\r
181     if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )\r
182     {\r
183         b_nonActive = NO;\r
184         [self fadeIn];\r
185     }\r
186 }\r
187 \r
188 /* This routine is called repeatedly to fade in the window */\r
189 - (void)focus:(NSTimer *)timer\r
190 {\r
191     /* we need to push ourselves to front if the vout window was closed since our last display */\r
192     if( b_voutWasUpdated )\r
193     {\r
194         [self orderFront: self];\r
195         b_voutWasUpdated = NO;\r
196     }\r
197 \r
198     if( [self alphaValue] < 1.0 )\r
199         [self setAlphaValue:[self alphaValue]+0.1];\r
200     if( [self alphaValue] >= 1.0 )\r
201     {\r
202         b_displayed = YES;\r
203         [self setAlphaValue: 1.0];\r
204         [self setFadeTimer:nil];\r
205         if( b_fadeQueued )\r
206         {\r
207             b_fadeQueued=NO;\r
208             [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];\r
209         }\r
210     }\r
211 }\r
212 \r
213 /* This routine is called repeatedly to hide the window */\r
214 - (void)unfocus:(NSTimer *)timer\r
215 {\r
216     if( b_keptVisible )\r
217     {\r
218         b_keptVisible = NO;\r
219         b_fadeQueued = NO;\r
220         [self setFadeTimer: NULL];\r
221         [self fadeIn];\r
222         return;\r
223     }\r
224     if( [self alphaValue] > 0.0 )\r
225         [self setAlphaValue:[self alphaValue]-0.1];\r
226     if( [self alphaValue] <= 0.1 )\r
227     {\r
228         b_displayed = NO;\r
229         [self setAlphaValue:0.0];\r
230         [self setFadeTimer:nil];\r
231         if( b_fadeQueued )\r
232         {\r
233             b_fadeQueued=NO;\r
234             [self setFadeTimer:\r
235                 [NSTimer scheduledTimerWithTimeInterval:0.1 \r
236                                                  target:self \r
237                                                selector:@selector(focus:) \r
238                                                userInfo:NULL \r
239                                                 repeats:YES]];\r
240         }\r
241     }\r
242 }\r
243 \r
244 - (void)mouseExited:(NSEvent *)theEvent\r
245 {\r
246     /* give up our focus, so the vout may show us again without letting the user clicking it */\r
247     if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )\r
248         [[[[[VLCMain sharedInstance] getControls] getVoutView] window] makeKeyWindow];\r
249 }\r
250 \r
251 - (void)fadeIn\r
252 {\r
253     /* in case that the user don't want us to appear, just return here */\r
254     if(! config_GetInt( VLCIntf, "macosx-fspanel" ) || b_nonActive )\r
255         return;\r
256     \r
257     [self orderFront: nil];\r
258     \r
259     if( [self alphaValue] < 1.0 || b_displayed != YES )\r
260     {\r
261         if (![self fadeTimer])\r
262             [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];\r
263         else if ([[[self fadeTimer] userInfo] shortValue]==0)\r
264             b_fadeQueued=YES;\r
265     }\r
266     [self autoHide];\r
267 }\r
268 \r
269 - (void)fadeOut\r
270 {\r
271     if( NSPointInRect([NSEvent mouseLocation],[self frame]))\r
272         return;\r
273 \r
274     if( ( [self alphaValue] > 0.0 ) )\r
275     {\r
276         if (![self fadeTimer])\r
277             [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];\r
278         else if ([[[self fadeTimer] userInfo] shortValue]==1)\r
279             b_fadeQueued=YES;\r
280     }\r
281 }\r
282 \r
283 /* triggers a timer to autoHide us again after some seconds of no activity */\r
284 - (void)autoHide\r
285 {\r
286     /* this will tell the timer to start over again or to start at all */\r
287     b_keptVisible = YES;\r
288     \r
289     /* get us a valid timer */\r
290     if(! b_alreadyCounting )\r
291     {\r
292         hideAgainTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5\r
293                                                           target: self \r
294                                                         selector: @selector(keepVisible:)\r
295                                                         userInfo: nil \r
296                                                          repeats: YES];\r
297         [hideAgainTimer fire];\r
298         [hideAgainTimer retain];\r
299         b_alreadyCounting = YES;\r
300     }\r
301 }\r
302 \r
303 - (void)keepVisible:(NSTimer *)timer\r
304 {\r
305     /* if the user triggered an action, start over again */\r
306     if( b_keptVisible )\r
307     {\r
308         i_timeToKeepVisibleInSec = KEEP_VISIBLE_AFTER_ACTION;\r
309         b_keptVisible = NO;\r
310     }\r
311     \r
312     /* count down until we hide ourselfes again and do so if necessary */\r
313     i_timeToKeepVisibleInSec -= 1;\r
314     if( i_timeToKeepVisibleInSec < 1 )\r
315     {\r
316         [self fadeOut];\r
317         [timer invalidate];\r
318         [timer release];\r
319         b_alreadyCounting = NO;\r
320         timer = NULL;\r
321     }\r
322 }\r
323 \r
324 /* A getter and setter for our main timer that handles window fading */\r
325 - (NSTimer *)fadeTimer\r
326 {\r
327     return fadeTimer;\r
328 }\r
329 \r
330 - (void)setFadeTimer:(NSTimer *)timer\r
331 {\r
332     [timer retain];\r
333     [fadeTimer invalidate];\r
334     [fadeTimer release];\r
335     fadeTimer=timer;\r
336 }\r
337 \r
338 - (void)mouseDown:(NSEvent *)theEvent\r
339 {\r
340     mouseClic = [theEvent locationInWindow];\r
341 }\r
342 \r
343 - (void)mouseDragged:(NSEvent *)theEvent\r
344 {\r
345     NSPoint point = [NSEvent mouseLocation];\r
346     point.x -= mouseClic.x;\r
347     point.y -= mouseClic.y;\r
348     [self setFrameOrigin:point];\r
349 }\r
350 \r
351 - (BOOL)isDisplayed\r
352 {\r
353     return b_displayed;\r
354 }\r
355 \r
356 - (void)setVoutWasUpdated: (int)i_newdevice;\r
357 {\r
358     b_voutWasUpdated = YES;\r
359     if( i_newdevice != i_device )\r
360     {\r
361         i_device = i_newdevice;\r
362         [self center];\r
363     }\r
364 }\r
365 @end\r
366 \r
367 /*****************************************************************************\r
368  * FSPanelView\r
369  *****************************************************************************/\r
370 @implementation VLCFSPanelView\r
371 \r
372 #define addButton( o_button, imageOff, imageOn, _x, _y, action )                                \\r
373     s_rc.origin.x = _x;                                                                         \\r
374     s_rc.origin.y = _y;                                                                         \\r
375     o_button = [[NSButton alloc] initWithFrame: s_rc];                                 \\r
376     [o_button setButtonType: NSMomentaryChangeButton];                                          \\r
377     [o_button setBezelStyle: NSRegularSquareBezelStyle];                                        \\r
378     [o_button setBordered: NO];                                                                 \\r
379     [o_button setFont:[NSFont systemFontOfSize:0]];                                             \\r
380     [o_button setImage:[NSImage imageNamed:imageOff]];                                 \\r
381     [o_button setAlternateImage:[NSImage imageNamed:imageOn]];                         \\r
382     [o_button sizeToFit];                                                                       \\r
383     [o_button setTarget: self];                                                                 \\r
384     [o_button setAction: @selector(action:)];                                                   \\r
385     [self addSubview:o_button];\r
386 \r
387 #define addTextfield( o_text, align, font, color, size )                                    \\r
388     o_text = [[NSTextField alloc] initWithFrame: s_rc];                            \\r
389     [o_text setDrawsBackground: NO];                                                        \\r
390     [o_text setBordered: NO];                                                               \\r
391     [o_text setEditable: NO];                                                               \\r
392     [o_text setSelectable: NO];                                                             \\r
393     [o_text setStringValue: _NS("(no item is being played)")];                                                    \\r
394     [o_text setAlignment: align];                                                           \\r
395     [o_text setTextColor: [NSColor color]];                                                 \\r
396     [o_text setFont:[NSFont font:[NSFont smallSystemFontSize] - size]];                     \\r
397     [self addSubview:o_text];\r
398 \r
399 - (id)initWithFrame:(NSRect)frameRect\r
400 {\r
401     id view = [super initWithFrame:frameRect];\r
402     fillColor = [[NSColor clearColor] retain];\r
403     NSRect s_rc = [self frame];\r
404     addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev );\r
405     addButton( o_bwd, @"fs_rewind"        , @"fs_rewind_highlight"       , 211, 14, backward );\r
406     addButton( o_play, @"fs_play"          , @"fs_play_highlight"         , 267, 10, play );\r
407     addButton( o_fwd, @"fs_forward"       , @"fs_forward_highlight"      , 313, 14, forward );\r
408     addButton( o_next, @"fs_skip_next"     , @"fs_skip_next_highlight"    , 365, 15, next );\r
409     addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, windowAction );\r
410 /*\r
411     addButton( o_button, @"image (off state)", @"image (on state)", 38, 51, something );\r
412  */\r
413 \r
414     /* time slider */\r
415     s_rc = [self frame];\r
416     s_rc.origin.x = 15;\r
417     s_rc.origin.y = 53;\r
418     s_rc.size.width = 518;\r
419     s_rc.size.height = 9;\r
420     o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];\r
421     [o_fs_timeSlider setMinValue:0];\r
422     [o_fs_timeSlider setMaxValue:10000];\r
423     [o_fs_timeSlider setFloatValue: 0];\r
424     [o_fs_timeSlider setContinuous: YES];\r
425     [o_fs_timeSlider setTarget: self];\r
426     [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];\r
427     [self addSubview: o_fs_timeSlider];\r
428 \r
429     /* volume slider */\r
430     s_rc = [self frame];\r
431     s_rc.origin.x = 26;\r
432     s_rc.origin.y = 17.5;\r
433     s_rc.size.width = 95;\r
434     s_rc.size.height = 10;\r
435     o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];\r
436     [o_fs_volumeSlider setMinValue:0];\r
437     [o_fs_volumeSlider setMaxValue:32];\r
438     [o_fs_volumeSlider setFloatValue: 0];\r
439     [o_fs_volumeSlider setContinuous: YES];\r
440     [o_fs_volumeSlider setTarget: self];\r
441     [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];\r
442     [self addSubview: o_fs_volumeSlider];\r
443     \r
444     /* time counter and stream title output fields */\r
445     s_rc = [self frame];\r
446     s_rc.origin.x = 98;\r
447     s_rc.origin.y = 64;\r
448     s_rc.size.width = 352;\r
449     s_rc.size.height = 14;\r
450     addTextfield( o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );\r
451     s_rc.origin.x = 486;\r
452     s_rc.origin.y = 64;\r
453     s_rc.size.width = 50;\r
454     addTextfield( o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor, 0 );\r
455 \r
456     return view;\r
457 }\r
458 \r
459 - (void)dealloc\r
460 {\r
461     [o_fs_timeSlider release];\r
462     [o_fs_volumeSlider release];\r
463     [o_prev release];\r
464     [o_next release];\r
465     [o_bwd release];\r
466     [o_play release];\r
467     [o_fwd release];\r
468     [o_fullscreen release];\r
469     [o_streamTitle_txt release];\r
470     [o_streamPosition_txt release];\r
471     [super dealloc];\r
472 }\r
473 \r
474 - (void)setPlay\r
475 {\r
476     [o_play setImage:[NSImage imageNamed:@"fs_play"]];\r
477     [o_play setAlternateImage: [NSImage imageNamed:@"fs_play_highlight"]];\r
478 }\r
479 \r
480 - (void)setPause\r
481 {\r
482     [o_play setImage: [NSImage imageNamed:@"fs_pause"]];\r
483     [o_play setAlternateImage: [NSImage imageNamed:@"fs_pause_highlight"]];\r
484 }\r
485 \r
486 - (void)setStreamTitle:(NSString *)o_title\r
487 {\r
488     [o_streamTitle_txt setStringValue: o_title];\r
489 }\r
490 \r
491 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time\r
492 {\r
493     [o_streamPosition_txt setStringValue: o_time];\r
494     [o_fs_timeSlider setFloatValue: f_pos];\r
495 }\r
496 \r
497 - (void)setSeekable:(BOOL)b_seekable\r
498 {\r
499     [o_bwd setEnabled: b_seekable];\r
500     [o_fwd setEnabled: b_seekable];\r
501     [o_fs_timeSlider setEnabled: b_seekable];\r
502 }\r
503 \r
504 - (void)setVolumeLevel: (float)f_volumeLevel\r
505 {\r
506     [o_fs_volumeSlider setFloatValue: f_volumeLevel];\r
507 }\r
508 \r
509 - (IBAction)play:(id)sender\r
510 {\r
511     [[[VLCMain sharedInstance] getControls] play: sender];\r
512 }\r
513 \r
514 - (IBAction)forward:(id)sender\r
515 {\r
516     [[[VLCMain sharedInstance] getControls] forward: sender];\r
517 }\r
518 \r
519 - (IBAction)backward:(id)sender\r
520 {\r
521     [[[VLCMain sharedInstance] getControls] backward: sender];\r
522 }\r
523 \r
524 - (IBAction)prev:(id)sender\r
525 {\r
526     [[[VLCMain sharedInstance] getControls] prev: sender];\r
527 }\r
528 \r
529 - (IBAction)next:(id)sender\r
530 {\r
531     [[[VLCMain sharedInstance] getControls] next: sender];\r
532 }\r
533 \r
534 - (IBAction)windowAction:(id)sender\r
535 {\r
536     [[[VLCMain sharedInstance] getControls] windowAction: sender];\r
537 }\r
538 \r
539 - (IBAction)fsTimeSliderUpdate:(id)sender\r
540 {\r
541     [[VLCMain sharedInstance] timesliderUpdate: sender];\r
542 }\r
543 \r
544 - (IBAction)fsVolumeSliderUpdate:(id)sender\r
545 {\r
546     [[[VLCMain sharedInstance] getControls] volumeSliderUpdated: sender];\r
547 }\r
548 \r
549 #define addImage(image, _x, _y, mode, _width)                                               \\r
550     img = [NSImage imageNamed:image];                                              \\r
551     image_rect.size = [img size];                                                           \\r
552     image_rect.origin.x = 0;                                                                \\r
553     image_rect.origin.y = 0;                                                                \\r
554     frame.origin.x = _x;                                                                    \\r
555     frame.origin.y = _y;                                                                    \\r
556     frame.size = [img size];                                                                \\r
557     if( _width ) frame.size.width = _width;                                                 \\r
558     [img drawInRect:frame fromRect:image_rect operation:mode fraction:1];\r
559 \r
560 - (void)drawRect:(NSRect)rect\r
561 {\r
562         NSRect frame = [self frame];\r
563     NSRect image_rect;\r
564     NSImage *img;\r
565     addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 );\r
566     addImage( @"fs_volume_slider_bar", 26, 22, NSCompositeSourceOver, 0 );\r
567     addImage( @"fs_volume_mute", 16, 18, NSCompositeSourceOver, 0 );\r
568     addImage( @"fs_volume_max", 124, 17, NSCompositeSourceOver, 0 );\r
569     addImage( @"fs_time_slider", 15, 53, NSCompositeSourceOver, 0);\r
570 }\r
571 \r
572 @end\r
573 \r
574 /*****************************************************************************\r
575  * VLCFSTimeSlider\r
576  *****************************************************************************/\r
577 @implementation VLCFSTimeSlider\r
578 - (void)drawKnobInRect:(NSRect)knobRect\r
579 {\r
580     NSRect image_rect;\r
581     NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];\r
582     image_rect.size = [img size];\r
583     image_rect.origin.x = 0;\r
584     image_rect.origin.y = 0;\r
585     knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;\r
586     knobRect.size.width = image_rect.size.width;\r
587     knobRect.size.height = image_rect.size.height;\r
588     [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];\r
589 }\r
590 \r
591 - (void)drawRect:(NSRect)rect\r
592 {\r
593     /* Draw default to make sure the slider behaves correctly */\r
594     [[NSGraphicsContext currentContext] saveGraphicsState];\r
595     NSRectClip(NSZeroRect);\r
596     [super drawRect:rect];\r
597     [[NSGraphicsContext currentContext] restoreGraphicsState];\r
598     \r
599     NSRect knobRect = [[self cell] knobRectFlipped:NO];\r
600     knobRect.origin.y+=7.5;\r
601     [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];\r
602     [self drawKnobInRect: knobRect];\r
603 }\r
604 \r
605 @end\r
606 \r
607 /*****************************************************************************\r
608 * VLCFSVolumeSlider\r
609 *****************************************************************************/\r
610 @implementation VLCFSVolumeSlider\r
611 - (void)drawKnobInRect:(NSRect) knobRect\r
612 {\r
613     NSRect image_rect;\r
614     NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];\r
615     image_rect.size = [img size];\r
616     image_rect.origin.x = 0;\r
617     image_rect.origin.y = 0;\r
618     knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;\r
619     knobRect.size.width = image_rect.size.width;\r
620     knobRect.size.height = image_rect.size.height;\r
621     [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];\r
622 }\r
623 \r
624 - (void)drawRect:(NSRect)rect\r
625 {\r
626     /* Draw default to make sure the slider behaves correctly */\r
627     [[NSGraphicsContext currentContext] saveGraphicsState];\r
628     NSRectClip(NSZeroRect);\r
629     [super drawRect:rect];\r
630     [[NSGraphicsContext currentContext] restoreGraphicsState];\r
631     \r
632     NSRect knobRect = [[self cell] knobRectFlipped:NO];\r
633     knobRect.origin.y+=6;\r
634     [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];\r
635     [self drawKnobInRect: knobRect];\r
636 }\r
637 \r
638 @end\r
639 \r