1 /*****************************************************************************
\r
2 * fspanel.m: MacOS X full screen panel
\r
3 *****************************************************************************
\r
4 * Copyright (C) 2006-2007 the VideoLAN team
\r
7 * Authors: J
\8er
\99me Decoodt <djc at videolan dot org>
\r
8 * Felix K
\9fhne <fkuehne at videolan dot org>
\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
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
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
25 /*****************************************************************************
\r
27 *****************************************************************************/
\r
29 #import "controls.h"
\r
34 #define KEEP_VISIBLE_AFTER_ACTION 4 /* time in half-sec until this panel will hide again after a user's action */
\r
36 /*****************************************************************************
\r
38 *****************************************************************************/
\r
39 @implementation VLCFSPanel
\r
40 /* We override this initializer so we can set the NSBorderlessWindowMask styleMask, and set a few other important settings */
\r
41 - (id)initWithContentRect:(NSRect)contentRect
\r
42 styleMask:(unsigned int)aStyle
\r
43 backing:(NSBackingStoreType)bufferingType
\r
46 id win = [super initWithContentRect:contentRect styleMask:NSTexturedBackgroundWindowMask backing:bufferingType defer:flag];
\r
48 [win setHasShadow: NO];
\r
49 [win setBackgroundColor:[NSColor clearColor]];
\r
51 /* let the window sit on top of everything else and start out completely transparent */
\r
52 [win setLevel:NSModalPanelWindowLevel];
\r
55 [self setNonActive:nil];
\r
60 - (void)awakeFromNib
\r
62 [self setContentView:[[VLCFSPanelView alloc] initWithFrame: [self frame]]];
\r
63 BOOL isInside = (NSPointInRect([NSEvent mouseLocation],[self frame]));
\r
64 [[self contentView] addTrackingRect:[[self contentView] bounds] owner:self userData:nil assumeInside:isInside];
\r
66 [self mouseEntered:NULL];
\r
68 [self mouseExited:NULL];
\r
70 /* get a notification if VLC isn't the active app anymore */
\r
71 [[NSNotificationCenter defaultCenter]
\r
73 selector: @selector(setNonActive:)
\r
74 name: NSApplicationDidResignActiveNotification
\r
77 /* get a notification if VLC is the active app again */
\r
78 [[NSNotificationCenter defaultCenter]
\r
80 selector: @selector(setActive:)
\r
81 name: NSApplicationDidBecomeActiveNotification
\r
85 /* Windows created with NSBorderlessWindowMask normally can't be key, but we want ours to be */
\r
86 - (BOOL)canBecomeKeyWindow
\r
91 - (BOOL)mouseDownCanMoveWindow
\r
99 /* dealloc isn't called on 10.5 in case that GC is enabled, so we need to provide the functionality here */
\r
100 [[NSNotificationCenter defaultCenter] removeObserver: self];
\r
101 [self setFadeTimer:nil];
\r
109 [[NSNotificationCenter defaultCenter] removeObserver: self];
\r
111 if( hideAgainTimer )
\r
112 [hideAgainTimer release];
\r
113 [self setFadeTimer:nil];
\r
119 /* centre the panel in the lower third of the screen */
\r
120 NSPoint theCoordinate;
\r
121 NSRect theScreensFrame;
\r
122 NSRect theWindowsFrame;
\r
125 /* user-defined screen */
\r
126 screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
\r
130 /* invalid preferences or none specified, using main screen */
\r
131 screen = [NSScreen mainScreen];
\r
134 theScreensFrame = [screen frame];
\r
136 theWindowsFrame = [self frame];
\r
138 theCoordinate.x = (theScreensFrame.size.width - theWindowsFrame.size.width) / 2 + theScreensFrame.origin.x;
\r
139 theCoordinate.y = (theScreensFrame.size.height / 3) - theWindowsFrame.size.height + theScreensFrame.origin.y;
\r
140 [self setFrameTopLeftPoint: theCoordinate];
\r
145 [[self contentView] setPlay];
\r
150 [[self contentView] setPause];
\r
153 - (void)setStreamTitle:(NSString *)o_title
\r
155 [[self contentView] setStreamTitle: o_title];
\r
158 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
\r
160 [[self contentView] setStreamPos:f_pos andTime: o_time];
\r
163 - (void)setSeekable:(BOOL) b_seekable
\r
165 [[self contentView] setSeekable: b_seekable];
\r
168 - (void)setVolumeLevel: (float)f_volumeLevel
\r
170 [[self contentView] setVolumeLevel: f_volumeLevel];
\r
173 - (void)setNonActive:(id)noData
\r
176 [self orderOut: self];
\r
178 /* here's fadeOut, just without visibly fading */
\r
180 [self setAlphaValue:0.0];
\r
181 [self setFadeTimer:nil];
\r
185 - (void)setActive:(id)noData
\r
187 if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )
\r
194 /* This routine is called repeatedly to fade in the window */
\r
195 - (void)focus:(NSTimer *)timer
\r
197 /* we need to push ourselves to front if the vout window was closed since our last display */
\r
198 if( b_voutWasUpdated )
\r
200 [self orderFront: self];
\r
201 b_voutWasUpdated = NO;
\r
204 if( [self alphaValue] < 1.0 )
\r
205 [self setAlphaValue:[self alphaValue]+0.1];
\r
206 if( [self alphaValue] >= 1.0 )
\r
209 [self setAlphaValue: 1.0];
\r
210 [self setFadeTimer:nil];
\r
214 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];
\r
219 /* This routine is called repeatedly to hide the window */
\r
220 - (void)unfocus:(NSTimer *)timer
\r
222 if( b_keptVisible )
\r
224 b_keptVisible = NO;
\r
226 [self setFadeTimer: NULL];
\r
230 if( [self alphaValue] > 0.0 )
\r
231 [self setAlphaValue:[self alphaValue]-0.05];
\r
232 if( [self alphaValue] <= 0.05 )
\r
235 [self setAlphaValue:0.0];
\r
236 [self setFadeTimer:nil];
\r
240 [self setFadeTimer:
\r
241 [NSTimer scheduledTimerWithTimeInterval:0.1
\r
243 selector:@selector(focus:)
\r
250 - (void)mouseExited:(NSEvent *)theEvent
\r
252 /* give up our focus, so the vout may show us again without letting the user clicking it */
\r
253 if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )
\r
254 [[[[[VLCMain sharedInstance] getControls] getVoutView] window] makeKeyWindow];
\r
259 /* in case that the user don't want us to appear, just return here */
\r
260 if(! config_GetInt( VLCIntf, "macosx-fspanel" ) || b_nonActive )
\r
263 [self orderFront: nil];
\r
265 if( [self alphaValue] < 1.0 || b_displayed != YES )
\r
267 if (![self fadeTimer])
\r
268 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];
\r
269 else if ([[[self fadeTimer] userInfo] shortValue]==0)
\r
277 if( NSPointInRect([NSEvent mouseLocation],[self frame]))
\r
280 if( ( [self alphaValue] > 0.0 ) )
\r
282 if (![self fadeTimer])
\r
283 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];
\r
284 else if ([[[self fadeTimer] userInfo] shortValue]==1)
\r
289 /* triggers a timer to autoHide us again after some seconds of no activity */
\r
292 /* this will tell the timer to start over again or to start at all */
\r
293 b_keptVisible = YES;
\r
295 /* get us a valid timer */
\r
296 if(! b_alreadyCounting )
\r
298 hideAgainTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5
\r
300 selector: @selector(keepVisible:)
\r
303 [hideAgainTimer fire];
\r
304 [hideAgainTimer retain];
\r
305 b_alreadyCounting = YES;
\r
309 - (void)keepVisible:(NSTimer *)timer
\r
311 /* if the user triggered an action, start over again */
\r
312 if( b_keptVisible )
\r
314 i_timeToKeepVisibleInSec = KEEP_VISIBLE_AFTER_ACTION;
\r
315 b_keptVisible = NO;
\r
318 /* count down until we hide ourselfes again and do so if necessary */
\r
319 i_timeToKeepVisibleInSec -= 1;
\r
320 if( i_timeToKeepVisibleInSec < 1 )
\r
322 [NSCursor setHiddenUntilMouseMoves: YES];
\r
324 [timer invalidate];
\r
326 b_alreadyCounting = NO;
\r
331 /* A getter and setter for our main timer that handles window fading */
\r
332 - (NSTimer *)fadeTimer
\r
337 - (void)setFadeTimer:(NSTimer *)timer
\r
340 [fadeTimer invalidate];
\r
341 [fadeTimer release];
\r
345 - (void)mouseDown:(NSEvent *)theEvent
\r
347 mouseClic = [theEvent locationInWindow];
\r
350 - (void)mouseDragged:(NSEvent *)theEvent
\r
352 NSPoint point = [NSEvent mouseLocation];
\r
353 point.x -= mouseClic.x;
\r
354 point.y -= mouseClic.y;
\r
355 [self setFrameOrigin:point];
\r
358 - (BOOL)isDisplayed
\r
360 return b_displayed;
\r
363 - (void)setVoutWasUpdated: (int)i_newdevice;
\r
365 b_voutWasUpdated = YES;
\r
366 if( i_newdevice != i_device )
\r
368 i_device = i_newdevice;
\r
374 /*****************************************************************************
\r
376 *****************************************************************************/
\r
377 @implementation VLCFSPanelView
\r
379 #define addButton( o_button, imageOff, imageOn, _x, _y, action ) \
\r
380 s_rc.origin.x = _x; \
\r
381 s_rc.origin.y = _y; \
\r
382 o_button = [[NSButton alloc] initWithFrame: s_rc]; \
\r
383 [o_button setButtonType: NSMomentaryChangeButton]; \
\r
384 [o_button setBezelStyle: NSRegularSquareBezelStyle]; \
\r
385 [o_button setBordered: NO]; \
\r
386 [o_button setFont:[NSFont systemFontOfSize:0]]; \
\r
387 [o_button setImage:[NSImage imageNamed:imageOff]]; \
\r
388 [o_button setAlternateImage:[NSImage imageNamed:imageOn]]; \
\r
389 [o_button sizeToFit]; \
\r
390 [o_button setTarget: self]; \
\r
391 [o_button setAction: @selector(action:)]; \
\r
392 [self addSubview:o_button];
\r
394 #define addTextfield( o_text, align, font, color, size ) \
\r
395 o_text = [[NSTextField alloc] initWithFrame: s_rc]; \
\r
396 [o_text setDrawsBackground: NO]; \
\r
397 [o_text setBordered: NO]; \
\r
398 [o_text setEditable: NO]; \
\r
399 [o_text setSelectable: NO]; \
\r
400 [o_text setStringValue: _NS("(no item is being played)")]; \
\r
401 [o_text setAlignment: align]; \
\r
402 [o_text setTextColor: [NSColor color]]; \
\r
403 [o_text setFont:[NSFont font:[NSFont smallSystemFontSize] - size]]; \
\r
404 [self addSubview:o_text];
\r
406 - (id)initWithFrame:(NSRect)frameRect
\r
408 id view = [super initWithFrame:frameRect];
\r
409 fillColor = [[NSColor clearColor] retain];
\r
410 NSRect s_rc = [self frame];
\r
411 addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev );
\r
412 addButton( o_bwd, @"fs_rewind" , @"fs_rewind_highlight" , 211, 14, backward );
\r
413 addButton( o_play, @"fs_play" , @"fs_play_highlight" , 267, 10, play );
\r
414 addButton( o_fwd, @"fs_forward" , @"fs_forward_highlight" , 313, 14, forward );
\r
415 addButton( o_next, @"fs_skip_next" , @"fs_skip_next_highlight" , 365, 15, next );
\r
416 addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, windowAction );
\r
418 addButton( o_button, @"image (off state)", @"image (on state)", 38, 51, something );
\r
422 s_rc = [self frame];
\r
423 s_rc.origin.x = 15;
\r
424 s_rc.origin.y = 53;
\r
425 s_rc.size.width = 518;
\r
426 s_rc.size.height = 9;
\r
427 o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];
\r
428 [o_fs_timeSlider setMinValue:0];
\r
429 [o_fs_timeSlider setMaxValue:10000];
\r
430 [o_fs_timeSlider setFloatValue: 0];
\r
431 [o_fs_timeSlider setContinuous: YES];
\r
432 [o_fs_timeSlider setTarget: self];
\r
433 [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];
\r
434 [self addSubview: o_fs_timeSlider];
\r
436 /* volume slider */
\r
437 s_rc = [self frame];
\r
438 s_rc.origin.x = 26;
\r
439 s_rc.origin.y = 17.5;
\r
440 s_rc.size.width = 95;
\r
441 s_rc.size.height = 10;
\r
442 o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];
\r
443 [o_fs_volumeSlider setMinValue:0];
\r
444 [o_fs_volumeSlider setMaxValue:32];
\r
445 [o_fs_volumeSlider setFloatValue: 0];
\r
446 [o_fs_volumeSlider setContinuous: YES];
\r
447 [o_fs_volumeSlider setTarget: self];
\r
448 [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];
\r
449 [self addSubview: o_fs_volumeSlider];
\r
451 /* time counter and stream title output fields */
\r
452 s_rc = [self frame];
\r
453 s_rc.origin.x = 98;
\r
454 s_rc.origin.y = 64;
\r
455 s_rc.size.width = 352;
\r
456 s_rc.size.height = 14;
\r
457 addTextfield( o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );
\r
458 s_rc.origin.x = 486;
\r
459 s_rc.origin.y = 64;
\r
460 s_rc.size.width = 50;
\r
461 addTextfield( o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor, 0 );
\r
468 [o_fs_timeSlider release];
\r
469 [o_fs_volumeSlider release];
\r
475 [o_fullscreen release];
\r
476 [o_streamTitle_txt release];
\r
477 [o_streamPosition_txt release];
\r
483 [o_play setImage:[NSImage imageNamed:@"fs_play"]];
\r
484 [o_play setAlternateImage: [NSImage imageNamed:@"fs_play_highlight"]];
\r
489 [o_play setImage: [NSImage imageNamed:@"fs_pause"]];
\r
490 [o_play setAlternateImage: [NSImage imageNamed:@"fs_pause_highlight"]];
\r
493 - (void)setStreamTitle:(NSString *)o_title
\r
495 [o_streamTitle_txt setStringValue: o_title];
\r
498 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
\r
500 [o_streamPosition_txt setStringValue: o_time];
\r
501 [o_fs_timeSlider setFloatValue: f_pos];
\r
504 - (void)setSeekable:(BOOL)b_seekable
\r
506 [o_bwd setEnabled: b_seekable];
\r
507 [o_fwd setEnabled: b_seekable];
\r
508 [o_fs_timeSlider setEnabled: b_seekable];
\r
511 - (void)setVolumeLevel: (float)f_volumeLevel
\r
513 [o_fs_volumeSlider setFloatValue: f_volumeLevel];
\r
516 - (IBAction)play:(id)sender
\r
518 [[[VLCMain sharedInstance] getControls] play: sender];
\r
521 - (IBAction)forward:(id)sender
\r
523 [[[VLCMain sharedInstance] getControls] forward: sender];
\r
526 - (IBAction)backward:(id)sender
\r
528 [[[VLCMain sharedInstance] getControls] backward: sender];
\r
531 - (IBAction)prev:(id)sender
\r
533 [[[VLCMain sharedInstance] getControls] prev: sender];
\r
536 - (IBAction)next:(id)sender
\r
538 [[[VLCMain sharedInstance] getControls] next: sender];
\r
541 - (IBAction)windowAction:(id)sender
\r
543 [[[VLCMain sharedInstance] getControls] windowAction: sender];
\r
546 - (IBAction)fsTimeSliderUpdate:(id)sender
\r
548 [[VLCMain sharedInstance] timesliderUpdate: sender];
\r
551 - (IBAction)fsVolumeSliderUpdate:(id)sender
\r
553 [[[VLCMain sharedInstance] getControls] volumeSliderUpdated: sender];
\r
556 #define addImage(image, _x, _y, mode, _width) \
\r
557 img = [NSImage imageNamed:image]; \
\r
558 image_rect.size = [img size]; \
\r
559 image_rect.origin.x = 0; \
\r
560 image_rect.origin.y = 0; \
\r
561 frame.origin.x = _x; \
\r
562 frame.origin.y = _y; \
\r
563 frame.size = [img size]; \
\r
564 if( _width ) frame.size.width = _width; \
\r
565 [img drawInRect:frame fromRect:image_rect operation:mode fraction:1];
\r
567 - (void)drawRect:(NSRect)rect
\r
569 NSRect frame = [self frame];
\r
572 addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 );
\r
573 addImage( @"fs_volume_slider_bar", 26, 22, NSCompositeSourceOver, 0 );
\r
574 addImage( @"fs_volume_mute", 16, 18, NSCompositeSourceOver, 0 );
\r
575 addImage( @"fs_volume_max", 124, 17, NSCompositeSourceOver, 0 );
\r
576 addImage( @"fs_time_slider", 15, 53, NSCompositeSourceOver, 0);
\r
581 /*****************************************************************************
\r
583 *****************************************************************************/
\r
584 @implementation VLCFSTimeSlider
\r
585 - (void)drawKnobInRect:(NSRect)knobRect
\r
588 NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];
\r
589 image_rect.size = [img size];
\r
590 image_rect.origin.x = 0;
\r
591 image_rect.origin.y = 0;
\r
592 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
\r
593 knobRect.size.width = image_rect.size.width;
\r
594 knobRect.size.height = image_rect.size.height;
\r
595 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
\r
598 - (void)drawRect:(NSRect)rect
\r
600 /* Draw default to make sure the slider behaves correctly */
\r
601 [[NSGraphicsContext currentContext] saveGraphicsState];
\r
602 NSRectClip(NSZeroRect);
\r
603 [super drawRect:rect];
\r
604 [[NSGraphicsContext currentContext] restoreGraphicsState];
\r
606 NSRect knobRect = [[self cell] knobRectFlipped:NO];
\r
607 knobRect.origin.y+=7.5;
\r
608 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
\r
609 [self drawKnobInRect: knobRect];
\r
614 /*****************************************************************************
\r
615 * VLCFSVolumeSlider
\r
616 *****************************************************************************/
\r
617 @implementation VLCFSVolumeSlider
\r
618 - (void)drawKnobInRect:(NSRect) knobRect
\r
621 NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];
\r
622 image_rect.size = [img size];
\r
623 image_rect.origin.x = 0;
\r
624 image_rect.origin.y = 0;
\r
625 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
\r
626 knobRect.size.width = image_rect.size.width;
\r
627 knobRect.size.height = image_rect.size.height;
\r
628 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
\r
631 - (void)drawRect:(NSRect)rect
\r
633 /* Draw default to make sure the slider behaves correctly */
\r
634 [[NSGraphicsContext currentContext] saveGraphicsState];
\r
635 NSRectClip(NSZeroRect);
\r
636 [super drawRect:rect];
\r
637 [[NSGraphicsContext currentContext] restoreGraphicsState];
\r
639 NSRect knobRect = [[self cell] knobRectFlipped:NO];
\r
640 knobRect.origin.y+=6;
\r
641 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
\r
642 [self drawKnobInRect: knobRect];
\r