fspanel.m
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:21k
源码类别:

midi

开发平台:

Unix_Linux

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