From 6314367b7084e2a679eb93ea0ae839a7b7a0e8c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Thu, 16 Dec 2004 21:26:36 +0000 Subject: [PATCH] * skins2: When a control changes, refresh only the needed part of the layout instead of refreshing everything --- modules/gui/skins2/controls/ctrl_button.cpp | 24 ++++++++----- modules/gui/skins2/controls/ctrl_button.hpp | 2 +- modules/gui/skins2/controls/ctrl_checkbox.cpp | 24 ++++++++----- modules/gui/skins2/controls/ctrl_generic.cpp | 35 +++++++++++++++++-- modules/gui/skins2/controls/ctrl_generic.hpp | 11 ++++-- .../gui/skins2/controls/ctrl_radialslider.cpp | 4 +-- modules/gui/skins2/controls/ctrl_slider.cpp | 14 +++++--- modules/gui/skins2/controls/ctrl_text.cpp | 8 +++-- modules/gui/skins2/src/generic_layout.cpp | 35 ++++++++++++++++--- modules/gui/skins2/src/generic_layout.hpp | 6 +++- 10 files changed, 126 insertions(+), 37 deletions(-) diff --git a/modules/gui/skins2/controls/ctrl_button.cpp b/modules/gui/skins2/controls/ctrl_button.cpp index fd4466d48f..4b7c94a501 100755 --- a/modules/gui/skins2/controls/ctrl_button.cpp +++ b/modules/gui/skins2/controls/ctrl_button.cpp @@ -133,8 +133,9 @@ void CtrlButton::transUpOverDownOver( SkinObject *pCtrl ) { CtrlButton *pThis = (CtrlButton*)pCtrl; pThis->captureMouse(); + const OSGraphics *pOldImg = pThis->m_pImg; pThis->m_pImg = pThis->m_pImgDown; - pThis->notifyLayout(); + pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImg ); } @@ -142,8 +143,9 @@ void CtrlButton::transDownOverUpOver( SkinObject *pCtrl ) { CtrlButton *pThis = (CtrlButton*)pCtrl; pThis->releaseMouse(); + const OSGraphics *pOldImg = pThis->m_pImg; pThis->m_pImg = pThis->m_pImgUp; - pThis->notifyLayout(); + pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImg ); // Execute the command associated to this button pThis->m_rCommand.execute(); } @@ -152,32 +154,36 @@ void CtrlButton::transDownOverUpOver( SkinObject *pCtrl ) void CtrlButton::transDownOverDown( SkinObject *pCtrl ) { CtrlButton *pThis = (CtrlButton*)pCtrl; + const OSGraphics *pOldImg = pThis->m_pImg; pThis->m_pImg = pThis->m_pImgUp; - pThis->notifyLayout(); + pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImg ); } void CtrlButton::transDownDownOver( SkinObject *pCtrl ) { CtrlButton *pThis = (CtrlButton*)pCtrl; + const OSGraphics *pOldImg = pThis->m_pImg; pThis->m_pImg = pThis->m_pImgDown; - pThis->notifyLayout(); + pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImg ); } void CtrlButton::transUpUpOver( SkinObject *pCtrl ) { CtrlButton *pThis = (CtrlButton*)pCtrl; + const OSGraphics *pOldImg = pThis->m_pImg; pThis->m_pImg = pThis->m_pImgOver; - pThis->notifyLayout(); + pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImg ); } void CtrlButton::transUpOverUp( SkinObject *pCtrl ) { CtrlButton *pThis = (CtrlButton*)pCtrl; + const OSGraphics *pOldImg = pThis->m_pImg; pThis->m_pImg = pThis->m_pImgUp; - pThis->notifyLayout(); + pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImg ); } @@ -191,15 +197,17 @@ void CtrlButton::transDownUp( SkinObject *pCtrl ) void CtrlButton::transUpHidden( SkinObject *pCtrl ) { CtrlButton *pThis = (CtrlButton*)pCtrl; + const OSGraphics *pOldImg = pThis->m_pImg; pThis->m_pImg = NULL; - pThis->notifyLayout(); + pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImg ); } void CtrlButton::transHiddenUp( SkinObject *pCtrl ) { CtrlButton *pThis = (CtrlButton*)pCtrl; + const OSGraphics *pOldImg = pThis->m_pImg; pThis->m_pImg = pThis->m_pImgUp; - pThis->notifyLayout(); + pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImg ); } diff --git a/modules/gui/skins2/controls/ctrl_button.hpp b/modules/gui/skins2/controls/ctrl_button.hpp index 2917ba7097..3b819b0dc8 100644 --- a/modules/gui/skins2/controls/ctrl_button.hpp +++ b/modules/gui/skins2/controls/ctrl_button.hpp @@ -2,7 +2,7 @@ * ctrl_button.hpp ***************************************************************************** * Copyright (C) 2003 VideoLAN - * $Id: ctrl_button.hpp,v 1.2 2004/02/29 16:49:55 asmax Exp $ + * $Id$ * * Authors: Cyril Deguet * Olivier Teulière diff --git a/modules/gui/skins2/controls/ctrl_checkbox.cpp b/modules/gui/skins2/controls/ctrl_checkbox.cpp index 4e36fc8753..f0daae0e1d 100755 --- a/modules/gui/skins2/controls/ctrl_checkbox.cpp +++ b/modules/gui/skins2/controls/ctrl_checkbox.cpp @@ -177,8 +177,9 @@ void CtrlCheckbox::transUpOverDownOver( SkinObject *pCtrl ) { CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl; pThis->captureMouse(); + const OSGraphics *pOldImg = pThis->m_pImgCurrent; pThis->m_pImgCurrent = pThis->m_pImgDown; - pThis->notifyLayout(); + pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImgCurrent ); } @@ -188,8 +189,9 @@ void CtrlCheckbox::transDownOverUpOver( SkinObject *pCtrl ) pThis->releaseMouse(); // Invert the state variable + const OSGraphics *pOldImg = pThis->m_pImgCurrent; pThis->m_pImgCurrent = pThis->m_pImgUp; - pThis->notifyLayout(); + pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImgCurrent ); // Execute the command pThis->m_pCommand->execute(); @@ -199,32 +201,36 @@ void CtrlCheckbox::transDownOverUpOver( SkinObject *pCtrl ) void CtrlCheckbox::transDownOverDown( SkinObject *pCtrl ) { CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl; + const OSGraphics *pOldImg = pThis->m_pImgCurrent; pThis->m_pImgCurrent = pThis->m_pImgUp; - pThis->notifyLayout(); + pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImgCurrent ); } void CtrlCheckbox::transDownDownOver( SkinObject *pCtrl ) { CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl; + const OSGraphics *pOldImg = pThis->m_pImgCurrent; pThis->m_pImgCurrent = pThis->m_pImgDown; - pThis->notifyLayout(); + pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImgCurrent ); } void CtrlCheckbox::transUpUpOver( SkinObject *pCtrl ) { CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl; + const OSGraphics *pOldImg = pThis->m_pImgCurrent; pThis->m_pImgCurrent = pThis->m_pImgOver; - pThis->notifyLayout(); + pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImgCurrent ); } void CtrlCheckbox::transUpOverUp( SkinObject *pCtrl ) { CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl; + const OSGraphics *pOldImg = pThis->m_pImgCurrent; pThis->m_pImgCurrent = pThis->m_pImgUp; - pThis->notifyLayout(); + pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImgCurrent ); } @@ -238,16 +244,18 @@ void CtrlCheckbox::transDownUp( SkinObject *pCtrl ) void CtrlCheckbox::transUpHidden( SkinObject *pCtrl ) { CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl; + const OSGraphics *pOldImg = pThis->m_pImgCurrent; pThis->m_pImgCurrent = NULL; - pThis->notifyLayout(); + pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImgCurrent ); } void CtrlCheckbox::transHiddenUp( SkinObject *pCtrl ) { CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl; + const OSGraphics *pOldImg = pThis->m_pImgCurrent; pThis->m_pImgCurrent = pThis->m_pImgUp; - pThis->notifyLayout(); + pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImgCurrent ); } diff --git a/modules/gui/skins2/controls/ctrl_generic.cpp b/modules/gui/skins2/controls/ctrl_generic.cpp index fc962b538a..524ba6a1bd 100755 --- a/modules/gui/skins2/controls/ctrl_generic.cpp +++ b/modules/gui/skins2/controls/ctrl_generic.cpp @@ -69,12 +69,41 @@ void CtrlGeneric::setLayout( GenericLayout *pLayout, } -void CtrlGeneric::notifyLayout() const +void CtrlGeneric::notifyLayout( int width, int height ) const { // Notify the layout if( m_pLayout ) { - m_pLayout->onControlUpdate( *this ); + m_pLayout->onControlUpdate( *this, width, height ); + } +} + + +void CtrlGeneric::notifyLayoutMaxSize( const OSGraphics *pImg1, + const OSGraphics *pImg2 ) +{ + if( pImg1 == NULL ) + { + if( pImg2 == NULL ) + { + notifyLayout(); + } + else + { + notifyLayout( pImg2->getWidth(), pImg2->getHeight() ); + } + } + else + { + if( pImg2 == NULL ) + { + notifyLayout( pImg1->getWidth(), pImg1->getHeight() ); + } + else + { + notifyLayout( max( pImg1->getWidth(), pImg2->getWidth() ), + max( pImg1->getHeight(), pImg2->getHeight() ) ); + } } } @@ -128,7 +157,7 @@ bool CtrlGeneric::isVisible() const void CtrlGeneric::onUpdate( Subject &rVariable ) { - // Is it the visibily variable ? + // Is it the visibility variable ? if( &rVariable == m_pVisible ) { // Redraw the layout diff --git a/modules/gui/skins2/controls/ctrl_generic.hpp b/modules/gui/skins2/controls/ctrl_generic.hpp index f159f944b1..78c940c5d5 100644 --- a/modules/gui/skins2/controls/ctrl_generic.hpp +++ b/modules/gui/skins2/controls/ctrl_generic.hpp @@ -83,8 +83,15 @@ class CtrlGeneric: public SkinObject, public Observer CtrlGeneric( intf_thread_t *pIntf, const UString &rHelp, VarBool *pVisible = NULL ); - /// Tell the layout when the image has changed - virtual void notifyLayout() const; + /// Tell the layout when the image has changed, with the size of the + /// rectangle to repaint (use the default values for repainting the + /// whole window) + virtual void notifyLayout( int witdh = -1, int height = -1 ) const; + + /// Same as notifyLayout(), but takes optional images as parameters. + /// The maximum size(s) of the images will be used for repainting. + void notifyLayoutMaxSize( const OSGraphics *pImg1 = NULL, + const OSGraphics *pImg2 = NULL ); /// Ask the layout to capture the mouse virtual void captureMouse() const; diff --git a/modules/gui/skins2/controls/ctrl_radialslider.cpp b/modules/gui/skins2/controls/ctrl_radialslider.cpp index dcf763c66c..b028ba2471 100644 --- a/modules/gui/skins2/controls/ctrl_radialslider.cpp +++ b/modules/gui/skins2/controls/ctrl_radialslider.cpp @@ -2,7 +2,7 @@ * ctrl_radialslider.cpp ***************************************************************************** * Copyright (C) 2003 VideoLAN - * $Id: ctrl_radialslider.cpp,v 1.3 2004/02/29 16:49:55 asmax Exp $ + * $Id$ * * Authors: Cyril Deguet * Olivier Teulière @@ -101,7 +101,7 @@ void CtrlRadialSlider::draw( OSGraphics &rImage, int xDest, int yDest ) void CtrlRadialSlider::onUpdate( Subject &rVariable ) { m_position = (int)( m_rVariable.get() * m_numImg ); - notifyLayout(); + notifyLayout( m_width, m_height ); } diff --git a/modules/gui/skins2/controls/ctrl_slider.cpp b/modules/gui/skins2/controls/ctrl_slider.cpp index 8e49da9b75..ba206a8fba 100644 --- a/modules/gui/skins2/controls/ctrl_slider.cpp +++ b/modules/gui/skins2/controls/ctrl_slider.cpp @@ -163,7 +163,7 @@ void CtrlSliderCursor::draw( OSGraphics &rImage, int xDest, int yDest ) void CtrlSliderCursor::onUpdate( Subject &rVariable ) { // The position has changed - notifyLayout(); + notifyLayout( m_rCurve.getWidth(), m_rCurve.getHeight() ); } @@ -189,7 +189,8 @@ void CtrlSliderCursor::transOverDown( SkinObject *pCtrl ) pThis->captureMouse(); pThis->m_pImg = pThis->m_pImgDown; - pThis->notifyLayout(); + pThis->notifyLayout( pThis->m_rCurve.getWidth(), + pThis->m_rCurve.getHeight() ); } @@ -202,7 +203,8 @@ void CtrlSliderCursor::transDownOver( SkinObject *pCtrl ) pThis->releaseMouse(); pThis->m_pImg = pThis->m_pImgUp; - pThis->notifyLayout(); + pThis->notifyLayout( pThis->m_rCurve.getWidth(), + pThis->m_rCurve.getHeight() ); } @@ -211,7 +213,8 @@ void CtrlSliderCursor::transUpOver( SkinObject *pCtrl ) CtrlSliderCursor *pThis = (CtrlSliderCursor*)pCtrl; pThis->m_pImg = pThis->m_pImgOver; - pThis->notifyLayout(); + pThis->notifyLayout( pThis->m_rCurve.getWidth(), + pThis->m_rCurve.getHeight() ); } @@ -220,7 +223,8 @@ void CtrlSliderCursor::transOverUp( SkinObject *pCtrl ) CtrlSliderCursor *pThis = (CtrlSliderCursor*)pCtrl; pThis->m_pImg = pThis->m_pImgUp; - pThis->notifyLayout(); + pThis->notifyLayout( pThis->m_rCurve.getWidth(), + pThis->m_rCurve.getHeight() ); } diff --git a/modules/gui/skins2/controls/ctrl_text.cpp b/modules/gui/skins2/controls/ctrl_text.cpp index b03db5879b..7cd218655b 100755 --- a/modules/gui/skins2/controls/ctrl_text.cpp +++ b/modules/gui/skins2/controls/ctrl_text.cpp @@ -227,7 +227,7 @@ void CtrlText::displayText( const UString &rText ) m_pTimer->stop(); } } - notifyLayout(); + notifyLayout( getPosition()->getWidth(), getPosition()->getHeight() ); } } @@ -311,7 +311,8 @@ void CtrlText::transMove( SkinObject *pCtrl ) pThis->m_xPos = (pEvtMouse->getXPos() - pThis->m_xOffset); pThis->adjust( pThis->m_xPos ); - pThis->notifyLayout(); + pThis->notifyLayout( pThis->getPosition()->getWidth(), + pThis->getPosition()->getHeight() ); } } @@ -323,7 +324,8 @@ void CtrlText::updateText( SkinObject *pCtrl ) pThis->m_xPos -= MOVING_TEXT_STEP; pThis->adjust( pThis->m_xPos ); - pThis->notifyLayout(); + pThis->notifyLayout( pThis->getPosition()->getWidth(), + pThis->getPosition()->getHeight() ); } diff --git a/modules/gui/skins2/src/generic_layout.cpp b/modules/gui/skins2/src/generic_layout.cpp index 7e025d18b6..65436cd1e1 100644 --- a/modules/gui/skins2/src/generic_layout.cpp +++ b/modules/gui/skins2/src/generic_layout.cpp @@ -121,10 +121,21 @@ const list &GenericLayout::getControlList() const } -void GenericLayout::onControlUpdate( const CtrlGeneric &rCtrl ) +void GenericLayout::onControlUpdate( const CtrlGeneric &rCtrl, + int width, int height ) { - // TODO: refresh only the needed area if possible - refreshAll(); + // The size was not specified (or invalid) + if( width <= 0 || height <= 0 ) + { + refreshAll(); + return; + } + + const Position *pPos = rCtrl.getPosition(); + if( pPos ) + { + refreshRect( pPos->getLeft(), pPos->getTop(), width, height ); + } } @@ -177,6 +188,12 @@ void GenericLayout::resize( int width, int height ) void GenericLayout::refreshAll() +{ + refreshRect( 0, 0, m_width, m_height ); +} + + +void GenericLayout::refreshRect( int x, int y, int width, int height ) { // Draw all the controls of the layout list::const_iterator iter; @@ -194,7 +211,17 @@ void GenericLayout::refreshAll() TopWindow *pWindow = getWindow(); if( pWindow ) { - pWindow->refresh( 0, 0, m_width, m_height ); + // Check boundaries + if( x < 0 ) + x = 0; + if( y < 0) + y = 0; + if( x + width > m_width ) + width = m_width - x; + if( y + height > m_height ) + height = m_height - y; + + pWindow->refresh( x, y, width, height ); } } diff --git a/modules/gui/skins2/src/generic_layout.hpp b/modules/gui/skins2/src/generic_layout.hpp index 64b3343154..8404fe11dd 100644 --- a/modules/gui/skins2/src/generic_layout.hpp +++ b/modules/gui/skins2/src/generic_layout.hpp @@ -105,7 +105,8 @@ class GenericLayout: public SkinObject, public Box virtual const list &getControlList() const; /// Called by a control when its image has changed - virtual void onControlUpdate( const CtrlGeneric &rCtrl ); + virtual void onControlUpdate( const CtrlGeneric &rCtrl, + int width, int height ); /// Get the list of the anchors of this layout virtual const list& getAnchorList() const; @@ -114,6 +115,9 @@ class GenericLayout: public SkinObject, public Box virtual void addAnchor( Anchor *pAnchor ); private: + /// Refresh a rectangular portion of the window + void GenericLayout::refreshRect( int x, int y, int width, int height ); + /// Parent window of the layout TopWindow *m_pWindow; /// Layout size -- GitLab