summaryrefslogtreecommitdiff
path: root/inputmethods/dasher/DasherViewSquare.inl
blob: c22c32ce7d19e437da666494015ac271f2b7a2fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// DasherViewSquare.inl
//
/////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2001-2002 David Ward
//
/////////////////////////////////////////////////////////////////////////////

namespace Dasher {

inline const void CDasherViewSquare::screen2dasher(int *mousex, int *mousey)
{
	int dashery=*mousey;

	double x=1.0*(CanvasX-*mousex)/CanvasX;
	dashery*=DasherModel().DasherY();
	dashery/=CanvasY;

	if (DasherModel().Dimensions()==false) {
		if (dashery>m_Y2)
			dashery= (dashery-m_Y2)*m_Y1 + m_Y2;
		else if (dashery<m_Y3)
			dashery= (dashery-m_Y3)*m_Y1+m_Y3;
	}

	x=ixmap(x)*DasherModel().DasherY();

	if (DasherModel().Dimensions()==true) {
		double distx, disty;	
		
		distx=2048-x;
		disty=DasherModel().DasherY()/2-dashery;

		if (disty>1500) {
			dashery=548+(548-dashery);
			disty=1298-dashery;
			if(disty<-750) {
				x=2048;
				dashery=2048;
			} else {
				x=2048+pow(pow(750,2)-pow(disty,2),0.5)*10;
			}
			*mousex=int(x);
			*mousey=dashery;
			return;
		}
		else if (disty <-1500) {
			dashery=3548+(3548-dashery);
			disty=2798-dashery;
			if(disty>750) {
				x=2048;
				dashery=2048;
			} else {
				x=2048+pow(pow(750,2)-pow(disty,2),0.5)*10;
			}
			*mousex=int(x);
			*mousey=dashery;
			return;
		} else {
			x=pow(pow(1500,2)-pow(disty,2),0.5);
		}
		x=2048-x;
	}
	*mousex=int(x);
	*mousey=dashery;
}

inline const int CDasherViewSquare::dasherx2screen(const myint sx)
{
	double x=1.0*sx/(DasherModel().DasherY());
	x=xmap(x);
//	return CanvasX-int(x*CanvasY);
	return CanvasX-int(x*CanvasX);

}


inline const int CDasherViewSquare::dashery2screen(myint y)
{
	if (y > m_Y2 )
		y= m_Y2 +  (y-m_Y2)/m_Y1;
	else if (y<m_Y3)
		y= m_Y3+   (y-m_Y3 )/m_Y1;

//	y*=CanvasY*Screen().GetFontSize();
	y*=CanvasY;
	y/=DasherModel().DasherY();
//	y-=(CanvasY*Screen().GetFontSize()-CanvasY)/2;
	return int(y);
}


inline void CDasherViewSquare::Crosshair(myint sx)
{
	CDasherScreen::point crosshair[2];
	
	crosshair[0].x = dasherx2screen(sx);
	crosshair[0].y = 0;
	crosshair[1].x = crosshair[0].x;
	crosshair[1].y = CanvasY;
	
	MapScreen(&crosshair[0].x, &crosshair[0].y);
	MapScreen(&crosshair[1].x, &crosshair[1].y);
	Screen().Polyline(crosshair,2);
	
	crosshair[0].x = dasherx2screen(12*sx/14);
	crosshair[0].y = CanvasY/2;
	crosshair[1].x = dasherx2screen(17*sx/14);
	crosshair[1].y = CanvasY/2;
	
	MapScreen(&crosshair[0].x, &crosshair[0].y);
	MapScreen(&crosshair[1].x, &crosshair[1].y);
	Screen().Polyline(crosshair,2);
}





inline double CDasherViewSquare::ixmap(double x)
// invert x non-linearity
{
	if (x<m_dXmpb*m_dXmpc)
		return x/m_dXmpc;
	else
		return m_dXmpb-m_dXmpa + m_dXmpa * exp( (x/m_dXmpc - m_dXmpb) / m_dXmpa);
	
}


inline double CDasherViewSquare::xmap(double x)
// x non-linearity
{
	if (x<m_dXmpb)
		return m_dXmpc*x;
	else
		return m_dXmpc*(m_dXmpa*log((x+m_dXmpa-m_dXmpb)/m_dXmpa) +m_dXmpb);
}



} // namespace Dasher