1 /*****************************************************************************
\r
2 * fspanel.m: MacOS X full screen panel
\r
3 *****************************************************************************
\r
4 * Copyright (C) 2006 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
33 #define KEEP_VISIBLE_AFTER_ACTION 4 /* time in half-sec until this panel will hide again after an user's action */
\r
35 /*****************************************************************************
\r
37 *****************************************************************************/
\r
38 @implementation VLCFSPanel
\r
39 /* We override this initializer so we can set the NSBorderlessWindowMask styleMask, and set a few other important settings */
\r
40 - (id)initWithContentRect:(NSRect)contentRect
\r
41 styleMask:(unsigned int)aStyle
\r
42 backing:(NSBackingStoreType)bufferingType
\r
45 id win = [super initWithContentRect:contentRect styleMask:NSTexturedBackgroundWindowMask backing:bufferingType defer:flag];
\r
47 [win setHasShadow: NO];
\r
48 [win setBackgroundColor:[NSColor clearColor]];
\r
50 /* let the window sit on top of everything else and start out completely transparent */
\r
51 [win setLevel:NSFloatingWindowLevel];
\r
52 [win setAlphaValue:0.0];
\r
59 - (void)awakeFromNib
\r
61 [self setContentView:[[VLCFSPanelView alloc] initWithFrame: [self frame]]];
\r
62 BOOL isInside = (NSPointInRect([NSEvent mouseLocation],[self frame]));
\r
63 [[self contentView] addTrackingRect:[[self contentView] bounds] owner:self userData:nil assumeInside:isInside];
\r
65 [self mouseEntered:NULL];
\r
67 [self mouseExited:NULL];
\r
69 /* get a notification if VLC isn't the active app anymore */
\r
70 [[NSNotificationCenter defaultCenter]
\r
72 selector: @selector(setNonActive:)
\r
73 name: NSApplicationDidResignActiveNotification
\r
76 /* get a notification if VLC is the active app again */
\r
77 [[NSNotificationCenter defaultCenter]
\r
79 selector: @selector(setActive:)
\r
80 name: NSApplicationDidBecomeActiveNotification
\r
84 /* Windows created with NSBorderlessWindowMask normally can't be key, but we want ours to be */
\r
85 - (BOOL)canBecomeKeyWindow
\r
90 - (BOOL)mouseDownCanMoveWindow
\r
97 [[NSNotificationCenter defaultCenter] removeObserver: self];
\r
99 if( hideAgainTimer )
\r
100 [hideAgainTimer release];
\r
101 [self setFadeTimer:nil];
\r
107 /* centre the panel in the lower third of the screen */
\r
108 NSPoint theCoordinate;
\r
109 NSRect theScreensFrame;
\r
110 NSRect theWindowsFrame;
\r
112 if( i_device < 0 || i_device >= (signed int)[[NSScreen screens] count] )
\r
113 /* invalid preferences or none specified, using main screen */
\r
114 theScreensFrame = [[NSScreen mainScreen] frame];
\r
116 /* user-defined screen */
\r
117 theScreensFrame = [[[NSScreen screens] objectAtIndex: i_device] frame];
\r
119 theWindowsFrame = [self frame];
\r
121 theCoordinate.x = (theScreensFrame.size.width - theWindowsFrame.size.width) / 2 + theScreensFrame.origin.x;
\r
122 theCoordinate.y = (theScreensFrame.size.height / 3) - theWindowsFrame.size.height + theScreensFrame.origin.y;
\r
123 [self setFrameTopLeftPoint: theCoordinate];
\r
128 [[self contentView] setPlay];
\r
133 [[self contentView] setPause];
\r
136 - (void)setStreamTitle:(NSString *)o_title
\r
138 [[self contentView] setStreamTitle: o_title];
\r
141 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
\r
143 [[self contentView] setStreamPos:f_pos andTime: o_time];
\r
146 - (void)setSeekable:(BOOL) b_seekable
\r
148 [[self contentView] setSeekable: b_seekable];
\r
151 - (void)setVolumeLevel: (float)f_volumeLevel
\r
153 [[self contentView] setVolumeLevel: f_volumeLevel];
\r
156 - (void)setNonActive:(id)noData
\r
159 [self orderOut: self];
\r
161 /* here's fadeOut, just without visibly fading */
\r
163 [self setAlphaValue:0.0];
\r
164 [self setFadeTimer:nil];
\r
168 - (void)setActive:(id)noData
\r
170 if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )
\r
177 /* This routine is called repeatedly to fade in the window */
\r
178 - (void)focus:(NSTimer *)timer
\r
180 /* we need to push ourselves to front if the vout window was closed since our last display */
\r
181 if( b_voutWasUpdated )
\r
183 [self orderFront: self];
\r
184 b_voutWasUpdated = NO;
\r
187 if( [self alphaValue] < 1.0 )
\r
188 [self setAlphaValue:[self alphaValue]+0.1];
\r
189 if( [self alphaValue] >= 1.0 )
\r
192 [self setAlphaValue: 1.0];
\r
193 [self setFadeTimer:nil];
\r
197 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];
\r
202 /* This routine is called repeatedly to hide the window */
\r
203 - (void)unfocus:(NSTimer *)timer
\r
205 if( b_keptVisible )
\r
207 b_keptVisible = NO;
\r
209 [[self fadeTimer] release];
\r
210 [self setFadeTimer: NULL];
\r
214 if( [self alphaValue] > 0.0 )
\r
215 [self setAlphaValue:[self alphaValue]-0.1];
\r
216 if( [self alphaValue] <= 0.1 )
\r
219 [self setAlphaValue:0.0];
\r
220 [self setFadeTimer:nil];
\r
224 [self setFadeTimer:
\r
225 [NSTimer scheduledTimerWithTimeInterval:0.1
\r
227 selector:@selector(focus:)
\r
234 - (void)mouseExited:(NSEvent *)theEvent
\r
236 /* give up our focus, so the vout may show us again without letting the user clicking it */
\r
237 if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )
\r
238 [[[[[VLCMain sharedInstance] getControls] getVoutView] window] makeKeyWindow];
\r
243 /* in case that the user don't want us to appear, just return here */
\r
244 if(! config_GetInt( VLCIntf, "macosx-fspanel" ) || b_nonActive )
\r
247 [self orderFront: nil];
\r
249 if( [self alphaValue] < 1.0 || b_displayed != YES )
\r
251 if (![self fadeTimer])
\r
252 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];
\r
253 else if ([[[self fadeTimer] userInfo] shortValue]==0)
\r
261 if( NSPointInRect([NSEvent mouseLocation],[self frame]))
\r
264 if( ( [self alphaValue] > 0.0 ) )
\r
266 if (![self fadeTimer])
\r
267 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];
\r
268 else if ([[[self fadeTimer] userInfo] shortValue]==1)
\r
273 /* triggers a timer to autoHide us again after some seconds of no activity */
\r
276 /* this will tell the timer to start over again or to start at all */
\r
277 b_keptVisible = YES;
\r
279 /* get us a valid timer */
\r
280 if(! b_alreadyCounting )
\r
282 hideAgainTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5
\r
284 selector: @selector(keepVisible:)
\r
287 [hideAgainTimer fire];
\r
288 [hideAgainTimer retain];
\r
289 b_alreadyCounting = YES;
\r
293 - (void)keepVisible:(NSTimer *)timer
\r
295 /* if the user triggered an action, start over again */
\r
296 if( b_keptVisible )
\r
298 i_timeToKeepVisibleInSec = KEEP_VISIBLE_AFTER_ACTION;
\r
299 b_keptVisible = NO;
\r
302 /* count down until we hide ourselfes again and do so if necessary */
\r
303 i_timeToKeepVisibleInSec -= 1;
\r
304 if( i_timeToKeepVisibleInSec < 1 )
\r
307 [timer invalidate];
\r
309 b_alreadyCounting = NO;
\r
314 /* A getter and setter for our main timer that handles window fading */
\r
315 - (NSTimer *)fadeTimer
\r
320 - (void)setFadeTimer:(NSTimer *)timer
\r
323 [fadeTimer invalidate];
\r
324 [fadeTimer release];
\r
328 - (void)mouseDown:(NSEvent *)theEvent
\r
330 mouseClic = [theEvent locationInWindow];
\r
333 - (void)mouseDragged:(NSEvent *)theEvent
\r
335 NSPoint point = [NSEvent mouseLocation];
\r
336 point.x -= mouseClic.x;
\r
337 point.y -= mouseClic.y;
\r
338 [self setFrameOrigin:point];
\r
341 - (BOOL)isDisplayed
\r
343 return b_displayed;
\r
346 - (void)setVoutWasUpdated: (int)i_newdevice;
\r
348 b_voutWasUpdated = YES;
\r
349 if( i_newdevice != i_device )
\r
351 i_device = i_newdevice;
\r
357 /*****************************************************************************
\r
359 *****************************************************************************/
\r
360 @implementation VLCFSPanelView
\r
362 #define addButton( o_button, imageOff, imageOn, _x, _y, action ) \
\r
363 s_rc.origin.x = _x; \
\r
364 s_rc.origin.y = _y; \
\r
365 o_button = [[NSButton alloc] initWithFrame: s_rc]; \
\r
366 [o_button setButtonType: NSMomentaryChangeButton]; \
\r
367 [o_button setBezelStyle: NSRegularSquareBezelStyle]; \
\r
368 [o_button setBordered: NO]; \
\r
369 [o_button setFont:[NSFont systemFontOfSize:0]]; \
\r
370 [o_button setImage:[NSImage imageNamed:imageOff]]; \
\r
371 [o_button setAlternateImage:[NSImage imageNamed:imageOn]]; \
\r
372 [o_button sizeToFit]; \
\r
373 [o_button setTarget: self]; \
\r
374 [o_button setAction: @selector(action:)]; \
\r
375 [self addSubview:o_button];
\r
377 #define addTextfield( o_text, align, font, color, size ) \
\r
378 o_text = [[NSTextField alloc] initWithFrame: s_rc]; \
\r
379 [o_text setDrawsBackground: NO]; \
\r
380 [o_text setBordered: NO]; \
\r
381 [o_text setEditable: NO]; \
\r
382 [o_text setSelectable: NO]; \
\r
383 [o_text setStringValue: _NS("(no item is being played)")]; \
\r
384 [o_text setAlignment: align]; \
\r
385 [o_text setTextColor: [NSColor color]]; \
\r
386 [o_text setFont:[NSFont font:[NSFont smallSystemFontSize] - size]]; \
\r
387 [self addSubview:o_text];
\r
389 - (id)initWithFrame:(NSRect)frameRect
\r
391 id view = [super initWithFrame:frameRect];
\r
392 fillColor = [[NSColor clearColor] retain];
\r
393 NSRect s_rc = [self frame];
\r
394 addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev );
\r
395 addButton( o_bwd, @"fs_rewind" , @"fs_rewind_highlight" , 211, 14, backward );
\r
396 addButton( o_play, @"fs_play" , @"fs_play_highlight" , 267, 10, play );
\r
397 addButton( o_fwd, @"fs_forward" , @"fs_forward_highlight" , 313, 14, forward );
\r
398 addButton( o_next, @"fs_skip_next" , @"fs_skip_next_highlight" , 365, 15, next );
\r
399 addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, windowAction );
\r
401 addButton( o_button, @"image (off state)", @"image (on state)", 38, 51, something );
\r
405 s_rc = [self frame];
\r
406 s_rc.origin.x = 15;
\r
407 s_rc.origin.y = 53;
\r
408 s_rc.size.width = 518;
\r
409 s_rc.size.height = 9;
\r
410 o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];
\r
411 [o_fs_timeSlider setMinValue:0];
\r
412 [o_fs_timeSlider setMaxValue:10000];
\r
413 [o_fs_timeSlider setFloatValue: 0];
\r
414 [o_fs_timeSlider setContinuous: YES];
\r
415 [o_fs_timeSlider setTarget: self];
\r
416 [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];
\r
417 [self addSubview: o_fs_timeSlider];
\r
419 /* volume slider */
\r
420 s_rc = [self frame];
\r
421 s_rc.origin.x = 26;
\r
422 s_rc.origin.y = 17.5;
\r
423 s_rc.size.width = 95;
\r
424 s_rc.size.height = 10;
\r
425 o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];
\r
426 [o_fs_volumeSlider setMinValue:0];
\r
427 [o_fs_volumeSlider setMaxValue:32];
\r
428 [o_fs_volumeSlider setFloatValue: 0];
\r
429 [o_fs_volumeSlider setContinuous: YES];
\r
430 [o_fs_volumeSlider setTarget: self];
\r
431 [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];
\r
432 [self addSubview: o_fs_volumeSlider];
\r
434 /* time counter and stream title output fields */
\r
435 s_rc = [self frame];
\r
436 s_rc.origin.x = 98;
\r
437 s_rc.origin.y = 64;
\r
438 s_rc.size.width = 352;
\r
439 s_rc.size.height = 14;
\r
440 addTextfield( o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );
\r
441 s_rc.origin.x = 486;
\r
442 s_rc.origin.y = 64;
\r
443 s_rc.size.width = 50;
\r
444 addTextfield( o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor, 0 );
\r
451 [o_fs_timeSlider release];
\r
452 [o_fs_volumeSlider release];
\r
458 [o_fullscreen release];
\r
459 [o_streamTitle_txt release];
\r
460 [o_streamPosition_txt release];
\r
466 [o_play setImage:[NSImage imageNamed:@"fs_play"]];
\r
467 [o_play setAlternateImage: [NSImage imageNamed:@"fs_play_highlight"]];
\r
472 [o_play setImage: [NSImage imageNamed:@"fs_pause"]];
\r
473 [o_play setAlternateImage: [NSImage imageNamed:@"fs_pause_highlight"]];
\r
476 - (void)setStreamTitle:(NSString *)o_title
\r
478 [o_streamTitle_txt setStringValue: o_title];
\r
481 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
\r
483 [o_streamPosition_txt setStringValue: o_time];
\r
484 [o_fs_timeSlider setFloatValue: f_pos];
\r
487 - (void)setSeekable:(BOOL)b_seekable
\r
489 [o_bwd setEnabled: b_seekable];
\r
490 [o_fwd setEnabled: b_seekable];
\r
491 [o_fs_timeSlider setEnabled: b_seekable];
\r
494 - (void)setVolumeLevel: (float)f_volumeLevel
\r
496 [o_fs_volumeSlider setFloatValue: f_volumeLevel];
\r
499 - (IBAction)play:(id)sender
\r
501 [[[VLCMain sharedInstance] getControls] play: sender];
\r
504 - (IBAction)forward:(id)sender
\r
506 [[[VLCMain sharedInstance] getControls] forward: sender];
\r
509 - (IBAction)backward:(id)sender
\r
511 [[[VLCMain sharedInstance] getControls] backward: sender];
\r
514 - (IBAction)prev:(id)sender
\r
516 [[[VLCMain sharedInstance] getControls] prev: sender];
\r
519 - (IBAction)next:(id)sender
\r
521 [[[VLCMain sharedInstance] getControls] next: sender];
\r
524 - (IBAction)windowAction:(id)sender
\r
526 [[[VLCMain sharedInstance] getControls] windowAction: sender];
\r
529 - (IBAction)fsTimeSliderUpdate:(id)sender
\r
531 [[VLCMain sharedInstance] timesliderUpdate: sender];
\r
534 - (IBAction)fsVolumeSliderUpdate:(id)sender
\r
536 [[[VLCMain sharedInstance] getControls] volumeSliderUpdated: sender];
\r
539 #define addImage(image, _x, _y, mode, _width) \
\r
540 img = [NSImage imageNamed:image]; \
\r
541 image_rect.size = [img size]; \
\r
542 image_rect.origin.x = 0; \
\r
543 image_rect.origin.y = 0; \
\r
544 frame.origin.x = _x; \
\r
545 frame.origin.y = _y; \
\r
546 frame.size = [img size]; \
\r
547 if( _width ) frame.size.width = _width; \
\r
548 [img drawInRect:frame fromRect:image_rect operation:mode fraction:1];
\r
550 - (void)drawRect:(NSRect)rect
\r
552 NSRect frame = [self frame];
\r
555 addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 );
\r
556 addImage( @"fs_volume_slider_bar", 26, 22, NSCompositeSourceOver, 0 );
\r
557 addImage( @"fs_volume_mute", 16, 18, NSCompositeSourceOver, 0 );
\r
558 addImage( @"fs_volume_max", 124, 17, NSCompositeSourceOver, 0 );
\r
559 addImage( @"fs_time_slider", 15, 53, NSCompositeSourceOver, 0);
\r
564 /*****************************************************************************
\r
566 *****************************************************************************/
\r
567 @implementation VLCFSTimeSlider
\r
568 - (void)drawKnobInRect:(NSRect)knobRect
\r
571 NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];
\r
572 image_rect.size = [img size];
\r
573 image_rect.origin.x = 0;
\r
574 image_rect.origin.y = 0;
\r
575 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
\r
576 knobRect.size.width = image_rect.size.width;
\r
577 knobRect.size.height = image_rect.size.height;
\r
578 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
\r
581 - (void)drawRect:(NSRect)rect
\r
583 /* Draw default to make sure the slider behaves correctly */
\r
584 [[NSGraphicsContext currentContext] saveGraphicsState];
\r
585 NSRectClip(NSZeroRect);
\r
586 [super drawRect:rect];
\r
587 [[NSGraphicsContext currentContext] restoreGraphicsState];
\r
589 NSRect knobRect = [[self cell] knobRectFlipped:NO];
\r
590 knobRect.origin.y+=7.5;
\r
591 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
\r
592 [self drawKnobInRect: knobRect];
\r
597 /*****************************************************************************
\r
598 * VLCFSVolumeSlider
\r
599 *****************************************************************************/
\r
600 @implementation VLCFSVolumeSlider
\r
601 - (void)drawKnobInRect:(NSRect) knobRect
\r
604 NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];
\r
605 image_rect.size = [img size];
\r
606 image_rect.origin.x = 0;
\r
607 image_rect.origin.y = 0;
\r
608 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
\r
609 knobRect.size.width = image_rect.size.width;
\r
610 knobRect.size.height = image_rect.size.height;
\r
611 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
\r
614 - (void)drawRect:(NSRect)rect
\r
616 /* Draw default to make sure the slider behaves correctly */
\r
617 [[NSGraphicsContext currentContext] saveGraphicsState];
\r
618 NSRectClip(NSZeroRect);
\r
619 [super drawRect:rect];
\r
620 [[NSGraphicsContext currentContext] restoreGraphicsState];
\r
622 NSRect knobRect = [[self cell] knobRectFlipped:NO];
\r
623 knobRect.origin.y+=6;
\r
624 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
\r
625 [self drawKnobInRect: knobRect];
\r