Diffstat (limited to 'inputmethods/dasher/DasherViewSquare.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | inputmethods/dasher/DasherViewSquare.cpp | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/inputmethods/dasher/DasherViewSquare.cpp b/inputmethods/dasher/DasherViewSquare.cpp new file mode 100644 index 0000000..1b12a58 --- a/dev/null +++ b/inputmethods/dasher/DasherViewSquare.cpp | |||
@@ -0,0 +1,229 @@ | |||
1 | // DasherViewSquare.cpp | ||
2 | // | ||
3 | ///////////////////////////////////////////////////////////////////////////// | ||
4 | // | ||
5 | // Copyright (c) 2001-2002 David Ward | ||
6 | // | ||
7 | ///////////////////////////////////////////////////////////////////////////// | ||
8 | |||
9 | |||
10 | ////////////////////////////////////////////////////////////////////// | ||
11 | // DasherViewSquare.cpp: implementation of the DasherViewSquare class. | ||
12 | // Copyright 2002 David Ward | ||
13 | ////////////////////////////////////////////////////////////////////// | ||
14 | |||
15 | #include "DasherModel.h" | ||
16 | #include "DasherViewSquare.h" | ||
17 | #include <iostream> | ||
18 | |||
19 | using namespace Dasher; | ||
20 | |||
21 | // ARG! MSVC++ V6 doesn't seem to come with min and max in <algorithm> | ||
22 | #ifdef _MSC_VER | ||
23 | #ifndef max | ||
24 | #define max(a,b) (((a) > (b)) ? (a) : (b)) | ||
25 | #endif | ||
26 | #ifndef min | ||
27 | #define min(a,b) (((a) < (b)) ? (a) : (b)) | ||
28 | #endif | ||
29 | #else | ||
30 | #include <algorithm> | ||
31 | using std::min; | ||
32 | using std::max; | ||
33 | #endif | ||
34 | |||
35 | |||
36 | CDasherViewSquare::CDasherViewSquare(CDasherScreen* DasherScreen, CDasherModel& DasherModel, Dasher::Opts::ScreenOrientations Orientation) | ||
37 | : CDasherView(DasherScreen, DasherModel, Orientation) | ||
38 | { | ||
39 | ChangeScreen(DasherScreen); | ||
40 | |||
41 | // tweak these if you know what you are doing | ||
42 | m_dXmpa=0.2; // these are for the x non-linearity | ||
43 | m_dXmpb=0.5; | ||
44 | m_dXmpc=0.9; | ||
45 | m_dXmpd=0.5; // slow X movement when accelerating Y | ||
46 | |||
47 | double dY1=0.25; // Amount of acceleration | ||
48 | double dY2=0.95; // Accelerate Y movement below this point | ||
49 | double dY3=0.05; // Accelerate Y movement above this point | ||
50 | |||
51 | m_Y2=int (dY2 * (CDasherView::DasherModel().DasherY()) ); | ||
52 | m_Y3=int (dY3 * (CDasherView::DasherModel().DasherY()) ); | ||
53 | m_Y1=int(1.0/dY1); | ||
54 | |||
55 | } | ||
56 | |||
57 | |||
58 | int CDasherViewSquare::RenderNode(const symbol Character, const int Color, Opts::ColorSchemes ColorScheme, | ||
59 | myint y1, myint y2, int& mostleft, bool& force, bool text) | ||
60 | { | ||
61 | int top = dashery2screen(y1); | ||
62 | if (top>CanvasY) | ||
63 | return 0; | ||
64 | if (top<0) | ||
65 | top=0; | ||
66 | |||
67 | int bottom = dashery2screen(y2); | ||
68 | if (bottom<0) | ||
69 | return 0; | ||
70 | if (bottom>CanvasY) | ||
71 | bottom=CanvasY; | ||
72 | |||
73 | int height=bottom-top; | ||
74 | |||
75 | if (height==0 && text==true) | ||
76 | force=false; | ||
77 | |||
78 | if (force || height>1) { | ||
79 | force=true; | ||
80 | |||
81 | int left=dasherx2screen(y2-y1); | ||
82 | |||
83 | int right=CanvasX; | ||
84 | |||
85 | int newleft=left, newtop=top, newright=right, newbottom=bottom; | ||
86 | MapScreen(&newleft, &newtop); | ||
87 | MapScreen(&newright, &newbottom); | ||
88 | if( !text ) | ||
89 | Screen().DrawRectangle(newleft, newtop, newright, newbottom, Color, ColorScheme); | ||
90 | else | ||
91 | { | ||
92 | if (left<mostleft) | ||
93 | left=mostleft; | ||
94 | |||
95 | int Size; | ||
96 | if (left*Screen().GetFontSize()<CanvasX*19/20) { | ||
97 | Size = 20*Screen().GetFontSize(); | ||
98 | } else if (left*Screen().GetFontSize()<CanvasX*159/160) { | ||
99 | Size = 14*Screen().GetFontSize(); | ||
100 | } else { | ||
101 | Size = 11*Screen().GetFontSize(); | ||
102 | } | ||
103 | |||
104 | int TextWidth, TextHeight, OriginX=0, OriginY=0; | ||
105 | Screen().TextSize(Character, &TextWidth, &TextHeight, Size); | ||
106 | UnMapScreen(&TextWidth, &TextHeight); | ||
107 | UnMapScreen(&OriginX, &OriginY); | ||
108 | int FontHeight = abs(TextHeight-OriginY); | ||
109 | int FontWidth = abs(TextWidth-OriginX); | ||
110 | mostleft = left + FontWidth; | ||
111 | |||
112 | int newleft2 = left; | ||
113 | int newtop2 = (height-FontHeight)/2 + top; | ||
114 | int newright2 = left + FontWidth; | ||
115 | int newbottom2 = (height+FontHeight)/2 + top; | ||
116 | MapScreen(&newleft2, &newtop2); | ||
117 | MapScreen(&newright2, &newbottom2); | ||
118 | newleft = min(newleft2, newright2); | ||
119 | newtop = min(newtop2, newbottom2); | ||
120 | |||
121 | Screen().DrawText(Character, newleft, newtop, Size); | ||
122 | } | ||
123 | |||
124 | return 1; | ||
125 | } else | ||
126 | return 0; | ||
127 | } | ||
128 | |||
129 | |||
130 | void CDasherViewSquare::CheckForNewRoot() | ||
131 | { | ||
132 | CDasherNode * const root=DasherModel().Root(); | ||
133 | CDasherNode ** const children=root->Children(); | ||
134 | |||
135 | |||
136 | myint y1=DasherModel().Rootmin(); | ||
137 | myint y2=DasherModel().Rootmax(); | ||
138 | |||
139 | if ((y1>0 || y2 < DasherModel().DasherY() || dasherx2screen(y2-y1)>0) && root->Symbol()!=0) { | ||
140 | DasherModel().Reparent_root(root->Lbnd(),root->Hbnd()); | ||
141 | } | ||
142 | |||
143 | if (children==0) | ||
144 | return; | ||
145 | |||
146 | int alive=0; | ||
147 | int theone=0; | ||
148 | unsigned int i; | ||
149 | for (i=1;i<root->Chars();i++) { | ||
150 | if (children[i]->Alive()) { | ||
151 | alive++; | ||
152 | theone=i; | ||
153 | } | ||
154 | } | ||
155 | |||
156 | if (alive==1) { | ||
157 | y1=DasherModel().Rootmin(); | ||
158 | y2=DasherModel().Rootmax(); | ||
159 | myint range=y2-y1; | ||
160 | myint newy1=y1+(range*children[theone]->Lbnd())/DasherModel().Normalization(); | ||
161 | myint newy2=y1+(range*children[theone]->Hbnd())/DasherModel().Normalization(); | ||
162 | if (newy1<0 && newy2> DasherModel().DasherY()) { | ||
163 | myint left=dasherx2screen(newy2-newy1); | ||
164 | if (left<0) { | ||
165 | DasherModel().Make_root(theone); | ||
166 | return; | ||
167 | } | ||
168 | } | ||
169 | } | ||
170 | } | ||
171 | |||
172 | |||
173 | // work out the next viewpoint | ||
174 | // move the rectangles accordingly | ||
175 | void CDasherViewSquare::TapOnDisplay(int mousex,int mousey, unsigned long Time) | ||
176 | { | ||
177 | // convert mouse (screen) coords into dasher coords | ||
178 | if (mousex>CanvasX) | ||
179 | mousex=CanvasX; | ||
180 | |||
181 | UnMapScreen(&mousex, &mousey); | ||
182 | screen2dasher(&mousex,&mousey); | ||
183 | DasherModel().Tap_on_display(mousex,mousey, Time); | ||
184 | CheckForNewRoot(); | ||
185 | } | ||
186 | |||
187 | void CDasherViewSquare::DrawMouse(int mousex, int mousey) | ||
188 | { | ||
189 | screen2dasher(&mousex,&mousey); | ||
190 | mousex=dasherx2screen(mousex); | ||
191 | mousey=dashery2screen(mousey); | ||
192 | Screen().DrawRectangle(mousex-5, mousey-5, mousex+5, mousey+5, 0, Opts::ColorSchemes(Objects)); | ||
193 | } | ||
194 | |||
195 | void CDasherViewSquare::DrawKeyboard() | ||
196 | { | ||
197 | CDasherScreen::point line[2]; | ||
198 | line[0].x = 200; | ||
199 | line[0].y = 0; | ||
200 | line[1].x = 200; | ||
201 | line[1].y = CanvasY/2; | ||
202 | |||
203 | Screen().Polyline(line,2); | ||
204 | |||
205 | line[0].x = 200; | ||
206 | line[0].y = CanvasY/2; | ||
207 | line[1].x = 0; | ||
208 | line[1].y = CanvasY/2; | ||
209 | |||
210 | Screen().Polyline(line,2); | ||
211 | |||
212 | line[0].x = 200; | ||
213 | line[0].y = CanvasY/2; | ||
214 | line[1].x = 200; | ||
215 | line[1].y = CanvasY; | ||
216 | |||
217 | Screen().Polyline(line,2); | ||
218 | } | ||
219 | |||
220 | void CDasherViewSquare::ChangeScreen(CDasherScreen* NewScreen) | ||
221 | { | ||
222 | CDasherView::ChangeScreen(NewScreen); | ||
223 | int Width = Screen().GetWidth(); | ||
224 | int Height = Screen().GetHeight(); | ||
225 | CanvasX=9*Width/10; | ||
226 | CanvasBorder=Width-CanvasX; | ||
227 | CanvasY=Height; | ||
228 | } | ||
229 | |||