fspanel.m 21.5 KB
Newer Older
1
2
3
/*****************************************************************************
 * fspanel.m: MacOS X full screen panel
 *****************************************************************************
4
 * Copyright (C) 2006-2007 the VideoLAN team
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 * $Id$
 *
 * Authors: Jrme Decoodt <djc at videolan dot org>
 *          Felix Khne <fkuehne at videolan dot org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#import "intf.h"
29
30
#import "controls.h"
#import "vout.h"
31
32
#import "fspanel.h"

33
#define KEEP_VISIBLE_AFTER_ACTION 4 /* time in half-sec until this panel will hide again after a user's action */
34
35
36
37
38

/*****************************************************************************
 * VLCFSPanel
 *****************************************************************************/
@implementation VLCFSPanel
39
/* We override this initializer so we can set the NSBorderlessWindowMask styleMask, and set a few other important settings */
40
41
42
43
44
- (id)initWithContentRect:(NSRect)contentRect 
                styleMask:(unsigned int)aStyle 
                  backing:(NSBackingStoreType)bufferingType 
                    defer:(BOOL)flag
{
hartman's avatar
hartman committed
45
    id win = [super initWithContentRect:contentRect styleMask:NSTexturedBackgroundWindowMask backing:bufferingType defer:flag];
46
47
48
    [win setOpaque:NO];
    [win setHasShadow: NO];
    [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
    [win setAlphaValue:0.0];
hartman's avatar
hartman committed
53
54
55
    i_device = 0;

    [win center];
56
57
58
59
60
61
    return win;
}

- (void)awakeFromNib
{
    [self setContentView:[[VLCFSPanelView alloc] initWithFrame: [self frame]]];
hartman's avatar
hartman committed
62
    BOOL isInside = (NSPointInRect([NSEvent mouseLocation],[self frame]));
63
64
    [[self contentView] addTrackingRect:[[self contentView] bounds] owner:self userData:nil assumeInside:isInside];
    if (isInside)
hartman's avatar
hartman committed
65
        [self mouseEntered:NULL];
66
    if (!isInside)
hartman's avatar
hartman committed
67
        [self mouseExited:NULL];
68
69
70
71
72
73
74
75
76
77
78
79
80
81
    
    /* get a notification if VLC isn't the active app anymore */
    [[NSNotificationCenter defaultCenter]
    addObserver: self
       selector: @selector(setNonActive:)
           name: NSApplicationDidResignActiveNotification
         object: NSApp];
    
    /* get a notification if VLC is the active app again */
    [[NSNotificationCenter defaultCenter]
    addObserver: self
       selector: @selector(setActive:)
           name: NSApplicationDidBecomeActiveNotification
         object: NSApp];
82
83
}

84
/* Windows created with NSBorderlessWindowMask normally can't be key, but we want ours to be */
85
86
87
88
89
- (BOOL)canBecomeKeyWindow
{
    return YES;
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
90
91
92
93
94
- (BOOL)mouseDownCanMoveWindow
{
    return YES;
}

95
96
97
98
99
100
101
102
103
104
105
#if GC_ENABLED
- (void)finalize
{
	/* dealloc isn't called on 10.5 in case that GC is enabled, so we need to provide the functionality here */
	[[NSNotificationCenter defaultCenter] removeObserver: self];
	[self setFadeTimer:nil];
	
	[super finalize];
}
#endif

106
107
-(void)dealloc
{
108
109
    [[NSNotificationCenter defaultCenter] removeObserver: self];
    
110
111
112
113
114
115
    if( hideAgainTimer )
        [hideAgainTimer release];
    [self setFadeTimer:nil];
    [super dealloc];
}

hartman's avatar
hartman committed
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
-(void)center
{
    /* centre the panel in the lower third of the screen */
    NSPoint theCoordinate;
    NSRect theScreensFrame;
    NSRect theWindowsFrame;

    if( i_device < 0 || i_device >= (signed int)[[NSScreen screens] count] )
        /* invalid preferences or none specified, using main screen */
        theScreensFrame = [[NSScreen mainScreen] frame];
    else
        /* user-defined screen */
        theScreensFrame = [[[NSScreen screens] objectAtIndex: i_device] frame];

    theWindowsFrame = [self frame];
    
    theCoordinate.x = (theScreensFrame.size.width - theWindowsFrame.size.width) / 2 + theScreensFrame.origin.x;
    theCoordinate.y = (theScreensFrame.size.height / 3) - theWindowsFrame.size.height + theScreensFrame.origin.y;
    [self setFrameTopLeftPoint: theCoordinate];
}

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
- (void)setPlay
{
    [[self contentView] setPlay];
}

- (void)setPause
{
    [[self contentView] setPause];
}

- (void)setStreamTitle:(NSString *)o_title
{
    [[self contentView] setStreamTitle: o_title];
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
152
153
154
155
156
- (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
{
    [[self contentView] setStreamPos:f_pos andTime: o_time];
}

157
- (void)setSeekable:(BOOL) b_seekable
158
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
159
    [[self contentView] setSeekable: b_seekable];
160
161
}

162
163
164
165
166
- (void)setVolumeLevel: (float)f_volumeLevel
{
    [[self contentView] setVolumeLevel: f_volumeLevel];
}

167
168
169
170
- (void)setNonActive:(id)noData
{
    b_nonActive = YES;
    [self orderOut: self];
171
172
173
174
175
176
    
    /* here's fadeOut, just without visibly fading */
    b_displayed = NO;
    [self setAlphaValue:0.0];
    [self setFadeTimer:nil];
    b_fadeQueued = NO;
177
178
179
180
}

- (void)setActive:(id)noData
{
181
182
183
184
185
    if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )
    {
        b_nonActive = NO;
        [self fadeIn];
    }
186
187
}

188
/* This routine is called repeatedly to fade in the window */
189
190
- (void)focus:(NSTimer *)timer
{
191
192
193
194
195
196
197
    /* we need to push ourselves to front if the vout window was closed since our last display */
    if( b_voutWasUpdated )
    {
        [self orderFront: self];
        b_voutWasUpdated = NO;
    }

198
199
200
201
    if( [self alphaValue] < 1.0 )
        [self setAlphaValue:[self alphaValue]+0.1];
    if( [self alphaValue] >= 1.0 )
    {
202
        b_displayed = YES;
203
204
205
206
207
208
209
210
211
212
        [self setAlphaValue: 1.0];
        [self setFadeTimer:nil];
        if( b_fadeQueued )
        {
            b_fadeQueued=NO;
            [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];
        }
    }
}

213
/* This routine is called repeatedly to hide the window */
214
215
- (void)unfocus:(NSTimer *)timer
{
216
217
218
219
220
221
222
223
    if( b_keptVisible )
    {
        b_keptVisible = NO;
        b_fadeQueued = NO;
        [self setFadeTimer: NULL];
        [self fadeIn];
        return;
    }
224
225
226
227
    if( [self alphaValue] > 0.0 )
        [self setAlphaValue:[self alphaValue]-0.1];
    if( [self alphaValue] <= 0.1 )
    {
228
        b_displayed = NO;
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
        [self setAlphaValue:0.0];
        [self setFadeTimer:nil];
        if( b_fadeQueued )
        {
            b_fadeQueued=NO;
            [self setFadeTimer:
                [NSTimer scheduledTimerWithTimeInterval:0.1 
                                                 target:self 
                                               selector:@selector(focus:) 
                                               userInfo:NULL 
                                                repeats:YES]];
        }
    }
}

- (void)mouseExited:(NSEvent *)theEvent
{
246
247
248
    /* give up our focus, so the vout may show us again without letting the user clicking it */
    if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )
        [[[[[VLCMain sharedInstance] getControls] getVoutView] window] makeKeyWindow];
249
250
251
252
}

- (void)fadeIn
{
253
    /* in case that the user don't want us to appear, just return here */
254
    if(! config_GetInt( VLCIntf, "macosx-fspanel" ) || b_nonActive )
255
256
        return;
    
257
258
259
    [self orderFront: nil];
    
    if( [self alphaValue] < 1.0 || b_displayed != YES )
260
261
    {
        if (![self fadeTimer])
262
            [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];
263
264
265
266
267
268
269
270
        else if ([[[self fadeTimer] userInfo] shortValue]==0)
            b_fadeQueued=YES;
    }
    [self autoHide];
}

- (void)fadeOut
{
hartman's avatar
hartman committed
271
272
273
    if( NSPointInRect([NSEvent mouseLocation],[self frame]))
        return;

274
    if( ( [self alphaValue] > 0.0 ) )
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
    {
        if (![self fadeTimer])
            [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];
        else if ([[[self fadeTimer] userInfo] shortValue]==1)
            b_fadeQueued=YES;
    }
}

/* triggers a timer to autoHide us again after some seconds of no activity */
- (void)autoHide
{
    /* this will tell the timer to start over again or to start at all */
    b_keptVisible = YES;
    
    /* get us a valid timer */
    if(! b_alreadyCounting )
    {
        hideAgainTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5
                                                          target: self 
                                                        selector: @selector(keepVisible:)
                                                        userInfo: nil 
                                                         repeats: YES];
        [hideAgainTimer fire];
        [hideAgainTimer retain];
        b_alreadyCounting = YES;
    }
}

- (void)keepVisible:(NSTimer *)timer
{
    /* if the user triggered an action, start over again */
    if( b_keptVisible )
    {
        i_timeToKeepVisibleInSec = KEEP_VISIBLE_AFTER_ACTION;
        b_keptVisible = NO;
    }
    
    /* count down until we hide ourselfes again and do so if necessary */
    i_timeToKeepVisibleInSec -= 1;
    if( i_timeToKeepVisibleInSec < 1 )
    {
        [self fadeOut];
        [timer invalidate];
        [timer release];
        b_alreadyCounting = NO;
        timer = NULL;
    }
}

324
/* A getter and setter for our main timer that handles window fading */
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
- (NSTimer *)fadeTimer
{
    return fadeTimer;
}

- (void)setFadeTimer:(NSTimer *)timer
{
    [timer retain];
    [fadeTimer invalidate];
    [fadeTimer release];
    fadeTimer=timer;
}

- (void)mouseDown:(NSEvent *)theEvent
{
    mouseClic = [theEvent locationInWindow];
}

- (void)mouseDragged:(NSEvent *)theEvent
{
    NSPoint point = [NSEvent mouseLocation];
    point.x -= mouseClic.x;
    point.y -= mouseClic.y;
    [self setFrameOrigin:point];
}
350
351
352
353
354
355

- (BOOL)isDisplayed
{
    return b_displayed;
}

hartman's avatar
hartman committed
356
- (void)setVoutWasUpdated: (int)i_newdevice;
357
358
{
    b_voutWasUpdated = YES;
hartman's avatar
hartman committed
359
360
361
362
363
    if( i_newdevice != i_device )
    {
        i_device = i_newdevice;
        [self center];
    }
364
}
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
@end

/*****************************************************************************
 * FSPanelView
 *****************************************************************************/
@implementation VLCFSPanelView

#define addButton( o_button, imageOff, imageOn, _x, _y, action )                                \
    s_rc.origin.x = _x;                                                                         \
    s_rc.origin.y = _y;                                                                         \
    o_button = [[NSButton alloc] initWithFrame: s_rc];                                 \
    [o_button setButtonType: NSMomentaryChangeButton];                                          \
    [o_button setBezelStyle: NSRegularSquareBezelStyle];                                        \
    [o_button setBordered: NO];                                                                 \
    [o_button setFont:[NSFont systemFontOfSize:0]];                                             \
380
381
    [o_button setImage:[NSImage imageNamed:imageOff]];                                 \
    [o_button setAlternateImage:[NSImage imageNamed:imageOn]];                         \
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
    [o_button sizeToFit];                                                                       \
    [o_button setTarget: self];                                                                 \
    [o_button setAction: @selector(action:)];                                                   \
    [self addSubview:o_button];

#define addTextfield( o_text, align, font, color, size )                                    \
    o_text = [[NSTextField alloc] initWithFrame: s_rc];                            \
    [o_text setDrawsBackground: NO];                                                        \
    [o_text setBordered: NO];                                                               \
    [o_text setEditable: NO];                                                               \
    [o_text setSelectable: NO];                                                             \
    [o_text setStringValue: _NS("(no item is being played)")];                                                    \
    [o_text setAlignment: align];                                                           \
    [o_text setTextColor: [NSColor color]];                                                 \
    [o_text setFont:[NSFont font:[NSFont smallSystemFontSize] - size]];                     \
    [self addSubview:o_text];

- (id)initWithFrame:(NSRect)frameRect
{
    id view = [super initWithFrame:frameRect];
    fillColor = [[NSColor clearColor] retain];
    NSRect s_rc = [self frame];
404
    addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev );
405
    addButton( o_bwd, @"fs_rewind"        , @"fs_rewind_highlight"       , 211, 14, backward );
406
    addButton( o_play, @"fs_play"          , @"fs_play_highlight"         , 267, 10, play );
407
    addButton( o_fwd, @"fs_forward"       , @"fs_forward_highlight"      , 313, 14, forward );
408
409
    addButton( o_next, @"fs_skip_next"     , @"fs_skip_next_highlight"    , 365, 15, next );
    addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, windowAction );
410
/*
411
    addButton( o_button, @"image (off state)", @"image (on state)", 38, 51, something );
412
 */
413

414
    /* time slider */
415
    s_rc = [self frame];
416
417
418
419
    s_rc.origin.x = 15;
    s_rc.origin.y = 53;
    s_rc.size.width = 518;
    s_rc.size.height = 9;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
420
421
422
423
424
425
426
427
    o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];
    [o_fs_timeSlider setMinValue:0];
    [o_fs_timeSlider setMaxValue:10000];
    [o_fs_timeSlider setFloatValue: 0];
    [o_fs_timeSlider setContinuous: YES];
    [o_fs_timeSlider setTarget: self];
    [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];
    [self addSubview: o_fs_timeSlider];
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442

    /* volume slider */
    s_rc = [self frame];
    s_rc.origin.x = 26;
    s_rc.origin.y = 17.5;
    s_rc.size.width = 95;
    s_rc.size.height = 10;
    o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];
    [o_fs_volumeSlider setMinValue:0];
    [o_fs_volumeSlider setMaxValue:32];
    [o_fs_volumeSlider setFloatValue: 0];
    [o_fs_volumeSlider setContinuous: YES];
    [o_fs_volumeSlider setTarget: self];
    [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];
    [self addSubview: o_fs_volumeSlider];
443
    
444
    /* time counter and stream title output fields */
445
    s_rc = [self frame];
446
447
448
449
    s_rc.origin.x = 98;
    s_rc.origin.y = 64;
    s_rc.size.width = 352;
    s_rc.size.height = 14;
450
    addTextfield( o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );
451
452
    s_rc.origin.x = 486;
    s_rc.origin.y = 64;
453
    s_rc.size.width = 50;
454
    addTextfield( o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor, 0 );
455
456
457
458

    return view;
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
459
460
461
- (void)dealloc
{
    [o_fs_timeSlider release];
462
463
464
    [o_fs_volumeSlider release];
    [o_prev release];
    [o_next release];
465
    [o_bwd release];
466
    [o_play release];
467
    [o_fwd release];
468
469
470
    [o_fullscreen release];
    [o_streamTitle_txt release];
    [o_streamPosition_txt release];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
471
472
473
    [super dealloc];
}

474
475
- (void)setPlay
{
hartman's avatar
hartman committed
476
477
    [o_play setImage:[NSImage imageNamed:@"fs_play"]];
    [o_play setAlternateImage: [NSImage imageNamed:@"fs_play_highlight"]];
478
479
480
481
}

- (void)setPause
{
hartman's avatar
hartman committed
482
483
    [o_play setImage: [NSImage imageNamed:@"fs_pause"]];
    [o_play setAlternateImage: [NSImage imageNamed:@"fs_pause_highlight"]];
484
485
486
487
}

- (void)setStreamTitle:(NSString *)o_title
{
488
    [o_streamTitle_txt setStringValue: o_title];
489
490
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
491
- (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
492
{
493
    [o_streamPosition_txt setStringValue: o_time];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
494
495
    [o_fs_timeSlider setFloatValue: f_pos];
}
496

Felix Paul Kühne's avatar
Felix Paul Kühne committed
497
498
- (void)setSeekable:(BOOL)b_seekable
{
499
500
    [o_bwd setEnabled: b_seekable];
    [o_fwd setEnabled: b_seekable];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
501
    [o_fs_timeSlider setEnabled: b_seekable];
502
503
}

504
505
506
507
508
- (void)setVolumeLevel: (float)f_volumeLevel
{
    [o_fs_volumeSlider setFloatValue: f_volumeLevel];
}

509
510
511
512
513
- (IBAction)play:(id)sender
{
    [[[VLCMain sharedInstance] getControls] play: sender];
}

514
- (IBAction)forward:(id)sender
515
{
516
    [[[VLCMain sharedInstance] getControls] forward: sender];
517
518
}

519
- (IBAction)backward:(id)sender
520
{
521
    [[[VLCMain sharedInstance] getControls] backward: sender];
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
}

- (IBAction)prev:(id)sender
{
    [[[VLCMain sharedInstance] getControls] prev: sender];
}

- (IBAction)next:(id)sender
{
    [[[VLCMain sharedInstance] getControls] next: sender];
}

- (IBAction)windowAction:(id)sender
{
    [[[VLCMain sharedInstance] getControls] windowAction: sender];
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
539
- (IBAction)fsTimeSliderUpdate:(id)sender
540
541
542
543
{
    [[VLCMain sharedInstance] timesliderUpdate: sender];
}

544
545
546
547
548
- (IBAction)fsVolumeSliderUpdate:(id)sender
{
    [[[VLCMain sharedInstance] getControls] volumeSliderUpdated: sender];
}

549
#define addImage(image, _x, _y, mode, _width)                                               \
550
    img = [NSImage imageNamed:image];                                              \
551
552
553
554
555
556
557
558
559
560
561
562
563
564
    image_rect.size = [img size];                                                           \
    image_rect.origin.x = 0;                                                                \
    image_rect.origin.y = 0;                                                                \
    frame.origin.x = _x;                                                                    \
    frame.origin.y = _y;                                                                    \
    frame.size = [img size];                                                                \
    if( _width ) frame.size.width = _width;                                                 \
    [img drawInRect:frame fromRect:image_rect operation:mode fraction:1];

- (void)drawRect:(NSRect)rect
{
	NSRect frame = [self frame];
    NSRect image_rect;
    NSImage *img;
565
566
567
568
569
    addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 );
    addImage( @"fs_volume_slider_bar", 26, 22, NSCompositeSourceOver, 0 );
    addImage( @"fs_volume_mute", 16, 18, NSCompositeSourceOver, 0 );
    addImage( @"fs_volume_max", 124, 17, NSCompositeSourceOver, 0 );
    addImage( @"fs_time_slider", 15, 53, NSCompositeSourceOver, 0);
570
571
572
573
574
575
576
577
}

@end

/*****************************************************************************
 * VLCFSTimeSlider
 *****************************************************************************/
@implementation VLCFSTimeSlider
578
- (void)drawKnobInRect:(NSRect)knobRect
579
580
{
    NSRect image_rect;
581
    NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];
582
583
584
585
586
587
588
589
590
    image_rect.size = [img size];
    image_rect.origin.x = 0;
    image_rect.origin.y = 0;
    knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
    knobRect.size.width = image_rect.size.width;
    knobRect.size.height = image_rect.size.height;
    [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
}

591
- (void)drawRect:(NSRect)rect
592
{
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
    /* Draw default to make sure the slider behaves correctly */
    [[NSGraphicsContext currentContext] saveGraphicsState];
    NSRectClip(NSZeroRect);
    [super drawRect:rect];
    [[NSGraphicsContext currentContext] restoreGraphicsState];
    
    NSRect knobRect = [[self cell] knobRectFlipped:NO];
    knobRect.origin.y+=7.5;
    [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
    [self drawKnobInRect: knobRect];
}

@end

/*****************************************************************************
* VLCFSVolumeSlider
*****************************************************************************/
@implementation VLCFSVolumeSlider
- (void)drawKnobInRect:(NSRect) knobRect
{
    NSRect image_rect;
    NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];
    image_rect.size = [img size];
    image_rect.origin.x = 0;
    image_rect.origin.y = 0;
    knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
    knobRect.size.width = image_rect.size.width;
    knobRect.size.height = image_rect.size.height;
    [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
622
623
}

624
625
- (void)drawRect:(NSRect)rect
{
626
    /* Draw default to make sure the slider behaves correctly */
627
628
629
630
631
632
    [[NSGraphicsContext currentContext] saveGraphicsState];
    NSRectClip(NSZeroRect);
    [super drawRect:rect];
    [[NSGraphicsContext currentContext] restoreGraphicsState];
    
    NSRect knobRect = [[self cell] knobRectFlipped:NO];
633
    knobRect.origin.y+=6;
634
    [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
635
    [self drawKnobInRect: knobRect];
636
637
}

hartman's avatar
hartman committed
638
639
@end