]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/controls/ctrl_resize.cpp
skins2: improve refresh of layouts
[vlc] / modules / gui / skins2 / controls / ctrl_resize.cpp
index f168ca162f2039d4cd7c4e755f6d22ee2de91aa1..7992d4b0fef4b983f731c09962b182da87fe4d14 100644 (file)
@@ -5,7 +5,7 @@
  * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
- *          Olivier Teulière <ipkiss@via.ecp.fr>
+ *          Olivier Teulière <ipkiss@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -17,9 +17,9 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #include "ctrl_resize.hpp"
 #include "../commands/cmd_resize.hpp"
 
 
-CtrlResize::CtrlResize( intf_thread_t *pIntf, CtrlFlat &rCtrl,
-                        GenericLayout &rLayout, const UString &rHelp,
-                        VarBool *pVisible, Direction_t direction ):
-    CtrlFlat( pIntf, rHelp, pVisible ), m_fsm( pIntf ), m_rCtrl( rCtrl ),
+CtrlResize::CtrlResize( intf_thread_t *pIntf, WindowManager &rWindowManager,
+                        CtrlFlat &rCtrl, GenericLayout &rLayout,
+                        const UString &rHelp, VarBool *pVisible,
+                        WindowManager::Direction_t direction ):
+    CtrlFlat( pIntf, rHelp, pVisible ), m_fsm( pIntf ),
+    m_rWindowManager( rWindowManager ), m_rCtrl( rCtrl ),
     m_rLayout( rLayout ), m_direction( direction ),  m_cmdOutStill( this ),
     m_cmdStillOut( this ),
     m_cmdStillStill( this ),
@@ -73,9 +75,9 @@ bool CtrlResize::mouseOver( int x, int y ) const
 }
 
 
-void CtrlResize::draw( OSGraphics &rImage, int xDest, int yDest )
+void CtrlResize::draw( OSGraphics &rImage, int xDest, int yDest, int w, int h )
 {
-    m_rCtrl.draw( rImage, xDest, yDest );
+    m_rCtrl.draw( rImage, xDest, yDest, w, h );
 }
 
 
@@ -87,12 +89,25 @@ void CtrlResize::setLayout( GenericLayout *pLayout, const Position &rPosition )
 }
 
 
+void CtrlResize::unsetLayout()
+{
+    m_rCtrl.unsetLayout();
+    CtrlGeneric::unsetLayout();
+}
+
+
 const Position *CtrlResize::getPosition() const
 {
     return m_rCtrl.getPosition();
 }
 
 
+void CtrlResize::onResize()
+{
+    m_rCtrl.onResize();
+}
+
+
 void CtrlResize::handleEvent( EvtGeneric &rEvent )
 {
     m_pEvt = &rEvent;
@@ -103,17 +118,18 @@ void CtrlResize::handleEvent( EvtGeneric &rEvent )
 }
 
 
-void CtrlResize::changeCursor( Direction_t direction ) const
+void CtrlResize::changeCursor( WindowManager::Direction_t direction ) const
 {
-    OSFactory *pOsFactory = OSFactory::instance( getIntf() );
-    if( direction == kResizeSE )
-        pOsFactory->changeCursor( OSFactory::kResizeNWSE );
-    else if( direction == kResizeS )
-        pOsFactory->changeCursor( OSFactory::kResizeNS );
-    else if( direction == kResizeE )
-        pOsFactory->changeCursor( OSFactory::kResizeWE );
-    else if( direction == kNone )
-        pOsFactory->changeCursor( OSFactory::kDefaultArrow );
+    OSFactory::CursorType_t cursor;
+    switch( direction )
+    {
+    default:
+    case WindowManager::kNone:     cursor = OSFactory::kDefaultArrow; break;
+    case WindowManager::kResizeSE: cursor = OSFactory::kResizeNWSE;   break;
+    case WindowManager::kResizeS:  cursor = OSFactory::kResizeNS;     break;
+    case WindowManager::kResizeE:  cursor = OSFactory::kResizeWE;     break;
+    }
+    OSFactory::instance( getIntf() )->changeCursor( cursor );
 }
 
 
@@ -125,7 +141,7 @@ void CtrlResize::CmdOutStill::execute()
 
 void CtrlResize::CmdStillOut::execute()
 {
-    m_pParent->changeCursor( kNone );
+    m_pParent->changeCursor( WindowManager::kNone );
 }
 
 
@@ -137,7 +153,7 @@ void CtrlResize::CmdStillStill::execute()
 
 void CtrlResize::CmdStillResize::execute()
 {
-    EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt;
+    EvtMouse *pEvtMouse = static_cast<EvtMouse*>(m_pParent->m_pEvt);
 
     // Set the cursor
     m_pParent->changeCursor( m_pParent->m_direction );
@@ -149,6 +165,9 @@ void CtrlResize::CmdStillResize::execute()
 
     m_pParent->m_width = m_pParent->m_rLayout.getWidth();
     m_pParent->m_height = m_pParent->m_rLayout.getHeight();
+
+    m_pParent->m_rWindowManager.startResize( m_pParent->m_rLayout,
+                                             m_pParent->m_direction);
 }
 
 
@@ -158,28 +177,29 @@ void CtrlResize::CmdResizeStill::execute()
     m_pParent->changeCursor( m_pParent->m_direction );
 
     m_pParent->releaseMouse();
+
+    m_pParent->m_rWindowManager.stopResize();
 }
 
 
 void CtrlResize::CmdResizeResize::execute()
 {
-    EvtMotion *pEvtMotion = (EvtMotion*)m_pParent->m_pEvt;
+    EvtMotion *pEvtMotion = static_cast<EvtMotion*>(m_pParent->m_pEvt);
 
-    // Set the cursor
     m_pParent->changeCursor( m_pParent->m_direction );
 
     int newWidth = m_pParent->m_width;
+    newWidth += pEvtMotion->getXPos() - m_pParent->m_xPos;
     int newHeight = m_pParent->m_height;
-    if( m_pParent->m_direction != kResizeS )
-        newWidth += pEvtMotion->getXPos() - m_pParent->m_xPos;
-    if( m_pParent->m_direction != kResizeE )
-        newHeight += pEvtMotion->getYPos() - m_pParent->m_yPos;
+    newHeight += pEvtMotion->getYPos() - m_pParent->m_yPos;
 
-    // Create a resize command
+    // Create a resize command, instead of calling the window manager directly.
+    // Thanks to this trick, the duplicate resizing commands will be trashed
+    // in the asynchronous queue, thus making resizing faster
     CmdGeneric *pCmd = new CmdResize( m_pParent->getIntf(),
+                                      m_pParent->m_rWindowManager,
                                       m_pParent->m_rLayout,
                                       newWidth, newHeight );
     // Push the command in the asynchronous command queue
-    AsyncQueue *pQueue = AsyncQueue::instance( m_pParent->getIntf() );
-    pQueue->push( CmdGenericPtr( pCmd ) );
+    AsyncQueue::instance( getIntf() )->push( CmdGenericPtr( pCmd ) );
 }