|
8 | 8 | #include "DasherModule.h" |
9 | 9 | #include "ModuleManager.h" |
10 | 10 | #include "DasherView.h" |
| 11 | +#include "DasherModel.h" |
11 | 12 |
|
12 | 13 | namespace Dasher { |
13 | 14 | class CDasherInput; |
14 | 15 | class CDasherCoordInput; |
15 | 16 | class CScreenCoordInput; |
| 17 | + class CDasherVectorInput; |
16 | 18 | class CDasherInterfaceBase; |
17 | 19 | } |
18 | 20 | /// \defgroup Input Input devices |
@@ -91,3 +93,29 @@ class Dasher::CDasherCoordInput : public CDasherInput { |
91 | 93 | }; |
92 | 94 |
|
93 | 95 | /// \} |
| 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