]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/win32/win32_window.cpp
skins2: rework and simplify transparency
[vlc] / modules / gui / skins2 / win32 / win32_window.cpp
index 8603a6b3f88a1c299198b3f7b998d071810a1844..cf771769eedd00cfd0eb2a9fae63157fddcfe6a0 100644 (file)
@@ -51,35 +51,38 @@ Win32Window::Win32Window( intf_thread_t *pIntf, GenericWindow &rWindow,
     OSWindow( pIntf ), m_dragDrop( dragDrop ), m_isLayered( false ),
     m_pParent( pParentWindow ), m_type ( type )
 {
+    Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
+
     // Create the window
     if( type == GenericWindow::VoutWindow )
     {
         // Child window (for vout)
         m_hWnd_parent = pParentWindow->getHandle();
         m_hWnd = CreateWindowEx( WS_EX_TOOLWINDOW | WS_EX_NOPARENTNOTIFY,
-                     "VoutWindowClass", "default name",
+                     "SkinWindowClass", "default name",
                      WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
-                     CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
-                     m_hWnd_parent, 0, hInst, NULL );
+                     0, 0, 0, 0, m_hWnd_parent, 0, hInst, NULL );
     }
     else if( type == GenericWindow::FullscreenWindow )
     {
-        // Normal window
-        m_hWnd_parent = NULL;
+        // top-level window
         m_hWnd = CreateWindowEx( WS_EX_APPWINDOW, "SkinWindowClass",
             "default name", WS_POPUP | WS_CLIPCHILDREN,
-            CW_USEDEFAULT, CW_USEDEFAULT,
-            CW_USEDEFAULT, CW_USEDEFAULT, m_hWnd_parent, 0, hInst, NULL );
-    }
+            0, 0, 0, 0, NULL, 0, hInst, NULL );
 
+        // Store with it a pointer to the interface thread
+        SetWindowLongPtr( m_hWnd, GWLP_USERDATA, (LONG_PTR)getIntf() );
+    }
     else
     {
-        // Normal window
-        m_hWnd_parent =  NULL;
-        m_hWnd = CreateWindowEx( WS_EX_TOOLWINDOW, "SkinWindowClass",
+        // top-level window (owned by the root window)
+        HWND hWnd_owner = pFactory->getParentWindow();
+        m_hWnd = CreateWindowEx( 0, "SkinWindowClass",
             "default name", WS_POPUP | WS_CLIPCHILDREN,
-            CW_USEDEFAULT, CW_USEDEFAULT,
-            CW_USEDEFAULT, CW_USEDEFAULT, m_hWnd_parent, 0, hInst, NULL );
+            0, 0, 0, 0, hWnd_owner, 0, hInst, NULL );
+
+        // Store with it a pointer to the interface thread
+        SetWindowLongPtr( m_hWnd, GWLP_USERDATA, (LONG_PTR)getIntf() );
     }
 
     if( !m_hWnd )
@@ -89,7 +92,6 @@ Win32Window::Win32Window( intf_thread_t *pIntf, GenericWindow &rWindow,
     }
 
     // Store a pointer to the GenericWindow in a map
-    Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
     pFactory->m_windowMap[m_hWnd] = &rWindow;
 
     // Drag & drop
@@ -133,18 +135,35 @@ void Win32Window::reparent( void* OSHandle, int x, int y, int w, int h )
     }
 
     SetParent( m_hWnd, (HWND)OSHandle );
-    MoveWindow( m_hWnd, x, y, w, h, true );
+    MoveWindow( m_hWnd, x, y, w, h, TRUE );
+}
+
+
+bool Win32Window::invalidateRect( int x, int y, int w, int h) const
+{
+    RECT rect = { x, y, x + w , y + h };
+    InvalidateRect( m_hWnd, &rect, FALSE );
+    UpdateWindow( m_hWnd );
+
+    return true;
 }
 
 
 void Win32Window::show() const
 {
 
-   if( m_type == GenericWindow::VoutWindow )
-       SetWindowPos( m_hWnd, HWND_BOTTOM, 0, 0, 0, 0,
-            SWP_NOMOVE | SWP_NOSIZE );
+    if( m_type == GenericWindow::VoutWindow )
+    {
+        SetWindowPos( m_hWnd, HWND_BOTTOM, 0, 0, 0, 0,
+                              SWP_NOMOVE | SWP_NOSIZE );
+    }
+    else if( m_type == GenericWindow::FullscreenWindow )
+    {
+        SetWindowPos( m_hWnd, HWND_TOPMOST, 0, 0, 0, 0,
+                              SWP_NOMOVE | SWP_NOSIZE );
+    }
 
-   ShowWindow( m_hWnd, SW_SHOW );
+    ShowWindow( m_hWnd, SW_SHOW );
 }
 
 
@@ -156,7 +175,7 @@ void Win32Window::hide() const
 
 void Win32Window::moveResize( int left, int top, int width, int height ) const
 {
-    MoveWindow( m_hWnd, left, top, width, height, true );
+    MoveWindow( m_hWnd, left, top, width, height, TRUE );
 }
 
 
@@ -171,47 +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;
-        }
-    }
-    else
-    {
-        if( pFactory->SetLayeredWindowAttributes )
-        {
-            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
-            pFactory->SetLayeredWindowAttributes(
-                m_hWnd, 0, value, LWA_ALPHA|LWA_COLORKEY );
-        }
+        m_isLayered = true;
     }
+
+    // Change the opacity
+    SetLayeredWindowAttributes( m_hWnd, 0, value, LWA_ALPHA );
 }