]> git.sesse.net Git - vlc/commitdiff
skins2: fix boolean variables
authorErwan Tulou <erwan10@videolan.org>
Tue, 1 Mar 2011 13:09:36 +0000 (14:09 +0100)
committerErwan Tulou <erwan10@videolan.org>
Tue, 1 Mar 2011 13:25:11 +0000 (14:25 +0100)
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

modules/gui/skins2/utils/var_bool.cpp
modules/gui/skins2/utils/var_bool.hpp

index 6c004ee80500e40347c1e6868ef39ffaf792fa9b..f5cb12cbaa10fecd60bcd7536446ea5c8227c07e 100644 (file)
@@ -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();
+    }
 }
 
 
index 4b0618ff57ee80e1beafdfc9fcabcd98bff147b4..0ee7bcd8360844bd0236aa70b25bf61eec14766f 100644 (file)
@@ -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;
 };