[dasher] Move handling of double/long/etc. clicks into subclasses - duplicates



commit 3394c8e1db3a0eeca1e48c187d2723693479a791
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Fri Aug 21 12:52:14 2009 +0100

    Move handling of double/long/etc. clicks into subclasses - duplicates
    a little code, but gives them much more flexibility (less hackery
    required!)

 ChangeLog                                 |    4 ++
 Src/DasherCore/ButtonMultiPress.h         |    4 +-
 Src/DasherCore/DynamicFilter.cpp          |   40 +++++++----------
 Src/DasherCore/OneButtonDynamicFilter.cpp |    6 +++
 Src/DasherCore/TwoButtonDynamicFilter.cpp |   70 +++++++++++-----------------
 Src/DasherCore/TwoButtonDynamicFilter.h   |    5 --
 Src/DasherCore/TwoPushDynamicFilter.cpp   |    8 +++-
 7 files changed, 63 insertions(+), 74 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6e4d401..7105210 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-08-21  Alan Lawrence <acl33 inf phy cam ac uk>
+
+	* Move handling of double/long/etc. clicks into subclasses.
+
 2009-08-18  Patrick Welche <prlw1 cam ac uk>
 
 	* libwnck really isn't used.
diff --git a/Src/DasherCore/ButtonMultiPress.h b/Src/DasherCore/ButtonMultiPress.h
index 6893a9e..7dd95c6 100644
--- a/Src/DasherCore/ButtonMultiPress.h
+++ b/Src/DasherCore/ButtonMultiPress.h
@@ -26,7 +26,9 @@
 namespace Dasher {
 /// \ingroup InputFilter
 /// @{
-///DynamicFilter which additionally starts reversing whenever a button is pushed enough times in a short interval
+///DynamicFilter which detects multiple presses of the same button occurring in a short space of time
+/// (such multi-presses are then passed onto the standard 'ActionButton' method, with iType equal
+/// to the number of presses, for subclasses to handle/decide how to respond.)
 class CButtonMultiPress : public CDynamicFilter {
  public:
   CButtonMultiPress(Dasher::CEventHandler * pEventHandler, CSettingsStore *pSettingsStore, CDasherInterfaceBase *pInterface, ModuleID_t iID, int iType, const char *szName);
diff --git a/Src/DasherCore/DynamicFilter.cpp b/Src/DasherCore/DynamicFilter.cpp
index 081cdee..96fd902 100644
--- a/Src/DasherCore/DynamicFilter.cpp
+++ b/Src/DasherCore/DynamicFilter.cpp
@@ -104,35 +104,27 @@ void CDynamicFilter::Event(int iTime, int iButton, int iType, CDasherModel *pMod
     pause();
     m_pInterface->PauseAt(0, 0);
   } else {
-    //examine event/button-press type
+    //running; examine event/button-press type
     switch(iType) {
-    case 0:
+    case 0: //single press
       if((iButton == 0) || (iButton == 100)) {
-	if(pUserLog)
-	  pUserLog->KeyDown(iButton, iType, 2);
-	pause();
-	m_pInterface->PauseAt(0, 0);
+        //dedicated pause button
+        if(pUserLog)
+          pUserLog->KeyDown(iButton, iType, 2);
+        pause();
+        m_pInterface->PauseAt(0, 0);
+        break;
       }
       else if(iButton == 1) {
-	if(pUserLog)
-	  pUserLog->KeyDown(iButton, iType, 6);
-	reverse();
+        //dedicated reverse button
+        if(pUserLog)
+          pUserLog->KeyDown(iButton, iType, 6);
+        reverse();
+        break;
       }
-      else {
-	ActionButton(iTime, iButton, iType, pModel, pUserLog);
-      }
-      break;
-    default: // _Any_ other kind of event - long, double, triple, ...
-      if((iButton >= 2) && (iButton <= 4)) {
-	if(pUserLog)
-	  pUserLog->KeyDown(iButton, iType, 6);
-	reverse(); //reversing!
-       }
-      else {
-	if(pUserLog)
-	  pUserLog->KeyDown(iButton, iType, 0);
-      }
-      break;
+      //else - any non-special button - fall through
+    default: //or, Any special kind of event - long, double, triple, ... 
+      ActionButton(iTime, iButton, iType, pModel, pUserLog);
     }
   }
 }
diff --git a/Src/DasherCore/OneButtonDynamicFilter.cpp b/Src/DasherCore/OneButtonDynamicFilter.cpp
index 25aa398..93a681e 100644
--- a/Src/DasherCore/OneButtonDynamicFilter.cpp
+++ b/Src/DasherCore/OneButtonDynamicFilter.cpp
@@ -120,6 +120,12 @@ bool COneButtonDynamicFilter::TimerImpl(int Time, CDasherView *m_pDasherView, CD
 }
 
 void COneButtonDynamicFilter::ActionButton(int iTime, int iButton, int iType, CDasherModel *pModel, CUserLogBase *pUserLog) {
+  if (iType != 0) {
+    //double/long push
+    reverse();
+    return;
+  }
+    
   if((iButton == 2) || (iButton == 3) || (iButton == 4)) {
     if(pUserLog)
       pUserLog->KeyDown(iButton, iType, 5);
diff --git a/Src/DasherCore/TwoButtonDynamicFilter.cpp b/Src/DasherCore/TwoButtonDynamicFilter.cpp
index c001ffc..855e403 100644
--- a/Src/DasherCore/TwoButtonDynamicFilter.cpp
+++ b/Src/DasherCore/TwoButtonDynamicFilter.cpp
@@ -49,7 +49,7 @@ static SModuleSettings sSettings[] = {
 };
 
 CTwoButtonDynamicFilter::CTwoButtonDynamicFilter(Dasher::CEventHandler * pEventHandler, CSettingsStore *pSettingsStore, CDasherInterfaceBase *pInterface)
-  : CButtonMultiPress(pEventHandler, pSettingsStore, pInterface, 14, 1, _("Two Button Dynamic Mode")), m_dMulSinceFirstPush(1.0)
+  : CButtonMultiPress(pEventHandler, pSettingsStore, pInterface, 14, 1, _("Two Button Dynamic Mode"))
 {
   //ensure that m_dLagMul is properly initialised
   Dasher::CParameterNotificationEvent oEvent(LP_DYNAMIC_BUTTON_LAG);
@@ -122,57 +122,43 @@ void CTwoButtonDynamicFilter::reverse() {
   CButtonMultiPress::reverse();
 }
 
-void CTwoButtonDynamicFilter::Event(int iTime, int iButton, int iType, CDasherModel *pModel, CUserLogBase *pUserLog)
-{
-  if (GetBoolParameter(BP_2B_INVERT_DOUBLE) && iType == 2 && iButton>=2 && iButton<=4)
-  { //double-press - treat as single-press of the other button....
-    iType = 0; //0=normal, 1=long press
-    iButton = (iButton == 2) ? 3 : 2;
-    m_dMulSinceFirstPush = exp(pModel->GetNats());
-  }
-  CDynamicFilter::Event(iTime, iButton, iType, pModel, pUserLog);
-}
-
-void CTwoButtonDynamicFilter::ApplyOffset(CDasherModel *pModel, long lOffset)
-{
-  lOffset *= m_dMulSinceFirstPush; m_dMulSinceFirstPush = 1.0;
-  pModel->Offset(lOffset);
-  m_pModel = pModel;
-  m_lOffsetApplied = lOffset;
-  pModel->ResetNats();
-}
-
-void CTwoButtonDynamicFilter::RevertPresses(int iCount)
-{
-  //invert the *last* invocation of ApplyOffset.
-  //this'll handle reverting single clicks and (if BP_2B_INVERT_DOUBLE is on) double-clicks,
-  //but we'll get into trouble if the user e.g. double-presses the reverse button!
-
-  //correct for expansion since the first click, if any (if we've rendered any frames!)
-  m_pModel->Offset(-m_lOffsetApplied * exp(m_pModel->GetNats()));
-  m_lOffsetApplied = 0;
-}
-
 void CTwoButtonDynamicFilter::ActionButton(int iTime, int iButton, int iType, CDasherModel *pModel, CUserLogBase *pUserLog) {
-  int iFactor(1);
-
-  if(GetBoolParameter(BP_TWOBUTTON_REVERSE))
-    iFactor = -1;
+  
+  double dFactor(GetBoolParameter(BP_TWOBUTTON_REVERSE) ? -1.0 : 1.0);
+  int iEffect; //for user log
 
+  if (GetBoolParameter(BP_2B_INVERT_DOUBLE) && iType == 2 && iButton>=2 && iButton<=4)
+  { //double-press - go BACK in opposite direction,
+    //far enough to invert previous jump (from first press of double-)
+    //and then AGAIN.
+    dFactor *= - (1.0 + exp(pModel->GetNats())); //prev jump is further now
+  }
+  else if (iType != 0) {
+    reverse();
+    return;
+  }
+  
   if(iButton == 2) {
-    ApplyOffset(pModel, iFactor * GetLongParameter(LP_TWO_BUTTON_OFFSET) * m_dLagMul);
-    if(pUserLog)
-      pUserLog->KeyDown(iButton, iType, 3);
+    iEffect = 3;
+    //fall through to apply offset.
   }
   else if((iButton == 3) || (iButton == 4)) {
-    ApplyOffset(pModel, iFactor * -GetLongParameter(LP_TWO_BUTTON_OFFSET) * m_dLagMul);
-    if(pUserLog)
-      pUserLog->KeyDown(iButton, iType, 4);
+    dFactor = -dFactor;
+    iEffect = 4;
+    //fall through to apply offset
   }
   else {
     if(pUserLog)
       pUserLog->KeyDown(iButton, iType, 0);
+    return;
   }
+  //fell through to apply offset
+  int iOffset(dFactor * GetLongParameter(LP_TWO_BUTTON_OFFSET) * m_dLagMul);
+  pModel->Offset(iOffset);
+  pModel->ResetNats();
+  
+  if(pUserLog)
+    pUserLog->KeyDown(iButton, iType, iEffect);  
 }
 
 bool CTwoButtonDynamicFilter::GetSettings(SModuleSettings **pSettings, int *iCount) {
diff --git a/Src/DasherCore/TwoButtonDynamicFilter.h b/Src/DasherCore/TwoButtonDynamicFilter.h
index ee35438..9284a4a 100644
--- a/Src/DasherCore/TwoButtonDynamicFilter.h
+++ b/Src/DasherCore/TwoButtonDynamicFilter.h
@@ -45,7 +45,6 @@ class CTwoButtonDynamicFilter : public CButtonMultiPress {
   virtual void HandleEvent(Dasher::CEvent *pEvent);
   
  protected:
-  void Event(int iTime, int iButton, int iType, CDasherModel *pModel, CUserLogBase *pUserLog);
   virtual void run(int iState);
   virtual void pause();
   virtual void reverse();
@@ -56,11 +55,7 @@ class CTwoButtonDynamicFilter : public CButtonMultiPress {
   virtual void ActionButton(int iTime, int iButton, int iType, CDasherModel *pModel, CUserLogBase *pUserLog);
   double m_dLagMul;
 
-  void RevertPresses(int iCount);
   void ApplyOffset(CDasherModel *pModel, long lOffset);
-  CDasherModel *m_pModel;
-  long m_lOffsetApplied;
-  double m_dMulSinceFirstPush;
 };
 }
 /// @}
diff --git a/Src/DasherCore/TwoPushDynamicFilter.cpp b/Src/DasherCore/TwoPushDynamicFilter.cpp
index 86a6805..517e924 100644
--- a/Src/DasherCore/TwoPushDynamicFilter.cpp
+++ b/Src/DasherCore/TwoPushDynamicFilter.cpp
@@ -194,10 +194,14 @@ void CTwoPushDynamicFilter::KeyUp(int Time, int iId, CDasherView *pDasherView, C
 void CTwoPushDynamicFilter::ActionButton(int iTime, int iButton, int iType, CDasherModel *pModel, CUserLogBase *pUserLog) {
   // Types:
   // 0 = ordinary click
-  // 1 = long click  
+  // 1 = long click
   int myState;
   if (!isRunning(myState)) DASHER_ASSERT(false);
-
+  
+  if (iType != 0) {
+    reverse();
+    return;
+  }
   if (myState == 0) //no button pushed (recently)
   {
 //cout << "First push - event type " << iType << " \n";



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]