[dasher] Refactor DynamicFilter: subclasses now handle their own states.
- From: Patrick Welche <pwelche src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [dasher] Refactor DynamicFilter: subclasses now handle their own states.
- Date: Mon, 24 Aug 2009 17:59:35 +0000 (UTC)
commit b78acce891b8218e3f3ed0ad8ae5592b440331e9
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date: Fri Aug 21 13:17:03 2009 +0100
Refactor DynamicFilter: subclasses now handle their own states.
Also remove two-push mode option for BP_FIXED_MARKERS - now compulsory.
ChangeLog | 2 +
Src/DasherCore/ButtonMultiPress.cpp | 11 +---
Src/DasherCore/ButtonMultiPress.h | 2 +-
Src/DasherCore/DynamicFilter.cpp | 7 +--
Src/DasherCore/DynamicFilter.h | 5 +-
Src/DasherCore/Parameters.h | 3 +-
Src/DasherCore/TwoButtonDynamicFilter.cpp | 4 +-
Src/DasherCore/TwoButtonDynamicFilter.h | 2 +-
Src/DasherCore/TwoPushDynamicFilter.cpp | 80 +++++++++-------------------
Src/DasherCore/TwoPushDynamicFilter.h | 4 +-
10 files changed, 44 insertions(+), 76 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7105210..324aae7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
2009-08-21 Alan Lawrence <acl33 inf phy cam ac uk>
* Move handling of double/long/etc. clicks into subclasses.
+ * Subclasses of DynamicFilter now handle their own states, and
+ BP_FIXED_MARKERS is now compulsory.
2009-08-18 Patrick Welche <prlw1 cam ac uk>
diff --git a/Src/DasherCore/ButtonMultiPress.cpp b/Src/DasherCore/ButtonMultiPress.cpp
index bff31eb..a1d12a2 100644
--- a/Src/DasherCore/ButtonMultiPress.cpp
+++ b/Src/DasherCore/ButtonMultiPress.cpp
@@ -72,13 +72,8 @@ void CButtonMultiPress::reverse()
m_deQueueTimes.clear();
}
-void CButtonMultiPress::run(int newState)
+void CButtonMultiPress::run()
{
- int oldState;
- if (isRunning(oldState))
- {
- if (oldState == newState) return;
- }
- CDynamicFilter::run(newState);
- m_deQueueTimes.clear();
+ if (!isRunning()) m_deQueueTimes.clear();
+ CDynamicFilter::run();
}
diff --git a/Src/DasherCore/ButtonMultiPress.h b/Src/DasherCore/ButtonMultiPress.h
index 7dd95c6..687b9ca 100644
--- a/Src/DasherCore/ButtonMultiPress.h
+++ b/Src/DasherCore/ButtonMultiPress.h
@@ -39,7 +39,7 @@ class CButtonMultiPress : public CDynamicFilter {
virtual unsigned int maxClickCount()=0;
virtual void reverse();
virtual void pause();
- virtual void run(int iSubclassState);
+ virtual void run();
private:
virtual void RevertPresses(int iCount) {};
diff --git a/Src/DasherCore/DynamicFilter.cpp b/Src/DasherCore/DynamicFilter.cpp
index 96fd902..538dc40 100644
--- a/Src/DasherCore/DynamicFilter.cpp
+++ b/Src/DasherCore/DynamicFilter.cpp
@@ -96,7 +96,7 @@ void CDynamicFilter::Event(int iTime, int iButton, int iType, CDasherModel *pMod
if(pUserLog)
pUserLog->KeyDown(iButton, iType, 1);
m_pInterface->Unpause(iTime);
- run(0);
+ run();
} else if (isReversing()) {
if(pUserLog)
pUserLog->KeyDown(iButton, iType, 2);
@@ -140,11 +140,10 @@ void CDynamicFilter::reverse()
}
}
-void CDynamicFilter::run(int iSubclassState)
+void CDynamicFilter::run()
{
- DASHER_ASSERT(iSubclassState>=0);
if (m_iState<2) //wasn't running previously
m_uSpeedControlTime = 0; //will be set in Timer()
- m_iState = iSubclassState+2;
+ m_iState = 2;
}
diff --git a/Src/DasherCore/DynamicFilter.h b/Src/DasherCore/DynamicFilter.h
index 78388ee..f42b78c 100644
--- a/Src/DasherCore/DynamicFilter.h
+++ b/Src/DasherCore/DynamicFilter.h
@@ -47,11 +47,10 @@ class CDynamicFilter : public CInputFilter {
bool m_bDecorationChanged;
bool isPaused() {return m_iState == 0;}
bool isReversing() {return m_iState == 1;}
- bool isRunning(int &iSubclassState)
- {if (m_iState < 2) return false; iSubclassState = m_iState-2; return true;}
+ bool isRunning() {return m_iState==2;}
virtual void pause() {m_iState = 0;}
virtual void reverse();
- virtual void run(int iSubclassState);
+ virtual void run();
virtual bool TimerImpl(int Time, CDasherView *m_pDasherView, CDasherModel *m_pDasherModel, Dasher::VECTOR_SYMBOL_PROB *pAdded, int *pNumDeleted) = 0;
diff --git a/Src/DasherCore/Parameters.h b/Src/DasherCore/Parameters.h
index e5c2ba8..4024731 100644
--- a/Src/DasherCore/Parameters.h
+++ b/Src/DasherCore/Parameters.h
@@ -44,7 +44,7 @@ enum {
BP_COMPASSMODE, BP_SOCKET_INPUT_ENABLE, BP_SOCKET_DEBUG,
BP_CIRCLE_START, BP_GLOBAL_KEYBOARD,
BP_SMOOTH_OFFSET, BP_CONVERSION_MODE, BP_PAUSE_OUTSIDE, BP_BACKOFF_BUTTON,
- BP_TWOBUTTON_REVERSE, BP_2B_INVERT_DOUBLE, BP_SLOW_START, BP_FIXED_MARKERS, END_OF_BPS
+ BP_TWOBUTTON_REVERSE, BP_2B_INVERT_DOUBLE, BP_SLOW_START, END_OF_BPS
};
enum {
@@ -165,7 +165,6 @@ static bp_table boolparamtable[] = {
{BP_TWOBUTTON_REVERSE, "TwoButtonReverse", PERS, false, "Reverse the up/down buttons in two button mode"},
{BP_2B_INVERT_DOUBLE, "TwoButtonInvertDouble", PERS, false, "Double-press acts as opposite button in two-button mode"},
{BP_SLOW_START, "SlowStart", PERS, false, "Start at low speed and increase"},
- {BP_FIXED_MARKERS, "TwoPushMarkersFixed", PERS, false, "Two-push Dynamic Mode markers fixed to canvas"},
};
static lp_table longparamtable[] = {
diff --git a/Src/DasherCore/TwoButtonDynamicFilter.cpp b/Src/DasherCore/TwoButtonDynamicFilter.cpp
index 855e403..f1749ef 100644
--- a/Src/DasherCore/TwoButtonDynamicFilter.cpp
+++ b/Src/DasherCore/TwoButtonDynamicFilter.cpp
@@ -105,9 +105,9 @@ void CTwoButtonDynamicFilter::Deactivate() {
SetBoolParameter(BP_SMOOTH_OFFSET, false);
}
-void CTwoButtonDynamicFilter::run(int iState) {
+void CTwoButtonDynamicFilter::run() {
SetBoolParameter(BP_SMOOTH_OFFSET, true);
- CButtonMultiPress::run(iState);
+ CButtonMultiPress::run();
}
void CTwoButtonDynamicFilter::pause() {
diff --git a/Src/DasherCore/TwoButtonDynamicFilter.h b/Src/DasherCore/TwoButtonDynamicFilter.h
index 9284a4a..0799530 100644
--- a/Src/DasherCore/TwoButtonDynamicFilter.h
+++ b/Src/DasherCore/TwoButtonDynamicFilter.h
@@ -45,7 +45,7 @@ class CTwoButtonDynamicFilter : public CButtonMultiPress {
virtual void HandleEvent(Dasher::CEvent *pEvent);
protected:
- virtual void run(int iState);
+ virtual void run();
virtual void pause();
virtual void reverse();
diff --git a/Src/DasherCore/TwoPushDynamicFilter.cpp b/Src/DasherCore/TwoPushDynamicFilter.cpp
index 517e924..5d8b265 100644
--- a/Src/DasherCore/TwoPushDynamicFilter.cpp
+++ b/Src/DasherCore/TwoPushDynamicFilter.cpp
@@ -35,7 +35,6 @@ static SModuleSettings sSettings[] = {
{LP_HOLD_TIME, T_LONG, 100, 10000, 1000, 100, _("Long press time")},
/* TRANSLATORS: Backoff = reversing in Dasher to correct mistakes. This allows a single button to be dedicated to activating backoff, rather than using multiple presses of other buttons, and another to be dedicated to starting and stopping. 'Button' in this context is a physical hardware device, not a UI element.*/
{BP_BACKOFF_BUTTON,T_BOOL, -1, -1, -1, -1, _("Enable backoff and start/stop buttons")},
- {BP_FIXED_MARKERS, T_BOOL, -1, -1, -1, -1, _("Markers fixed to canvas")},
{BP_SLOW_START,T_BOOL, -1, -1, -1, -1, _("Slow startup")},
{LP_SLOW_START_TIME, T_LONG, 0, 10000, 1000, 100, _("Slow startup time")},
{LP_DYNAMIC_SPEED_INC, T_LONG, 1, 100, 1, 1, _("%age by which to automatically increase speed")},
@@ -45,7 +44,7 @@ static SModuleSettings sSettings[] = {
};
CTwoPushDynamicFilter::CTwoPushDynamicFilter(Dasher::CEventHandler * pEventHandler, CSettingsStore *pSettingsStore, CDasherInterfaceBase *pInterface)
- : CDynamicFilter(pEventHandler, pSettingsStore, pInterface, 14, 1, _("Two-push Dynamic Mode (New One Button)")) {
+ : CDynamicFilter(pEventHandler, pSettingsStore, pInterface, 14, 1, _("Two-push Dynamic Mode (New One Button)")), m_dNatsSinceFirstPush(-INFINITY) {
Dasher::CParameterNotificationEvent oEvent(LP_TWO_PUSH_OUTER);//and all the others too!
HandleEvent(&oEvent);
@@ -84,15 +83,12 @@ bool CTwoPushDynamicFilter::DecorateView(CDasherView *pView)
GuideLine(pView, 2048 - GetLongParameter(LP_TWO_PUSH_UP), 1);
GuideLine(pView, 2048 + GetLongParameter(LP_TWO_PUSH_DOWN), 1);
- if (GetBoolParameter(BP_FIXED_MARKERS))
- { //outer guides (at center of rects) - red lines
- GuideLine(pView, 2048 - GetLongParameter(LP_TWO_PUSH_OUTER), 1);
- GuideLine(pView, 2048 + GetLongParameter(LP_TWO_PUSH_OUTER), 1);
- }
+ //outer guides (at center of rects) - red lines
+ GuideLine(pView, 2048 - GetLongParameter(LP_TWO_PUSH_OUTER), 1);
+ GuideLine(pView, 2048 + GetLongParameter(LP_TWO_PUSH_OUTER), 1);
//moving markers - green if active, else yellow
- int myState;
- if (m_bDecorationChanged && isRunning(myState) && myState == 1)
+ if (m_bDecorationChanged && isRunning() && m_dNatsSinceFirstPush > -INFINITY)
{
for (int i = 0; i < 2; i++)
{
@@ -149,25 +145,12 @@ void CTwoPushDynamicFilter::HandleEvent(Dasher::CEvent * pEvent)
double dMaxRate = GetLongParameter(LP_MAX_BITRATE) * GetLongParameter(LP_BOOSTFACTOR) / 10000.0;
m_dLagBits = dMaxRate * GetLongParameter(LP_DYNAMIC_BUTTON_LAG)/1000.0;
//cout << " lag (" << m_dLagBits[0] << ", " << m_dLagBits[1] << ", " << m_dLagBits[2] << ", " << m_dLagBits[3] << ")";
- } //and fallthrough
- case BP_FIXED_MARKERS:
- if (GetBoolParameter(BP_FIXED_MARKERS))
- {
- m_aaiGuideAreas[0][0] = 2048 - GetLongParameter(LP_TWO_PUSH_UP)*exp(m_dMaxShortTwoPushTime);
- m_aaiGuideAreas[0][1] = 2048 - GetLongParameter(LP_TWO_PUSH_UP)*exp(m_dMinShortTwoPushTime);
- m_aaiGuideAreas[1][0] = 2048 + GetLongParameter(LP_TWO_PUSH_DOWN)*exp(m_dMinLongTwoPushTime);
- m_aaiGuideAreas[1][1] = 2048 + GetLongParameter(LP_TWO_PUSH_DOWN)*exp(m_dMaxLongTwoPushTime);
- }
- else
- {
- double dUp(GetLongParameter(LP_TWO_PUSH_UP)), dDown(GetLongParameter(LP_TWO_PUSH_DOWN)),
- dOuter(GetLongParameter(LP_TWO_PUSH_OUTER));
- m_aaiGuideAreas[0][0] = 2048 - dUp * exp((m_dMaxShortTwoPushTime*dUp + m_dLogUpMul*dOuter) / (dOuter+dUp));
- m_aaiGuideAreas[0][1] = 2048 - dUp * exp((m_dMinShortTwoPushTime*dUp + m_dLogUpMul*dOuter) / (dOuter+dUp));
- m_aaiGuideAreas[1][0] = 2048 + dDown * exp((m_dMinLongTwoPushTime*dDown + m_dLogDownMul*dOuter) / (dOuter+dDown));
- m_aaiGuideAreas[1][1] = 2048 + dDown * exp((m_dMaxLongTwoPushTime*dDown + m_dLogDownMul*dOuter) / (dOuter+dDown));
- }
- break;
+ m_aaiGuideAreas[0][0] = 2048 - GetLongParameter(LP_TWO_PUSH_UP)*exp(m_dMaxShortTwoPushTime);
+ m_aaiGuideAreas[0][1] = 2048 - GetLongParameter(LP_TWO_PUSH_UP)*exp(m_dMinShortTwoPushTime);
+ m_aaiGuideAreas[1][0] = 2048 + GetLongParameter(LP_TWO_PUSH_DOWN)*exp(m_dMinLongTwoPushTime);
+ m_aaiGuideAreas[1][1] = 2048 + GetLongParameter(LP_TWO_PUSH_DOWN)*exp(m_dMaxLongTwoPushTime);
+ break;
+ }
}
}
@@ -195,23 +178,19 @@ void CTwoPushDynamicFilter::ActionButton(int iTime, int iButton, int iType, CDas
// Types:
// 0 = ordinary click
// 1 = long click
- int myState;
- if (!isRunning(myState)) DASHER_ASSERT(false);
if (iType != 0) {
reverse();
return;
}
- if (myState == 0) //no button pushed (recently)
+ if (m_dNatsSinceFirstPush == -INFINITY) //no button pushed (recently)
{
-//cout << "First push - event type " << iType << " \n";
- pModel->GetNats();
- run(1);
- pModel->ResetNats();
+ m_dNatsSinceFirstPush = pModel->GetNats();
+ //note, could be negative if overall reversed since last ResetNats (Offset)
+//cout << "First push - got " << m_dNatsSinceFirstPush << std::endl;
}
else
{
- DASHER_ASSERT (myState == 1);
//cout << "Second push - event type " << iType << " logGrowth " << pModel->GetNats() << "\n";
if (m_iActiveMarker == -1)
reverse();
@@ -219,10 +198,12 @@ void CTwoPushDynamicFilter::ActionButton(int iTime, int iButton, int iType, CDas
{
pModel->Offset(m_aiTarget[m_iActiveMarker]);
pModel->ResetNats();
- run(0);
+ //don't really have to reset there, but seems as good a place as any
+ m_dNatsSinceFirstPush = -INFINITY; //"waiting for first push"
}
}
}
+
bool doSet(int &var, const int val)
{
if (var == val) return false;
@@ -232,11 +213,10 @@ bool doSet(int &var, const int val)
bool CTwoPushDynamicFilter::TimerImpl(int iTime, CDasherView *m_pDasherView, CDasherModel *m_pDasherModel, Dasher::VECTOR_SYMBOL_PROB *pAdded, int *pNumDeleted)
{
- int myState;
- if (!isRunning(myState)) DASHER_ASSERT(false);
- if (myState == 1) // button pushed
+ DASHER_ASSERT(isRunning());
+ if (m_dNatsSinceFirstPush > -INFINITY) // first button has been pushed
{
- double dLogGrowth(m_pDasherModel->GetNats()), dOuter(GetLongParameter(LP_TWO_PUSH_OUTER)),
+ double dLogGrowth(m_pDasherModel->GetNats() - m_dNatsSinceFirstPush), dOuter(GetLongParameter(LP_TWO_PUSH_OUTER)),
dUp(GetLongParameter(LP_TWO_PUSH_UP)), dDown(GetLongParameter(LP_TWO_PUSH_DOWN));
//to move to point currently at outer marker: set m_aiTarget to dOuter==exp( log(dOuter/dUp) ) * dUp
@@ -253,17 +233,8 @@ bool CTwoPushDynamicFilter::TimerImpl(int iTime, CDasherView *m_pDasherView, CDa
double dDownDist = exp( dDownBits ) * dDown;
m_aiTarget[0] = dUpDist * exp(m_dLagBits);
m_aiTarget[1] = -dDownDist * exp(m_dLagBits);
- if (GetBoolParameter(BP_FIXED_MARKERS))
- {
- m_bDecorationChanged |= doSet(m_aiMarker[0], 2048 - exp(m_dLagBits + dLogGrowth) * dUp);
- m_bDecorationChanged |= doSet(m_aiMarker[1], 2048 + exp(m_dLagBits + dLogGrowth) * dDown);
- }
- else
- {
- //apply amount of lag corresponding to the first (inner) push only
- m_bDecorationChanged |= doSet(m_aiMarker[0], 2048 - dUpDist * exp(m_dLagBits * (dUp/(dOuter+dUp))));
- m_bDecorationChanged |= doSet(m_aiMarker[1], 2048 + dDownDist * exp(m_dLagBits * (dDown/(dOuter+dUp))));
- }
+ m_bDecorationChanged |= doSet(m_aiMarker[0], 2048 - exp(m_dLagBits + dLogGrowth) * dUp);
+ m_bDecorationChanged |= doSet(m_aiMarker[1], 2048 + exp(m_dLagBits + dLogGrowth) * dDown);
if (dLogGrowth > m_dMaxLongTwoPushTime)
{
//cout << " growth " << dLogGrowth << " - reversing\n";
@@ -287,9 +258,10 @@ void CTwoPushDynamicFilter::Deactivate() {
SetBoolParameter(BP_SMOOTH_OFFSET, false);
}
-void CTwoPushDynamicFilter::run(int iState) {
+void CTwoPushDynamicFilter::run() {
+ m_dNatsSinceFirstPush = -INFINITY;
SetBoolParameter(BP_SMOOTH_OFFSET, true);
- CDynamicFilter::run(iState);
+ CDynamicFilter::run();
}
void CTwoPushDynamicFilter::pause() {
diff --git a/Src/DasherCore/TwoPushDynamicFilter.h b/Src/DasherCore/TwoPushDynamicFilter.h
index 34ee8d2..e6db1c3 100644
--- a/Src/DasherCore/TwoPushDynamicFilter.h
+++ b/Src/DasherCore/TwoPushDynamicFilter.h
@@ -47,7 +47,7 @@ class CTwoPushDynamicFilter : public CDynamicFilter /*long push, but do our own
virtual void HandleEvent(Dasher::CEvent * pEvent);
- virtual void run(int iState);
+ virtual void run();
virtual void pause();
virtual void reverse();
@@ -59,6 +59,8 @@ class CTwoPushDynamicFilter : public CDynamicFilter /*long push, but do our own
int m_iActiveMarker;
int m_aiTarget[2];
int m_aaiGuideAreas[2][2];
+
+ double m_dNatsSinceFirstPush;
};
}
/// @}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]