tagging release
[dasher.git] / trunk / Src / DasherCore / DefaultFilter.cpp
blob6ddcffc973a70f6274e6d1f2d9a73ee5ec33456c
1 #include "../Common/Common.h"
2 #include "DefaultFilter.h"
3 #include "DasherInterfaceBase.h"
4 #include "Event.h"
6 #include "CircleStartHandler.h"
7 #include "TwoBoxStartHandler.h"
9 #include <iostream>
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) {
13 m_pStartHandler = 0;
14 m_pAutoSpeedControl = new CAutoSpeedControl(m_pEventHandler, m_pSettingsStore, m_pDasherModel->Framerate());
16 CreateStartHandler();
19 CDefaultFilter::~CDefaultFilter() {
20 delete m_pAutoSpeedControl;
23 bool CDefaultFilter::DecorateView(CDasherView *pView) {
25 bool bDidSomething(false);
27 if(GetBoolParameter(BP_DRAW_MOUSE)) {
28 DrawMouse(pView);
29 bDidSomething = true;
32 if(GetBoolParameter(BP_DRAW_MOUSE_LINE)) {
33 DrawMouseLine(pView);
34 bDidSomething = true;
37 if(m_pStartHandler)
38 bDidSomething = m_pStartHandler->DecorateView(pView) || bDidSomething;
40 return bDidSomething;
43 bool CDefaultFilter::Timer(int Time, CDasherView *m_pDasherView, CDasherModel *m_pDasherModel, Dasher::VECTOR_SYMBOL_PROB *pAdded, int *pNumDeleted) {
44 myint iDasherX;
45 myint iDasherY;
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)) {
53 myint iDasherMinX;
54 myint iDasherMinY;
55 myint iDasherMaxX;
56 myint iDasherMaxY;
57 m_pDasherView->VisibleRegion(iDasherMinX, iDasherMinY, iDasherMaxX, iDasherMaxY);
59 if((iDasherX > iDasherMaxX) || (iDasherX < iDasherMinX) || (iDasherY > iDasherMaxY) || (iDasherY < iDasherMinY))
60 m_pInterface->PauseAt(0,0);
63 bool bDidSomething;
64 bDidSomething = m_pDasherModel->UpdatePosition(iDasherX,iDasherY, Time, pAdded, pNumDeleted);
66 m_pAutoSpeedControl->SpeedControl(iDasherX, iDasherY, m_pDasherModel->Framerate(), m_pDasherView);
68 if(m_pStartHandler)
69 m_pStartHandler->Timer(Time, m_pDasherView, m_pDasherModel);
71 return bDidSomething;
74 void CDefaultFilter::KeyDown(int iTime, int iId, CDasherModel *pModel, CUserLogBase *pUserLog) {
76 switch(iId) {
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);
82 else
83 m_pInterface->PauseAt(0, 0);
85 break;
86 case 100: // Start on mouse
87 if(GetBoolParameter(BP_START_MOUSE)) {
88 if(GetBoolParameter(BP_DASHER_PAUSED))
89 m_pInterface->Unpause(iTime);
90 else
91 m_pInterface->PauseAt(0, 0);
93 break;
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();
105 break;
110 void CDefaultFilter::CreateStartHandler() {
111 if(m_pStartHandler) {
112 delete m_pStartHandler;
113 m_pStartHandler = 0;
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) {
124 myint iDasherX;
125 myint iDasherY;
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) {
136 myint x[2];
137 myint y[2];
139 // Start of line is the crosshair location
141 x[0] = (myint)GetLongParameter(LP_OX);
142 y[0] = (myint)GetLongParameter(LP_OY);
144 myint iDasherX;
145 myint iDasherY;
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) {