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
70 /* Windows created with NSBorderlessWindowMask normally can't be key, but we want ours to be */
\r
71 - (BOOL)canBecomeKeyWindow
\r
76 - (BOOL)mouseDownCanMoveWindow
\r
83 if( hideAgainTimer )
\r
84 [hideAgainTimer release];
\r
85 [self setFadeTimer:nil];
\r
91 /* centre the panel in the lower third of the screen */
\r
92 NSPoint theCoordinate;
\r
93 NSRect theScreensFrame;
\r
94 NSRect theWindowsFrame;
\r
96 if( i_device < 0 || i_device >= (signed int)[[NSScreen screens] count] )
\r
97 /* invalid preferences or none specified, using main screen */
\r
98 theScreensFrame = [[NSScreen mainScreen] frame];
\r
100 /* user-defined screen */
\r
101 theScreensFrame = [[[NSScreen screens] objectAtIndex: i_device] frame];
\r
103 theWindowsFrame = [self frame];
\r
105 theCoordinate.x = (theScreensFrame.size.width - theWindowsFrame.size.width) / 2 + theScreensFrame.origin.x;
\r
106 theCoordinate.y = (theScreensFrame.size.height / 3) - theWindowsFrame.size.height + theScreensFrame.origin.y;
\r
107 [self setFrameTopLeftPoint: theCoordinate];
\r
112 [[self contentView] setPlay];
\r
117 [[self contentView] setPause];
\r
120 - (void)setStreamTitle:(NSString *)o_title
\r
122 [[self contentView] setStreamTitle: o_title];
\r
125 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
\r
127 [[self contentView] setStreamPos:f_pos andTime: o_time];
\r
130 - (void)setSeekable:(BOOL) b_seekable
\r
132 [[self contentView] setSeekable: b_seekable];
\r
135 - (void)setVolumeLevel: (float)f_volumeLevel
\r
137 [[self contentView] setVolumeLevel: f_volumeLevel];
\r
140 /* This routine is called repeatedly to fade in the window */
\r
141 - (void)focus:(NSTimer *)timer
\r
143 /* we need to push ourselves to front if the vout window was closed since our last display */
\r
144 if( b_voutWasUpdated )
\r
146 [self orderFront: self];
\r
147 b_voutWasUpdated = NO;
\r
150 if( [self alphaValue] < 1.0 )
\r
151 [self setAlphaValue:[self alphaValue]+0.1];
\r
152 if( [self alphaValue] >= 1.0 )
\r
155 [self setAlphaValue: 1.0];
\r
156 [self setFadeTimer:nil];
\r
160 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];
\r
165 /* This routine is called repeatedly to hide the window */
\r
166 - (void)unfocus:(NSTimer *)timer
\r
168 if( b_keptVisible )
\r
170 b_keptVisible = NO;
\r
172 [[self fadeTimer] release];
\r
173 [self setFadeTimer: NULL];
\r
177 if( [self alphaValue] > 0.0 )
\r
178 [self setAlphaValue:[self alphaValue]-0.1];
\r
179 if( [self alphaValue] <= 0.1 )
\r
182 [self setAlphaValue:0.0];
\r
183 [self setFadeTimer:nil];
\r
187 [self setFadeTimer:
\r
188 [NSTimer scheduledTimerWithTimeInterval:0.1
\r
190 selector:@selector(focus:)
\r
197 - (void)mouseExited:(NSEvent *)theEvent
\r
199 /* give up our focus, so the vout may show us again without letting the user clicking it */
\r
200 if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )
\r
201 [[[[[VLCMain sharedInstance] getControls] getVoutView] window] makeKeyWindow];
\r
206 if( [self alphaValue] < 1.0 )
\r
208 if (![self fadeTimer])
\r
209 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];
\r
210 else if ([[[self fadeTimer] userInfo] shortValue]==0)
\r
218 if( NSPointInRect([NSEvent mouseLocation],[self frame]))
\r
221 if( ( [self alphaValue] > 0.0 ) )
\r
223 if (![self fadeTimer])
\r
224 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];
\r
225 else if ([[[self fadeTimer] userInfo] shortValue]==1)
\r
230 /* triggers a timer to autoHide us again after some seconds of no activity */
\r
233 /* this will tell the timer to start over again or to start at all */
\r
234 b_keptVisible = YES;
\r
236 /* get us a valid timer */
\r
237 if(! b_alreadyCounting )
\r
239 hideAgainTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5
\r
241 selector: @selector(keepVisible:)
\r
244 [hideAgainTimer fire];
\r
245 [hideAgainTimer retain];
\r
246 b_alreadyCounting = YES;
\r
250 - (void)keepVisible:(NSTimer *)timer
\r
252 /* if the user triggered an action, start over again */
\r
253 if( b_keptVisible )
\r
255 i_timeToKeepVisibleInSec = KEEP_VISIBLE_AFTER_ACTION;
\r
256 b_keptVisible = NO;
\r
259 /* count down until we hide ourselfes again and do so if necessary */
\r
260 i_timeToKeepVisibleInSec -= 1;
\r
261 if( i_timeToKeepVisibleInSec < 1 )
\r
264 [timer invalidate];
\r
266 b_alreadyCounting = NO;
\r
271 /* A getter and setter for our main timer that handles window fading */
\r
272 - (NSTimer *)fadeTimer
\r
277 - (void)setFadeTimer:(NSTimer *)timer
\r
280 [fadeTimer invalidate];
\r
281 [fadeTimer release];
\r
285 - (void)mouseDown:(NSEvent *)theEvent
\r
287 mouseClic = [theEvent locationInWindow];
\r
290 - (void)mouseDragged:(NSEvent *)theEvent
\r
292 NSPoint point = [NSEvent mouseLocation];
\r
293 point.x -= mouseClic.x;
\r
294 point.y -= mouseClic.y;
\r
295 [self setFrameOrigin:point];
\r
298 - (BOOL)isDisplayed
\r
300 return b_displayed;
\r
303 - (void)setVoutWasUpdated: (int)i_newdevice;
\r
305 b_voutWasUpdated = YES;
\r
306 if( i_newdevice != i_device )
\r
308 i_device = i_newdevice;
\r
314 /*****************************************************************************
\r
316 *****************************************************************************/
\r
317 @implementation VLCFSPanelView
\r
319 #define addButton( o_button, imageOff, imageOn, _x, _y, action ) \
\r
320 s_rc.origin.x = _x; \
\r
321 s_rc.origin.y = _y; \
\r
322 o_button = [[NSButton alloc] initWithFrame: s_rc]; \
\r
323 [o_button setButtonType: NSMomentaryChangeButton]; \
\r
324 [o_button setBezelStyle: NSRegularSquareBezelStyle]; \
\r
325 [o_button setBordered: NO]; \
\r
326 [o_button setFont:[NSFont systemFontOfSize:0]]; \
\r
327 [o_button setImage:[NSImage imageNamed:imageOff]]; \
\r
328 [o_button setAlternateImage:[NSImage imageNamed:imageOn]]; \
\r
329 [o_button sizeToFit]; \
\r
330 [o_button setTarget: self]; \
\r
331 [o_button setAction: @selector(action:)]; \
\r
332 [self addSubview:o_button];
\r
334 #define addTextfield( o_text, align, font, color, size ) \
\r
335 o_text = [[NSTextField alloc] initWithFrame: s_rc]; \
\r
336 [o_text setDrawsBackground: NO]; \
\r
337 [o_text setBordered: NO]; \
\r
338 [o_text setEditable: NO]; \
\r
339 [o_text setSelectable: NO]; \
\r
340 [o_text setStringValue: _NS("(no item is being played)")]; \
\r
341 [o_text setAlignment: align]; \
\r
342 [o_text setTextColor: [NSColor color]]; \
\r
343 [o_text setFont:[NSFont font:[NSFont smallSystemFontSize] - size]]; \
\r
344 [self addSubview:o_text];
\r
346 - (id)initWithFrame:(NSRect)frameRect
\r
348 id view = [super initWithFrame:frameRect];
\r
349 fillColor = [[NSColor clearColor] retain];
\r
350 NSRect s_rc = [self frame];
\r
351 addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev );
\r
352 addButton( o_slow, @"fs_rewind" , @"fs_rewind_highlight" , 211, 14, slower );
\r
353 addButton( o_play, @"fs_play" , @"fs_play_highlight" , 267, 10, play );
\r
354 addButton( o_fast, @"fs_forward" , @"fs_forward_highlight" , 313, 14, faster );
\r
355 addButton( o_next, @"fs_skip_next" , @"fs_skip_next_highlight" , 365, 15, next );
\r
356 addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, windowAction );
\r
358 addButton( o_button, @"image (off state)", @"image (on state)", 38, 51, something );
\r
362 s_rc = [self frame];
\r
363 s_rc.origin.x = 15;
\r
364 s_rc.origin.y = 53;
\r
365 s_rc.size.width = 518;
\r
366 s_rc.size.height = 9;
\r
367 o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];
\r
368 [o_fs_timeSlider setMinValue:0];
\r
369 [o_fs_timeSlider setMaxValue:10000];
\r
370 [o_fs_timeSlider setFloatValue: 0];
\r
371 [o_fs_timeSlider setContinuous: YES];
\r
372 [o_fs_timeSlider setTarget: self];
\r
373 [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];
\r
374 [self addSubview: o_fs_timeSlider];
\r
376 /* volume slider */
\r
377 s_rc = [self frame];
\r
378 s_rc.origin.x = 26;
\r
379 s_rc.origin.y = 17.5;
\r
380 s_rc.size.width = 95;
\r
381 s_rc.size.height = 10;
\r
382 o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];
\r
383 [o_fs_volumeSlider setMinValue:0];
\r
384 [o_fs_volumeSlider setMaxValue:32];
\r
385 [o_fs_volumeSlider setFloatValue: 0];
\r
386 [o_fs_volumeSlider setContinuous: YES];
\r
387 [o_fs_volumeSlider setTarget: self];
\r
388 [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];
\r
389 [self addSubview: o_fs_volumeSlider];
\r
391 /* time counter and stream title output fields */
\r
392 s_rc = [self frame];
\r
393 s_rc.origin.x = 98;
\r
394 s_rc.origin.y = 64;
\r
395 s_rc.size.width = 352;
\r
396 s_rc.size.height = 14;
\r
397 addTextfield( o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );
\r
398 s_rc.origin.x = 486;
\r
399 s_rc.origin.y = 64;
\r
400 s_rc.size.width = 50;
\r
401 addTextfield( o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor, 0 );
\r
408 [o_fs_timeSlider release];
\r
409 [o_fs_volumeSlider release];
\r
415 [o_fullscreen release];
\r
416 [o_streamTitle_txt release];
\r
417 [o_streamPosition_txt release];
\r
423 [o_play setImage:[NSImage imageNamed:@"fs_play"]];
\r
424 [o_play setAlternateImage: [NSImage imageNamed:@"fs_play_highlight"]];
\r
429 [o_play setImage: [NSImage imageNamed:@"fs_pause"]];
\r
430 [o_play setAlternateImage: [NSImage imageNamed:@"fs_pause_highlight"]];
\r
433 - (void)setStreamTitle:(NSString *)o_title
\r
435 [o_streamTitle_txt setStringValue: o_title];
\r
438 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
\r
440 [o_streamPosition_txt setStringValue: o_time];
\r
441 [o_fs_timeSlider setFloatValue: f_pos];
\r
444 - (void)setSeekable:(BOOL)b_seekable
\r
446 [o_slow setEnabled: b_seekable];
\r
447 [o_fast setEnabled: b_seekable];
\r
448 [o_fs_timeSlider setEnabled: b_seekable];
\r
451 - (void)setVolumeLevel: (float)f_volumeLevel
\r
453 [o_fs_volumeSlider setFloatValue: f_volumeLevel];
\r
456 - (IBAction)play:(id)sender
\r
458 [[[VLCMain sharedInstance] getControls] play: sender];
\r
461 - (IBAction)faster:(id)sender
\r
463 [[[VLCMain sharedInstance] getControls] faster: sender];
\r
466 - (IBAction)slower:(id)sender
\r
468 [[[VLCMain sharedInstance] getControls] slower: sender];
\r
471 - (IBAction)prev:(id)sender
\r
473 [[[VLCMain sharedInstance] getControls] prev: sender];
\r
476 - (IBAction)next:(id)sender
\r
478 [[[VLCMain sharedInstance] getControls] next: sender];
\r
481 - (IBAction)windowAction:(id)sender
\r
483 [[[VLCMain sharedInstance] getControls] windowAction: sender];
\r
486 - (IBAction)fsTimeSliderUpdate:(id)sender
\r
488 [[VLCMain sharedInstance] timesliderUpdate: sender];
\r
491 - (IBAction)fsVolumeSliderUpdate:(id)sender
\r
493 [[[VLCMain sharedInstance] getControls] volumeSliderUpdated: sender];
\r
496 #define addImage(image, _x, _y, mode, _width) \
\r
497 img = [NSImage imageNamed:image]; \
\r
498 image_rect.size = [img size]; \
\r
499 image_rect.origin.x = 0; \
\r
500 image_rect.origin.y = 0; \
\r
501 frame.origin.x = _x; \
\r
502 frame.origin.y = _y; \
\r
503 frame.size = [img size]; \
\r
504 if( _width ) frame.size.width = _width; \
\r
505 [img drawInRect:frame fromRect:image_rect operation:mode fraction:1];
\r
507 - (void)drawRect:(NSRect)rect
\r
509 NSRect frame = [self frame];
\r
512 addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 );
\r
513 addImage( @"fs_volume_slider_bar", 26, 22, NSCompositeSourceOver, 0 );
\r
514 addImage( @"fs_volume_mute", 16, 18, NSCompositeSourceOver, 0 );
\r
515 addImage( @"fs_volume_max", 124, 17, NSCompositeSourceOver, 0 );
\r
516 addImage( @"fs_time_slider", 15, 53, NSCompositeSourceOver, 0);
\r
521 /*****************************************************************************
\r
523 *****************************************************************************/
\r
524 @implementation VLCFSTimeSlider
\r
525 - (void)drawKnobInRect:(NSRect)knobRect
\r
528 NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];
\r
529 image_rect.size = [img size];
\r
530 image_rect.origin.x = 0;
\r
531 image_rect.origin.y = 0;
\r
532 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
\r
533 knobRect.size.width = image_rect.size.width;
\r
534 knobRect.size.height = image_rect.size.height;
\r
535 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
\r
538 - (void)drawRect:(NSRect)rect
\r
540 /* Draw default to make sure the slider behaves correctly */
\r
541 [[NSGraphicsContext currentContext] saveGraphicsState];
\r
542 NSRectClip(NSZeroRect);
\r
543 [super drawRect:rect];
\r
544 [[NSGraphicsContext currentContext] restoreGraphicsState];
\r
546 NSRect knobRect = [[self cell] knobRectFlipped:NO];
\r
547 knobRect.origin.y+=7.5;
\r
548 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
\r
549 [self drawKnobInRect: knobRect];
\r
554 /*****************************************************************************
\r
555 * VLCFSVolumeSlider
\r
556 *****************************************************************************/
\r
557 @implementation VLCFSVolumeSlider
\r
558 - (void)drawKnobInRect:(NSRect) knobRect
\r
561 NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];
\r
562 image_rect.size = [img size];
\r
563 image_rect.origin.x = 0;
\r
564 image_rect.origin.y = 0;
\r
565 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
\r
566 knobRect.size.width = image_rect.size.width;
\r
567 knobRect.size.height = image_rect.size.height;
\r
568 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
\r
571 - (void)drawRect:(NSRect)rect
\r
573 /* Draw default to make sure the slider behaves correctly */
\r
574 [[NSGraphicsContext currentContext] saveGraphicsState];
\r
575 NSRectClip(NSZeroRect);
\r
576 [super drawRect:rect];
\r
577 [[NSGraphicsContext currentContext] restoreGraphicsState];
\r
579 NSRect knobRect = [[self cell] knobRectFlipped:NO];
\r
580 knobRect.origin.y+=6;
\r
581 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
\r
582 [self drawKnobInRect: knobRect];
\r