1 #include "../Common/Common.h"
2 #include "DefaultFilter.h"
3 #include "DasherInterfaceBase.h"
6 #include "CircleStartHandler.h"
7 #include "TwoBoxStartHandler.h"
11 CDefaultFilter::CDefaultFilter(Dasher::CEventHandler
* pEventHandler
, CSettingsStore
*pSettingsStore
, CDasherInterfaceBase
*pInterface
, CDasherModel
*m_pDasherModel
, ModuleID_t iID
, const char *szName
)
12 : CInputFilter(pEventHandler
, pSettingsStore
, pInterface
, iID
, 1, szName
) {
14 m_pAutoSpeedControl
= new CAutoSpeedControl(m_pEventHandler
, m_pSettingsStore
, m_pDasherModel
->Framerate());
19 CDefaultFilter::~CDefaultFilter() {
20 delete m_pAutoSpeedControl
;
23 bool CDefaultFilter::DecorateView(CDasherView
*pView
) {
25 bool bDidSomething(false);
27 if(GetBoolParameter(BP_DRAW_MOUSE
)) {
32 if(GetBoolParameter(BP_DRAW_MOUSE_LINE
)) {
38 bDidSomething
= m_pStartHandler
->DecorateView(pView
) || bDidSomething
;
43 bool CDefaultFilter::Timer(int Time
, CDasherView
*m_pDasherView
, CDasherModel
*m_pDasherModel
, Dasher::VECTOR_SYMBOL_PROB
*pAdded
, int *pNumDeleted
) {
47 m_pDasherView
->GetCoordinates(Time
, iDasherX
, iDasherY
);
49 ApplyAutoCalibration(iDasherX
, iDasherY
, true);
50 ApplyTransform(iDasherX
, iDasherY
);
52 if(GetBoolParameter(BP_PAUSE_OUTSIDE
) && !GetBoolParameter(BP_DASHER_PAUSED
)) {
57 m_pDasherView
->VisibleRegion(iDasherMinX
, iDasherMinY
, iDasherMaxX
, iDasherMaxY
);
59 if((iDasherX
> iDasherMaxX
) || (iDasherX
< iDasherMinX
) || (iDasherY
> iDasherMaxY
) || (iDasherY
< iDasherMinY
))
60 m_pInterface
->PauseAt(0,0);
64 bDidSomething
= m_pDasherModel
->UpdatePosition(iDasherX
,iDasherY
, Time
, pAdded
, pNumDeleted
);
66 m_pAutoSpeedControl
->SpeedControl(iDasherX
, iDasherY
, m_pDasherModel
->Framerate(), m_pDasherView
);
69 m_pStartHandler
->Timer(Time
, m_pDasherView
, m_pDasherModel
);
74 void CDefaultFilter::KeyDown(int iTime
, int iId
, CDasherModel
*pModel
, CUserLogBase
*pUserLog
) {
77 case 0: // Start on space
78 // FIXME - wrap this in a 'start/stop' method (and use for buttons as well as keys)
79 if(GetBoolParameter(BP_START_SPACE
)) {
80 if(GetBoolParameter(BP_DASHER_PAUSED
))
81 m_pInterface
->Unpause(iTime
);
83 m_pInterface
->PauseAt(0, 0);
86 case 100: // Start on mouse
87 if(GetBoolParameter(BP_START_MOUSE
)) {
88 if(GetBoolParameter(BP_DASHER_PAUSED
))
89 m_pInterface
->Unpause(iTime
);
91 m_pInterface
->PauseAt(0, 0);
97 void CDefaultFilter::HandleEvent(Dasher::CEvent
* pEvent
) {
98 if(pEvent
->m_iEventType
== 1) {
99 Dasher::CParameterNotificationEvent
* pEvt(static_cast < Dasher::CParameterNotificationEvent
* >(pEvent
));
101 switch (pEvt
->m_iParameter
) {
102 case BP_CIRCLE_START
:
103 case BP_MOUSEPOS_MODE
:
104 CreateStartHandler();
110 void CDefaultFilter::CreateStartHandler() {
111 if(m_pStartHandler
) {
112 delete m_pStartHandler
;
116 if(GetBoolParameter(BP_CIRCLE_START
))
117 m_pStartHandler
= new CCircleStartHandler(m_pEventHandler
, m_pSettingsStore
, m_pInterface
);
118 else if(GetBoolParameter(BP_MOUSEPOS_MODE
))
119 m_pStartHandler
= new CTwoBoxStartHandler(m_pEventHandler
, m_pSettingsStore
, m_pInterface
);
123 void CDefaultFilter::DrawMouse(CDasherView
*pView
) {
127 pView
->GetCoordinates(0, iDasherX
, iDasherY
);
129 ApplyAutoCalibration(iDasherX
, iDasherY
, false);
130 ApplyTransform(iDasherX
, iDasherY
);
132 pView
->DasherDrawCentredRectangle(iDasherX
, iDasherY
, 5, 2, Opts::ColorSchemes(Objects
), false);
135 void CDefaultFilter::DrawMouseLine(CDasherView
*pView
) {
139 // Start of line is the crosshair location
141 x
[0] = (myint
)GetLongParameter(LP_OX
);
142 y
[0] = (myint
)GetLongParameter(LP_OY
);
147 pView
->GetCoordinates(0, x
[1], y
[1]);
149 ApplyAutoCalibration(x
[1], y
[1], false);
150 ApplyTransform(x
[1], y
[1]);
152 // Actually plot the line
154 pView
->DasherPolyline(x
, y
, 2, GetLongParameter(LP_LINE_WIDTH
), 1);
157 void CDefaultFilter::ApplyTransform(myint
&iDasherX
, myint
&iDasherY
) {
160 void CDefaultFilter::ApplyAutoCalibration(myint
&iDasherX
, myint
&iDasherY
, bool bUpdate
) {