[vlc-commits] win32: re-organize audio button/slider updating methods

Daniel Amm git at videolan.org
Thu Dec 17 23:59:10 CET 2015


npapi-vlc | branch: master | Daniel Amm <da2424 at t-online.de> | Wed Dec 16 19:59:02 2015 +0100| [37db61d3c8fc514f39a8d2dc8529c858a6f7cb79] | committer: Jean-Baptiste Kempf

win32: re-organize audio button/slider updating methods

This is needed for the next commit

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> https://code.videolan.org/videolan/npapi-vlc/commit/37db61d3c8fc514f39a8d2dc8529c858a6f7cb79
---

 common/win32_fullscreen.cpp | 67 ++++++++++++++++++++-------------------------
 common/win32_fullscreen.h   |  4 +--
 2 files changed, 31 insertions(+), 40 deletions(-)

diff --git a/common/win32_fullscreen.cpp b/common/win32_fullscreen.cpp
index 5c20dca..2f276be 100644
--- a/common/win32_fullscreen.cpp
+++ b/common/win32_fullscreen.cpp
@@ -216,8 +216,13 @@ LRESULT VLCControlsWnd::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
                          SWP_NOZORDER|SWP_NOOWNERZORDER|SWP_NOACTIVATE);
 
             CreateToolTip();
-            RegisterToVLCEvents();
-            SyncVolumeSliderWithVLCVolume();
+
+            if( VP() ){
+                RegisterToVLCEvents();
+                UpdateVolumeSlider( VP()->get_mp().volume() );
+                UpdateMuteButton( VP()->get_mp().mute() );
+            }
+
             break;
         }
         case WM_LBUTTONUP:{
@@ -280,8 +285,9 @@ LRESULT VLCControlsWnd::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
                         }
                         case ID_FS_MUTE:{
                             if( VP() ){
-                                VP()->get_mp().setMute( IsDlgButtonChecked(hWnd(), ID_FS_MUTE) != FALSE );
-                                SyncVolumeSliderWithVLCVolume();
+                                bool newMutedState = IsDlgButtonChecked(hWnd(), ID_FS_MUTE) != FALSE;
+                                VP()->get_mp().setMute( newMutedState );
+                                UpdateMuteButton( newMutedState );
                             }
                             break;
                         }
@@ -380,10 +386,10 @@ LRESULT VLCControlsWnd::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
         }
         case WM_HSCROLL:
         case WM_VSCROLL: {
-            if( VP() ){
-                if(hVolumeSlider==(HWND)lParam){
+            if( hVolumeSlider == (HWND)lParam ){
+                if( VP() ){
                     LRESULT SliderPos = SendMessage(hVolumeSlider, (UINT) TBM_GETPOS, 0, 0);
-                    SetVLCVolumeBySliderPos(SliderPos);
+                    VP()->get_mp().setVolume( SliderPos );
                 }
             }
             break;
@@ -444,44 +450,29 @@ void VLCControlsWnd::SetVideoPos(float Pos) //0-start, 1-end
     }
 }
 
-void VLCControlsWnd::SyncVolumeSliderWithVLCVolume()
+void VLCControlsWnd::UpdateVolumeSlider(unsigned int vol)
 {
-    if( VP() ){
-        vlc_player& vp = *VP();
-        unsigned int vol = vp.get_mp().volume();
-        const LRESULT SliderPos = SendMessage(hVolumeSlider, (UINT) TBM_GETPOS, 0, 0);
-        if((UINT)SliderPos!=vol)
-            PostMessage(hVolumeSlider, (UINT) TBM_SETPOS, (WPARAM) TRUE, (LPARAM) vol);
-
-        bool muted = vp.get_mp().mute();
-        int MuteButtonState = SendMessage(hMuteButton, (UINT) BM_GETCHECK, 0, 0);
-        if((muted&&(BST_UNCHECKED==MuteButtonState))||(!muted&&(BST_CHECKED==MuteButtonState))){
-            PostMessage(hMuteButton, BM_SETCHECK, (WPARAM)(muted?BST_CHECKED:BST_UNCHECKED), 0);
-        }
-        LRESULT lResult = SendMessage(hMuteButton, BM_GETIMAGE, (WPARAM)IMAGE_BITMAP, 0);
-        if( (muted && ((HANDLE)lResult == RC().hVolumeBitmap)) ||
-            (!muted&&((HANDLE)lResult == RC().hVolumeMutedBitmap)) )
-        {
-            HANDLE hBmp = muted ? RC().hVolumeMutedBitmap : RC().hVolumeBitmap ;
-            PostMessage(hMuteButton, BM_SETIMAGE,
-                        (WPARAM)IMAGE_BITMAP, (LPARAM)hBmp);
-        }
-    }
+    const LRESULT SliderPos = SendMessage(hVolumeSlider, (UINT) TBM_GETPOS, 0, 0);
+    if( (UINT)SliderPos != vol )
+        PostMessage(hVolumeSlider, (UINT) TBM_SETPOS, (WPARAM) TRUE, (LPARAM) vol);
 }
 
-void VLCControlsWnd::SetVLCVolumeBySliderPos(int CurPos)
+void VLCControlsWnd::UpdateMuteButton(bool muted)
 {
-    if( VP() ){
-        vlc_player& vp = *VP();
-        vp.get_mp().setVolume( CurPos );
-        if(0==CurPos){
-            vp.get_mp().setMute( IsDlgButtonChecked( hWnd(), ID_FS_MUTE) != FALSE );
-        }
-        SyncVolumeSliderWithVLCVolume();
+    int MuteButtonState = SendMessage(hMuteButton, (UINT) BM_GETCHECK, 0, 0);
+    if((muted&&(BST_UNCHECKED==MuteButtonState))||(!muted&&(BST_CHECKED==MuteButtonState))){
+        PostMessage(hMuteButton, BM_SETCHECK, (WPARAM)(muted?BST_CHECKED:BST_UNCHECKED), 0);
+    }
+    LRESULT lResult = SendMessage(hMuteButton, BM_GETIMAGE, (WPARAM)IMAGE_BITMAP, 0);
+    if( (muted && ((HANDLE)lResult == RC().hVolumeBitmap)) ||
+        (!muted&&((HANDLE)lResult == RC().hVolumeMutedBitmap)) )
+    {
+        HANDLE hBmp = muted ? RC().hVolumeMutedBitmap : RC().hVolumeBitmap ;
+        PostMessage(hMuteButton, BM_SETIMAGE,
+             (WPARAM)IMAGE_BITMAP, (LPARAM)hBmp);
     }
 }
 
-
 void VLCControlsWnd::UpdateFullscreenButton(bool fullscreen)
 {
     if (fullscreen)
diff --git a/common/win32_fullscreen.h b/common/win32_fullscreen.h
index c1ff55e..1bd65be 100644
--- a/common/win32_fullscreen.h
+++ b/common/win32_fullscreen.h
@@ -107,8 +107,8 @@ protected:
 private:
     void SetVideoPos(float Pos); //0-start, 1-end
 
-    void SyncVolumeSliderWithVLCVolume();
-    void SetVLCVolumeBySliderPos(int CurScrollPos);
+    void UpdateVolumeSlider(unsigned int vol);
+    void UpdateMuteButton(bool muted);
     void RegisterToVLCEvents();
 
     void NeedHideControls();



More information about the vlc-commits mailing list