Subversion Repositories Kolibri OS

Rev

Rev 7427 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7427 theonlymir 1
 
2
3
 
4
;       mov [Object.FigData], (tl_node_add(врем. стр.),tl_node_get_data)
5
6
 
7441 IgorA 7
7427 theonlymir 8
 
9
        OType dd ?
10
        FigCount dd ?
11
        FigData dd ? ;array pointers to Figures
12
        MinX dq ?
13
        MinY dq ?
14
        SizeX dq ?
15
        SizeY dq ?
16
        WScale dq ? ;prewiew window scale
17
        MScale dq ? ;mouse scale (show partition figure)
18
        MCentrX dd ? ;mouse centr X
19
        MCentrY dd ? ;mouse centr Y
20
        Caption rb 32
21
ends
22
23
 
24
        OType dd ?
25
        PoiCount dd ?
26
        PoiData dd ?
27
        MinX dq ?
28
        MinY dq ?
29
        SizeX dq ?
30
        SizeY dq ?
31
        WScale dq ? ;prewiew window scale (show all figure)
32
        MScale dq ? ;mouse scale (show partition figure)
33
        MCentrX dd ? ;mouse centr X
34
        MCentrY dd ? ;mouse centr Y
35
        Caption rb 32
36
ends
37
38
 
39
        Prop dd ? ;prorerties
40
        CoordX dq ? ;coord X
41
        CoordY dq ? ;coord Y
42
ends
43
44
 
45
txt_err_2 db 'Ошибка при считывании фигуры',0
46
txt_err_3 db 'Не найдена точка в фигуре',0
47
txt_err_no_figure_select db 'Не выбрана команда для перемещения',0
48
txt_err_figure_is_0 db 'Команда не может быть сдвинута вверх,',13,10,'она в начале списка.',0
49
txt_err_figure_is_last db 'Команда не может быть сдвинута вниз,',13,10,'она в конце списка.',0
50
txt_err_no_point_del db 'Не можна удалить все точки из фигуры.',0
51
txt_err_poi_is_0 db 'Не можна переместить точку вверх,',13,10,'она в начале списка.',0
52
txt_err_poi_is_last db 'Не можна переместить точку вниз,',13,10,'она в конце списка.',0
53
txt_err_no_1_point_sel db 'Выберите не больше одной точки.',0
54
55
 
56
txt_min_y db 'min y: ',0
57
58
 
59
;
60
; rus
61
;
62
txt_preview db 'Предпросмотр результата:',0
63
txt_port db 'Порт:',0
64
txt_but_cancel db 'Отмена',0
65
txt_but_run db 'Выполнить',0
66
txt_size_x db 'размер x: ',0
67
txt_size_y db 'размер y: ',0
68
txt_command:
69
  db 'Команда:', 0
70
  .end:
71
txt_filename:
72
  db 'Файл (полный путь):', 0
73
  .end:
74
else
75
;
76
; eng
77
;
78
txt_preview db 'Preview:',0
79
txt_port db 'Port:',0
80
txt_but_cancel db 'Cancel',0
81
txt_but_run db 'Run',0
82
txt_size_x db 'size x: ',0
83
txt_size_y db 'size y: ',0
84
txt_command:
85
  db 'Command:', 0
86
  .end:
87
txt_filename:
88
  db 'Full file name (path):', 0
89
  .end:
90
end if
91
92
 
93
txt_s_poi db 'X',0
94
txt_s_poi_Y db ' Y',0
95
txt_s_poi_Z db ' Z',0
96
txt_n db 13,0
97
98
 
99
zoom_plus dq 1.25992105
100
mouse_prop_x dd 0 ;курсор мыши относительно центра окна buf_0 (для измен. масштаба)
101
mouse_prop_y dd 0
102
mouse_down_x dd 0 ;курсор мыши относительно левого верхнего угла окна buf_0 (для сдвига фигуры)
103
mouse_down_y dd 0
104
opt_draw  dd 1
105
graf_margin_left   dd 3 ;margin in pixels
106
graf_margin_right  dd 3+6 ;margin in pixels
107
graf_margin_top    dd 3+9 ;margin in pixels
108
graf_margin_bot    dd 3+9 ;margin in pixels
109
data_printed dd ? ;число выполненных команд
7441 IgorA 110
data_all     dd ? ;число всех команд
111
7427 theonlymir 112
 
113
ObjData Object
114
FigData Figure ;временная структура для заполнения tree1
115
PoiData Point
116
117
 
118
119
 
120
   ... need fix size_one_list
121
end if
122
123
 
124
   ... need fix offsets
125
end if
126
127
 
128
txt_sp db ' ',0
129
130
 
131
; esi - text pointer
132
align 4
133
proc txt_next_line uses eax ecx edi, mlen:dword
134
        mov al,13
135
        mov ecx,[mlen]
136
        mov edi,esi
137
        repne scasb
138
        cmp byte[edi],10
139
        jne @f
140
                inc edi
141
        @@:
142
        mov esi,edi
143
        ret
144
endp
145
146
 
147
; edi - destination buffer
148
; esi - source text string: '...\nl
149
; mlen - maximum len destination buffer
150
align 4
151
proc txt_load_line uses eax ebx ecx esi, mlen:dword
152
        mov byte[edi],0
153
        mov al,13
154
        cmp byte[esi],al
155
        je .end_f
156
                mov ecx,[mlen]
157
                mov ebx,edi
158
                mov edi,esi
159
                repne scasb ;found end of string
160
                mov ecx,edi
161
                sub ecx,esi
162
                dec ecx ;ecx = string len
163
                mov edi,ebx
164
                rep movsb ;copy caption string
165
                cmp byte[esi],13
166
                je @f
167
                .cycle0:
168
                        inc esi
169
                        cmp byte[esi],13
170
                        jne .cycle0
171
                @@:
172
                mov byte[edi],0
173
                inc esi
174
        .end_f:
175
        ret
176
endp
177
178
 
179
; itxt - input description text
180
; msize - max size
181
align 4
182
proc FileInit uses eax ebx ecx edi esi, itxt:dword, msize:dword
183
        cmp dword[ObjData.FigData],0
184
        je @f
185
        cmp dword[ObjData.FigCount],0 ;or Figure.PoiCount
186
        je @f
187
                stdcall mem.Free,[ObjData.FigData] ;or Figure.PoiData
188
        @@:
189
        mov dword[offs_last_timer],0
190
191
 
192
        mov ebx,esi
193
        add ebx,[msize]
194
        stdcall ObjectInit,ObjData,ebx
195
        ret
196
endp
197
198
 
199
; esi - input description text
200
; pobj - pointer to object struct
201
; etxt - pointer to end of input text
202
align 4
203
proc ObjectInit uses eax ebx ecx edi, pobj:dword, etxt:dword
204
                mov ebx,[pobj]
205
                mov [ebx+Object.OType],'Obj'
206
                mov edi,ebx
207
                add edi,Object.Caption
208
                mov dword[edi],'CNC'
209
210
 
211
                test eax,eax
212
                jz .err_init
213
                mov [ebx+Object.FigCount],eax
214
                mov ecx,eax
215
216
 
217
                stdcall mem.Alloc,eax
218
                mov [ebx+Object.FigData],eax
219
                push ecx
220
                        mov edi,eax
221
                        xor eax,eax
222
                        mov [data_all],eax ;хитрое начальное обнуление счетчика
7441 IgorA 223
                        mov [data_printed],eax
224
                        rep stosd ;clear memory
7427 theonlymir 225
                pop ecx
226
227
 
228
align 4
229
                .cycle0:
230
                        stdcall FigureInit,edi
231
                        mov eax,[edi]
7441 IgorA 232
                        mov eax,[eax+Figure.PoiCount]
233
                        or eax,eax
234
                        jnz @f
235
                        	inc eax ;минимум 1-на команда
236
                        @@:
237
                        add [data_all],eax
238
                        cmp esi,[etxt]
7427 theonlymir 239
                        jge .cycle0end
240
                        add edi,4
241
                loop .cycle0
242
                .cycle0end:
243
                inc dword[ebx+Object.FigCount]
7441 IgorA 244
                or ecx,ecx
7427 theonlymir 245
                jz @f
246
                        ;уменьшаем объем памяти выделенный для команд
247
                        sub [ebx+Object.FigCount],ecx
248
                        mov eax,[ebx+Object.FigCount]
249
                        shl eax,2
250
                        stdcall mem.ReAlloc,[ebx+Object.FigData],eax
251
                        mov [ebx+Object.FigData],eax
252
                @@:
253
                ;установка счетчика и прогресбара на 25 %
7441 IgorA 254
                mov eax,[data_all]
255
                mov [pb.max],eax
256
                shr eax,2
257
                mov [data_printed],eax
258
                mov [pb.value],eax
259
7427 theonlymir 260
 
261
262
 
263
        .err_init:
264
                notify_window_run txt_err_1
265
        .end_f:
266
        ret
267
endp
268
269
 
270
proc ObjCalculateScale uses eax ebx ecx edi, pobj:dword
271
        mov ebx,[pobj]
272
273
 
274
        finit
275
276
 
277
        mov ecx,[ebx+Object.FigCount]
278
        jecxz .cycle2end
279
        mov edi,[ebx+Object.FigData]
280
        @@:
281
                mov eax,[edi]
282
                dec ecx
283
                jecxz .cycle2end
284
                add edi,4
285
                or eax,eax
286
                jz @b
287
                cmp [eax+Figure.PoiCount],0
288
                je @b
289
        push edi esi ;copy first min X
290
                lea esi,[eax+Figure.MinX]
291
                lea edi,[ebx+Object.MinX]
292
                movsd
293
                movsd
294
        pop esi edi
295
align 4
296
        .cycle2:
297
                mov eax,[edi]
298
                or eax,eax
299
                jz @f
300
                cmp [eax+Figure.PoiCount],0
301
                je @f
302
                fld qword[eax+Figure.MinX]
303
                fcomp qword[ebx+Object.MinX]
304
                fstsw ax
305
                sahf
306
                jae @f
307
                        push edi esi
308
                        mov eax,[edi]
309
                        lea esi,[eax+Figure.MinX]
310
                        lea edi,[ebx+Object.MinX]
311
                        movsd
312
                        movsd
313
                        pop esi edi
314
                @@:
315
                add edi,4
316
        loop .cycle2
317
        .cycle2end:
318
319
 
320
        mov ecx,[ebx+Object.FigCount]
321
        jecxz .cycle3end
322
        mov edi,[ebx+Object.FigData]
323
        @@:
324
                mov eax,[edi]
325
                dec ecx
326
                jecxz .cycle3end
327
                add edi,4
328
                or eax,eax
329
                jz @b
330
                cmp [eax+Figure.PoiCount],0
331
                je @b
332
        push edi esi ;copy first min Y
333
                lea esi,[eax+Figure.MinY]
334
                lea edi,[ebx+Object.MinY]
335
                movsd
336
                movsd
337
        pop esi edi
338
align 4
339
        .cycle3:
340
                mov eax,[edi]
341
                or eax,eax
342
                jz @f
343
                cmp [eax+Figure.PoiCount],0
344
                je @f
345
                fld qword[eax+Figure.MinY]
346
                fcomp qword[ebx+Object.MinY]
347
                fstsw ax
348
                sahf
349
                jae @f
350
                        push edi esi
351
                        mov eax,[edi]
352
                        lea esi,[eax+Figure.MinY]
353
                        lea edi,[ebx+Object.MinY]
354
                        movsd
355
                        movsd
356
                        pop esi edi
357
                @@:
358
                add edi,4
359
        loop .cycle3
360
        .cycle3end:
361
362
 
363
        mov ecx,[ebx+Object.FigCount]
364
        jecxz .cycle4end
365
        mov edi,[ebx+Object.FigData]
366
        ;copy first min X
367
        mov eax,[edi]
368
        fld qword[eax+Figure.MinX]
369
        fadd qword[eax+Figure.SizeX]
370
        fstp qword[ebx+Object.SizeX]
371
        dec ecx
372
        jecxz .cycle4end
373
align 4
374
        .cycle4:
375
                add edi,4
376
                mov eax,[edi]
377
                or eax,eax
378
                jz @f
379
                cmp [eax+Figure.PoiCount],0
380
                je @f
381
                fld qword[eax+Figure.MinX]
382
                fadd qword[eax+Figure.SizeX]
383
                fcomp qword[ebx+Object.SizeX]
384
                fstsw ax
385
                sahf
386
                jbe @f
387
                        mov eax,[edi]
388
                        fld qword[eax+Figure.MinX]
389
                        fadd qword[eax+Figure.SizeX]
390
                        fstp qword[ebx+Object.SizeX]
391
                @@:
392
        loop .cycle4
393
        .cycle4end:
394
395
 
396
        mov ecx,[ebx+Object.FigCount]
397
        jecxz .cycle5end
398
        mov edi,[ebx+Object.FigData]
399
        ;copy first min Y
400
        mov eax,[edi]
401
        fld qword[eax+Figure.MinY]
402
        fadd qword[eax+Figure.SizeY]
403
        fstp qword[ebx+Object.SizeY]
404
        dec ecx
405
        jecxz .cycle5end
406
align 4
407
        .cycle5:
408
                add edi,4
409
                mov eax,[edi]
410
                or eax,eax
411
                jz @f
412
                cmp [eax+Figure.PoiCount],0
413
                je @f
414
                fld qword[eax+Figure.MinY]
415
                fadd qword[eax+Figure.SizeY]
416
                fcomp qword[ebx+Object.SizeY]
417
                fstsw ax
418
                sahf
419
                jbe @f
420
                        mov eax,[edi]
421
                        fld qword[eax+Figure.MinY]
422
                        fadd qword[eax+Figure.SizeY]
423
                        fstp qword[ebx+Object.SizeY]
424
                @@:
425
        loop .cycle5
426
        .cycle5end:
427
428
 
429
        fld qword[ebx+Object.SizeX]
430
        fsub qword[ebx+Object.MinX]
431
        fstp qword[ebx+Object.SizeX]
432
        ;found size Y
433
        fld qword[ebx+Object.SizeY]
434
        fsub qword[ebx+Object.MinY]
435
        fstp qword[ebx+Object.SizeY]
436
437
 
438
                fld1
439
                fstp qword[ebx+Object.WScale] ;set default scale
440
441
 
442
                ftst
443
                fstsw ax
444
                sahf
445
                jne .els_0 ;if (SizeX == 0.0)
446
                        ffree st0
447
                        fincstp
448
                        jmp .els_1
449
                .els_0: ;else if (SizeX != 0.0)
450
                        fild dword[buf_0.w]
451
                        fisub dword[graf_margin_left]
452
                        fisub dword[graf_margin_right]
453
                        fxch st1
454
                        fdivp
455
                        fstp qword[ebx+Object.WScale]
456
                .els_1:
457
458
 
459
                ftst
460
                fstsw ax
461
                sahf
462
                jne .els_2 ;if (SizeY == 0.0)
463
                        ffree st0
464
                        fincstp
465
                        jmp .els_3
466
                .els_2: ;else if (SizeY != 0.0)
467
                        fild dword[buf_0.h]
468
                        fisub dword[graf_margin_top]
469
                        fisub dword[graf_margin_bot]
470
                        fxch st1
471
                        fdivp
472
                        fcom qword[ebx+Object.WScale]
473
                        fstsw ax
474
                        sahf
475
                        jbe @f
476
                                ffree st0
477
                                fincstp
478
                                jmp .els_3
479
                        @@:
480
                        fstp qword[ebx+Object.WScale]
481
                .els_3:
482
483
 
484
                fstp qword[ebx+Figure.MScale]
485
                mov dword[ebx+Figure.MCentrX],0
486
                mov dword[ebx+Figure.MCentrY],0
487
        ret
488
endp
489
490
 
491
; esi - input description text
492
; pfig - pointer to figure struct
493
;output:
494
; esi - output description text
495
align 4
496
proc FigureInit uses eax ebx ecx edx edi, pfig:dword
497
        mov ebx,FigData ; temp struct
498
        mov [ebx+Figure.OType],'Fig'
499
        mov edi,ebx
500
        add edi,Figure.Caption
501
        stdcall txt_load_line,32
502
503
 
504
        mov [ebx+Figure.PoiCount],eax
505
        mov [ebx+Figure.PoiData],eax
506
        cmp byte[esi],'X'
507
        jne .end0
508
                stdcall get_max_points
509
                mov [ebx+Figure.PoiCount],eax
510
                or eax,eax
511
                jz .end0
512
                mov ecx,eax
513
                imul eax,sizeof.Point
514
                stdcall mem.Alloc,eax
515
                mov [ebx+Figure.PoiData],eax
516
                or eax,eax
517
                jz .err_init
518
                mov edi,eax
519
align 4
520
                .cycle0:
521
                        stdcall PointInit,edi
522
                        or eax,eax
523
                        jz .cycle0end
524
                        add edi,sizeof.Point
525
                        loop .cycle0
526
                .cycle0end:
527
                or ecx,ecx
528
                jz .end1
529
                        ;уменьшаем объем памяти выделенный для точек
530
                        sub [ebx+Figure.PoiCount],ecx
531
                        mov eax,[ebx+Figure.PoiCount]
532
                        imul eax,sizeof.Point
533
                        stdcall mem.ReAlloc,[ebx+Figure.PoiData],eax
534
                        mov [ebx+Figure.PoiData],eax
535
                jmp .end1
536
        .err_init:
537
                notify_window_run txt_err_2
538
        .end0:
539
                ;command
540
                stdcall txt_next_line, 80
541
                cmp byte[esi],13
542
                jne @f
543
                        ;if null line
544
                        inc esi
545
                        cmp byte[esi],10
546
                        jne .end2
547
                                inc esi
548
                        .end2:
549
                        mov dword[edi],(10 shl 8)+13 ;new line
550
                @@:
551
                stdcall add_object_in_list,ebx,[pfig]
552
                jmp .end_f
553
        .end1:
554
                ;coords
555
                stdcall add_object_in_list,ebx,[pfig]
556
                or eax,eax
557
                jz .end_f
558
                stdcall FigCalculateSizes,eax,1
559
        .end_f:
560
        ret
561
endp
562
563
 
564
; esi - pointer to file
565
;output:
566
; eax - max lines in file
567
align 4
568
proc get_max_lines uses esi
569
        xor eax,eax
570
        .cycle0:
571
                cmp byte[esi],13
572
                jne @f
573
                        inc eax
574
                @@:
575
                inc esi
576
                cmp byte[esi],0
577
                jne .cycle0
578
        ret
579
endp
580
581
 
582
; esi - pointer to file
583
;output:
584
; eax - max point coords in file
585
align 4
586
proc get_max_points uses esi
587
        xor eax,eax
588
        .cycle0:
589
                cmp word[esi],' Y'
590
                jne @f
591
                        inc eax
592
                @@:
593
                inc esi
594
                cmp byte[esi+1],0
595
                jne .cycle0
596
        ret
597
endp
598
599
 
600
; opt_calc - если 0 - пересчитать масштаб фигуры,
601
;                 1 - пересчитать размеры и масштаб фигуры
602
align 4
603
proc FigCalculateSizes uses eax ebx ecx edi esi, pfig:dword, opt_calc:dword
604
        mov ebx,[pfig]
605
        or ebx,ebx
606
        jz .end_f
607
608
 
609
        bt dword[opt_calc],0
610
        jnc .calc_scale
611
612
 
613
        mov esi,[ebx+Figure.PoiData]
614
        or esi,esi
615
        jz .end_f
616
617
 
618
        lea edi,[ebx+Figure.MinX]
619
        movsd
620
        movsd ;Figure.MinX = Point[0].CoordX
621
        sub esi,8
622
        lea edi,[ebx+Figure.SizeX]
623
        movsd
624
        movsd ;Figure.SizeX = Point[0].CoordX
625
        mov esi,[ebx+Figure.PoiData]
626
        lea esi,[esi+Point.CoordY]
627
        lea edi,[ebx+Figure.MinY]
628
        movsd
629
        movsd ;Figure.MinY = Point[0].CoordY
630
        sub esi,8
631
        lea edi,[ebx+Figure.SizeY]
632
        movsd
633
        movsd ;Figure.SizeY = Point[0].CoordY
634
635
 
636
        mov ecx,[ebx+Figure.PoiCount]
637
        jecxz .cycle2end
638
        mov edi,[ebx+Figure.PoiData]
639
align 4
640
        .cycle2:
641
                fld qword[edi+Point.CoordX]
642
                fcomp qword[ebx+Figure.MinX]
643
                fstsw ax
644
                sahf
645
                ja @f
646
                        push edi esi
647
                        lea esi,[edi+Point.CoordX]
648
                        lea edi,[ebx+Figure.MinX]
649
                        movsd
650
                        movsd
651
                        pop esi edi
652
                @@:
653
                add edi,sizeof.Point
654
        loop .cycle2
655
        .cycle2end:
656
657
 
658
        mov ecx,[ebx+Figure.PoiCount]
659
        jecxz .cycle3end
660
        mov edi,[ebx+Figure.PoiData]
661
align 4
662
        .cycle3:
663
                fld qword[edi+Point.CoordY]
664
                fcomp qword[ebx+Figure.MinY]
665
                fstsw ax
666
                sahf
667
                ja @f
668
                        push edi esi
669
                        lea esi,[edi+Point.CoordY]
670
                        lea edi,[ebx+Figure.MinY]
671
                        movsd
672
                        movsd
673
                        pop esi edi
674
                @@:
675
                add edi,sizeof.Point
676
        loop .cycle3
677
        .cycle3end:
678
679
 
680
        mov ecx,[ebx+Figure.PoiCount]
681
        jecxz .cycle4end
682
        mov edi,[ebx+Figure.PoiData]
683
align 4
684
        .cycle4:
685
                fld qword[edi+Point.CoordX]
686
                fcomp qword[ebx+Figure.SizeX]
687
                fstsw ax
688
                sahf
689
                jbe @f
690
                        push edi esi
691
                        lea esi,[edi+Point.CoordX]
692
                        lea edi,[ebx+Figure.SizeX]
693
                        movsd
694
                        movsd
695
                        pop esi edi
696
                @@:
697
                add edi,sizeof.Point
698
        loop .cycle4
699
        .cycle4end:
700
701
 
702
        mov ecx,[ebx+Figure.PoiCount]
703
        jecxz .cycle5end
704
        mov edi,[ebx+Figure.PoiData]
705
align 4
706
        .cycle5:
707
                fld qword[edi+Point.CoordY]
708
                fcomp qword[ebx+Figure.SizeY]
709
                fstsw ax
710
                sahf
711
                jbe @f
712
                        push edi esi
713
                        lea esi,[edi+Point.CoordY]
714
                        lea edi,[ebx+Figure.SizeY]
715
                        movsd
716
                        movsd
717
                        pop esi edi
718
                @@:
719
                add edi,sizeof.Point
720
        loop .cycle5
721
        .cycle5end:
722
723
 
724
        fld qword[ebx+Figure.SizeX]
725
        fsub qword[ebx+Figure.MinX]
726
        fstp qword[ebx+Figure.SizeX]
727
        ;found size Y
728
        fld qword[ebx+Figure.SizeY]
729
        fsub qword[ebx+Figure.MinY]
730
        fstp qword[ebx+Figure.SizeY]
731
732
 
733
align 4
734
        .calc_scale:
735
        mov dword[ebx+Figure.MCentrX],0
736
        mov dword[ebx+Figure.MCentrY],0
737
        fld1
738
        fst qword[ebx+Figure.MScale] ;???
739
        fstp qword[ebx+Figure.WScale] ;set default scale
740
741
 
742
        ftst
743
        fstsw ax
744
        sahf
745
        jne .els_0 ;if (SizeX == 0.0)
746
                ffree st0
747
                fincstp
748
                jmp .els_1
749
        .els_0: ;else if (SizeX != 0.0)
750
                fild dword[buf_0.w]
751
                fisub dword[graf_margin_left]
752
                fisub dword[graf_margin_right]
753
                fxch st1
754
                fdivp
755
                fstp qword[ebx+Figure.WScale]
756
        .els_1:
757
758
 
759
        ftst
760
        fstsw ax
761
        sahf
762
        jne .els_2 ;if (SizeY == 0.0)
763
                ffree st0
764
                fincstp
765
                jmp .els_3
766
        .els_2: ;else if (SizeY != 0.0)
767
                fild dword[buf_0.h]
768
                fisub dword[graf_margin_top]
769
                fisub dword[graf_margin_bot]
770
                fxch st1
771
                fdivp
772
                fcom qword[ebx+Figure.WScale]
773
                fstsw ax
774
                sahf
775
                jbe @f
776
                        ffree st0
777
                        fincstp
778
                        jmp .els_3
779
                @@:
780
                fstp qword[ebx+Figure.WScale]
781
        .els_3:
782
783
 
784
        ret
785
endp
786
787
 
788
; esi - input description text
789
; ppoi - pointer to point struct
790
;output:
791
; eax - 0 (if error init) or 1
792
; esi - output description text
793
align 4
794
proc PointInit uses ebx ecx edi, ppoi:dword
795
        mov     ecx,64 ;защита от зацикливания
796
        @@:
797
                lodsb
798
                cmp     al,' '
799
                jne     @f
800
                loop @b
801
        @@:
802
        dec esi
803
        cmp byte[esi],'X'
804
        jne .err_init
805
                inc esi
806
                stdcall conv_str_to_int, esi
807
                mov ebx,[ppoi]
808
809
 
810
                push esi
811
                        mov ecx,32
812
                        mov edi,esi
813
                        @@:
814
                                lodsb
815
                                or al,al
816
                                jz @f
817
                                cmp al,' '
818
                                je @f
819
                                cmp al,13
820
                                je @f
821
                                loop @b
822
                        @@:
823
                        mov esi,edi
824
                        sub ecx,32
825
                        neg ecx
826
                        mov edi,Data_String
827
                        rep movsb
828
                        mov byte[edi],0
829
                pop esi
830
                stdcall String_to_DoubleFloat
831
                ;Data_Double -> Point.CoordX
832
                push esi
833
                        mov esi,Data_Double
834
                        lea edi,[ebx+Point.CoordX]
835
                        movsd
836
                        movsd
837
                pop esi
838
839
 
840
                mov al,'Y'
841
                mov ecx,80
842
                mov edi,esi
843
                repne scasb
844
                mov esi,edi
845
                pop edi
846
                ;Data_String <- esi
847
                push esi
848
                        mov ecx,32
849
                        mov edi,esi
850
                        @@:
851
                                lodsb
852
                                or al,al
853
                                jz @f
854
                                cmp al,' '
855
                                je @f
856
                                cmp al,13
857
                                je @f
858
                                loop @b
859
                        @@:
860
                        mov esi,edi
861
                        sub ecx,32
862
                        neg ecx
863
                        mov edi,Data_String
864
                        rep movsb
865
                        mov byte[edi],0
866
                pop esi
867
                stdcall String_to_DoubleFloat
868
                ;Data_Double -> Point.CoordY
869
                push esi
870
                        mov esi,Data_Double
871
                        lea edi,[ebx+Point.CoordY]
872
                        movsd
873
                        movsd
874
                pop esi
875
876
 
877
                jmp @f
878
        .err_init:
879
                xor eax,eax
880
                jmp .end_f
881
        @@:
882
                xor eax,eax
883
                inc eax
884
        .end_f:
885
        ret
886
endp
887
888
 
889
; buffer - добавляемые данные
890
; pfig - указатель на добавленную фигуру (для контроля со стороны родительского объекта)
891
;output:
892
; eax - object data pointer
893
align 4
894
proc add_object_in_list uses ebx ecx edi esi, buffer:dword, pfig:dword
895
        mov ebx,[pfig]
896
        or ebx,ebx
897
        jz @f
898
                stdcall mem.Alloc,sizeof.Figure
899
                mov [ebx],eax
900
                mov ecx,sizeof.Figure
901
                mov edi,eax
902
                mov esi,[buffer]
903
                rep movsb
904
        @@:
905
        ret
906
endp
907
908
 
909
; функция для рисования выбранного объекта
910
align 4
911
proc draw_obj2d, pobj:dword
912
locals
913
        data_draw dd ?
7441 IgorA 914
        CentrX dd ?
7427 theonlymir 915
        CentrY dd ?
916
endl
917
pushad
918
        mov ebx,[pobj]
919
        stdcall [buf2d_clear], buf_0, [buf_0.color]
920
        mov ecx,[ebx+Object.FigCount]
921
        or ecx,ecx
922
        jz .end_f
923
        ;;jecxz .end_f
924
                mov edi,[ebx+Object.FigData]
925
                finit
926
                fld qword[ebx+Object.SizeY]
927
                fmul qword[ebx+Object.WScale]
928
                fmul qword[ebx+Object.MScale]
929
                fchs
930
                fistp dword[CentrY]
931
                mov eax,[CentrY]
932
                sub eax,[graf_margin_top]
933
                sub eax,[graf_margin_bot]
934
                add eax,[buf_0.h]
935
                sar eax,1
936
                add eax,[graf_margin_bot] ;_bot а не _top - в связи с тем что коорд. Y перевернута
937
                add eax,[ebx+Object.MCentrY]
938
                mov [CentrY],eax
939
                fld qword[ebx+Object.SizeX]
940
                fmul qword[ebx+Object.WScale]
941
                fmul qword[ebx+Object.MScale]
942
                fchs
943
                fistp dword[CentrX]
944
                mov edx,[CentrX]
945
                sub edx,[graf_margin_left]
946
                sub edx,[graf_margin_right]
947
                add edx,[buf_0.w]
948
                sar edx,1
949
                add edx,[graf_margin_left]
950
                add edx,[ebx+Object.MCentrX]
951
                mov [CentrX],edx
952
                mov dword[data_draw],0
7441 IgorA 953
align 4
7427 theonlymir 954
                .cycle0:
955
                        stdcall draw_fig2d_litl, buf_0,ebx,[edi],[data_draw],0,edx,eax
7441 IgorA 956
                        mov esi,[edi]
957
                        mov esi,[esi+Figure.PoiCount]
958
                        or esi,esi
959
                        jnz @f
960
                        inc esi
961
                        @@:
962
                        add [data_draw],esi
963
                        add edi,4
7427 theonlymir 964
                        loop .cycle0
965
                stdcall [buf2d_flip_v], buf_0
966
967
 
968
        jnc .end_f
969
                ; draw min & sizes
970
                mov word[NumberSymbolsAD],8
971
                stdcall mem_copy, txt_buf,txt_size_x,20
972
                fld qword[ebx+Object.SizeX]
973
                fstp qword[Data_Double]
974
                call DoubleFloat_to_String
975
                call String_crop_0
976
                stdcall str_cat,txt_buf,Data_String
977
                stdcall str_cat,txt_buf,txt_n
978
                stdcall str_cat,txt_buf,txt_size_y
979
                fld qword[ebx+Object.SizeY]
980
                fstp qword[Data_Double]
981
                call DoubleFloat_to_String
982
                call String_crop_0
983
                stdcall str_cat,txt_buf,Data_String
984
                stdcall [buf2d_draw_text], buf_0, buf_1,txt_buf,3,23,0
985
986
 
987
                fstp qword[Data_Double]
988
                stdcall mem_copy, txt_buf,txt_min_x,20
989
                call DoubleFloat_to_String
990
                call String_crop_0
991
                stdcall str_cat,txt_buf,Data_String
992
                stdcall str_cat,txt_buf,txt_n
993
                stdcall str_cat,txt_buf,txt_min_y
994
                fld qword[ebx+Object.MinY]
995
                fstp qword[Data_Double]
996
                call DoubleFloat_to_String
997
                call String_crop_0
998
                stdcall str_cat,txt_buf,Data_String
999
                stdcall [buf2d_draw_text], buf_0, buf_1,txt_buf,3,3,0
1000
        .end_f:
1001
popad
1002
        ret
1003
endp
1004
1005
 
1006
; pbuf - pointer to buffer 2d
1007
; pobj - указатель на объект
7441 IgorA 1008
; pfig - указатель на фигуру
1009
; fign - номер фигуры
1010
;description:
7427 theonlymir 1011
; функция для рисования объекта по частям
1012
align 4
1013
proc draw_fig2d_litl, pbuf:dword, pobj:dword, pfig:dword, fign:dword,\
7441 IgorA 1014
	Scale:dword, CentrX:dword, CentrY:dword
1015
locals
7427 theonlymir 1016
        line_col dd ? ;figure color
7441 IgorA 1017
		PervX dd 0 ;pervios point coord X
1018
        PervY dd 0 ;pervios point coord Y
7427 theonlymir 1019
        GrafX dd ? ;active point coord X
1020
        GrafY dd ? ;active point coord Y
1021
endl
1022
pushad
1023
        mov ebx,[pfig]
1024
        test ebx,ebx
1025
        jz .end_f
1026
        mov ecx,[ebx+Figure.PoiCount]
1027
        ;;jecxz .end_f
1028
        test ecx,ecx
1029
        jz .end_f
1030
        mov edi,[ebx+Figure.PoiData]
1031
        mov edx,[pobj]
1032
1033
 
1034
        mov eax,[Scale]
1035
        or eax,eax
1036
        jnz @f
1037
                lea eax,[edx+Object.MScale]
1038
                fmul qword[eax]
1039
                lea eax,[edx+Object.WScale]
1040
        @@:
1041
        fmul qword[eax]
1042
        mov esi,[fign]
7441 IgorA 1043
align 4
7427 theonlymir 1044
        .cycle0:
1045
                fld qword[edi+Point.CoordX]
1046
                fsub qword[edx+Object.MinX]
1047
                fmul st0,st1
1048
                fiadd dword[CentrX]
1049
                fistp dword[ebp-8]
1050
                fld qword[edi+Point.CoordY]
1051
                fsub qword[edx+Object.MinY]
1052
                fmul st0,st1
1053
                fiadd dword[CentrY]
1054
                fistp dword[ebp-4]
1055
                stdcall [buf2d_set_pixel], [pbuf], [GrafX],[GrafY], 0xff0000
1056
                cmp ecx,[ebx+Figure.PoiCount]
1057
                je .end0
7441 IgorA 1058
                        ;определение цвета
1059
                        cmp esi,[data_printed]
1060
                        jl @f
1061
                        mov [line_col],0x80 ;if not printed
1062
                        jmp .end1
1063
                        @@:
1064
                        mov [line_col],0xff0000 ;if was printed
1065
                        .end1:
1066
                        stdcall [buf2d_line_sm], [pbuf], [PervX],[PervY], [GrafX],[GrafY], [line_col]
1067
                        stdcall [buf2d_line], [pbuf], [PervX],[PervY], [GrafX],[GrafY], [line_col]
1068
                .end0:
1069
                mov eax,[GrafX]
7427 theonlymir 1070
                mov [PervX],eax
1071
                mov eax,[GrafY]
1072
                mov [PervY],eax
1073
                add edi,sizeof.Point
1074
                inc esi
7441 IgorA 1075
        ;;loop .cycle0
7427 theonlymir 1076
                dec ecx
1077
        jnz .cycle0
1078
        ffree st0
1079
        fincstp
1080
1081
 
1082
popad
1083
        ret
1084
endp
1085
1086
 
1087
; функция для рисования выбранной фигуры
1088
align 4
1089
proc draw_fig2d, pfig:dword
1090
locals
1091
        n dd 0
1092
        col_lin dd 0 ;цвет линий фигуры
1093
        CentrX dd ?
1094
        CentrY dd ?
1095
        PervX dd 0 ;pervios point coord X
1096
        PervY dd 0 ;pervios point coord Y
1097
        GrafX dd ? ;active point coord X
1098
        GrafY dd ? ;active point coord Y
1099
        old_tl dd 0 ;old text coord X0
1100
        old_tt dd 0 ;old text coord Y0
1101
        old_tw dd 0 ;old text coord X1
1102
        old_th dd 0 ;old text coord Y1
1103
        new_tl dd 0 ;new text coord X0
1104
        ;new_tt dd 0 ;new text coord Y0
1105
        new_tw dd 0 ;new text coord X1
1106
        ;new_th dd 0 ;new text coord Y1
1107
endl
1108
pushad
1109
        stdcall [buf2d_clear], buf_0, [buf_0.color]
1110
        mov ebx,[pfig]
1111
        test ebx,ebx
1112
        jz .end_f
1113
        mov ecx,[ebx+Figure.PoiCount]
1114
        ;;jecxz .end_f
1115
        test ecx,ecx
1116
        jz .end_f
1117
        mov edi,[ebx+Figure.PoiData]
1118
        finit
1119
        fld qword[ebx+Figure.SizeY]
1120
        fmul qword[ebx+Figure.WScale]
1121
        fmul qword[ebx+Figure.MScale]
1122
        fchs
1123
        fistp dword[CentrY]
1124
        mov eax,[CentrY]
1125
        sub eax,[graf_margin_top]
1126
        sub eax,[graf_margin_bot]
1127
        add eax,[buf_0.h]
1128
        sar eax,1
1129
        add eax,[graf_margin_bot]
1130
        add eax,[ebx+Figure.MCentrY]
1131
        mov [CentrY],eax
1132
        ;CentrY = (-(Figure.SizeY * Figure.WScale) - graf_margin_top - graf_margin_bot + buf_0.h) / 2 + graf_margin_bot
1133
        fld qword[ebx+Figure.SizeX]
1134
        fmul qword[ebx+Figure.WScale]
1135
        fmul qword[ebx+Figure.MScale]
1136
        fchs
1137
        fistp dword[CentrX]
1138
        mov eax,[CentrX]
1139
        sub eax,[graf_margin_left]
1140
        sub eax,[graf_margin_right]
1141
        add eax,[buf_0.w]
1142
        sar eax,1
1143
        add eax,[graf_margin_left]
1144
        add eax,[ebx+Figure.MCentrX]
1145
        mov [CentrX],eax
1146
        ;CentrX = (-(Figure.SizeX * Figure.WScale) - graf_margin_left - graf_margin_right + buf_0.w) / 2 + graf_margin_left
1147
1148
 
1149
        .cycle0:
1150
                fld qword[edi+Point.CoordX]
1151
                fsub qword[ebx+Figure.MinX]
1152
                fmul qword[ebx+Figure.WScale]
1153
                fmul qword[ebx+Figure.MScale]
1154
                fiadd dword[CentrX]
1155
                fistp dword[GrafX]
1156
                ;GrafX = (Point.CoordX - Figure.MinX) * Figure.WScale + CentrX
1157
                fld qword[edi+Point.CoordY]
1158
                fsub qword[ebx+Figure.MinY]
1159
                fmul qword[ebx+Figure.WScale]
1160
                fmul qword[ebx+Figure.MScale]
1161
                fiadd dword[CentrY]
1162
                fisub dword[buf_0.h] ;invert coord Y
1163
                fchs
1164
                fistp dword[GrafY]
1165
                ;GrafY = -((Point.CoordY - Figure.MinY) * Figure.WScale + CentrY - buf_0.h)
1166
1167
 
1168
                mov dword[col_lin],0x80
1169
                cmp ecx,[ebx+Figure.PoiCount]
1170
                je @f
1171
                        stdcall [buf2d_line_sm], buf_0, [PervX],[PervY], [GrafX],[GrafY], [col_lin]
1172
                        stdcall [buf2d_line], buf_0, [PervX],[PervY], [GrafX],[GrafY], [col_lin]
1173
                @@:
1174
                mov eax,[GrafX]
1175
                mov [PervX],eax
1176
                mov edx,[GrafY]
1177
                mov [PervY],edx
1178
                add edi,sizeof.Point
1179
1180
 
1181
                jnc .end0
1182
                ; draw number points
1183
                ;mov eax,[GrafX]
1184
                ;mov edx,[GrafY]
1185
                add eax,2
1186
                add edx,2
1187
                push eax edi
1188
                        mov eax,[n]
1189
                        mov edi,txt_buf
1190
                        stdcall convert_int_to_str,20
1191
                pop edi eax
1192
1193
 
1194
                ;calculate new text coords
1195
                mov [new_tl],eax
1196
                mov esi,eax
1197
                stdcall str_len,txt_buf
1198
                imul eax,[buf_1.w]
1199
                add eax,esi
1200
                mov [new_tw],eax
1201
                ;rect compare coords
1202
                cmp [old_tl],eax
1203
                jg .no_comp
1204
                cmp [old_tw],esi
1205
                jl .no_comp
1206
                        ;calculate new text coord Y1
1207
                        mov esi,edx
1208
                        add esi,[font_h]
1209
                cmp [old_tt],esi
1210
                jg .no_comp
1211
                cmp [old_th],edx
1212
                ;jl .no_comp
1213
                        ;jmp .end0
1214
                jge .end0
1215
                .no_comp:
1216
                        mov eax,[new_tl]
1217
                        mov [old_tl],eax
1218
                        mov eax,[new_tw]
1219
                        mov [old_tw],eax
1220
                        mov [old_tt],edx
1221
                        add edx,[font_h]
1222
                        mov [old_th],edx
1223
                        stdcall [buf2d_draw_text], buf_0, buf_1,txt_buf,[old_tl],[old_tt],0x000000
1224
                .end0:
1225
                dec ecx
1226
        jnz .cycle0
1227
1228
 
1229
        jnc .end_f
1230
                ; draw min & sizes
1231
                mov word[NumberSymbolsAD],8
1232
                stdcall mem_copy, txt_buf,txt_size_x,20
1233
                fld qword[ebx+Figure.SizeX]
1234
                fstp qword[Data_Double]
1235
                call DoubleFloat_to_String
1236
                call String_crop_0
1237
                stdcall str_cat,txt_buf,Data_String
1238
                stdcall str_cat,txt_buf,txt_n
1239
                stdcall str_cat,txt_buf,txt_size_y
1240
                fld qword[ebx+Figure.SizeY]
1241
                fstp qword[Data_Double]
1242
                call DoubleFloat_to_String
1243
                call String_crop_0
1244
                stdcall str_cat,txt_buf,Data_String
1245
                stdcall [buf2d_draw_text], buf_0, buf_1,txt_buf,3,23,0
1246
1247
 
1248
                fstp qword[Data_Double]
1249
                stdcall mem_copy, txt_buf,txt_min_x,20
1250
                call DoubleFloat_to_String
1251
                call String_crop_0
1252
                stdcall str_cat,txt_buf,Data_String
1253
                stdcall str_cat,txt_buf,txt_n
1254
                stdcall str_cat,txt_buf,txt_min_y
1255
                fld qword[ebx+Figure.MinY]
1256
                fstp qword[Data_Double]
1257
                call DoubleFloat_to_String
1258
                call String_crop_0
1259
                stdcall str_cat,txt_buf,Data_String
1260
                stdcall [buf2d_draw_text], buf_0, buf_1,txt_buf,3,3,0
1261
        .end_f:
1262
popad
1263
        ret
1264
endp
1265
1266
 
1267
proc mouse_left_d uses eax ebx
1268
        call buf_get_mouse_coord
1269
        cmp eax,-1
1270
        je .end_f
1271
                mov [mouse_down_x],eax
1272
                mov [mouse_down_y],ebx
1273
        .end_f:
1274
        ret
1275
endp
1276
1277
 
1278
proc mouse_left_u uses eax ebx ecx
1279
        call buf_get_mouse_coord
1280
        cmp eax,-1
1281
        je .end_f
1282
                sub eax,[mouse_down_x]
1283
                sub ebx,[mouse_down_y]
1284
                mov ecx,ObjData
1285
                add [ecx+Figure.MCentrX],eax
1286
                sub [ecx+Figure.MCentrY],ebx
1287
                mov dword[offs_last_timer],0
1288
        .end_f:
1289
        ret
1290
endp
1291