Skip to content

Commit 1116799

Browse files
committed
Adding VectorInput
1 parent 5539335 commit 1116799

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Src/DasherCore/DasherInput.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
#include "DasherModule.h"
99
#include "ModuleManager.h"
1010
#include "DasherView.h"
11+
#include "DasherModel.h"
1112

1213
namespace Dasher {
1314
class CDasherInput;
1415
class CDasherCoordInput;
1516
class CScreenCoordInput;
17+
class CDasherVectorInput;
1618
class CDasherInterfaceBase;
1719
}
1820
/// \defgroup Input Input devices
@@ -91,3 +93,29 @@ class Dasher::CDasherCoordInput : public CDasherInput {
9193
};
9294

9395
/// \}
96+
97+
/// Abstract superclasses for CDasherInputs which natively provides [0,1] inputs;
98+
/// Coordinate system spans from bottom left (-1,-1) to top right (1,1)
99+
/// (=> Subclasses must implement GetVectorCoords)
100+
class Dasher::CDasherVectorInput : public Dasher::CDasherCoordInput {
101+
public:
102+
CDasherVectorInput(const char *szName) : CDasherCoordInput(szName) {}
103+
104+
virtual bool GetVectorCoords(float &VectorX, float &VectorY) = 0;
105+
106+
virtual bool GetDasherCoords(myint &iDasherX, myint &iDasherY, CDasherView *pView) {
107+
float iX, iY;
108+
if (!GetVectorCoords(iX, iY)) return false;
109+
110+
const CDasherView::DasherCoordScreenRegion vR = pView->VisibleRegion();
111+
const myint top = vR.minY - CDasherModel::ORIGIN_Y;
112+
const myint bottom = vR.maxY - CDasherModel::ORIGIN_Y;
113+
const myint left = vR.maxX - CDasherModel::ORIGIN_X;
114+
const myint right = vR.minX - CDasherModel::ORIGIN_X;
115+
116+
iDasherX = ((iX > 0) ? right * iX : left * -iX) + CDasherModel::ORIGIN_X;
117+
iDasherY = ((iY > 0) ? top * iY : bottom * -iY) + CDasherModel::ORIGIN_Y;
118+
119+
return true;
120+
}
121+
};

0 commit comments

Comments
 (0)