Rev 2870 | Rev 6761 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1005 | barsuk | 1 | #include "func.h" |
2 | #include "parser.h" |
||
3 | #include "kolibri.h" |
||
4 | #include "use_library.h" |
||
5 | |||
6 | const char header[] = "Graph"; |
||
7 | const char empty_text[] = "No function loaded. Type file name and press Enter. "; |
||
8 | const char er_file_not_found[] = "Cannot open file. "; |
||
9 | const char str_filename[]="Filename:"; |
||
10 | const char str_editfile[]="Edit"; |
||
11 | |||
12 | // начальные размеры |
||
13 | #define WND_W 400 |
||
14 | #define WND_H 300 |
||
15 | |||
16 | #define LIGHTGREEN 0xff0000 |
||
17 | #define WHITE 0xffffff |
||
18 | #define BLACK 0x0 |
||
19 | #define LIGHTBLUE 0x0000ff |
||
20 | #define LIGHTRED 0xff0000 |
||
21 | |||
22 | // font colors |
||
23 | #define BIGFONTCOLOR BLACK |
||
24 | #define SMALLFONTCOLOR BLACK |
||
25 | |||
26 | #define THREE 3.0 |
||
27 | // minimum space: 3 pixels |
||
28 | |||
29 | #define BIG_HEIGHT 4.0 |
||
30 | #define SMALL_HEIGHT 2.0 |
||
31 | #define TEXT_X 15.0 |
||
32 | // numeric format for output |
||
33 | #define FORMAT "%f" |
||
34 | // format for two coords |
||
35 | #define FORMAT_COORD "(%f,%f)" |
||
36 | // special value to text if enough space |
||
37 | #define FORMAT_TEST "0.00" |
||
38 | |||
39 | #define DELTA_BIG 1.0 |
||
40 | #define DELTA_SMALL 0.1 |
||
41 | |||
42 | double *points; |
||
43 | Dword point_count = 0; |
||
44 | double x1,y1,x2,y2; |
||
45 | char *funct = NULL; |
||
46 | |||
2870 | leency | 47 | char edit_path[1024]; |
1005 | barsuk | 48 | //Dword editbox_y = WND_H - 16, editbox_w = WND_W - 70; |
2871 | leency | 49 | edit_box mybox = {0,9*8-5,WND_H - 16-32,0xffffff,0x6a9480,0,0x808080,0,512,(dword)&edit_path, 64}; |
1005 | barsuk | 50 | |
2871 | leency | 51 | |
1005 | barsuk | 52 | char *full_head; |
53 | |||
54 | char *HugeBuf = NULL; |
||
55 | |||
56 | //char fuck[64] = "$this is a fucking marker$"; |
||
57 | // параметры командной строки |
||
1764 | clevermous | 58 | #ifdef AUTOBUILD |
59 | extern char params[1024]; |
||
60 | char params[1024]; |
||
61 | #else |
||
1005 | barsuk | 62 | char params[1024] = "_FIND_ME_"; |
1764 | clevermous | 63 | #endif |
1005 | barsuk | 64 | |
65 | /* |
||
66 | |||
67 | fucking piece of shit |
||
68 | |||
69 | */ |
||
70 | |||
71 | // constructor of TCoord |
||
72 | TCoord coord(double x, double y) |
||
73 | { |
||
74 | TCoord r; |
||
75 | r.x = x; |
||
76 | r.y = y; |
||
77 | return r; |
||
78 | } |
||
79 | |||
80 | // move and scale mathematical coords to fit screen coords |
||
81 | TCoord mat2Graf(TCoord c, TCoord scrMin, TCoord scrMax, TCoord mMin, TCoord mMax) |
||
82 | { |
||
83 | TCoord r; |
||
84 | if (c.x > mMax.x) |
||
85 | c.x = mMax.x; |
||
86 | if (c.x < mMin.x) |
||
87 | c.x = mMin.x; |
||
88 | if (c.y > mMax.y) |
||
89 | c.y = mMax.y; |
||
90 | if (c.y < mMin.y) |
||
91 | c.y = mMin.y; |
||
92 | r.x = (scrMax.x - scrMin.x) / (mMax.x - mMin.x) * (c.x - mMin.x) + scrMin.x; |
||
93 | r.y = (scrMax.y - scrMin.y) / (mMax.y - mMin.y) * (mMax.y - c.y) + scrMin.y; |
||
94 | |||
95 | return r; |
||
96 | } |
||
97 | |||
98 | // double-обертки |
||
99 | void line_d( double x1, double y1, double x2, double y2) |
||
100 | { |
||
101 | line(di(x1), di(y1), di(x2), di(y2)); |
||
102 | } |
||
103 | |||
104 | void outtextxy_d( double x, double y, char * text, int len) |
||
105 | { |
||
106 | outtextxy(di(x), di(y), text, len); |
||
107 | } |
||
108 | |||
109 | // huge function to draw all the stuff except the function itself |
||
110 | void drawAxis( TCoord scrMin, TCoord scrMax, TCoord mMin, TCoord mMax) |
||
111 | { |
||
112 | TCoord cZero={0.0,0.0}, |
||
113 | gMin, gMax, gZero, step; |
||
114 | TCoord from, to; |
||
115 | double i=0.0; |
||
116 | int j; |
||
117 | double xmin, xmin2, ymin, ymin2; |
||
118 | char buf[30]=""; |
||
119 | |||
120 | |||
121 | // scr means Screen(bounding rect) |
||
122 | // m means Mathematical |
||
123 | // g means Graphic(real screen position) |
||
124 | |||
125 | //rtlDebugOutString("draw axis called\n"); |
||
126 | |||
127 | //format(debuf, 30, "test: %f,%f,%f,%f\n", 123.45, 1.0, -0.9, 12.57); |
||
128 | //rtlDebugOutString(debuf); |
||
129 | |||
130 | gMin = mat2Graf(mMin, scrMin, scrMax, mMin, mMax); |
||
131 | gMax = mat2Graf(mMax, scrMin, scrMax, mMin, mMax); |
||
132 | gZero = mat2Graf(cZero, scrMin, scrMax, mMin, mMax); |
||
133 | |||
134 | // clear |
||
135 | // setcolor(WHITE); |
||
136 | //rectangle(di(gMin.x), di(gMin.y), di(gMax.x), di(gMax.y)); |
||
137 | // ftopku |
||
138 | |||
139 | setcolor(BLACK); |
||
140 | // osy X |
||
141 | line_d(gMin.x, gZero.y ,gMax.x, gZero.y); |
||
142 | // osy Y |
||
143 | line_d(gZero.x, gMin.y, gZero.x, gMax.y); |
||
144 | // bounding rect |
||
145 | line_d(gMin.x, gMin.y, gMax.x, gMin.y); |
||
146 | line_d(gMin.x, gMax.y, gMax.x, gMax.y); |
||
147 | |||
148 | line_d(gMin.x, gMin.y, gMin.x, gMax.y); |
||
149 | line_d(gMax.x, gMin.y, gMax.x, gMax.y); |
||
150 | |||
151 | // coords of the rect : lower left |
||
152 | format(buf, 30, FORMAT_COORD, x1, y1); |
||
153 | //rtlDebugOutString(buf); |
||
154 | outtextxy_d(gMin.x, gMin.y + textheight(buf, 20), buf, 20); |
||
155 | // upper left |
||
156 | format(buf, 30, FORMAT_COORD, x1, y2); |
||
157 | outtextxy_d(gMin.x, gMax.y - textheight(buf, 20), buf, 20); |
||
158 | // lower right |
||
159 | format(buf, 30, FORMAT_COORD, x2, y1); |
||
160 | outtextxy_d(gMax.x - textwidth(buf, 20), gMin.y + textheight(buf, 20), buf, 20); |
||
161 | // upper right |
||
162 | format(buf, 30, FORMAT_COORD, x2, y2); |
||
163 | outtextxy_d(gMax.x - textwidth(buf, 20), gMax.y - textheight(buf, 20), buf, 20); |
||
164 | |||
165 | //rtlDebugOutString("some lines painted\n"); |
||
166 | |||
167 | |||
168 | step.x = (mMax.x - mMin.x) / (scrMax.x - scrMin.x); |
||
169 | step.y = (mMax.y - mMin.y) / (scrMax.y - scrMin.y); |
||
170 | |||
171 | // round values |
||
172 | xmin = id(di((mMin.x / DELTA_BIG) * DELTA_BIG)); |
||
173 | ymin = id(di((mMin.y / DELTA_BIG) * DELTA_BIG)); |
||
174 | |||
175 | // (0,0) |
||
176 | |||
177 | if ((x1 * x2 <= 0.0) && (y1 * y2 <= 0.0)) |
||
178 | { |
||
179 | from.x=0.0; |
||
180 | from.y=0.0; |
||
181 | from = mat2Graf(from, scrMin, scrMax, mMin, mMax); |
||
182 | setcolor(BLACK); |
||
183 | format(buf, 30, FORMAT, 0.0); |
||
184 | outtextxy_d(from.x - textwidth(buf, 20), from.y + textheight(buf, 20), buf, 20); |
||
185 | } |
||
186 | |||
187 | |||
188 | // big marks on X |
||
189 | //settextstyle(0, 0, 1); |
||
190 | if (DELTA_BIG / step.x > THREE) |
||
191 | { |
||
192 | for (i = xmin; i <= mMax.x; i += DELTA_BIG) |
||
193 | { |
||
194 | if (i != 0.0) |
||
195 | { |
||
196 | from.x = i; |
||
197 | to.x = from.x; |
||
198 | from.y = -BIG_HEIGHT * step.y; |
||
199 | to.y = BIG_HEIGHT * step.y; |
||
200 | from = mat2Graf(from, scrMin, scrMax, mMin, mMax); |
||
201 | to = mat2Graf(to, scrMin, scrMax, mMin, mMax); |
||
202 | setcolor(BLACK); |
||
203 | line_d(from.x, from.y, to.x, to.y); |
||
204 | // write number |
||
205 | format(buf, 30, FORMAT, i); |
||
206 | // if it fits in the GAP, then write it |
||
207 | if (from.y > scrMin.y && (DELTA_BIG > (textwidth(buf, 20) + 1.0) * step.x)) |
||
208 | { |
||
209 | setcolor(BIGFONTCOLOR); |
||
210 | outtextxy_d(from.x - textwidth(buf, 20) / 2.0, to.y - textheight(buf, 20), buf, 20); |
||
211 | } |
||
212 | } |
||
213 | } |
||
214 | } |
||
215 | //rtlDebugOutString("big marks x painted\n"); |
||
216 | |||
217 | // big marks on Y |
||
218 | if (DELTA_BIG / step.y > THREE) |
||
219 | { |
||
220 | for (i = ymin; i <= mMax.y; i += DELTA_BIG) |
||
221 | { |
||
222 | if (i != 0.0) |
||
223 | { |
||
224 | from.y = i; |
||
225 | to.y = from.y; |
||
226 | from.x = -BIG_HEIGHT * step.x; |
||
227 | to.x = BIG_HEIGHT * step.x; |
||
228 | from = mat2Graf(from, scrMin, scrMax, mMin, mMax); |
||
229 | to = mat2Graf(to, scrMin, scrMax, mMin, mMax); |
||
230 | setcolor(BLACK); |
||
231 | line_d(from.x, from.y, to.x, to.y); |
||
232 | format(buf, 30, FORMAT, i); |
||
233 | if (from.x > scrMin.x && (DELTA_BIG > textheight(buf, 20) * step.y)) |
||
234 | { |
||
235 | setcolor(BIGFONTCOLOR); |
||
236 | outtextxy_d(from.x + TEXT_X, to.y - textheight(buf, 20) / 2.0, buf, 20); |
||
237 | } |
||
238 | } |
||
239 | } |
||
240 | } |
||
241 | |||
242 | xmin2 = id(di(mMin.x / DELTA_SMALL)) * DELTA_SMALL; |
||
243 | ymin2 = id(di(mMin.y / DELTA_SMALL)) * DELTA_SMALL; |
||
244 | |||
245 | if (DELTA_SMALL / step.x > THREE) |
||
246 | { |
||
247 | j = di((( - xmin + xmin2 ) / DELTA_SMALL)); |
||
248 | for (i = xmin2; i <= mMax.x; i += DELTA_SMALL, j++) |
||
249 | { |
||
250 | if (j % 10 == 0) |
||
251 | { |
||
252 | // we need to skip every tenth mark, to avoid overwriting big marks |
||
253 | j = 0; |
||
254 | continue; |
||
255 | } |
||
256 | from.x = i; |
||
257 | to.x = from.x; |
||
258 | from.y = -SMALL_HEIGHT * step.y; |
||
259 | to.y = SMALL_HEIGHT * step.y; |
||
260 | from = mat2Graf(from, scrMin, scrMax, mMin, mMax); |
||
261 | to = mat2Graf(to, scrMin, scrMax, mMin, mMax); |
||
262 | setcolor(BLACK); |
||
263 | line_d(from.x, from.y, to.x, to.y); |
||
264 | format(buf, 30, FORMAT, i); |
||
265 | |||
266 | if (from.y > scrMin.y && (DELTA_SMALL > textwidth(buf, 20) * step.x)) |
||
267 | { |
||
268 | setcolor(SMALLFONTCOLOR); |
||
269 | outtextxy_d(from.x - textwidth(buf, 20) / 2.0, to.y - textheight(buf, 20), buf, 20); |
||
270 | } |
||
271 | |||
272 | |||
273 | } |
||
274 | |||
275 | } |
||
276 | |||
277 | // finally small marks on Y |
||
278 | if (DELTA_SMALL / step.y > THREE) |
||
279 | { |
||
280 | //rtlDebugOutString("really small marks y painted\n"); |
||
281 | j = di((( - ymin + ymin2) / DELTA_SMALL)); |
||
282 | for (i = ymin2; i <= mMax.y; i += DELTA_SMALL, j++) |
||
283 | { |
||
284 | if (j % 10 == 0) |
||
285 | { |
||
286 | // we need to skip every tenth, to avoid overwriting |
||
287 | j = 0; |
||
288 | continue; |
||
289 | } |
||
290 | from.y = i; |
||
291 | to.y = from.y; |
||
292 | from.x = -SMALL_HEIGHT * step.x; |
||
293 | to.x = SMALL_HEIGHT * step.x; |
||
294 | from = mat2Graf(from, scrMin, scrMax, mMin, mMax); |
||
295 | to = mat2Graf(to, scrMin, scrMax, mMin, mMax); |
||
296 | setcolor(BLACK); |
||
297 | line_d(from.x, from.y, to.x, to.y); |
||
298 | format(buf, 30, FORMAT, i); |
||
299 | if (from.x > scrMin.x && (DELTA_SMALL > textheight(buf, 20) * step.y)) |
||
300 | { |
||
301 | setcolor(SMALLFONTCOLOR); |
||
302 | outtextxy_d(from.x + TEXT_X, from.y - textheight(buf, 20) / 2.0, buf, 20); |
||
303 | } |
||
304 | } |
||
305 | } |
||
306 | |||
307 | } |
||
308 | |||
309 | /* |
||
310 | ends fucking piece of shit |
||
311 | */ |
||
312 | |||
313 | void drawFunction( function_t fi, TCoord scrMin, TCoord scrMax, |
||
314 | TCoord mMin, TCoord mMax, DWORD color) |
||
315 | { |
||
316 | double x; |
||
317 | double y; |
||
318 | int firstPoint = 1; |
||
319 | TCoord p, p0 = {0.0, 0.0}, step; |
||
320 | |||
321 | drawAxis(scrMin, scrMax, mMin, mMax); |
||
322 | |||
323 | setcolor(color); |
||
324 | step.x = (mMax.x - mMin.x) / (scrMax.x - scrMin.x); |
||
325 | |||
326 | for (x = mMin.x; x < mMax.x; x += step.x) |
||
327 | { |
||
328 | y = fi(x); |
||
329 | // function is defined here and gets in the range |
||
330 | if (1) // тут было условие, что функция правильно вычислена |
||
331 | { |
||
332 | if ((y > mMin.y) && (y < mMax.y)) |
||
333 | { |
||
334 | p = mat2Graf(coord(x, y), scrMin, scrMax, mMin, mMax); |
||
335 | // if it's our first point, only remember its coords |
||
336 | // otherwise, draw a line_d from prev to current |
||
337 | if (firstPoint == 0) |
||
338 | { |
||
339 | line_d(p0.x, p0.y, p.x, p.y); |
||
340 | } |
||
341 | else |
||
342 | firstPoint = 0; |
||
343 | |||
344 | p0 = p; |
||
345 | } |
||
346 | else // too big/small |
||
347 | { |
||
348 | firstPoint = 1; |
||
349 | } |
||
350 | } |
||
351 | else // no value |
||
352 | { |
||
353 | firstPoint = 1; |
||
354 | } |
||
355 | } |
||
356 | |||
357 | } |
||
358 | |||
359 | struct kosBDVK |
||
360 | { |
||
361 | Dword attrib; |
||
362 | Dword name_type; |
||
363 | Dword create_time; |
||
364 | Dword create_date; |
||
365 | Dword access_time; |
||
366 | Dword access_date; |
||
367 | Dword modify_time; |
||
368 | Dword modify_date; |
||
369 | Dword size_low; |
||
370 | Dword size_high; |
||
371 | }; |
||
372 | |||
373 | // итоговая версия читалки текстовых файлов |
||
374 | int load_points3() |
||
375 | { |
||
376 | kosFileInfo fileInfo; |
||
377 | kosBDVK bdvk; |
||
378 | int filePointer = 0; |
||
379 | |||
380 | int i,j,k; |
||
381 | double d; |
||
382 | Dword filesize, num_number; |
||
383 | |||
384 | double *p2; |
||
385 | |||
386 | if (edit_path[0] == '\0') |
||
387 | return 0; |
||
388 | |||
389 | // get file size |
||
390 | strcpy(fileInfo.fileURL,edit_path); |
||
391 | fileInfo.OffsetLow = 0; |
||
392 | fileInfo.OffsetHigh = 0; |
||
393 | fileInfo.dataCount = 0; |
||
394 | fileInfo.rwMode = 5; |
||
395 | fileInfo.bufferPtr = (Byte *)&bdvk; |
||
396 | Dword rr = kos_FileSystemAccess( &(fileInfo) ); // в CKosFile нет определения размера |
||
397 | sprintf(debuf, "getsize: %U\n", rr); |
||
398 | rtlDebugOutString(debuf); |
||
399 | if (rr != 0) |
||
400 | { |
||
401 | kos_WriteTextToWindow(10,10,0,0x00,(char*)er_file_not_found,strlen(er_file_not_found)); |
||
402 | return 0; |
||
403 | } |
||
404 | |||
405 | filesize = bdvk.size_low; |
||
406 | num_number = filesize / 2; |
||
407 | |||
408 | HugeBuf = (char *)allocmem(filesize + 1); // разбираем как строку, отсюда терминатор \0 |
||
409 | |||
410 | for (i=0;i |
||
411 | HugeBuf[i] = 0; |
||
412 | |||
413 | strcpy(fileInfo.fileURL,edit_path); |
||
414 | fileInfo.OffsetLow = 0; |
||
415 | |||
416 | fileInfo.OffsetHigh = 0; |
||
417 | fileInfo.dataCount = filesize; |
||
418 | fileInfo.rwMode = 0; |
||
419 | fileInfo.bufferPtr = (Byte *)HugeBuf; |
||
420 | rr = kos_FileSystemAccess( &(fileInfo) ); // какая-то проблема с hands.dll, CKosFile не работал |
||
421 | |||
422 | sprintf(debuf, "read3: %U\n", rr); |
||
423 | rtlDebugOutString(debuf); |
||
424 | |||
425 | strcpy(full_head, header); |
||
426 | strcpy(full_head+strlen(full_head), " - "); |
||
427 | strcpy(full_head+strlen(full_head), edit_path); // bad code |
||
428 | |||
429 | // а теперь разобраться в этом |
||
430 | |||
431 | i=0; |
||
432 | k=0; |
||
433 | while (i < filesize) |
||
434 | { |
||
435 | |||
436 | while (isalpha(HugeBuf[i]) && i |
||
437 | if (i == filesize) break; |
||
438 | if (k==4 && HugeBuf[i] == '=') |
||
439 | { |
||
440 | //sprintf(debuf,"function: %S",HugeBuf + i); |
||
441 | //rtlDebugOutString(debuf); |
||
442 | // we have a function here |
||
443 | //HugeBuf[0] = ' '; |
||
444 | funct = HugeBuf + i + 1; |
||
445 | strcpy(full_head+strlen(full_head), ". Function y="); |
||
446 | strcpy(full_head+strlen(full_head), funct); |
||
447 | return 1; |
||
448 | } |
||
449 | |||
450 | d = convert(HugeBuf+i, &j); |
||
451 | if (d == ERROR) |
||
452 | { |
||
453 | sprintf(debuf, "Error in input file, byte %U, count %U\n", i, k); |
||
454 | rtlDebugOutString(debuf); |
||
455 | kos_WriteTextToWindow(10, 10, 0, 0x00, (char*)debuf, strlen(debuf)); |
||
456 | return 0; |
||
457 | } |
||
458 | if (d == ERROR_END) |
||
459 | { |
||
460 | rtlDebugOutString("EOF :)!\n"); |
||
461 | break; |
||
462 | } |
||
463 | |||
464 | i+=j; |
||
465 | switch (k) |
||
466 | { |
||
467 | case 0: |
||
468 | x1=d; |
||
469 | break; |
||
470 | case 1: |
||
471 | x2=d; |
||
472 | break; |
||
473 | case 2: |
||
474 | y1=d; |
||
475 | break; |
||
476 | case 3: |
||
477 | y2=d; |
||
478 | break; |
||
479 | default: |
||
480 | { |
||
481 | if (p2 == NULL) |
||
482 | p2 = (double *)allocmem(num_number * 8); |
||
483 | p2[k-4]=d; |
||
484 | } |
||
485 | } |
||
486 | k++; |
||
487 | } |
||
488 | // format(debuf, 30, "(%f,%f)-(%f,%f)",x1,y1,x2,y2); |
||
489 | // rtlDebugOutString(debuf); |
||
490 | point_count=(k - 4)/2; |
||
491 | |||
492 | // |
||
493 | points = (double *)allocmem(point_count * 2 * 8); |
||
494 | for (i = 0; i < point_count * 2; i++) |
||
495 | points[i] = p2[i]; |
||
496 | freemem(p2); |
||
497 | // sprintf(debuf, "count: %U\n", point_count); |
||
498 | // rtlDebugOutString(debuf); |
||
499 | sprintf(debuf, ". Number of points: %U.", point_count); |
||
500 | strcpy(full_head+strlen(full_head), debuf); |
||
501 | freemem(HugeBuf); |
||
502 | HugeBuf = NULL; |
||
503 | return 1; |
||
504 | } |
||
505 | |||
506 | void LaunchTinypad() |
||
507 | { |
||
508 | kosFileInfo fileInfo; |
||
509 | |||
510 | strcpy(fileInfo.fileURL,"/sys/tinypad"); |
||
511 | fileInfo.OffsetLow = 0; |
||
512 | fileInfo.OffsetHigh = (Dword)edit_path; |
||
513 | fileInfo.rwMode = 7; // launch |
||
514 | kos_FileSystemAccess(&fileInfo); |
||
515 | |||
516 | } |
||
517 | |||
518 | // вычислить заданную функцию или кусочно-линейную между точками |
||
519 | double fu(double x) |
||
520 | { |
||
521 | int i; |
||
522 | double res; |
||
523 | |||
524 | |||
525 | if (funct) |
||
526 | { |
||
527 | set_exp(funct,x); |
||
528 | get_exp(&res); // парсить для каждого значения х? да я с ума сошел. |
||
529 | return res; |
||
530 | } |
||
531 | |||
532 | if (point_count == 0) |
||
533 | { |
||
534 | return 0.0; |
||
535 | } |
||
536 | |||
537 | if (x <= points[0]) |
||
538 | return points[1]; |
||
539 | if (x >= points[(point_count-1) * 2]) |
||
540 | return points[(point_count-1) * 2 + 1]; |
||
541 | |||
542 | for (i = 0; i < point_count; i++) |
||
543 | { |
||
544 | if ((x >= points[2 * i]) && (x < points[2 * (i + 1)])) |
||
545 | break; |
||
546 | } |
||
547 | |||
548 | return (x - points[2 * i]) / (points[2 * (i + 1)] - points[2 * i]) |
||
549 | * (points[2 * (i + 1) + 1] - points[2 * i + 1]) + points[2 * i + 1]; |
||
550 | |||
551 | } |
||
552 | |||
553 | void draw_window(void) |
||
554 | { |
||
2870 | leency | 555 | double xx0=0.0, yy0=0.0; |
1005 | barsuk | 556 | sProcessInfo info; |
557 | Dword wi, he; |
||
558 | void *p; |
||
559 | |||
2870 | leency | 560 | for (int i = 0; i < 1024; i++) |
1005 | barsuk | 561 | info.rawData[i] = 0; |
562 | kos_ProcessInfo(&info, 0xFFFFFFFF); |
||
563 | |||
564 | p = info.rawData + 42; // magic |
||
565 | wi = *(Dword *)(p); |
||
566 | he = *(Dword *)((Byte *)p + 4); |
||
567 | |||
568 | if (wi == 0) |
||
569 | wi = WND_W; |
||
570 | if (he == 0) |
||
571 | he = WND_H; |
||
572 | |||
573 | mybox.top = he - 45; |
||
574 | mybox.width = wi - mybox.left - 80; |
||
575 | |||
576 | kos_WindowRedrawStatus(1); |
||
2870 | leency | 577 | kos_DefineAndDrawWindow(10,40,WND_W,WND_H, 0x33,0xFFFFFF,0,0,(Dword)full_head); |
578 | kos_WindowRedrawStatus(2); |
||
1005 | barsuk | 579 | |
2870 | leency | 580 | if (info.rawData[70]&0x04) return; //ничего не делать если окно схлопнуто в заголовок |
1005 | barsuk | 581 | |
582 | if (point_count == 0 && funct == NULL) |
||
583 | { |
||
584 | kos_WriteTextToWindow((wi - 6 * strlen(empty_text))/2,he/2,0,0x000000,(char *)empty_text,strlen(empty_text)); |
||
585 | } |
||
586 | else |
||
587 | { |
||
588 | drawFunction(&fu, coord(10, 20), coord(id(wi - 20), id(he - 70)), |
||
589 | coord(x1,y1), coord(x2,y2), 0x00ff0000); |
||
590 | |||
591 | } |
||
592 | |||
593 | kos_WriteTextToWindow(4, mybox.top + 4, 0, 0, (char*)str_filename, strlen(str_filename)); |
||
594 | |||
595 | if ((void*)edit_box_draw != NULL) |
||
596 | edit_box_draw((DWORD)&mybox); |
||
597 | |||
598 | kos_DefineButton(wi - 70, mybox.top, 50, 12, 5, 0xc0c0c0); |
||
599 | kos_WriteTextToWindow(wi - 58, mybox.top + 4, 0, 0, (char*)str_editfile, strlen(str_editfile)); |
||
600 | |||
601 | } |
||
602 | |||
603 | void kos_Main() |
||
604 | { |
||
605 | kos_InitHeap(); |
||
606 | full_head = (char*)allocmem(300); |
||
607 | strcpy(full_head, "Graph"); |
||
608 | load_edit_box(); |
||
609 | if (params[0]) // fuck[0] for debug |
||
610 | { |
||
611 | rtlDebugOutString("launched with params"); |
||
612 | rtlDebugOutString((char*)params); |
||
613 | strcpy(edit_path, params); |
||
2871 | leency | 614 | mybox.size=mybox.pos=strlen(edit_path); |
1005 | barsuk | 615 | //rtlDebugOutString((char*)edit_path); |
616 | load_points3(); |
||
617 | } |
||
618 | rtlDebugOutString("data loaded.\n"); |
||
619 | draw_window(); |
||
620 | for (;;) |
||
621 | { |
||
622 | edit_box_mouse((dword)&mybox); |
||
623 | switch (kos_WaitForEvent()) |
||
624 | { |
||
625 | case 1: |
||
626 | draw_window(); |
||
627 | break; |
||
628 | case 2: |
||
629 | // key pressed, read it |
||
630 | Byte keyCode; |
||
631 | kos_GetKey(keyCode); |
||
632 | |||
633 | switch (keyCode) |
||
634 | { |
||
635 | case 0x0D: |
||
636 | if (HugeBuf!=NULL) |
||
637 | { |
||
638 | //sprintf(debuf, "freemem: HugeBuf = %X", HugeBuf); |
||
639 | //rtlDebugOutString(debuf); |
||
640 | freemem((void*)HugeBuf); // что за баг - понять не могу. |
||
641 | HugeBuf = NULL; |
||
642 | funct = NULL; |
||
643 | } |
||
644 | if (points!=NULL) |
||
645 | { |
||
646 | //sprintf(debuf, "freemem: points = %X", points); |
||
647 | //rtlDebugOutString(debuf); |
||
648 | freemem((void*)points); // и тут. ну не обращаюсь я к этому указателю, только память в него |
||
649 | // потом снова выделяю |
||
650 | points = NULL; |
||
651 | } |
||
652 | point_count = 0; |
||
653 | kos_DrawBar(10,10,200,20,0xFFFFFF); // фон для сообщений об ошибках |
||
654 | if (load_points3()) |
||
655 | draw_window(); |
||
656 | break; |
||
657 | default: |
||
658 | { |
||
659 | __asm |
||
660 | { |
||
661 | mov ah, keyCode |
||
662 | } |
||
663 | edit_box_key((dword)&mybox); |
||
664 | } |
||
665 | } |
||
666 | break; |
||
667 | |||
668 | |||
669 | case 3: |
||
670 | // button pressed; we have only one button, close |
||
671 | Dword button; |
||
672 | kos_GetButtonID(button); |
||
673 | if (button == 1) |
||
674 | kos_ExitApp(); |
||
2870 | leency | 675 | if (button == 5) |
1005 | barsuk | 676 | LaunchTinypad(); |
677 | } |
||
678 | } |
||
679 | }>>>=>>> |
||
680 |