[dasher] StartHandlers: disable in stylus mode, move start Circle in 1d mode



commit 191a9d79e342cc68d47c0a41e683c0c77fc384ce
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Wed Dec 1 11:54:33 2010 +0000

    StartHandlers: disable in stylus mode, move start Circle in 1d mode
    
    Start handler made in Activate not c'tor so subclasses can override virtual
    MakeStartHandler (which returns handler stored into field by CreateStartHandler)

 Src/DasherCore/DefaultFilter.cpp        |   29 +++++++++++++++++---------
 Src/DasherCore/DefaultFilter.h          |    8 ++++--
 Src/DasherCore/OneDimensionalFilter.cpp |   34 +++++++++++++++++++++++++++++++
 Src/DasherCore/OneDimensionalFilter.h   |    5 ++-
 Src/DasherCore/StylusFilter.cpp         |    4 +++
 Src/DasherCore/StylusFilter.h           |    3 ++
 Src/iPhone/Classes/IPhoneFilters.h      |    3 +-
 Src/iPhone/Classes/IPhoneFilters.mm     |   17 +++++++++++---
 8 files changed, 83 insertions(+), 20 deletions(-)
---
diff --git a/Src/DasherCore/DefaultFilter.cpp b/Src/DasherCore/DefaultFilter.cpp
index 87913ed..6f931b3 100644
--- a/Src/DasherCore/DefaultFilter.cpp
+++ b/Src/DasherCore/DefaultFilter.cpp
@@ -27,8 +27,6 @@ CDefaultFilter::CDefaultFilter(Dasher::CEventHandler * pEventHandler, CSettingsS
   m_pStartHandler = 0;
   m_pAutoSpeedControl = new CAutoSpeedControl(m_pEventHandler, m_pSettingsStore);
 
-  CreateStartHandler();
-  
   // Initialize autocalibration (i.e. seen nothing yet)
   m_iSum = 0;
   
@@ -37,6 +35,7 @@ CDefaultFilter::CDefaultFilter(Dasher::CEventHandler * pEventHandler, CSettingsS
 
 CDefaultFilter::~CDefaultFilter() {
   delete m_pAutoSpeedControl;
+  delete m_pStartHandler;
 }
 
 bool CDefaultFilter::DecorateView(CDasherView *pView, CDasherInput *pInput) {
@@ -177,16 +176,26 @@ void CDefaultFilter::HandleEvent(Dasher::CEvent * pEvent) {
 }
 
 void CDefaultFilter::CreateStartHandler() {
-  if(m_pStartHandler) {
-    delete m_pStartHandler;
-    m_pStartHandler = 0;
-  }
+  delete m_pStartHandler;
+  m_pStartHandler = MakeStartHandler();
+}
 
-  if(GetBoolParameter(BP_CIRCLE_START))
-    m_pStartHandler = new CCircleStartHandler(m_pEventHandler, m_pSettingsStore, m_pInterface);
-  else if(GetBoolParameter(BP_MOUSEPOS_MODE))
-    m_pStartHandler = new CTwoBoxStartHandler(m_pEventHandler, m_pSettingsStore, m_pInterface);
+void CDefaultFilter::Activate() {
+  CreateStartHandler();
+  CInputFilter::Activate();
+}
 
+void CDefaultFilter::Deactivate() {
+  delete m_pStartHandler;
+  m_pStartHandler = 0;
+}
+
+CStartHandler *CDefaultFilter::MakeStartHandler() {
+  if(GetBoolParameter(BP_CIRCLE_START))
+    return new CCircleStartHandler(m_pEventHandler, m_pSettingsStore, m_pInterface);
+  if(GetBoolParameter(BP_MOUSEPOS_MODE))
+    return new CTwoBoxStartHandler(m_pEventHandler, m_pSettingsStore, m_pInterface);
+  return NULL;
 }
 
 double xmax(double y) {
diff --git a/Src/DasherCore/DefaultFilter.h b/Src/DasherCore/DefaultFilter.h
index 5e3eb7e..2cafd09 100644
--- a/Src/DasherCore/DefaultFilter.h
+++ b/Src/DasherCore/DefaultFilter.h
@@ -19,20 +19,22 @@ class CDefaultFilter : public CInputFilter {
   virtual bool DecorateView(CDasherView *pView, CDasherInput *pInput);
   virtual bool Timer(int Time, CDasherView *pView, CDasherInput *pInput, CDasherModel *pModel, Dasher::VECTOR_SYMBOL_PROB *pAdded, int *pNumDeleted, CExpansionPolicy **pol);
   virtual void KeyDown(int iTime, int iId, CDasherView *pDasherView, CDasherInput *pInput, CDasherModel *pModel, CUserLogBase *pUserLog);
+  virtual void Activate();
+  virtual void Deactivate();
   bool GetSettings(SModuleSettings **, int *);
  protected:
-  virtual void CreateStartHandler();
+  void CreateStartHandler();
+  virtual CStartHandler *MakeStartHandler();
   virtual void ApplyTransform(myint &iDasherX, myint &iDasherY, CDasherView *pView);
   void ApplyOffset(myint &iDasherX, myint &iDasherY);
   
-protected:
   /// Last-known Dasher-coords of the target
   myint m_iLastX, m_iLastY;
   bool m_bGotMouseCoords;
 private:
   CAutoSpeedControl *m_pAutoSpeedControl;
-  CStartHandler *m_pStartHandler;
   myint m_iSum;
+  CStartHandler *m_pStartHandler;
   int m_iCounter;
 };
 }
diff --git a/Src/DasherCore/OneDimensionalFilter.cpp b/Src/DasherCore/OneDimensionalFilter.cpp
index 6d2777d..279dbd9 100644
--- a/Src/DasherCore/OneDimensionalFilter.cpp
+++ b/Src/DasherCore/OneDimensionalFilter.cpp
@@ -1,5 +1,6 @@
 #include "../Common/Common.h"
 #include "OneDimensionalFilter.h"
+#include "CircleStartHandler.h"
 
 using namespace Dasher;
 
@@ -71,4 +72,37 @@ void COneDimensionalFilter::ApplyTransform(myint &iDasherX, myint &iDasherY, CDa
 
 bool COneDimensionalFilter::GetSettings(SModuleSettings **pSettings, int *iCount) {
   return false;
+}
+
+CStartHandler *COneDimensionalFilter::MakeStartHandler() {
+  if (GetBoolParameter(BP_CIRCLE_START)) {
+    class C1DCircleStartHandler : public CCircleStartHandler {
+    public:
+      C1DCircleStartHandler(COneDimensionalFilter *f) : CCircleStartHandler(f->m_pEventHandler, f->m_pSettingsStore, f->m_pInterface), filter(f) {
+      }
+      void ComputeScreenLoc(CDasherView *pView) {
+        if (m_iScreenRadius!=-1) return;
+        CCircleStartHandler::ComputeScreenLoc(pView);
+        if (GetBoolParameter(BP_DASHER_PAUSED)) {
+          //put start circle at center of 1D transform, rather than center of screen
+          // (leave m_iScreenRadius, in pixels, as computed by above)
+          const myint rad(GetLongParameter(LP_CIRCLE_PERCENT) * GetLongParameter(LP_OY) / 100); //~~rad/2 in dasher-coords
+          pView->Dasher2Screen(GetLongParameter(LP_OX)-filter->forwardmax+rad, GetLongParameter(LP_OY),m_screenCircleCenter.x, m_screenCircleCenter.y);
+        } 
+      }
+      void HandleEvent(CEvent *pEvent) {
+        if (pEvent->m_iEventType == EV_PARAM_NOTIFY &&
+            ((CParameterNotificationEvent *)pEvent)->m_iParameter==BP_DASHER_PAUSED) {
+          //circle needs to move for pause/unpause; setting radius to -1 causes
+          // next call to DecorateView or Timer to re-call ComputeScreenLoc.
+          m_iScreenRadius=-1;
+        }
+        CCircleStartHandler::HandleEvent(pEvent);
+      }
+    private:
+      const COneDimensionalFilter *filter;
+    };
+    return new C1DCircleStartHandler(this);
+  }
+  return CDefaultFilter::MakeStartHandler();
 }
\ No newline at end of file
diff --git a/Src/DasherCore/OneDimensionalFilter.h b/Src/DasherCore/OneDimensionalFilter.h
index 1c06789..dcbdf5b 100644
--- a/Src/DasherCore/OneDimensionalFilter.h
+++ b/Src/DasherCore/OneDimensionalFilter.h
@@ -13,8 +13,9 @@ class COneDimensionalFilter : public CDefaultFilter {
   ///Override to remove DefaultFilters BP_REMAP_XTREME, BP_AUTOCALIBRATE, LP_OFFSET
   bool GetSettings(SModuleSettings **pSettings, int *iCount);
  protected:
-   virtual void ApplyTransform(myint &iDasherX, myint &iDasherY, CDasherView *pView);
-   const myint forwardmax;
+  virtual void ApplyTransform(myint &iDasherX, myint &iDasherY, CDasherView *pView);
+  const myint forwardmax;
+  virtual CStartHandler *MakeStartHandler();
 };
 }
 /// @}
diff --git a/Src/DasherCore/StylusFilter.cpp b/Src/DasherCore/StylusFilter.cpp
index 8e54a0f..fa30031 100644
--- a/Src/DasherCore/StylusFilter.cpp
+++ b/Src/DasherCore/StylusFilter.cpp
@@ -45,3 +45,7 @@ void CStylusFilter::KeyUp(int iTime, int iId, CDasherView *pView, CDasherInput *
 void CStylusFilter::ApplyClickTransform(myint &iDasherX, myint &iDasherY, CDasherView *pView) {
   CClickFilter::AdjustZoomCoords(iDasherX, iDasherY, pView);
 }
+
+CStartHandler *CStylusFilter::MakeStartHandler() {
+  return NULL;
+}
diff --git a/Src/DasherCore/StylusFilter.h b/Src/DasherCore/StylusFilter.h
index 521d013..61df611 100644
--- a/Src/DasherCore/StylusFilter.h
+++ b/Src/DasherCore/StylusFilter.h
@@ -15,11 +15,14 @@ class CStylusFilter : public CDefaultFilter {
   virtual bool Timer(int Time, CDasherView *pView, CDasherInput *pInput, CDasherModel *pModel, Dasher::VECTOR_SYMBOL_PROB *pAdded, int *pNumDeleted, CExpansionPolicy **pol);
   virtual void KeyDown(int iTime, int iId, CDasherView *pView, CDasherInput *pInput, CDasherModel *pModel, CUserLogBase *pUserLog);
   virtual void KeyUp(int iTime, int iId, CDasherView *pView, CDasherInput *pInput, CDasherModel *pModel);
+ protected:
   ///Transform coordinates of a click, to get location to zoom into.
   /// Default is to call CClickFilter::AdjustZoomCoords, which adds
   /// a safety margin according to LP_S, checks we don't exceed the
   /// zoom factor given by LP_MAXZOOM, and ensures x>=2.
   virtual void ApplyClickTransform(myint &iDasherX, myint &iDasherY, CDasherView *pView);
+  ///Do not make a start handler when in stylus mode
+  virtual CStartHandler *MakeStartHandler();
  private:
   int m_iKeyDownTime;
 };
diff --git a/Src/iPhone/Classes/IPhoneFilters.h b/Src/iPhone/Classes/IPhoneFilters.h
index f98225a..855773e 100644
--- a/Src/iPhone/Classes/IPhoneFilters.h
+++ b/Src/iPhone/Classes/IPhoneFilters.h
@@ -50,7 +50,8 @@ protected:
 	virtual void ApplyTransform(myint &iDasherX, myint &iDasherY, CDasherView *pView);
   ///Never apply offset (just eyetracker remapping!) - otherwise would be done when operating in 2d mode
   virtual void ApplyOffset(myint &iDasherX, myint &iDasherY);
-
+  ///Override to choose whether to use 1D start handler or not
+  virtual CStartHandler *MakeStartHandler();
 private:
   CDasherInput *m_pTouch;
   bool bHoldToGo, bUseTouchX, bTilt1D;
diff --git a/Src/iPhone/Classes/IPhoneFilters.mm b/Src/iPhone/Classes/IPhoneFilters.mm
index a0da456..acdd512 100644
--- a/Src/iPhone/Classes/IPhoneFilters.mm
+++ b/Src/iPhone/Classes/IPhoneFilters.mm
@@ -112,17 +112,26 @@ void CIPhoneTiltFilter::HandleEvent(CEvent *pEvent) {
 
 void CIPhoneTiltFilter::iPhonePrefsChanged(NSString *key) {
   bool val = [[NSUserDefaults standardUserDefaults] boolForKey:key];
-  if ([key isEqualToString:HOLD_TO_GO])
+  if ([key isEqualToString:HOLD_TO_GO]) {
     bHoldToGo = val;
-  else if ([key isEqualToString:TILT_USE_TOUCH_X])
+    CreateStartHandler();
+  } else if ([key isEqualToString:TILT_USE_TOUCH_X])
     bUseTouchX = val;
-  else if ([key isEqualToString:TILT_1D])
+  else if ([key isEqualToString:TILT_1D]) {
     bTilt1D = val;
-  else if ([key isEqualToString:@"CircleStart"])
+    CreateStartHandler();
+  } else if ([key isEqualToString:@"CircleStart"])
     SetBoolParameter(BP_CIRCLE_START, val);
   //Hmmm, do we need to do anything _now_?
 }
 
+CStartHandler *CIPhoneTiltFilter::MakeStartHandler() {
+  NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
+  if ([sud boolForKey:HOLD_TO_GO]) return NULL; //no start handler if finger-holding required
+  if ([sud boolForKey:TILT_1D]) return COneDimensionalFilter::MakeStartHandler();
+  return CDefaultFilter::MakeStartHandler();
+}
+
 CIPhoneTouchFilter::CIPhoneTouchFilter(Dasher::CEventHandler * pEventHandler, CSettingsStore *pSettingsStore, CDasherInterfaceBase *pInterface, ModuleID_t iID, UndoubledTouch *pUndoubledTouch, CIPhoneTiltInput *pTilt)
 : CStylusFilter(pEventHandler, pSettingsStore, pInterface, iID, TOUCH_FILTER), m_pUndoubledTouch(pUndoubledTouch), m_pTilt(pTilt) {
   ObserveKeys(TOUCH_USE_TILT_X,nil);



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