Skip to content

Commit 1ad8749

Browse files
committed
Replacing previous VectorInput with a screenspace-based variant that is not subject to the non-linearity of Dasher coordinates
1 parent 1116799 commit 1ad8749

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

Src/DasherCore/DasherInput.h

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,28 +94,31 @@ class Dasher::CDasherCoordInput : public CDasherInput {
9494

9595
/// \}
9696

97-
/// Abstract superclasses for CDasherInputs which natively provides [0,1] inputs;
97+
/// Abstract superclasses for CDasherInputs which natively provides [0,1] inputs in screenspace (not subject to non-linearity);
9898
/// Coordinate system spans from bottom left (-1,-1) to top right (1,1)
9999
/// (=> Subclasses must implement GetVectorCoords)
100-
class Dasher::CDasherVectorInput : public Dasher::CDasherCoordInput {
100+
class Dasher::CDasherVectorInput : public Dasher::CScreenCoordInput {
101101
public:
102-
CDasherVectorInput(const char *szName) : CDasherCoordInput(szName) {}
102+
CDasherVectorInput(const char *szName) : CScreenCoordInput(szName) {}
103103

104104
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-
105+
106+
virtual bool GetScreenCoords(screenint &iX, screenint &iY, CDasherView *pView) {
107+
float inputX, inputY;
108+
if (!GetVectorCoords(inputX, inputY)) return false;
109+
110+
Dasher::screenint originX, originY;
111+
pView->Dasher2Screen(CDasherModel::ORIGIN_X,CDasherModel::ORIGIN_Y, originX, originY);
112+
113+
const CDasherView::ScreenRegion vR = {0,0,pView->Screen()->GetWidth(), pView->Screen()->GetHeight()};
114+
const myint top = vR.minY - originY;
115+
const myint bottom = vR.maxY - originY;
116+
const myint left = vR.minX - originX;
117+
const myint right = vR.maxX - originX;
118+
119+
iX = ((inputX > 0) ? right * inputX : left * -inputX) + originX;
120+
iY = ((inputY > 0) ? top * inputY : bottom * -inputY) + originY;
121+
119122
return true;
120123
}
121124
};

0 commit comments

Comments
 (0)