fspanel.m 26.5 KB
Newer Older
1 2 3
/*****************************************************************************
 * fspanel.m: MacOS X full screen panel
 *****************************************************************************
4
 * Copyright (C) 2006-2013 VLC authors and VideoLAN
5 6 7 8
 * $Id$
 *
 * Authors: Jérôme Decoodt <djc at videolan dot org>
 *          Felix Paul Kühne <fkuehne at videolan dot org>
9
 *          David Fuhrmann <david dot fuhrmann at googlemail dot com>
10 11 12 13 14
 *
 * 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.
15
 *
16 17 18 19 20 21 22 23 24 25 26 27 28 29
 * 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"
30
#import "VLCCoreInteraction.h"
31
#import "VLCMainWindow.h"
32 33
#import "misc.h"
#import "fspanel.h"
34
#import "CompatibilityFixes.h"
35

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
@interface VLCFSPanel()
{
    NSTimer *fadeTimer,*hideAgainTimer;
    NSPoint mouseClic;
    BOOL b_fadeQueued;
    BOOL b_keptVisible;
    BOOL b_alreadyCounting;
    int i_timeToKeepVisibleInSec;

    BOOL b_nonActive;
    BOOL b_displayed;
    BOOL b_voutWasUpdated;
    int i_device;

    VLCWindow *o_vout_window;
}

53 54 55
- (void)hideMouse;
@end

56 57 58 59 60
/*****************************************************************************
 * VLCFSPanel
 *****************************************************************************/
@implementation VLCFSPanel
/* We override this initializer so we can set the NSBorderlessWindowMask styleMask, and set a few other important settings */
61 62 63
- (id)initWithContentRect:(NSRect)contentRect
                styleMask:(NSUInteger)aStyle
                  backing:(NSBackingStoreType)bufferingType
64 65 66
                    defer:(BOOL)flag
{
    id win = [super initWithContentRect:contentRect styleMask:NSTexturedBackgroundWindowMask backing:bufferingType defer:flag];
67 68 69 70

    if (!win)
        return win;

71
    self.contentView = [[VLCFSPanelView alloc] initWithFrame:contentRect];
72 73 74
    [win setOpaque:NO];
    [win setHasShadow: NO];
    [win setBackgroundColor:[NSColor clearColor]];
75
    [win setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
76

77 78
    /* let the window sit on top of everything else and start out completely transparent */
    [win setLevel:NSModalPanelWindowLevel];
79
    i_device = config_GetInt(getIntf(), "macosx-vdev");
80
    hideAgainTimer = fadeTimer = nil;
81
    [self setFrameAutosaveName:@"fspanel"];
82 83 84 85 86 87 88 89 90
    [self setNonActive:nil];

    [self setContentView:[[VLCFSPanelView alloc] initWithFrame: [self frame]]];
    BOOL isInside = (NSPointInRect([NSEvent mouseLocation],[self frame]));
    [[self contentView] addTrackingRect:[[self contentView] bounds] owner:self userData:nil assumeInside:isInside];
    if (isInside)
        [self mouseEntered:NULL];
    if (!isInside)
        [self mouseExited:NULL];
91

92
    [self setAnimationBehavior:NSWindowAnimationBehaviorNone];
93

94 95
    /* get a notification if VLC isn't the active app anymore */
    [[NSNotificationCenter defaultCenter]
96 97 98 99
     addObserver: self
     selector: @selector(setNonActive:)
     name: NSApplicationDidResignActiveNotification
     object: NSApp];
100

101 102
    /* Get a notification if VLC is the active app again.
     Needed as becomeKeyWindow does not get called when window is activated by clicking */
103
    [[NSNotificationCenter defaultCenter]
104 105 106 107 108 109
     addObserver: self
     selector: @selector(setActive:)
     name: NSApplicationDidBecomeActiveNotification
     object: NSApp];

    return win;
110 111
}

112
/* make sure that we don't become key, since we can't handle hotkeys */
113 114
- (BOOL)canBecomeKeyWindow
{
115
    return NO;
116 117 118 119 120 121 122 123 124 125
}

- (BOOL)mouseDownCanMoveWindow
{
    return YES;
}

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver: self];
126

127
    if (hideAgainTimer) {
128 129
        [hideAgainTimer invalidate];
    }
130

131 132 133 134 135 136 137 138 139 140
    [self setFadeTimer:nil];
}

-(void)center
{
    /* centre the panel in the lower third of the screen */
    NSPoint theCoordinate;
    NSRect theScreensFrame;
    NSRect theWindowsFrame;
    NSScreen *screen;
141

142 143
    /* user-defined screen */
    screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
144

145 146 147 148 149 150
    if (!screen)
        /* invalid preferences or none specified, using main screen */
        screen = [NSScreen mainScreen];

    theScreensFrame = [screen frame];
    theWindowsFrame = [self frame];
151

152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
    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];
}

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

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

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

172
- (void)updatePositionAndTime
173
{
174
    [[self contentView] updatePositionAndTime];
175 176 177 178 179 180 181
}

- (void)setSeekable:(BOOL) b_seekable
{
    [[self contentView] setSeekable: b_seekable];
}

182
- (void)setVolumeLevel: (int)i_volumeLevel
183
{
184
    [[self contentView] setVolumeLevel: i_volumeLevel];
185 186 187 188 189
}

- (void)setNonActive:(id)noData
{
    b_nonActive = YES;
190

191 192 193 194
    /* here's fadeOut, just without visibly fading */
    b_displayed = NO;
    [self setAlphaValue:0.0];
    [self setFadeTimer:nil];
195

196
    b_fadeQueued = NO;
197 198

    [self orderOut: self];
199 200 201 202
}

- (void)setActive:(id)noData
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
203
    b_nonActive = NO;
204

205
    [[VLCMain sharedInstance] showFullscreenController];
206 207 208 209 210 211
}

/* This routine is called repeatedly to fade in the window */
- (void)focus:(NSTimer *)timer
{
    /* we need to push ourselves to front if the vout window was closed since our last display */
212
    if (b_voutWasUpdated) {
213 214 215 216
        [self orderFront: self];
        b_voutWasUpdated = NO;
    }

217
    if ([self alphaValue] < 1.0) {
218
        [self setAlphaValue:[self alphaValue]+0.1];
219
    }
220
    if ([self alphaValue] >= 1.0) {
221 222 223
        b_displayed = YES;
        [self setAlphaValue: 1.0];
        [self setFadeTimer:nil];
224
        if (b_fadeQueued) {
225 226 227 228 229 230 231 232 233
            b_fadeQueued=NO;
            [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];
        }
    }
}

/* This routine is called repeatedly to hide the window */
- (void)unfocus:(NSTimer *)timer
{
234
    if (b_keptVisible) {
235 236 237 238 239 240
        b_keptVisible = NO;
        b_fadeQueued = NO;
        [self setFadeTimer: NULL];
        [self fadeIn];
        return;
    }
241
    if ([self alphaValue] > 0.0) {
242
        [self setAlphaValue:[self alphaValue]-0.05];
243
    }
244
    if ([self alphaValue] <= 0.05) {
245 246 247
        b_displayed = NO;
        [self setAlphaValue:0.0];
        [self setFadeTimer:nil];
248
        if (b_fadeQueued) {
249 250
            b_fadeQueued=NO;
            [self setFadeTimer:
251 252 253 254
                [NSTimer scheduledTimerWithTimeInterval:0.1
                                                 target:self
                                               selector:@selector(focus:)
                                               userInfo:NULL
255 256 257 258 259 260 261 262
                                                repeats:YES]];
        }
    }
}

- (void)mouseExited:(NSEvent *)theEvent
{
    /* give up our focus, so the vout may show us again without letting the user clicking it */
263
    if (o_vout_window && var_GetBool(pl_Get(getIntf()), "fullscreen"))
264
        [o_vout_window makeKeyWindow];
265 266
}

267 268 269 270 271
- (void)hideMouse
{
    [NSCursor setHiddenUntilMouseMoves: YES];
}

272 273
- (void)fadeIn
{
274 275
    /* in case that the user don't want us to appear, make sure we hide the mouse */

276 277
    if (!config_GetInt(getIntf(), "macosx-fspanel")) {
        float time = (float)var_CreateGetInteger(getIntf(), "mouse-hide-timeout") / 1000.;
278 279 280 281
        [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:time target:self selector:@selector(hideMouse) userInfo:nil repeats:NO]];
        return;
    }

282
    if (b_nonActive)
283
        return;
284

285
    [self orderFront: nil];
286

287
    if ([self alphaValue] < 1.0 || b_displayed != YES) {
288
        if (![self fadeTimer])
289
            [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithInt:1] repeats:YES]];
290 291 292 293 294 295 296 297
        else if ([[[self fadeTimer] userInfo] shortValue]==0)
            b_fadeQueued=YES;
    }
    [self autoHide];
}

- (void)fadeOut
{
298
    if (NSPointInRect([NSEvent mouseLocation],[self frame]))
299 300
        return;

301
    if (([self alphaValue] > 0.0)) {
302
        if (![self fadeTimer])
303
            [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithInt:0] repeats:YES]];
304 305 306 307 308 309 310 311 312 313
        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;
314

315
    /* get us a valid timer */
316
    if (!b_alreadyCounting) {
317
        i_timeToKeepVisibleInSec = var_CreateGetInteger(getIntf(), "mouse-hide-timeout") / 500;
318
        if (hideAgainTimer) {
319 320 321
            [hideAgainTimer invalidate];
        }
        /* released in -autoHide and -dealloc */
322
        hideAgainTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5
323
                                                          target: self
324
                                                        selector: @selector(keepVisible:)
325
                                                        userInfo: nil
326
                                                         repeats: YES];
327 328 329 330 331 332 333
        b_alreadyCounting = YES;
    }
}

- (void)keepVisible:(NSTimer *)timer
{
    /* if the user triggered an action, start over again */
334
    if (b_keptVisible)
335 336 337
        b_keptVisible = NO;

    /* count down until we hide ourselfes again and do so if necessary */
338
    if (--i_timeToKeepVisibleInSec < 1) {
339
        [self hideMouse];
340
        [self fadeOut];
341
        [hideAgainTimer invalidate]; /* released in -autoHide and -dealloc */
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
        b_alreadyCounting = NO;
    }
}

/* A getter and setter for our main timer that handles window fading */
- (NSTimer *)fadeTimer
{
    return fadeTimer;
}

- (void)setFadeTimer:(NSTimer *)timer
{
    [fadeTimer invalidate];
    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];
}

371
- (void)setVoutWasUpdated: (VLCWindow *)o_window
372 373
{
    b_voutWasUpdated = YES;
374
    o_vout_window = o_window;
375
    int i_newdevice = (int)[[o_vout_window screen] displayID];
376 377
    if ((i_newdevice != i_device && i_device != 0) || i_newdevice != [[self screen] displayID]) {
        i_device = i_newdevice;
378
        [self center];
379 380
    } else
        i_device = i_newdevice;
381 382 383 384 385 386
}
@end

/*****************************************************************************
 * FSPanelView
 *****************************************************************************/
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402

@interface VLCFSPanelView()
{
    NSColor *fillColor;
    NSButton *o_prev, *o_next, *o_bwd, *o_fwd, *o_play, *o_fullscreen;
    NSTextField *o_streamTitle_txt;
    VLCTimeField *o_streamPosition_txt, *o_streamLength_txt;
    NSSlider *o_fs_timeSlider;
    VLCFSVolumeSlider *o_fs_volumeSlider;
    VLCProgressView *o_progress_view;
    NSImage *o_background_img, *o_vol_sld_img, *o_vol_mute_img, *o_vol_max_img, *o_time_sld_img;
    NSTimeInterval last_fwd_event;
    NSTimeInterval last_bwd_event;
}
@end

403 404
@implementation VLCFSPanelView

405
#define addButton(o_button, imageOff, imageOn, _x, _y, action, AXDesc, ToolTip)               \
406 407 408 409 410 411 412
    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]];                                             \
413 414
    [o_button setImage:imageFromRes(imageOff)];                                 \
    [o_button setAlternateImage:imageFromRes(imageOn)];                         \
415 416 417
    [o_button sizeToFit];                                                                       \
    [o_button setTarget: self];                                                                 \
    [o_button setAction: @selector(action:)];                                                   \
418
    [[o_button cell] accessibilitySetOverrideValue:AXDesc forAttribute:NSAccessibilityDescriptionAttribute]; \
419
    [[o_button cell] accessibilitySetOverrideValue:ToolTip forAttribute:NSAccessibilityTitleAttribute]; \
420
    [o_button setToolTip: ToolTip]; \
421 422
    [self addSubview:o_button];

423
#define addTextfield(class, o_text, align, font, color)                                    \
424
    o_text = [[class alloc] initWithFrame: s_rc];                            \
425 426 427 428 429 430 431
    [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]];                                                 \
432
    [o_text setFont:[NSFont font:[NSFont smallSystemFontSize]]];                     \
433 434 435 436 437
    [self addSubview:o_text];

- (id)initWithFrame:(NSRect)frameRect
{
    id view = [super initWithFrame:frameRect];
438
    fillColor = [NSColor clearColor];
439
    NSRect s_rc = [self frame];
440 441 442 443 444 445
    addButton(o_prev, @"fs_skip_previous_highlight" , @"fs_skip_previous", 174, 15, prev, _NS("Click to go to the previous playlist item."), _NS("Previous"));
    addButton(o_bwd, @"fs_rewind_highlight"        , @"fs_rewind"       , 211, 14, backward, _NS("Click and hold to skip backward through the current media."), _NS("Backward"));
    addButton(o_play, @"fs_play_highlight"          , @"fs_play"         , 265, 10, play, _NS("Click to play or pause the current media."), _NS("Play/Pause"));
    addButton(o_fwd, @"fs_forward_highlight"       , @"fs_forward"      , 313, 14, forward, _NS("Click and hold to skip forward through the current media."), _NS("Forward"));
    addButton(o_next, @"fs_skip_next_highlight"     , @"fs_skip_next"    , 365, 15, next, _NS("Click to go to the next playlist item."), _NS("Next"));
    addButton(o_fullscreen, @"fs_exit_fullscreen_highlight", @"fs_exit_fullscreen", 507, 13, toggleFullscreen, _NS("Click to exit fullscreen playback."), _NS("Toggle Fullscreen mode"));
446
/*
447
    addButton(o_button, @"image (off state)", @"image (on state)", 38, 51, something, accessibility help string, usual tool tip);
448
 */
449 450
    [o_fwd setContinuous:YES];
    [o_bwd setContinuous:YES];
451 452

    /* time slider */
453
    // (surrounding progress view for swipe behaviour)
454
    s_rc.origin.x = 15;
455
    s_rc.origin.y = 45;
456
    s_rc.size.width = 518;
457
    s_rc.size.height = 13;
458 459 460
    o_progress_view = [[VLCProgressView alloc] initWithFrame: s_rc];
    s_rc.origin.x = 0;
    s_rc.origin.y = 0;
461 462 463 464 465 466
    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];
467
    [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];
468
    [[o_fs_volumeSlider cell] accessibilitySetOverrideValue:_NS("Position") forAttribute:NSAccessibilityTitleAttribute];
469
    [[o_fs_timeSlider cell] accessibilitySetOverrideValue:_NS("Click and move the mouse while keeping the button pressed to use this slider to change current playback position.") forAttribute:NSAccessibilityDescriptionAttribute];
470 471
    [self addSubview: o_progress_view];
    [o_progress_view addSubview: o_fs_timeSlider];
472 473 474 475

    /* volume slider */
    s_rc = [self frame];
    s_rc.origin.x = 26;
476
    s_rc.origin.y = 20;
477
    s_rc.size.width = 95;
478
    s_rc.size.height = 12;
479 480
    o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];
    [o_fs_volumeSlider setMinValue:0];
481
    [o_fs_volumeSlider setMaxValue: [[VLCCoreInteraction sharedInstance] maxVolume]];
482
    [o_fs_volumeSlider setIntValue:AOUT_VOLUME_DEFAULT];
483 484 485
    [o_fs_volumeSlider setContinuous: YES];
    [o_fs_volumeSlider setTarget: self];
    [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];
486
    [o_fs_volumeSlider setUsesBrightArtwork:NO];
487
    [[o_fs_volumeSlider cell] accessibilitySetOverrideValue:_NS("Volume") forAttribute:NSAccessibilityTitleAttribute];
488
    [[o_fs_volumeSlider cell] accessibilitySetOverrideValue:_NS("Click and move the mouse while keeping the button pressed to use this slider to change the volume.") forAttribute:NSAccessibilityDescriptionAttribute];
489
    [self addSubview: o_fs_volumeSlider];
490

491 492
    /* time counter and stream title output fields */
    s_rc = [self frame];
493 494
    // 10 px gap between time fields
    s_rc.origin.x = 90;
495
    s_rc.origin.y = 64;
496
    s_rc.size.width = 361;
497
    s_rc.size.height = 14;
498
    addTextfield(NSTextField, o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor);
499 500 501 502
    s_rc.origin.x = 15;
    s_rc.origin.y = 64;
    s_rc.size.width = 65;
    addTextfield(VLCTimeField, o_streamPosition_txt, NSLeftTextAlignment, systemFontOfSize, whiteColor);
503
    s_rc.origin.x = 471;
504
    s_rc.origin.y = 64;
505
    s_rc.size.width = 65;
506
    addTextfield(VLCTimeField, o_streamLength_txt, NSRightTextAlignment, systemFontOfSize, whiteColor);
507
    [o_streamLength_txt setRemainingIdentifier: @"DisplayFullscreenTimeAsTimeRemaining"];
508

509 510 511 512 513
    o_background_img = imageFromRes(@"fs_background");
    o_vol_sld_img = imageFromRes(@"fs_volume_slider_bar");
    o_vol_mute_img = imageFromRes(@"fs_volume_mute_highlight");
    o_vol_max_img = imageFromRes(@"fs_volume_max_highlight");
    o_time_sld_img = imageFromRes(@"fs_time_slider");
514

515 516 517 518 519
    return view;
}

- (void)setPlay
{
520 521
    [o_play setImage:imageFromRes(@"fs_play_highlight")];
    [o_play setAlternateImage: imageFromRes(@"fs_play")];
522 523 524 525
}

- (void)setPause
{
526 527
    [o_play setImage: imageFromRes(@"fs_pause_highlight")];
    [o_play setAlternateImage: imageFromRes(@"fs_pause")];
528 529 530 531 532 533 534
}

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

535
- (void)updatePositionAndTime
536
{
537
    input_thread_t * p_input;
538
    p_input = pl_CurrentInput(getIntf());
539 540 541 542 543 544 545 546 547 548 549
    if (p_input) {
        
        vlc_value_t pos;
        float f_updated;

        var_Get(p_input, "position", &pos);
        f_updated = 10000. * pos.f_float;
        [o_fs_timeSlider setFloatValue: f_updated];

        char psz_time[MSTRTIME_MAX_SIZE];

550
        int64_t t = var_GetInteger(p_input, "time");
551 552 553 554 555 556 557 558 559 560 561
        mtime_t dur = input_item_GetDuration(input_GetItem(p_input));

        // update total duration (right field)
        if(dur <= 0) {
            [o_streamLength_txt setHidden: YES];
        } else {
            [o_streamLength_txt setHidden: NO];

            NSString *o_total_time;
            if ([o_streamLength_txt timeRemaining]) {
                mtime_t remaining = 0;
562 563
                if (dur > t)
                    remaining = dur - t;
564 565
                o_total_time = [NSString stringWithFormat: @"-%s", secstotimestr(psz_time, (remaining / 1000000))];
            } else
566
                o_total_time = toNSStr(secstotimestr(psz_time, (dur / 1000000)));
567 568 569 570 571

            [o_streamLength_txt setStringValue: o_total_time];
        }

        // update current position (left field)
572 573
        NSString *o_playback_pos = toNSStr(secstotimestr(psz_time, t / CLOCK_FREQ));

574 575 576 577 578 579 580 581
        [o_streamPosition_txt setStringValue: o_playback_pos];
        vlc_object_release(p_input);
    } else {
        [o_fs_timeSlider setFloatValue: 0.0];
        [o_streamPosition_txt setStringValue: @"00:00"];
        [o_streamLength_txt setHidden: YES];
    }

582 583 584 585 586 587 588 589 590
}

- (void)setSeekable:(BOOL)b_seekable
{
    [o_bwd setEnabled: b_seekable];
    [o_fwd setEnabled: b_seekable];
    [o_fs_timeSlider setEnabled: b_seekable];
}

591
- (void)setVolumeLevel: (int)i_volumeLevel
592
{
593
    [o_fs_volumeSlider setIntValue: i_volumeLevel];
594 595 596 597
}

- (IBAction)play:(id)sender
{
598
    [[VLCCoreInteraction sharedInstance] playOrPause];
599 600 601 602
}

- (IBAction)forward:(id)sender
{
603
    if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) > 0.16) {
604 605 606 607
        // we just skipped 4 "continous" events, otherwise we are too fast
        [[VLCCoreInteraction sharedInstance] forwardExtraShort];
        last_fwd_event = [NSDate timeIntervalSinceReferenceDate];
    }
608 609 610 611
}

- (IBAction)backward:(id)sender
{
612
    if (([NSDate timeIntervalSinceReferenceDate] - last_bwd_event) > 0.16) {
613 614 615 616
        // we just skipped 4 "continous" events, otherwise we are too fast
        [[VLCCoreInteraction sharedInstance] backwardExtraShort];
        last_bwd_event = [NSDate timeIntervalSinceReferenceDate];
    }
617 618 619 620
}

- (IBAction)prev:(id)sender
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
621
    [[VLCCoreInteraction sharedInstance] previous];
622 623 624 625
}

- (IBAction)next:(id)sender
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
626
    [[VLCCoreInteraction sharedInstance] next];
627 628
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
629
- (IBAction)toggleFullscreen:(id)sender
630
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
631
    [[VLCCoreInteraction sharedInstance] toggleFullscreen];
632 633 634 635
}

- (IBAction)fsTimeSliderUpdate:(id)sender
{
636
    input_thread_t * p_input;
637
    p_input = pl_CurrentInput(getIntf());
638
    if (p_input != NULL) {
639 640 641
        vlc_value_t pos;

        pos.f_float = [o_fs_timeSlider floatValue] / 10000.;
642 643
        var_Set(p_input, "position", pos);
        vlc_object_release(p_input);
644
    }
645
    [[[VLCMain sharedInstance] mainWindow] updateTimeSlider];
646 647 648 649
}

- (IBAction)fsVolumeSliderUpdate:(id)sender
{
650
    [[VLCCoreInteraction sharedInstance] setVolume: [sender intValue]];
651 652
}

653 654 655
#define addImage(image, _x, _y, mode)                                                       \
    image_size = [image size];                                                              \
    image_rect.size = image_size;                                                           \
656 657 658 659
    image_rect.origin.x = 0;                                                                \
    image_rect.origin.y = 0;                                                                \
    frame.origin.x = _x;                                                                    \
    frame.origin.y = _y;                                                                    \
660
    frame.size = image_size;                                                                \
661
    [image drawInRect:frame fromRect:image_rect operation:mode fraction:1];
662 663 664 665 666

- (void)drawRect:(NSRect)rect
{
    NSRect frame = [self frame];
    NSRect image_rect;
667
    NSSize image_size;
668
    NSImage *img;
669 670 671 672
    addImage(o_background_img, 0, 0, NSCompositeCopy);
    addImage(o_vol_sld_img, 26, 23, NSCompositeSourceOver);
    addImage(o_vol_mute_img, 16, 18, NSCompositeSourceOver);
    addImage(o_vol_max_img, 124, 18, NSCompositeSourceOver);
673
    addImage(o_time_sld_img, 15, 45, NSCompositeSourceOver);
674 675 676 677 678 679 680 681 682 683 684
}

@end

/*****************************************************************************
 * VLCFSTimeSlider
 *****************************************************************************/
@implementation VLCFSTimeSlider
- (void)drawKnobInRect:(NSRect)knobRect
{
    NSRect image_rect;
685
    NSImage *img = imageFromRes(@"fs_time_slider_knob_highlight");
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
    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];
}

- (void)drawRect:(NSRect)rect
{
    /* Draw default to make sure the slider behaves correctly */
    [[NSGraphicsContext currentContext] saveGraphicsState];
    NSRectClip(NSZeroRect);
    [super drawRect:rect];
    [[NSGraphicsContext currentContext] restoreGraphicsState];
702

703
    NSRect knobRect = [[self cell] knobRectFlipped:NO];
704
    knobRect.origin.y+=4;
705 706 707 708 709 710 711 712 713 714
    [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
    [self drawKnobInRect: knobRect];
}

@end

/*****************************************************************************
* VLCFSVolumeSlider
*****************************************************************************/
@implementation VLCFSVolumeSlider
715

716 717 718 719
- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];
    if(self) {
720
        [self setCell:[[VolumeSliderCell alloc] init]];
721 722 723 724 725
    }

    return self;
}

726 727 728
- (void)drawKnobInRect:(NSRect) knobRect
{
    NSRect image_rect;
729
    NSImage *img = imageFromRes(@"fs_volume_slider_knob_highlight");
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
    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];
}

- (void)drawRect:(NSRect)rect
{
    /* Draw default to make sure the slider behaves correctly */
    [[NSGraphicsContext currentContext] saveGraphicsState];
    NSRectClip(NSZeroRect);
    [super drawRect:rect];
    [[NSGraphicsContext currentContext] restoreGraphicsState];
746

747 748
    [self drawFullVolumeMarker];

749
    NSRect knobRect = [[self cell] knobRectFlipped:NO];
750
    knobRect.origin.y+=7.5;
751 752 753 754
    [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
    [self drawKnobInRect: knobRect];
}

755 756 757 758 759 760 761
- (void)drawFullVolBezierPath:(NSBezierPath*)bezierPath
{
    CGFloat fullVolPos = [self fullVolumePos];
    [bezierPath moveToPoint:NSMakePoint(fullVolPos, [self frame].size.height)];
    [bezierPath lineToPoint:NSMakePoint(fullVolPos, 1.)];
}

762 763
@end