[vlc-commits] commit: skins2: rework and simplify transparency (Erwan Tulou )

git at videolan.org git at videolan.org
Mon Nov 22 22:45:22 CET 2010


vlc | branch: master | Erwan Tulou <erwan10 at videolan.org> | Mon Nov 22 21:10:52 2010 +0100| [64c2daf417e2525f19ac608b9c02e2c1dab42757] | committer: Erwan Tulou 

skins2: rework and simplify transparency

Several redraw were no longer needed
(tested successfully on Ubuntu/metacity and WinNT)

On Win32, switching back and forth between layered Window and not layered
 window (case where only one of the two alpha parameters is < 255) was removed
because display was not satisfactory. (transition a bit weird)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=64c2daf417e2525f19ac608b9c02e2c1dab42757
---

 modules/gui/skins2/src/window_manager.cpp |   27 ++++++++++--------
 modules/gui/skins2/src/window_manager.hpp |    9 +++++-
 modules/gui/skins2/win32/win32_window.cpp |   41 +++++------------------------
 3 files changed, 29 insertions(+), 48 deletions(-)

diff --git a/modules/gui/skins2/src/window_manager.cpp b/modules/gui/skins2/src/window_manager.cpp
index 7582e1d..807fcb7 100644
--- a/modules/gui/skins2/src/window_manager.cpp
+++ b/modules/gui/skins2/src/window_manager.cpp
@@ -33,13 +33,15 @@
 
 WindowManager::WindowManager( intf_thread_t *pIntf ):
     SkinObject( pIntf ), m_magnet( 0 ), m_direction( kNone ),
-    m_maximizeRect(0, 0, 50, 50),
-    m_pTooltip( NULL ), m_pPopup( NULL )
+    m_maximizeRect(0, 0, 50, 50), m_pTooltip( NULL ), m_pPopup( NULL ),
+    m_alpha( 255 ), m_moveAlpha( 255 ), m_OpacityEnabled( false )
 {
     // Create and register a variable for the "on top" status
     VarManager *pVarManager = VarManager::instance( getIntf() );
     m_cVarOnTop = VariablePtr( new VarBoolImpl( getIntf() ) );
     pVarManager->registerVar( m_cVarOnTop, "vlc.isOnTop" );
+
+    m_OpacityEnabled = var_InheritBool( getIntf(), "skins2-transparency" );
 }
 
 
@@ -71,7 +73,7 @@ void WindowManager::startMove( TopWindow &rWindow )
     m_movingWindows.clear();
     buildDependSet( m_movingWindows, &rWindow );
 
-    if( var_InheritBool( getIntf(), "skins2-transparency" ) )
+    if( isOpacityNeeded() )
     {
         // Change the opacity of the moving windows
         WinSet_t::const_iterator it;
@@ -79,14 +81,6 @@ void WindowManager::startMove( TopWindow &rWindow )
         {
             (*it)->setOpacity( m_moveAlpha );
         }
-
-        // FIXME: We need to refresh the windows, because if 2 windows overlap
-        // and one of them becomes transparent, the other one is not refreshed
-        // automatically. I don't know why... -- Ipkiss
-        for( it = m_allWindows.begin(); it != m_allWindows.end(); ++it )
-        {
-            (*it)->refresh( 0, 0, (*it)->getWidth(), (*it)->getHeight() );
-        }
     }
 }
 
@@ -96,7 +90,7 @@ void WindowManager::stopMove()
     WinSet_t::const_iterator itWin1, itWin2;
     AncList_t::const_iterator itAnc1, itAnc2;
 
-    if( var_InheritBool( getIntf(), "skins2-transparency" ) )
+    if( isOpacityNeeded() )
     {
         // Restore the opacity of the moving windows
         WinSet_t::const_iterator it;
@@ -429,6 +423,15 @@ void WindowManager::showAll( bool firstTime ) const
 }
 
 
+void WindowManager::show( TopWindow &rWindow ) const
+{
+    rWindow.show();
+
+    if( isOpacityNeeded() )
+        rWindow.setOpacity( m_alpha );
+}
+
+
 void WindowManager::hideAll() const
 {
     WinSet_t::const_iterator it;
diff --git a/modules/gui/skins2/src/window_manager.hpp b/modules/gui/skins2/src/window_manager.hpp
index 8f1ba64..c631491 100644
--- a/modules/gui/skins2/src/window_manager.hpp
+++ b/modules/gui/skins2/src/window_manager.hpp
@@ -120,8 +120,7 @@ public:
     void raise( TopWindow &rWindow ) const { rWindow.raise(); }
 
     /// Show the given window
-    void show( TopWindow &rWindow ) const
-        { rWindow.show(); rWindow.setOpacity( m_alpha); }
+    void show( TopWindow &rWindow ) const;
 
     /// Hide the given window
     void hide( TopWindow &rWindow ) const { rWindow.hide(); }
@@ -163,6 +162,10 @@ public:
     /// Return the active popup, or NULL if none is active
     Popup * getActivePopup() const { return m_pPopup; }
 
+    /// getter to know whether opacity is needed
+    bool isOpacityNeeded() const
+    { return (m_OpacityEnabled && (m_alpha != 255 || m_moveAlpha != 255 )); }
+
 private:
     /// Some useful typedefs for lazy people like me
     typedef set<TopWindow*> WinSet_t;
@@ -206,6 +209,8 @@ private:
     int m_alpha;
     /// Alpha value of the moving windows
     int m_moveAlpha;
+    /// transparency set by user
+    bool m_OpacityEnabled;
     /// Direction of the current resizing
     Direction_t m_direction;
     /// Rect of the last maximized window
diff --git a/modules/gui/skins2/win32/win32_window.cpp b/modules/gui/skins2/win32/win32_window.cpp
index 0a2a6ea..cf77176 100644
--- a/modules/gui/skins2/win32/win32_window.cpp
+++ b/modules/gui/skins2/win32/win32_window.cpp
@@ -190,44 +190,17 @@ void Win32Window::setOpacity( uint8_t value ) const
 {
     Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
 
-    if( value == 255 )
+    if( !m_isLayered )
     {
-        // If the window is opaque, we remove the WS_EX_LAYERED attribute
-        // which slows down resizing for nothing
-        if( m_isLayered )
-        {
-            SetWindowLongPtr( m_hWnd, GWL_EXSTYLE,
-                GetWindowLongPtr( m_hWnd, GWL_EXSTYLE ) & ~WS_EX_LAYERED );
-
-            // Redraw the window, otherwise we may end up with a grey rectangle
-            // for some strange reason
-            RedrawWindow(m_hWnd, NULL, NULL,
-                RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
+        // add the WS_EX_LAYERED attribute.
+        SetWindowLongPtr( m_hWnd, GWL_EXSTYLE,
+            GetWindowLongPtr( m_hWnd, GWL_EXSTYLE ) | WS_EX_LAYERED );
 
-            m_isLayered = false;
-        }
+        m_isLayered = true;
     }
-    else
-    {
-        if( ! m_isLayered )
-        {
-            // (Re)Add the WS_EX_LAYERED attribute.
-            // Resizing will be very slow, now :)
-            SetWindowLongPtr( m_hWnd, GWL_EXSTYLE,
-                GetWindowLongPtr( m_hWnd, GWL_EXSTYLE ) | WS_EX_LAYERED );
-
-            // Redraw the window, otherwise we may end up with a grey
-            // rectangle for some strange reason
-            RedrawWindow(m_hWnd, NULL, NULL,
-                RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
 
-            m_isLayered = true;
-        }
-
-        // Change the opacity
-        SetLayeredWindowAttributes(
-            m_hWnd, 0, value, LWA_ALPHA|LWA_COLORKEY );
-    }
+    // Change the opacity
+    SetLayeredWindowAttributes( m_hWnd, 0, value, LWA_ALPHA );
 }
 
 



More information about the vlc-commits mailing list