Diffstat (limited to 'inputmethods/dasher/DasherViewSquare.inl') (more/less context) (show whitespace changes)
-rw-r--r-- | inputmethods/dasher/DasherViewSquare.inl | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/inputmethods/dasher/DasherViewSquare.inl b/inputmethods/dasher/DasherViewSquare.inl new file mode 100644 index 0000000..c22c32c --- a/dev/null +++ b/inputmethods/dasher/DasherViewSquare.inl | |||
@@ -0,0 +1,142 @@ | |||
1 | // DasherViewSquare.inl | ||
2 | // | ||
3 | ///////////////////////////////////////////////////////////////////////////// | ||
4 | // | ||
5 | // Copyright (c) 2001-2002 David Ward | ||
6 | // | ||
7 | ///////////////////////////////////////////////////////////////////////////// | ||
8 | |||
9 | namespace Dasher { | ||
10 | |||
11 | inline const void CDasherViewSquare::screen2dasher(int *mousex, int *mousey) | ||
12 | { | ||
13 | int dashery=*mousey; | ||
14 | |||
15 | double x=1.0*(CanvasX-*mousex)/CanvasX; | ||
16 | dashery*=DasherModel().DasherY(); | ||
17 | dashery/=CanvasY; | ||
18 | |||
19 | if (DasherModel().Dimensions()==false) { | ||
20 | if (dashery>m_Y2) | ||
21 | dashery= (dashery-m_Y2)*m_Y1 + m_Y2; | ||
22 | else if (dashery<m_Y3) | ||
23 | dashery= (dashery-m_Y3)*m_Y1+m_Y3; | ||
24 | } | ||
25 | |||
26 | x=ixmap(x)*DasherModel().DasherY(); | ||
27 | |||
28 | if (DasherModel().Dimensions()==true) { | ||
29 | double distx, disty; | ||
30 | |||
31 | distx=2048-x; | ||
32 | disty=DasherModel().DasherY()/2-dashery; | ||
33 | |||
34 | if (disty>1500) { | ||
35 | dashery=548+(548-dashery); | ||
36 | disty=1298-dashery; | ||
37 | if(disty<-750) { | ||
38 | x=2048; | ||
39 | dashery=2048; | ||
40 | } else { | ||
41 | x=2048+pow(pow(750,2)-pow(disty,2),0.5)*10; | ||
42 | } | ||
43 | *mousex=int(x); | ||
44 | *mousey=dashery; | ||
45 | return; | ||
46 | } | ||
47 | else if (disty <-1500) { | ||
48 | dashery=3548+(3548-dashery); | ||
49 | disty=2798-dashery; | ||
50 | if(disty>750) { | ||
51 | x=2048; | ||
52 | dashery=2048; | ||
53 | } else { | ||
54 | x=2048+pow(pow(750,2)-pow(disty,2),0.5)*10; | ||
55 | } | ||
56 | *mousex=int(x); | ||
57 | *mousey=dashery; | ||
58 | return; | ||
59 | } else { | ||
60 | x=pow(pow(1500,2)-pow(disty,2),0.5); | ||
61 | } | ||
62 | x=2048-x; | ||
63 | } | ||
64 | *mousex=int(x); | ||
65 | *mousey=dashery; | ||
66 | } | ||
67 | |||
68 | inline const int CDasherViewSquare::dasherx2screen(const myint sx) | ||
69 | { | ||
70 | double x=1.0*sx/(DasherModel().DasherY()); | ||
71 | x=xmap(x); | ||
72 | //return CanvasX-int(x*CanvasY); | ||
73 | return CanvasX-int(x*CanvasX); | ||
74 | |||
75 | } | ||
76 | |||
77 | |||
78 | inline const int CDasherViewSquare::dashery2screen(myint y) | ||
79 | { | ||
80 | if (y > m_Y2 ) | ||
81 | y= m_Y2 + (y-m_Y2)/m_Y1; | ||
82 | else if (y<m_Y3) | ||
83 | y= m_Y3+ (y-m_Y3 )/m_Y1; | ||
84 | |||
85 | //y*=CanvasY*Screen().GetFontSize(); | ||
86 | y*=CanvasY; | ||
87 | y/=DasherModel().DasherY(); | ||
88 | //y-=(CanvasY*Screen().GetFontSize()-CanvasY)/2; | ||
89 | return int(y); | ||
90 | } | ||
91 | |||
92 | |||
93 | inline void CDasherViewSquare::Crosshair(myint sx) | ||
94 | { | ||
95 | CDasherScreen::point crosshair[2]; | ||
96 | |||
97 | crosshair[0].x = dasherx2screen(sx); | ||
98 | crosshair[0].y = 0; | ||
99 | crosshair[1].x = crosshair[0].x; | ||
100 | crosshair[1].y = CanvasY; | ||
101 | |||
102 | MapScreen(&crosshair[0].x, &crosshair[0].y); | ||
103 | MapScreen(&crosshair[1].x, &crosshair[1].y); | ||
104 | Screen().Polyline(crosshair,2); | ||
105 | |||
106 | crosshair[0].x = dasherx2screen(12*sx/14); | ||
107 | crosshair[0].y = CanvasY/2; | ||
108 | crosshair[1].x = dasherx2screen(17*sx/14); | ||
109 | crosshair[1].y = CanvasY/2; | ||
110 | |||
111 | MapScreen(&crosshair[0].x, &crosshair[0].y); | ||
112 | MapScreen(&crosshair[1].x, &crosshair[1].y); | ||
113 | Screen().Polyline(crosshair,2); | ||
114 | } | ||
115 | |||
116 | |||
117 | |||
118 | |||
119 | |||
120 | inline double CDasherViewSquare::ixmap(double x) | ||
121 | // invert x non-linearity | ||
122 | { | ||
123 | if (x<m_dXmpb*m_dXmpc) | ||
124 | return x/m_dXmpc; | ||
125 | else | ||
126 | return m_dXmpb-m_dXmpa + m_dXmpa * exp( (x/m_dXmpc - m_dXmpb) / m_dXmpa); | ||
127 | |||
128 | } | ||
129 | |||
130 | |||
131 | inline double CDasherViewSquare::xmap(double x) | ||
132 | // x non-linearity | ||
133 | { | ||
134 | if (x<m_dXmpb) | ||
135 | return m_dXmpc*x; | ||
136 | else | ||
137 | return m_dXmpc*(m_dXmpa*log((x+m_dXmpa-m_dXmpb)/m_dXmpa) +m_dXmpb); | ||
138 | } | ||
139 | |||
140 | |||
141 | |||
142 | } // namespace Dasher | ||