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