* implemented the volume slider
authorFelix Paul Kühne <fkuehne@videolan.org>
Wed, 4 Oct 2006 08:19:38 +0000 (08:19 +0000)
committerFelix Paul Kühne <fkuehne@videolan.org>
Wed, 4 Oct 2006 08:19:38 +0000 (08:19 +0000)
* major speed and memory improvements to the image handling (the panel launches noticebly faster now) and controls
* coding style fixes

- just FYI: The VLCFSVolumeSlider and VLCFSTimeSlider classes will be merged later on to add as little code duplication as possible.

extras/MacOSX/Resources/English.lproj/MainMenu.nib/info.nib
extras/MacOSX/Resources/English.lproj/MainMenu.nib/keyedobjects.nib
modules/gui/macosx/fspanel.h
modules/gui/macosx/fspanel.m
modules/gui/macosx/intf.m

index b2b8806..098933b 100644 (file)
        <key>IBOpenObjects</key>
        <array>
                <integer>21</integer>
-               <integer>2197</integer>
                <integer>2730</integer>
-               <integer>2769</integer>
                <integer>29</integer>
+               <integer>2416</integer>
+               <integer>2769</integer>
        </array>
        <key>IBSystem Version</key>
        <string>8L127</string>
index 8724cb1..c052c57 100644 (file)
Binary files a/extras/MacOSX/Resources/English.lproj/MainMenu.nib/keyedobjects.nib and b/extras/MacOSX/Resources/English.lproj/MainMenu.nib/keyedobjects.nib differ
index f5f0e03..b5041d7 100644 (file)
@@ -44,6 +44,7 @@
 - (void)setStreamTitle:(NSString *)o_title;\r
 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time;\r
 - (void)setSeekable:(BOOL) b_seekable;\r
+- (void)setVolumeLevel: (float)f_volumeLevel;\r
 \r
 - (void)focus:(NSTimer *)timer;\r
 - (void)unfocus:(NSTimer *)timer;\r
@@ -67,8 +68,8 @@
 {\r
     NSColor *fillColor;\r
     NSButton *o_prev, *o_next, *o_slow, *o_fast, *o_play, *o_fullscreen;\r
-    NSTextField *o_textfield, *o_textPos;\r
-    NSSlider *o_fs_timeSlider;\r
+    NSTextField *o_streamTitle_txt, *o_streamPosition_txt;\r
+    NSSlider *o_fs_timeSlider, *o_fs_volumeSlider;\r
 }\r
 - (id)initWithFrame:(NSRect)frameRect;\r
 - (void)drawRect:(NSRect)rect;\r
 - (void)setPlay;\r
 - (void)setPause;\r
 - (void)setStreamTitle: (NSString *)o_title;\r
-- (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time;\r
+- (void)setStreamPos: (float)f_pos andTime: (NSString *)o_time;\r
 - (void)setSeekable: (BOOL)b_seekable; \r
+- (void)setVolumeLevel: (float)f_volumeLevel;\r
 - (IBAction)play:(id)sender;\r
 - (IBAction)prev:(id)sender;\r
 - (IBAction)next:(id)sender;\r
 - (IBAction)faster:(id)sender;\r
 - (IBAction)slower:(id)sender;\r
 - (IBAction)fsTimeSliderUpdate:(id)sender;\r
+- (IBAction)fsVolumeSliderUpdate:(id)sender;\r
 \r
 @end\r
 \r
 @interface VLCFSTimeSlider : NSSlider\r
-{}\r
-void drawKnobInRect(NSRect knobRect);\r
-void drawFrameInRect(NSRect frameRect);\r
+{\r
+}\r
+- (void)drawKnobInRect:(NSRect)knobRect;\r
+- (void)drawRect:(NSRect)rect;\r
+\r
+@end\r
+\r
+@interface VLCFSVolumeSlider : NSSlider\r
+{\r
+}\r
+- (void)drawKnobInRect:(NSRect)knobRect;\r
 - (void)drawRect:(NSRect)rect;\r
 \r
 @end\r
index b27fab7..05911ec 100644 (file)
     [[self contentView] setStreamPos:f_pos andTime: o_time];\r
 }\r
 \r
-- (void)setSeekable:(BOOL) b_seekable;\r
+- (void)setSeekable:(BOOL) b_seekable\r
 {\r
     [[self contentView] setSeekable: b_seekable];\r
 }\r
 \r
+- (void)setVolumeLevel: (float)f_volumeLevel\r
+{\r
+    [[self contentView] setVolumeLevel: f_volumeLevel];\r
+}\r
+\r
 /* This routine is called repeatedly when the mouse enters the window from outside it. */\r
 - (void)focus:(NSTimer *)timer\r
 {\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 setImage:[NSImage imageNamed:imageOff]];                                 \\r
+    [o_button setAlternateImage:[NSImage imageNamed:imageOn]];                         \\r
     [o_button sizeToFit];                                                                       \\r
     [o_button setTarget: self];                                                                 \\r
     [o_button setAction: @selector(action:)];                                                   \\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, @"fs_skip_previous.png" , @"fs_skip_previous_highlight.png", 174, 15, prev );\r
-    addButton( o_slow, @"fs_rewind.png"        , @"fs_rewind_highlight.png"       , 211, 14, slower );\r
-    addButton( o_play, @"fs_play.png"          , @"fs_play_highlight.png"         , 269, 10, play );\r
-    addButton( o_fast, @"fs_forward.png"       , @"fs_forward_highlight.png"      , 313, 14, faster );\r
-    addButton( o_next, @"fs_skip_next.png"     , @"fs_skip_next_highlight.png"    , 365, 15, next );\r
-    addButton( o_fullscreen, @"fs_exit_fullscreen.png", @"fs_exit_fullscreen_hightlight.png", 507, 13, windowAction );\r
+    addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev );\r
+    addButton( o_slow, @"fs_rewind"        , @"fs_rewind_highlight"       , 211, 14, slower );\r
+    addButton( o_play, @"fs_play"          , @"fs_play_highlight"         , 267, 10, play );\r
+    addButton( o_fast, @"fs_forward"       , @"fs_forward_highlight"      , 313, 14, faster );\r
+    addButton( o_next, @"fs_skip_next"     , @"fs_skip_next_highlight"    , 365, 15, next );\r
+    addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, windowAction );\r
 /*\r
-    addButton( o_button, @"FSVolumeThumbOff.tif"   , @"FSVolumeThumbOn.tif"  ,  38, 51, something );\r
+    addButton( o_button, @"image (off state)", @"image (on state)", 38, 51, something );\r
  */\r
 \r
+    /* time slider */\r
     s_rc = [self frame];\r
     s_rc.origin.x = 15;\r
     s_rc.origin.y = 53;\r
     [o_fs_timeSlider setTarget: self];\r
     [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];\r
     [self addSubview: o_fs_timeSlider];\r
+\r
+    /* volume slider */\r
+    s_rc = [self frame];\r
+    s_rc.origin.x = 26;\r
+    s_rc.origin.y = 17.5;\r
+    s_rc.size.width = 95;\r
+    s_rc.size.height = 10;\r
+    o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];\r
+    [o_fs_volumeSlider setMinValue:0];\r
+    [o_fs_volumeSlider setMaxValue:32];\r
+    [o_fs_volumeSlider setFloatValue: 0];\r
+    [o_fs_volumeSlider setContinuous: YES];\r
+    [o_fs_volumeSlider setTarget: self];\r
+    [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];\r
+    [self addSubview: o_fs_volumeSlider];\r
     \r
+    /* time counter and stream title output fields */\r
     s_rc = [self frame];\r
     s_rc.origin.x = 98;\r
     s_rc.origin.y = 64;\r
     s_rc.size.width = 352;\r
     s_rc.size.height = 14;\r
-    addTextfield( o_textfield, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );\r
+    addTextfield( o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );\r
     s_rc.origin.x = 486;\r
     s_rc.origin.y = 64;\r
     s_rc.size.width = 50;\r
-    addTextfield( o_textPos, NSRightTextAlignment, systemFontOfSize, whiteColor, 0 );\r
+    addTextfield( o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor, 0 );\r
 \r
     return view;\r
 }\r
 - (void)dealloc\r
 {\r
     [o_fs_timeSlider release];\r
+    [o_fs_volumeSlider release];\r
+    [o_prev release];\r
+    [o_next release];\r
+    [o_slow release];\r
+    [o_play release];\r
+    [o_fast release];\r
+    [o_fullscreen release];\r
+    [o_streamTitle_txt release];\r
+    [o_streamPosition_txt release];\r
     [super dealloc];\r
 }\r
 \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:@"fs_play.png"]];\r
+    image = [NSImage imageNamed:@"fs_play"];\r
     [o_play setImage:image];\r
-    image = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"fs_play_highlight.png"]];\r
+    image = [NSImage imageNamed:@"fs_play_highlight"];\r
     [o_play setAlternateImage:image];\r
 }\r
 \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:@"fs_pause.png"]];\r
+    image = [NSImage imageNamed:@"fs_pause"];\r
     [o_play setImage:image];\r
-    image = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"fs_pause_highlight.png"]];\r
+    image = [NSImage imageNamed:@"fs_pause_highlight"];\r
     [o_play setAlternateImage:image];\r
 }\r
 \r
 - (void)setStreamTitle:(NSString *)o_title\r
 {\r
-    [o_textfield setStringValue: o_title];\r
+    [o_streamTitle_txt setStringValue: o_title];\r
 }\r
 \r
 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time\r
 {\r
-    [o_textPos setStringValue: o_time];\r
+    [o_streamPosition_txt setStringValue: o_time];\r
     [o_fs_timeSlider setFloatValue: f_pos];\r
 }\r
 \r
     [o_fs_timeSlider setEnabled: b_seekable];\r
 }\r
 \r
+- (void)setVolumeLevel: (float)f_volumeLevel\r
+{\r
+    [o_fs_volumeSlider setFloatValue: f_volumeLevel];\r
+}\r
+\r
 - (IBAction)play:(id)sender\r
 {\r
     [[[VLCMain sharedInstance] getControls] play: sender];\r
     [[VLCMain sharedInstance] timesliderUpdate: sender];\r
 }\r
 \r
+- (IBAction)fsVolumeSliderUpdate:(id)sender\r
+{\r
+    [[[VLCMain sharedInstance] getControls] volumeSliderUpdated: sender];\r
+}\r
+\r
 #define addImage(image, _x, _y, mode, _width)                                               \\r
-    img = [[[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:image]] autorelease];     \\r
+    img = [NSImage imageNamed:image];                                              \\r
     image_rect.size = [img size];                                                           \\r
     image_rect.origin.x = 0;                                                                \\r
     image_rect.origin.y = 0;                                                                \\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( @"fs_background.png", 0, 0, NSCompositeCopy, 0 );\r
-    addImage( @"fs_volume_slider_bar.png" , 26, 22, NSCompositeSourceOver, 0 );\r
-    addImage( @"fs_volume_mute.png", 16, 18, NSCompositeSourceOver, 0 );\r
-    addImage( @"fs_volume_max.png", 124, 17, NSCompositeSourceOver, 0 );\r
-    addImage(@"fs_time_slider.png" ,  15, 53, NSCompositeSourceOver, 0);\r
+    addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 );\r
+    addImage( @"fs_volume_slider_bar", 26, 22, NSCompositeSourceOver, 0 );\r
+    addImage( @"fs_volume_mute", 16, 18, NSCompositeSourceOver, 0 );\r
+    addImage( @"fs_volume_max", 124, 17, NSCompositeSourceOver, 0 );\r
+    addImage( @"fs_time_slider", 15, 53, NSCompositeSourceOver, 0);\r
 }\r
 \r
 @end\r
  * VLCFSTimeSlider\r
  *****************************************************************************/\r
 @implementation VLCFSTimeSlider\r
-void drawKnobInRect(NSRect knobRect)\r
+- (void)drawKnobInRect:(NSRect)knobRect\r
 {\r
     NSBundle *bundle = [NSBundle mainBundle];\r
     NSRect image_rect;\r
-    NSImage *img = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"fs_time_slider_knob.png"]];\r
+    NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];\r
     image_rect.size = [img size];\r
     image_rect.origin.x = 0;\r
     image_rect.origin.y = 0;\r
@@ -469,9 +502,38 @@ void drawKnobInRect(NSRect knobRect)
     [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];\r
 }\r
 \r
-void drawFrameInRect(NSRect frameRect) \r
+- (void)drawRect:(NSRect)rect\r
 {\r
-    /* we don't do anything here atm */\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+=7.5;\r
+    [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];\r
+    [self drawKnobInRect: knobRect];\r
+}\r
+\r
+@end\r
+\r
+/*****************************************************************************\r
+* VLCFSVolumeSlider\r
+*****************************************************************************/\r
+@implementation VLCFSVolumeSlider\r
+- (void)drawKnobInRect:(NSRect) knobRect\r
+{\r
+    NSBundle *bundle = [NSBundle mainBundle];\r
+    NSRect image_rect;\r
+    NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];\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)drawRect:(NSRect)rect\r
@@ -483,10 +545,9 @@ void drawFrameInRect(NSRect frameRect)
     [[NSGraphicsContext currentContext] restoreGraphicsState];\r
     \r
     NSRect knobRect = [[self cell] knobRectFlipped:NO];\r
-    knobRect.origin.y+=7.5;\r
+    knobRect.origin.y+=6;\r
     [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];\r
-    drawFrameInRect(rect);\r
-    drawKnobInRect(knobRect);\r
+    [self drawKnobInRect: knobRect];\r
 }\r
 \r
-@end\r
+@end
\ No newline at end of file
index 046b74f..a30fe7a 100644 (file)
@@ -1212,6 +1212,7 @@ static VLCMain *_o_sharedMainInstance = nil;
             i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
             [o_volumeslider setFloatValue: (float)i_lastShownVolume / i_volume_step];
             [o_volumeslider setEnabled: TRUE];
+            [[[self getControls] getFSPanel] setVolumeLevel: (float)i_lastShownVolume / i_volume_step];
             p_intf->p_sys->b_mute = ( i_lastShownVolume == 0 );
             p_intf->p_sys->b_volume_update = FALSE;
         }