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
54 /* centre the panel in the lower third of the screen */
\r
55 NSPoint theCoordinate;
\r
56 NSRect theScreensFrame;
\r
57 NSRect theWindowsFrame;
\r
60 i_outputScreen = var_GetInteger( VLCIntf, "video-device" );
\r
61 if( i_outputScreen <=0 || i_outputScreen > (signed int)[[NSScreen screens] count] )
\r
62 /* invalid preferences or none specified, using main screen */
\r
63 theScreensFrame = [[NSScreen mainScreen] frame];
\r
65 /* user-defined screen */
\r
66 theScreensFrame = [[[NSScreen screens] objectAtIndex: i_outputScreen] frame];
\r
68 theWindowsFrame = [win frame];
\r
69 theCoordinate.x = (theScreensFrame.size.width - theWindowsFrame.size.width) / 2;
\r
70 theCoordinate.y = (theScreensFrame.size.height / 3) - theWindowsFrame.size.height;
\r
71 [win setFrameTopLeftPoint: theCoordinate];
\r
75 - (void)awakeFromNib
\r
77 [self setContentView:[[VLCFSPanelView alloc] initWithFrame: [self frame]]];
\r
78 BOOL isInside=(NSPointInRect([NSEvent mouseLocation],[self frame]));
\r
79 [[self contentView] addTrackingRect:[[self contentView] bounds] owner:self userData:nil assumeInside:isInside];
\r
81 [self mouseEntered:NULL];
\r
83 [self mouseExited:NULL];
\r
86 /* Windows created with NSBorderlessWindowMask normally can't be key, but we want ours to be */
\r
87 - (BOOL)canBecomeKeyWindow
\r
92 - (BOOL)mouseDownCanMoveWindow
\r
99 if( hideAgainTimer )
\r
100 [hideAgainTimer release];
\r
101 [self setFadeTimer:nil];
\r
107 [[self contentView] setPlay];
\r
112 [[self contentView] setPause];
\r
115 - (void)setStreamTitle:(NSString *)o_title
\r
117 [[self contentView] setStreamTitle: o_title];
\r
120 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
\r
122 [[self contentView] setStreamPos:f_pos andTime: o_time];
\r
125 - (void)setSeekable:(BOOL) b_seekable
\r
127 [[self contentView] setSeekable: b_seekable];
\r
130 - (void)setVolumeLevel: (float)f_volumeLevel
\r
132 [[self contentView] setVolumeLevel: f_volumeLevel];
\r
135 /* This routine is called repeatedly to fade in the window */
\r
136 - (void)focus:(NSTimer *)timer
\r
138 /* we need to push ourselves to front if the vout window was closed since our last display */
\r
139 if( b_voutWasUpdated )
\r
141 [self orderFront: self];
\r
142 b_voutWasUpdated = NO;
\r
145 if( [self alphaValue] < 1.0 )
\r
146 [self setAlphaValue:[self alphaValue]+0.1];
\r
147 if( [self alphaValue] >= 1.0 )
\r
150 [self setAlphaValue: 1.0];
\r
151 [self setFadeTimer:nil];
\r
155 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];
\r
160 /* This routine is called repeatedly to hide the window */
\r
161 - (void)unfocus:(NSTimer *)timer
\r
163 if( b_keptVisible )
\r
165 b_keptVisible = NO;
\r
167 [[self fadeTimer] release];
\r
168 [self setFadeTimer: NULL];
\r
172 if( [self alphaValue] > 0.0 )
\r
173 [self setAlphaValue:[self alphaValue]-0.1];
\r
174 if( [self alphaValue] <= 0.1 )
\r
177 [self setAlphaValue:0.0];
\r
178 [self setFadeTimer:nil];
\r
182 [self setFadeTimer:
\r
183 [NSTimer scheduledTimerWithTimeInterval:0.1
\r
185 selector:@selector(focus:)
\r
192 - (void)mouseExited:(NSEvent *)theEvent
\r
194 /* give up our focus, so the vout may show us again without letting the user clicking it */
\r
195 if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )
\r
196 [[[[[VLCMain sharedInstance] getControls] getVoutView] window] makeKeyWindow];
\r
201 if( [self alphaValue] < 1.0 )
\r
203 if (![self fadeTimer])
\r
204 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];
\r
205 else if ([[[self fadeTimer] userInfo] shortValue]==0)
\r
213 if( ( [self alphaValue] > 0.0 ) )
\r
215 if (![self fadeTimer])
\r
216 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];
\r
217 else if ([[[self fadeTimer] userInfo] shortValue]==1)
\r
222 /* triggers a timer to autoHide us again after some seconds of no activity */
\r
225 /* this will tell the timer to start over again or to start at all */
\r
226 b_keptVisible = YES;
\r
228 /* get us a valid timer */
\r
229 if(! b_alreadyCounting )
\r
231 hideAgainTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5
\r
233 selector: @selector(keepVisible:)
\r
236 [hideAgainTimer fire];
\r
237 [hideAgainTimer retain];
\r
238 b_alreadyCounting = YES;
\r
242 - (void)keepVisible:(NSTimer *)timer
\r
244 /* if the user triggered an action, start over again */
\r
245 if( b_keptVisible )
\r
247 i_timeToKeepVisibleInSec = KEEP_VISIBLE_AFTER_ACTION;
\r
248 b_keptVisible = NO;
\r
251 /* count down until we hide ourselfes again and do so if necessary */
\r
252 i_timeToKeepVisibleInSec -= 1;
\r
253 if( i_timeToKeepVisibleInSec < 1 )
\r
256 [timer invalidate];
\r
258 b_alreadyCounting = NO;
\r
263 /* A getter and setter for our main timer that handles window fading */
\r
264 - (NSTimer *)fadeTimer
\r
269 - (void)setFadeTimer:(NSTimer *)timer
\r
272 [fadeTimer invalidate];
\r
273 [fadeTimer release];
\r
277 - (void)mouseDown:(NSEvent *)theEvent
\r
279 mouseClic = [theEvent locationInWindow];
\r
282 - (void)mouseDragged:(NSEvent *)theEvent
\r
284 NSPoint point = [NSEvent mouseLocation];
\r
285 point.x -= mouseClic.x;
\r
286 point.y -= mouseClic.y;
\r
287 [self setFrameOrigin:point];
\r
290 - (BOOL)isDisplayed
\r
292 return b_displayed;
\r
295 - (void)setVoutWasUpdated
\r
297 b_voutWasUpdated = YES;
\r
301 /*****************************************************************************
\r
303 *****************************************************************************/
\r
304 @implementation VLCFSPanelView
\r
306 #define addButton( o_button, imageOff, imageOn, _x, _y, action ) \
\r
307 s_rc.origin.x = _x; \
\r
308 s_rc.origin.y = _y; \
\r
309 o_button = [[NSButton alloc] initWithFrame: s_rc]; \
\r
310 [o_button setButtonType: NSMomentaryChangeButton]; \
\r
311 [o_button setBezelStyle: NSRegularSquareBezelStyle]; \
\r
312 [o_button setBordered: NO]; \
\r
313 [o_button setFont:[NSFont systemFontOfSize:0]]; \
\r
314 [o_button setImage:[NSImage imageNamed:imageOff]]; \
\r
315 [o_button setAlternateImage:[NSImage imageNamed:imageOn]]; \
\r
316 [o_button sizeToFit]; \
\r
317 [o_button setTarget: self]; \
\r
318 [o_button setAction: @selector(action:)]; \
\r
319 [self addSubview:o_button];
\r
321 #define addTextfield( o_text, align, font, color, size ) \
\r
322 o_text = [[NSTextField alloc] initWithFrame: s_rc]; \
\r
323 [o_text setDrawsBackground: NO]; \
\r
324 [o_text setBordered: NO]; \
\r
325 [o_text setEditable: NO]; \
\r
326 [o_text setSelectable: NO]; \
\r
327 [o_text setStringValue: _NS("(no item is being played)")]; \
\r
328 [o_text setAlignment: align]; \
\r
329 [o_text setTextColor: [NSColor color]]; \
\r
330 [o_text setFont:[NSFont font:[NSFont smallSystemFontSize] - size]]; \
\r
331 [self addSubview:o_text];
\r
333 - (id)initWithFrame:(NSRect)frameRect
\r
335 id view = [super initWithFrame:frameRect];
\r
336 fillColor = [[NSColor clearColor] retain];
\r
337 NSRect s_rc = [self frame];
\r
338 addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev );
\r
339 addButton( o_slow, @"fs_rewind" , @"fs_rewind_highlight" , 211, 14, slower );
\r
340 addButton( o_play, @"fs_play" , @"fs_play_highlight" , 267, 10, play );
\r
341 addButton( o_fast, @"fs_forward" , @"fs_forward_highlight" , 313, 14, faster );
\r
342 addButton( o_next, @"fs_skip_next" , @"fs_skip_next_highlight" , 365, 15, next );
\r
343 addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, windowAction );
\r
345 addButton( o_button, @"image (off state)", @"image (on state)", 38, 51, something );
\r
349 s_rc = [self frame];
\r
350 s_rc.origin.x = 15;
\r
351 s_rc.origin.y = 53;
\r
352 s_rc.size.width = 518;
\r
353 s_rc.size.height = 9;
\r
354 o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];
\r
355 [o_fs_timeSlider setMinValue:0];
\r
356 [o_fs_timeSlider setMaxValue:10000];
\r
357 [o_fs_timeSlider setFloatValue: 0];
\r
358 [o_fs_timeSlider setContinuous: YES];
\r
359 [o_fs_timeSlider setTarget: self];
\r
360 [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];
\r
361 [self addSubview: o_fs_timeSlider];
\r
363 /* volume slider */
\r
364 s_rc = [self frame];
\r
365 s_rc.origin.x = 26;
\r
366 s_rc.origin.y = 17.5;
\r
367 s_rc.size.width = 95;
\r
368 s_rc.size.height = 10;
\r
369 o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];
\r
370 [o_fs_volumeSlider setMinValue:0];
\r
371 [o_fs_volumeSlider setMaxValue:32];
\r
372 [o_fs_volumeSlider setFloatValue: 0];
\r
373 [o_fs_volumeSlider setContinuous: YES];
\r
374 [o_fs_volumeSlider setTarget: self];
\r
375 [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];
\r
376 [self addSubview: o_fs_volumeSlider];
\r
378 /* time counter and stream title output fields */
\r
379 s_rc = [self frame];
\r
380 s_rc.origin.x = 98;
\r
381 s_rc.origin.y = 64;
\r
382 s_rc.size.width = 352;
\r
383 s_rc.size.height = 14;
\r
384 addTextfield( o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );
\r
385 s_rc.origin.x = 486;
\r
386 s_rc.origin.y = 64;
\r
387 s_rc.size.width = 50;
\r
388 addTextfield( o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor, 0 );
\r
395 [o_fs_timeSlider release];
\r
396 [o_fs_volumeSlider release];
\r
402 [o_fullscreen release];
\r
403 [o_streamTitle_txt release];
\r
404 [o_streamPosition_txt release];
\r
411 image = [NSImage imageNamed:@"fs_play"];
\r
412 [o_play setImage:image];
\r
413 image = [NSImage imageNamed:@"fs_play_highlight"];
\r
414 [o_play setAlternateImage:image];
\r
420 image = [NSImage imageNamed:@"fs_pause"];
\r
421 [o_play setImage:image];
\r
422 image = [NSImage imageNamed:@"fs_pause_highlight"];
\r
423 [o_play setAlternateImage:image];
\r
426 - (void)setStreamTitle:(NSString *)o_title
\r
428 [o_streamTitle_txt setStringValue: o_title];
\r
431 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
\r
433 [o_streamPosition_txt setStringValue: o_time];
\r
434 [o_fs_timeSlider setFloatValue: f_pos];
\r
437 - (void)setSeekable:(BOOL)b_seekable
\r
439 [o_slow setEnabled: b_seekable];
\r
440 [o_fast setEnabled: b_seekable];
\r
441 [o_fs_timeSlider setEnabled: b_seekable];
\r
444 - (void)setVolumeLevel: (float)f_volumeLevel
\r
446 [o_fs_volumeSlider setFloatValue: f_volumeLevel];
\r
449 - (IBAction)play:(id)sender
\r
451 [[[VLCMain sharedInstance] getControls] play: sender];
\r
454 - (IBAction)faster:(id)sender
\r
456 [[[VLCMain sharedInstance] getControls] faster: sender];
\r
459 - (IBAction)slower:(id)sender
\r
461 [[[VLCMain sharedInstance] getControls] slower: sender];
\r
464 - (IBAction)prev:(id)sender
\r
466 [[[VLCMain sharedInstance] getControls] prev: sender];
\r
469 - (IBAction)next:(id)sender
\r
471 [[[VLCMain sharedInstance] getControls] next: sender];
\r
474 - (IBAction)windowAction:(id)sender
\r
476 [[[VLCMain sharedInstance] getControls] windowAction: sender];
\r
479 - (IBAction)fsTimeSliderUpdate:(id)sender
\r
481 [[VLCMain sharedInstance] timesliderUpdate: sender];
\r
484 - (IBAction)fsVolumeSliderUpdate:(id)sender
\r
486 [[[VLCMain sharedInstance] getControls] volumeSliderUpdated: sender];
\r
489 #define addImage(image, _x, _y, mode, _width) \
\r
490 img = [NSImage imageNamed:image]; \
\r
491 image_rect.size = [img size]; \
\r
492 image_rect.origin.x = 0; \
\r
493 image_rect.origin.y = 0; \
\r
494 frame.origin.x = _x; \
\r
495 frame.origin.y = _y; \
\r
496 frame.size = [img size]; \
\r
497 if( _width ) frame.size.width = _width; \
\r
498 [img drawInRect:frame fromRect:image_rect operation:mode fraction:1];
\r
500 - (void)drawRect:(NSRect)rect
\r
502 NSRect frame = [self frame];
\r
505 addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 );
\r
506 addImage( @"fs_volume_slider_bar", 26, 22, NSCompositeSourceOver, 0 );
\r
507 addImage( @"fs_volume_mute", 16, 18, NSCompositeSourceOver, 0 );
\r
508 addImage( @"fs_volume_max", 124, 17, NSCompositeSourceOver, 0 );
\r
509 addImage( @"fs_time_slider", 15, 53, NSCompositeSourceOver, 0);
\r
514 /*****************************************************************************
\r
516 *****************************************************************************/
\r
517 @implementation VLCFSTimeSlider
\r
518 - (void)drawKnobInRect:(NSRect)knobRect
\r
521 NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];
\r
522 image_rect.size = [img size];
\r
523 image_rect.origin.x = 0;
\r
524 image_rect.origin.y = 0;
\r
525 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
\r
526 knobRect.size.width = image_rect.size.width;
\r
527 knobRect.size.height = image_rect.size.height;
\r
528 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
\r
531 - (void)drawRect:(NSRect)rect
\r
533 /* Draw default to make sure the slider behaves correctly */
\r
534 [[NSGraphicsContext currentContext] saveGraphicsState];
\r
535 NSRectClip(NSZeroRect);
\r
536 [super drawRect:rect];
\r
537 [[NSGraphicsContext currentContext] restoreGraphicsState];
\r
539 NSRect knobRect = [[self cell] knobRectFlipped:NO];
\r
540 knobRect.origin.y+=7.5;
\r
541 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
\r
542 [self drawKnobInRect: knobRect];
\r
547 /*****************************************************************************
\r
548 * VLCFSVolumeSlider
\r
549 *****************************************************************************/
\r
550 @implementation VLCFSVolumeSlider
\r
551 - (void)drawKnobInRect:(NSRect) knobRect
\r
554 NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];
\r
555 image_rect.size = [img size];
\r
556 image_rect.origin.x = 0;
\r
557 image_rect.origin.y = 0;
\r
558 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
\r
559 knobRect.size.width = image_rect.size.width;
\r
560 knobRect.size.height = image_rect.size.height;
\r
561 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
\r
564 - (void)drawRect:(NSRect)rect
\r
566 /* Draw default to make sure the slider behaves correctly */
\r
567 [[NSGraphicsContext currentContext] saveGraphicsState];
\r
568 NSRectClip(NSZeroRect);
\r
569 [super drawRect:rect];
\r
570 [[NSGraphicsContext currentContext] restoreGraphicsState];
\r
572 NSRect knobRect = [[self cell] knobRectFlipped:NO];
\r
573 knobRect.origin.y+=6;
\r
574 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
\r
575 [self drawKnobInRect: knobRect];
\r