[vlc-commits] skins2: fix boolean variables

Erwan Tulou git at videolan.org
Tue Mar 1 14:29:05 CET 2011


vlc/vlc-1.1 | branch: master | Erwan Tulou <erwan10 at videolan.org> | Tue Mar  1 14:09:36 2011 +0100| [256e1775c7f51916b04e108d57ae8b6fc60240b5] | committer: Erwan Tulou

skins2: fix boolean variables

skins2 expects notification to occur if and only if the variable really changes.

This patch fixes things for And and Or variables.
This fixes trac #4529

> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.1.git/?a=commit;h=256e1775c7f51916b04e108d57ae8b6fc60240b5
---

 modules/gui/skins2/utils/var_bool.cpp |   18 ++++++++++++++----
 modules/gui/skins2/utils/var_bool.hpp |    6 ++++--
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/modules/gui/skins2/utils/var_bool.cpp b/modules/gui/skins2/utils/var_bool.cpp
index 6c004ee..f5cb12c 100644
--- a/modules/gui/skins2/utils/var_bool.cpp
+++ b/modules/gui/skins2/utils/var_bool.cpp
@@ -46,7 +46,8 @@ void VarBoolImpl::set( bool value )
 
 VarBoolAndBool::VarBoolAndBool( intf_thread_t *pIntf, VarBool &rVar1,
                                 VarBool &rVar2 ):
-    VarBool( pIntf ), m_rVar1( rVar1 ), m_rVar2( rVar2 )
+    VarBool( pIntf ), m_rVar1( rVar1 ), m_rVar2( rVar2 ),
+    m_value( rVar1.get() && rVar2.get() )
 {
     m_rVar1.addObserver( this );
     m_rVar2.addObserver( this );
@@ -62,13 +63,18 @@ VarBoolAndBool::~VarBoolAndBool()
 
 void VarBoolAndBool::onUpdate( Subject<VarBool> &rVariable, void *arg )
 {
-    notify();
+    if( m_value != ( m_rVar1.get() && m_rVar2.get() ) )
+    {
+        m_value = ( m_rVar1.get() && m_rVar2.get() );
+        notify();
+    }
 }
 
 
 VarBoolOrBool::VarBoolOrBool( intf_thread_t *pIntf, VarBool &rVar1,
                               VarBool &rVar2 ):
-    VarBool( pIntf ), m_rVar1( rVar1 ), m_rVar2( rVar2 )
+    VarBool( pIntf ), m_rVar1( rVar1 ), m_rVar2( rVar2 ),
+    m_value( rVar1.get() || rVar2.get() )
 {
     m_rVar1.addObserver( this );
     m_rVar2.addObserver( this );
@@ -84,7 +90,11 @@ VarBoolOrBool::~VarBoolOrBool()
 
 void VarBoolOrBool::onUpdate( Subject<VarBool> &rVariable , void*arg)
 {
-    notify();
+    if( m_value != ( m_rVar1.get() || m_rVar2.get() ) )
+    {
+        m_value = ( m_rVar1.get() || m_rVar2.get() );
+        notify();
+    }
 }
 
 
diff --git a/modules/gui/skins2/utils/var_bool.hpp b/modules/gui/skins2/utils/var_bool.hpp
index 4b0618f..0ee7bcd 100644
--- a/modules/gui/skins2/utils/var_bool.hpp
+++ b/modules/gui/skins2/utils/var_bool.hpp
@@ -94,7 +94,7 @@ class VarBoolAndBool: public VarBool, public Observer<VarBool>
 public:
     VarBoolAndBool( intf_thread_t *pIntf, VarBool &rVar1, VarBool &rVar2 );
     virtual ~VarBoolAndBool();
-    virtual bool get() const { return m_rVar1.get() && m_rVar2.get(); }
+    virtual bool get() const { return m_value; }
 
     // Called when one of the observed variables is changed
     void onUpdate( Subject<VarBool> &rVariable, void* );
@@ -102,6 +102,7 @@ public:
 private:
     /// Boolean variables
     VarBool &m_rVar1, &m_rVar2;
+    bool m_value;
 };
 
 
@@ -111,7 +112,7 @@ class VarBoolOrBool: public VarBool, public Observer<VarBool>
 public:
     VarBoolOrBool( intf_thread_t *pIntf, VarBool &rVar1, VarBool &rVar2 );
     virtual ~VarBoolOrBool();
-    virtual bool get() const { return m_rVar1.get() || m_rVar2.get(); }
+    virtual bool get() const { return m_value; }
 
     // Called when one of the observed variables is changed
     void onUpdate( Subject<VarBool> &rVariable, void* );
@@ -119,6 +120,7 @@ public:
 private:
     /// Boolean variables
     VarBool &m_rVar1, &m_rVar2;
+    bool m_value;
 };
 
 



More information about the vlc-commits mailing list