+/*****************************************************************************\r
+ * fspanel.m: MacOS X full screen panel\r
+ *****************************************************************************\r
+ * Copyright (C) 2006 the VideoLAN team\r
+ * $Id$\r
+ *\r
+ * Authors: J\8er\99me Decoodt <djc at videolan dot org>\r
+ * Felix K\9fhne <fkuehne at videolan dot org>\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.\r
+ *****************************************************************************/\r
+\r
+/*****************************************************************************\r
+ * Preamble\r
+ *****************************************************************************/\r
+#import "intf.h"\r
+#import "fspanel.h"\r
+\r
+#define KEEP_VISIBLE_AFTER_ACTION 4 /* time in half-sec until this panel will hide again after an user's action */\r
+\r
+/*****************************************************************************\r
+ * VLCFSPanel\r
+ *****************************************************************************/\r
+@implementation VLCFSPanel\r
+// We override this initializer so we can set the NSBorderlessWindowMask styleMask, and set a few other important settings\r
+- (id)initWithContentRect:(NSRect)contentRect \r
+ styleMask:(unsigned int)aStyle \r
+ backing:(NSBackingStoreType)bufferingType \r
+ defer:(BOOL)flag\r
+{\r
+ id win=[super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:bufferingType defer:flag];\r
+ [win setOpaque:NO];\r
+ [win setHasShadow: NO];\r
+ [win setBackgroundColor:[NSColor clearColor]];\r
+ [win setLevel:NSFloatingWindowLevel]; // Let's make it sit on top of everything else\r
+ [win setAlphaValue:0.2]; // It'll start out mostly transparent\r
+ return win;\r
+}\r
+\r
+- (void)awakeFromNib\r
+{\r
+ [self setContentView:[[VLCFSPanelView alloc] initWithFrame: [self frame]]];\r
+ BOOL isInside=(NSPointInRect([NSEvent mouseLocation],[self frame]));\r
+ [[self contentView] addTrackingRect:[[self contentView] bounds] owner:self userData:nil assumeInside:isInside];\r
+ if (isInside)\r
+ [self mouseEntered:NULL];\r
+ if (!isInside)\r
+ [self mouseExited:NULL];\r
+}\r
+\r
+// Windows created with NSBorderlessWindowMask normally can't be key, but we want ours to be\r
+- (BOOL)canBecomeKeyWindow\r
+{\r
+ return YES;\r
+}\r
+\r
+-(void)dealloc\r
+{\r
+ if( hideAgainTimer )\r
+ [hideAgainTimer release];\r
+ [self setFadeTimer:nil];\r
+ [super dealloc];\r
+}\r
+\r
+- (void)setPlay\r
+{\r
+ [[self contentView] setPlay];\r
+}\r
+\r
+- (void)setPause\r
+{\r
+ [[self contentView] setPause];\r
+}\r
+\r
+- (void)setStreamTitle:(NSString *)o_title\r
+{\r
+ [[self contentView] setStreamTitle: o_title];\r
+}\r
+\r
+- (void)setStreamPos:(float) f_pos setSeconds:(int)i_seconds;\r
+{\r
+ [[self contentView] setStreamPos:f_pos setSeconds:i_seconds];\r
+}\r
+\r
+// This routine is called repeatedly when the mouse enters the window from outside it.\r
+- (void)focus:(NSTimer *)timer\r
+{\r
+ if( [self alphaValue] < 1.0 )\r
+ [self setAlphaValue:[self alphaValue]+0.1];\r
+ if( [self alphaValue] >= 1.0 )\r
+ {\r
+ [self setAlphaValue: 1.0];\r
+ [self setFadeTimer:nil];\r
+ if( b_fadeQueued )\r
+ {\r
+ b_fadeQueued=NO;\r
+ [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];\r
+ }\r
+ }\r
+}\r
+\r
+// This routine is called repeatedly when the mouse exits the window from inside it.\r
+- (void)unfocus:(NSTimer *)timer\r
+{\r
+ if( [self alphaValue] > 0.0 )\r
+ [self setAlphaValue:[self alphaValue]-0.1];\r
+ if( [self alphaValue] <= 0.1 )\r
+ {\r
+ [self setAlphaValue:0.0];\r
+ [self setFadeTimer:nil];\r
+ if( b_fadeQueued )\r
+ {\r
+ b_fadeQueued=NO;\r
+ [self setFadeTimer:\r
+ [NSTimer scheduledTimerWithTimeInterval:0.1 \r
+ target:self \r
+ selector:@selector(focus:) \r
+ userInfo:NULL \r
+ repeats:YES]];\r
+ }\r
+ }\r
+}\r
+\r
+// If the mouse enters a window, go make sure we fade in\r
+- (void)mouseEntered:(NSEvent *)theEvent\r
+{\r
+ [self fadeIn];\r
+}\r
+\r
+// If the mouse exits a window, go make sure we fade out\r
+- (void)mouseExited:(NSEvent *)theEvent\r
+{\r
+ /* the user left the window, fade out immediatelly and prevent any timer action */\r
+ if( b_alreadyCounting )\r
+ {\r
+ [hideAgainTimer invalidate];\r
+ [hideAgainTimer release];\r
+ b_alreadyCounting = NO;\r
+ hideAgainTimer = NULL;\r
+ }\r
+\r
+ [self fadeOut];\r
+}\r
+\r
+- (void)fadeIn\r
+{\r
+ if( [self alphaValue] < 1.0 )\r
+ {\r
+ if (![self fadeTimer])\r
+ [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];\r
+ else if ([[[self fadeTimer] userInfo] shortValue]==0)\r
+ b_fadeQueued=YES;\r
+ }\r
+ [self autoHide];\r
+}\r
+\r
+- (void)fadeOut\r
+{\r
+ if(( [self alphaValue] > 0.0 ) && !NSPointInRect( [NSEvent mouseLocation], [self frame] ) )\r
+ {\r
+ if (![self fadeTimer])\r
+ [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];\r
+ else if ([[[self fadeTimer] userInfo] shortValue]==1)\r
+ b_fadeQueued=YES;\r
+ }\r
+}\r
+\r
+/* triggers a timer to autoHide us again after some seconds of no activity */\r
+- (void)autoHide\r
+{\r
+ /* this will tell the timer to start over again or to start at all */\r
+ b_keptVisible = YES;\r
+ \r
+ /* get us a valid timer */\r
+ if(! b_alreadyCounting )\r
+ {\r
+ hideAgainTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5\r
+ target: self \r
+ selector: @selector(keepVisible:)\r
+ userInfo: nil \r
+ repeats: YES];\r
+ [hideAgainTimer fire];\r
+ [hideAgainTimer retain];\r
+ b_alreadyCounting = YES;\r
+ }\r
+}\r
+\r
+- (void)keepVisible:(NSTimer *)timer\r
+{\r
+ /* if the user triggered an action, start over again */\r
+ if( b_keptVisible )\r
+ {\r
+ i_timeToKeepVisibleInSec = KEEP_VISIBLE_AFTER_ACTION;\r
+ b_keptVisible = NO;\r
+ }\r
+ \r
+ /* count down until we hide ourselfes again and do so if necessary */\r
+ i_timeToKeepVisibleInSec -= 1;\r
+ if( i_timeToKeepVisibleInSec < 1 )\r
+ {\r
+ [self fadeOut];\r
+ [timer invalidate];\r
+ [timer release];\r
+ b_alreadyCounting = NO;\r
+ timer = NULL;\r
+ }\r
+}\r
+\r
+// A getter and setter for our main timer that handles window fading\r
+- (NSTimer *)fadeTimer\r
+{\r
+ return fadeTimer;\r
+}\r
+\r
+- (void)setFadeTimer:(NSTimer *)timer\r
+{\r
+ [timer retain];\r
+ [fadeTimer invalidate];\r
+ [fadeTimer release];\r
+ fadeTimer=timer;\r
+}\r
+\r
+- (void)mouseDown:(NSEvent *)theEvent\r
+{\r
+ mouseClic = [theEvent locationInWindow];\r
+}\r
+\r
+- (void)mouseDragged:(NSEvent *)theEvent\r
+{\r
+ NSPoint point = [NSEvent mouseLocation];\r
+ point.x -= mouseClic.x;\r
+ point.y -= mouseClic.y;\r
+ [self setFrameOrigin:point];\r
+}\r
+@end\r
+\r
+/*****************************************************************************\r
+ * FSPanelView\r
+ *****************************************************************************/\r
+@implementation VLCFSPanelView\r
+\r
+#define addButton( o_button, imageOff, imageOn, _x, _y, action ) \\r
+ s_rc.origin.x = _x; \\r
+ s_rc.origin.y = _y; \\r
+ o_button = [[NSButton alloc] initWithFrame: s_rc]; \\r
+ [o_button setButtonType: NSMomentaryChangeButton]; \\r
+ [o_button setBezelStyle: NSRegularSquareBezelStyle]; \\r
+ [o_button setBordered: NO]; \\r
+ [o_button setFont:[NSFont systemFontOfSize:0]]; \\r
+ image = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:imageOff]]; \\r
+ [o_button setImage:image]; \\r
+ image = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:imageOn]]; \\r
+ [o_button setAlternateImage:image]; \\r
+ [o_button sizeToFit]; \\r
+ [o_button setTarget: self]; \\r
+ [o_button setAction: @selector(action:)]; \\r
+ [self addSubview:o_button];\r
+\r
+#define addTextfield( o_text, align, font, color, size ) \\r
+ o_text = [[NSTextField alloc] initWithFrame: s_rc]; \\r
+ [o_text setDrawsBackground: NO]; \\r
+ [o_text setBordered: NO]; \\r
+ [o_text setEditable: NO]; \\r
+ [o_text setSelectable: NO]; \\r
+ [o_text setStringValue: _NS("(no item is being played)")]; \\r
+ [o_text setAlignment: align]; \\r
+ [o_text setTextColor: [NSColor color]]; \\r
+ [o_text setFont:[NSFont font:[NSFont smallSystemFontSize] - size]]; \\r
+ [self addSubview:o_text];\r
+\r
+- (id)initWithFrame:(NSRect)frameRect\r
+{\r
+ NSBundle * bundle = [NSBundle mainBundle];\r
+ id view = [super initWithFrame:frameRect];\r
+ fillColor = [[NSColor clearColor] retain];\r
+ NSRect s_rc = [self frame];\r
+ NSImage * image;\r
+ addButton( o_prev, @"FSGotoBeginningOff.tif" , @"FSGotoBeginningOn.tif", 106, 37, prev );\r
+ addButton( o_slow, @"FSRewindOff.tif" , @"FSRewindOn.tif" , 143, 37, slower );\r
+ addButton( o_play, @"FSPlayOff.tif" , @"FSPlayOn.tif" , 191, 37, play );\r
+ addButton( o_fast, @"FSFastForwardOff.tif" , @"FSFastForwardOn.tif" , 238, 37, faster );\r
+ addButton( o_next, @"FSGotoEndOff.tif" , @"FSGotoEndOn.tif" , 286, 37, next );\r
+ addButton( o_fullscreen, @"FSExitOff.tif", @"FSExitOn.tif", 382, 45, windowAction );\r
+// addButton( o_button, @"FSVolumeThumbOff.tif" , @"FSVolumeThumbOn.tif" , 38, 51, something );\r
+\r
+ s_rc = [self frame];\r
+ s_rc.origin.x = 25;\r
+ s_rc.origin.y = 14;\r
+ s_rc.size.width = 329;\r
+ s_rc.size.height = 13;\r
+ o_time_slider = [[[VLCFSTimeSlider alloc] initWithFrame: s_rc] retain];\r
+ [o_time_slider setMinValue:0];\r
+ [o_time_slider setMaxValue:1];\r
+ [o_time_slider setFloatValue: 0];\r
+ [o_time_slider setAction: @selector(timesliderUpdate:)];\r
+ [self addSubview: o_time_slider];\r
+ \r
+ s_rc = [self frame];\r
+ s_rc.origin.x = 25;\r
+ s_rc.origin.y = 83;\r
+ s_rc.size.width = s_rc.size.width - s_rc.origin.x * 2;\r
+ s_rc.size.height = 16;\r
+ addTextfield( o_textfield, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );\r
+ s_rc.origin.x = 349;\r
+ s_rc.origin.y = 10;\r
+ s_rc.size.width = 50;\r
+ addTextfield( o_textPos, NSRightTextAlignment, systemFontOfSize, blackColor, 2 );\r
+\r
+ return view;\r
+}\r
+\r
+- (void)setPlay\r
+{\r
+ NSBundle *bundle = [NSBundle mainBundle];\r
+ NSImage *image;\r
+ [[o_play image] release];\r
+ [[o_play alternateImage] release];\r
+ image = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"FSPlayOff.tif"]];\r
+ [o_play setImage:image];\r
+ image = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"FSPlayOn.tif"]];\r
+ [o_play setAlternateImage:image];\r
+}\r
+\r
+- (void)setPause\r
+{\r
+ NSBundle *bundle = [NSBundle mainBundle];\r
+ NSImage *image;\r
+ [[o_play image] release];\r
+ [[o_play alternateImage] release];\r
+ image = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"FSPauseOff.tif"]];\r
+ [o_play setImage:image];\r
+ image = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"FSPauseOn.tif"]];\r
+ [o_play setAlternateImage:image];\r
+}\r
+\r
+- (void)setStreamTitle:(NSString *)o_title\r
+{\r
+ [o_textfield setStringValue: o_title];\r
+}\r
+\r
+- (void)setStreamPos:(float) f_pos setSeconds:(int)i_seconds\r
+{\r
+ NSString *o_pos = [NSString stringWithFormat: @"%d:%02d:%02d",\r
+ (int) (i_seconds / (60 * 60)),\r
+ (int) (i_seconds / 60 % 60),\r
+ (int) (i_seconds % 60)];\r
+\r
+ [o_textPos setStringValue: o_pos];\r
+ [o_time_slider setFloatValue: f_pos];\r
+}\r
+\r
+- (IBAction)play:(id)sender\r
+{\r
+ [[[VLCMain sharedInstance] getControls] play: sender];\r
+}\r
+\r
+- (IBAction)faster:(id)sender\r
+{\r
+ [[[VLCMain sharedInstance] getControls] faster: sender];\r
+}\r
+\r
+- (IBAction)slower:(id)sender\r
+{\r
+ [[[VLCMain sharedInstance] getControls] slower: sender];\r
+}\r
+\r
+- (IBAction)prev:(id)sender\r
+{\r
+ [[[VLCMain sharedInstance] getControls] prev: sender];\r
+}\r
+\r
+- (IBAction)next:(id)sender\r
+{\r
+ [[[VLCMain sharedInstance] getControls] next: sender];\r
+}\r
+\r
+- (IBAction)windowAction:(id)sender\r
+{\r
+ [[[VLCMain sharedInstance] getControls] windowAction: sender];\r
+}\r
+\r
+- (IBAction)timesliderUpdate:(id)sender\r
+{\r
+ [[VLCMain sharedInstance] timesliderUpdate: sender];\r
+}\r
+\r
+#define addImage(image, _x, _y, mode, _width) \\r
+ img = [[[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:image]] autorelease]; \\r
+ image_rect.size = [img size]; \\r
+ image_rect.origin.x = 0; \\r
+ image_rect.origin.y = 0; \\r
+ frame.origin.x = _x; \\r
+ frame.origin.y = _y; \\r
+ frame.size = [img size]; \\r
+ if( _width ) frame.size.width = _width; \\r
+ [img drawInRect:frame fromRect:image_rect operation:mode fraction:1];\r
+\r
+- (void)drawRect:(NSRect)rect\r
+{\r
+ NSBundle *bundle = [NSBundle mainBundle];\r
+ NSRect frame = [self frame];\r
+ NSRect image_rect;\r
+ NSImage *img;\r
+ addImage( @"FSBase.tif", 0, 0, NSCompositeCopy, 0 );\r
+ addImage( @"FSVolumeBackground.tif" , 25, 49, NSCompositeSourceOver, 0 );\r
+ addImage( @"FSLCDTimeBackground.tif", 354, 14, NSCompositeSourceOver, 0 );\r
+}\r
+\r
+@end\r
+\r
+/*****************************************************************************\r
+ * VLCFSTimeSlider\r
+ *****************************************************************************/\r
+@implementation VLCFSTimeSlider\r
+void drawKnobInRect(NSRect knobRect)\r
+{\r
+ NSBundle *bundle = [NSBundle mainBundle];\r
+ NSRect image_rect;\r
+ NSImage *img = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"FSLCDSliderPlayHead"]];\r
+ image_rect.size = [img size];\r
+ image_rect.origin.x = 0;\r
+ image_rect.origin.y = 0;\r
+ knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;\r
+ knobRect.size.width = image_rect.size.width;\r
+ knobRect.size.height = image_rect.size.height;\r
+ [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];\r
+}\r
+\r
+void drawFrameInRect(NSRect frameRect)\r
+{\r
+ // Draw frame\r
+ NSBundle *bundle = [NSBundle mainBundle];\r
+ NSRect frame = frameRect;\r
+ NSRect image_rect;\r
+ NSImage *img;\r
+ addImage(@"FSLCDSliderLeft.tif" , 0, 0, NSCompositeSourceOver, 0);\r
+ addImage(@"FSLCDSliderCenter.tif" , 9, 0, NSCompositeSourceOver, 311);\r
+ addImage(@"FSLCDSliderRight.tif" , 320, 0, NSCompositeSourceOver, 0);\r
+}\r
+\r
+- (void)drawRect:(NSRect)rect\r
+{\r
+ // Draw default to make sure the slider behaves correctly\r
+ [[NSGraphicsContext currentContext] saveGraphicsState];\r
+ NSRectClip(NSZeroRect);\r
+ [super drawRect:rect];\r
+ [[NSGraphicsContext currentContext] restoreGraphicsState];\r
+ \r
+ NSRect knobRect = [[self cell] knobRectFlipped:NO];\r
+ knobRect.origin.y+=6;\r
+ [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];\r
+ drawFrameInRect(rect);\r
+ drawKnobInRect(knobRect);\r
+}\r
+\r
+@end\r