Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
7360 IgorA 1
 
2
3
 
4
;	mov [Object.FigData], (tl_node_add(врем. стр.),tl_node_get_data)
5
6
 
7
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_err_no_point_sel db 'Не выбраны точки.',0
63
txt_err_no_point_sel_1 db 'Выберите одну точку.',0
64
txt_but_cancel db 'Отмена',0
65
txt_but_apply db 'Применить',0
66
txt_but_create db 'Создать',0
67
txt_size_x db 'размер x: ',0
68
txt_size_y db 'размер y: ',0
69
txt_poi_sel: db 'Выбрано точек: '
70
.end db 0
71
txt_err_save_txt_file_0:
72
	db 'Не могу сохранить *.nc файл.',0
73
txt_err_save_txt_file_1:
74
	db 'Не удалось сохранить весь *.nc файл.',0
75
txt_err_save_img_file:
76
	db 'Не могу сохранить *.png файл.',0
77
txt_obj: db 'Объект: ',39
78
.end db 0
79
else
80
;
81
; eng
82
;
83
txt_err_no_point_sel db 'No select points.',0
84
txt_err_no_point_sel_1 db 'Select one point.',0
85
txt_but_cancel db 'Cancel',0
86
txt_but_apply db 'Apply',0
87
txt_but_create db 'Create',0
88
txt_size_x db 'size x: ',0
89
txt_size_y db 'size y: ',0
90
txt_poi_sel: db 'Select points: '
91
.end db 0
92
txt_err_save_txt_file_0:
93
txt_err_save_txt_file_1:
94
	db 'Can',39,'t save *.nc file.',0
95
txt_err_save_img_file:
96
	db 'Can',39,'t save *.png file.',0
97
txt_obj: db 'Object: ',39
98
.end db 0
99
end if
100
101
 
102
txt_s_39 db 39,' ',0
103
txt_s_poi db 'X',0
104
txt_s_poi_Y db ' Y',0
105
txt_s_poi_Z db ' Z',0
106
txt_coma db ','
107
txt_space db ' ',0 ;не отрывать от запятой
108
txt_nl db 13,10,0
109
txt_n db 13,0
110
txt_ls db ' (',0
111
txt_rs db ')',0
112
txt_len db ' len=',0
113
txt_39 db 39,0
114
115
 
116
PROP_BIT_SELECT    equ 30 ;точка под выделением
117
118
 
119
zoom_plus dq 1.25992105
120
opt_koef dq 0.02 ;коеф. для оптимизации (чем ближе к 0, тем прямее линия)
7663 IgorA 121
mouse_prop_x dd 0 ;курсор мыши относительно центра окна buf_0 (для измен. масштаба)
7360 IgorA 122
mouse_prop_y dd 0
123
mouse_down_x dd 0 ;курсор мыши относительно левого верхнего угла окна buf_0 (для сдвига фигуры)
124
mouse_down_y dd 0
125
opt_draw  dd 1
126
graf_margin_left   dd 3 ;margin in pixels
127
graf_margin_right  dd 3+6 ;margin in pixels
128
graf_margin_top    dd 3+9 ;margin in pixels
129
graf_margin_bot    dd 3+9 ;margin in pixels
130
png_data dd ?
131
png_size dd ?
132
133
 
134
ObjData Object
135
FigData Figure ;временная структура для заполнения tree1
136
PoiData Point
137
138
 
139
140
 
141
   ... need fix size_one_list
142
end if
143
144
 
145
   ... need fix offsets
146
end if
147
148
 
149
Scale1mm dq 11.81102362204724 ;pixels in 1 mm -> 300 dpi
150
	;5.905511811023622 ;pixels in 1 mm -> 150 dpi
151
152
 
153
txt_sp db ' ',0
154
155
 
156
; esi - text pointer
157
align 4
158
proc txt_next_line uses eax ecx edi, mlen:dword
159
	mov al,13
160
	mov ecx,[mlen]
161
	mov edi,esi
162
	repne scasb
163
	cmp byte[edi],10
164
	jne @f
165
		inc edi
166
	@@:
167
	mov esi,edi
168
	ret
169
endp
170
171
 
172
; edi - destination buffer
173
; esi - source text string: '...\nl
174
; mlen - maximum len destination buffer
175
align 4
176
proc txt_load_line uses eax ebx ecx esi, mlen:dword
177
	mov byte[edi],0
178
	mov al,13
179
	cmp byte[esi],al
180
	je .end_f
181
		mov ecx,[mlen]
182
		mov ebx,edi
183
		mov edi,esi
184
		repne scasb ;found end of string
185
		mov ecx,edi
186
		sub ecx,esi
187
		dec ecx ;ecx = string len
188
		mov edi,ebx
189
		rep movsb ;copy caption string
190
		cmp byte[esi],13
191
		je @f
192
		.cycle0:
193
			inc esi
194
			cmp byte[esi],13
195
			jne .cycle0
196
		@@:
197
		mov byte[edi],0
198
		inc esi
199
	.end_f:
200
	ret
201
endp
202
203
 
204
; itxt - input description text
205
; msize - max size
206
align 4
207
proc FileInit uses eax ebx ecx edi esi, itxt:dword, msize:dword
208
	stdcall [tl_node_poi_get_info], tree1,0
209
	or eax,eax
210
	jz @f
211
		mov ebx,eax
212
		stdcall [tl_node_poi_get_data], tree1,ebx
213
		stdcall clear_object_in_list, eax
214
	@@:
215
	stdcall [tl_info_clear], tree1 ;очистка списка объектов
216
	mov dword[offs_last_timer],0
217
218
 
219
	mov ebx,esi
220
	add ebx,[msize]
221
	stdcall ObjectInit,ObjData,ebx
222
	stdcall [tl_cur_beg], tree1
223
	ret
224
endp
225
226
 
227
; esi - input description text
228
; pobj - pointer to object struct
229
; etxt - pointer to end of input text
230
align 4
231
proc ObjectInit uses eax ebx ecx edi, pobj:dword, etxt:dword
232
		mov ebx,[pobj]
233
		mov [ebx+Object.OType],'Obj'
234
		mov edi,ebx
235
		add edi,Object.Caption
236
		mov dword[edi],'CNC'
237
238
 
239
		test eax,eax
240
		jz .err_init
241
		mov [ebx+Object.FigCount],eax
242
		mov ecx,eax
243
244
 
245
		stdcall mem.Alloc,eax
246
		mov [ebx+Object.FigData],eax
247
		push ecx
248
			mov edi,eax
249
			xor eax,eax
250
			rep stosd ;clear memory
251
		pop ecx
252
253
 
254
		;eax -> pointer to object node
255
		mov edi,[ebx+Object.FigData]
256
align 4
257
		.cycle0:
258
			stdcall FigureInit,FigData,edi
259
			cmp esi,[etxt]
260
			jge .cycle0end
261
			add edi,4
262
		loop .cycle0
263
		.cycle0end:
264
		inc dword[ebx+Object.FigCount] ;???
265
		or ecx,ecx
266
		jz @f
267
			;уменьшаем объем памяти выделенный для команд
268
			sub [ebx+Object.FigCount],ecx
269
			mov eax,[ebx+Object.FigCount]
270
			shl eax,2
271
			stdcall mem.ReAlloc,[ebx+Object.FigData],eax
272
			mov [ebx+Object.FigData],eax
273
		@@:
274
275
 
276
277
 
278
	.err_init:
279
		notify_window_run txt_err_1
280
	.end_f:
281
	ret
282
endp
283
284
 
285
proc ObjCalculateScale uses eax ebx ecx edi, pobj:dword
286
	mov ebx,[pobj]
287
288
 
289
	finit
290
291
 
292
	mov ecx,[ebx+Object.FigCount]
293
	jecxz .cycle2end
294
	mov edi,[ebx+Object.FigData]
295
	@@:
7415 IgorA 296
		mov eax,[edi]
297
		dec ecx
298
		jecxz .cycle2end
299
		add edi,4
300
		or eax,eax
301
		jz @b
302
		cmp [eax+Figure.PoiCount],0
303
		je @b
304
	push edi esi ;copy first min X
7360 IgorA 305
		lea esi,[eax+Figure.MinX]
306
		lea edi,[ebx+Object.MinX]
307
		movsd
308
		movsd
309
	pop esi edi
310
align 4
311
	.cycle2:
312
		mov eax,[edi]
313
		or eax,eax
314
		jz @f
315
		cmp [eax+Figure.PoiCount],0
316
		je @f
317
		fld qword[eax+Figure.MinX]
318
		fcomp qword[ebx+Object.MinX]
319
		fstsw ax
320
		sahf
321
		jae @f
7415 IgorA 322
			push edi esi
7360 IgorA 323
			mov eax,[edi]
324
			lea esi,[eax+Figure.MinX]
325
			lea edi,[ebx+Object.MinX]
326
			movsd
327
			movsd
328
			pop esi edi
329
		@@:
330
		add edi,4
331
	loop .cycle2
332
	.cycle2end:
333
334
 
335
	mov ecx,[ebx+Object.FigCount]
336
	jecxz .cycle3end
337
	mov edi,[ebx+Object.FigData]
338
	@@:
7415 IgorA 339
		mov eax,[edi]
340
		dec ecx
341
		jecxz .cycle3end
342
		add edi,4
343
		or eax,eax
344
		jz @b
345
		cmp [eax+Figure.PoiCount],0
346
		je @b
347
	push edi esi ;copy first min Y
7360 IgorA 348
		lea esi,[eax+Figure.MinY]
349
		lea edi,[ebx+Object.MinY]
350
		movsd
351
		movsd
352
	pop esi edi
353
align 4
354
	.cycle3:
355
		mov eax,[edi]
356
		or eax,eax
357
		jz @f
358
		cmp [eax+Figure.PoiCount],0
359
		je @f
360
		fld qword[eax+Figure.MinY]
361
		fcomp qword[ebx+Object.MinY]
362
		fstsw ax
363
		sahf
364
		jae @f
7415 IgorA 365
			push edi esi
7360 IgorA 366
			mov eax,[edi]
367
			lea esi,[eax+Figure.MinY]
368
			lea edi,[ebx+Object.MinY]
369
			movsd
370
			movsd
371
			pop esi edi
372
		@@:
373
		add edi,4
374
	loop .cycle3
375
	.cycle3end:
376
377
 
378
	mov ecx,[ebx+Object.FigCount]
379
	jecxz .cycle4end
380
	mov edi,[ebx+Object.FigData]
381
	;copy first min X
382
	mov eax,[edi]
383
	fld qword[eax+Figure.MinX]
384
	fadd qword[eax+Figure.SizeX]
385
	fstp qword[ebx+Object.SizeX]
386
	dec ecx
387
	jecxz .cycle4end
388
align 4
389
	.cycle4:
390
		add edi,4
391
		mov eax,[edi]
392
		or eax,eax
393
		jz @f
394
		cmp [eax+Figure.PoiCount],0
395
		je @f
396
		fld qword[eax+Figure.MinX]
397
		fadd qword[eax+Figure.SizeX]
398
		fcomp qword[ebx+Object.SizeX]
399
		fstsw ax
400
		sahf
401
		jbe @f
402
			mov eax,[edi]
403
			fld qword[eax+Figure.MinX]
404
			fadd qword[eax+Figure.SizeX]
405
			fstp qword[ebx+Object.SizeX]
406
		@@:
407
	loop .cycle4
408
	.cycle4end:
409
410
 
411
	mov ecx,[ebx+Object.FigCount]
412
	jecxz .cycle5end
413
	mov edi,[ebx+Object.FigData]
414
	;copy first min Y
415
	mov eax,[edi]
416
	fld qword[eax+Figure.MinY]
417
	fadd qword[eax+Figure.SizeY]
418
	fstp qword[ebx+Object.SizeY]
419
	dec ecx
420
	jecxz .cycle5end
421
align 4
422
	.cycle5:
423
		add edi,4
424
		mov eax,[edi]
425
		or eax,eax
426
		jz @f
427
		cmp [eax+Figure.PoiCount],0
428
		je @f
429
		fld qword[eax+Figure.MinY]
430
		fadd qword[eax+Figure.SizeY]
431
		fcomp qword[ebx+Object.SizeY]
432
		fstsw ax
433
		sahf
434
		jbe @f
435
			mov eax,[edi]
436
			fld qword[eax+Figure.MinY]
437
			fadd qword[eax+Figure.SizeY]
438
			fstp qword[ebx+Object.SizeY]
439
		@@:
440
	loop .cycle5
441
	.cycle5end:
442
443
 
444
	fld qword[ebx+Object.SizeX]
445
	fsub qword[ebx+Object.MinX]
446
	fstp qword[ebx+Object.SizeX]
447
	;found size Y
448
	fld qword[ebx+Object.SizeY]
449
	fsub qword[ebx+Object.MinY]
450
	fstp qword[ebx+Object.SizeY]
451
452
 
453
		fld1
454
		fstp qword[ebx+Object.WScale] ;set default scale
455
456
 
457
		ftst
458
		fstsw ax
459
		sahf
460
		jne .els_0 ;if (SizeX == 0.0)
461
			ffree st0
462
			fincstp
463
			jmp .els_1
464
		.els_0: ;else if (SizeX != 0.0)
465
			fild dword[buf_0.w]
466
			fisub dword[graf_margin_left]
467
			fisub dword[graf_margin_right]
468
			fxch st1
469
			fdivp
470
			fstp qword[ebx+Object.WScale]
471
		.els_1:
472
473
 
474
		ftst
475
		fstsw ax
476
		sahf
477
		jne .els_2 ;if (SizeY == 0.0)
478
			ffree st0
479
			fincstp
480
			jmp .els_3
481
		.els_2: ;else if (SizeY != 0.0)
482
			fild dword[buf_0.h]
483
			fisub dword[graf_margin_top]
484
			fisub dword[graf_margin_bot]
485
			fxch st1
486
			fdivp
487
			fcom qword[ebx+Object.WScale]
488
			fstsw ax
489
			sahf
490
			jbe @f
491
				ffree st0
492
				fincstp
493
				jmp .els_3
494
			@@:
495
			fstp qword[ebx+Object.WScale]
496
		.els_3:
497
498
 
499
		fstp qword[ebx+Figure.MScale]
500
		mov dword[ebx+Figure.MCentrX],0
501
		mov dword[ebx+Figure.MCentrY],0
502
	ret
503
endp
504
505
 
506
; esi - input description text
507
; pmem - pointer to memory for struct
508
; pfig - pointer to figure struct
509
;output:
510
; esi - output description text
511
align 4
512
proc FigureInit uses eax ebx ecx edx edi, pmem:dword, pfig:dword
513
	mov ebx,[pmem]
514
	mov [ebx+Figure.OType],'Fig'
515
	mov edi,ebx
516
	add edi,Figure.Caption
517
	stdcall txt_load_line,32
518
519
 
520
	mov [ebx+Figure.PoiCount],eax
521
	mov [ebx+Figure.PoiData],eax
522
	cmp byte[esi],'X'
523
	jne .end0
524
		stdcall get_max_points
525
		mov [ebx+Figure.PoiCount],eax
526
		or eax,eax
527
		jz .end0
528
		mov ecx,eax
529
		imul eax,sizeof.Point
530
		stdcall mem.Alloc,eax
531
		mov [ebx+Figure.PoiData],eax
532
		or eax,eax
533
		jz .err_init
534
		mov edi,eax
535
align 4
536
		.cycle0:
537
			stdcall PointInit,edi
538
			or eax,eax
539
			jz .cycle0end
540
			add edi,sizeof.Point
541
			loop .cycle0
542
		.cycle0end:
543
		or ecx,ecx
544
		jz .end1
545
			;уменьшаем объем памяти выделенный для точек
546
			sub [ebx+Figure.PoiCount],ecx
547
			mov eax,[ebx+Figure.PoiCount]
548
			imul eax,sizeof.Point
549
			stdcall mem.ReAlloc,[ebx+Figure.PoiData],eax
550
			mov [ebx+Figure.PoiData],eax
551
		jmp .end1
552
	.err_init:
553
		notify_window_run txt_err_2
554
	.end0:
555
		;command
556
		stdcall txt_next_line, 80
557
		cmp byte[esi],13
558
		jne @f
559
			;if null line
560
			inc esi
561
			cmp byte[esi],10
562
			jne .end2
563
				inc esi
564
			.end2:
565
			mov dword[edi],(10 shl 8)+13 ;new line
566
		@@:
567
		stdcall add_object_in_list,1,1,ebx,[pfig]
568
		jmp .end_f
569
	.end1:
570
		;coords
571
		stdcall add_object_in_list,2,1,ebx,[pfig]
572
		or eax,eax
573
		jz .end_f
574
		stdcall FigCalculateSizes,eax,1
575
	.end_f:
576
	ret
577
endp
578
579
 
580
; esi - pointer to file
581
;output:
582
; eax - max lines in file
583
align 4
584
proc get_max_lines uses esi
585
	xor eax,eax
586
	.cycle0:
587
		cmp byte[esi],13
588
		jne @f
589
			inc eax
590
		@@:
591
		inc esi
592
		cmp byte[esi],0
593
		jne .cycle0
594
	ret
595
endp
596
597
 
598
; esi - pointer to file
599
;output:
600
; eax - max point coords in file
601
align 4
602
proc get_max_points uses esi
603
	xor eax,eax
604
	.cycle0:
605
		cmp word[esi],' Y'
606
		jne @f
607
			inc eax
608
		@@:
609
		inc esi
610
		cmp byte[esi+1],0
611
		jne .cycle0
612
	ret
613
endp
614
615
 
616
; opt_calc - если 0 - пересчитать масштаб фигуры,
617
;                 1 - пересчитать размеры и масштаб фигуры
618
align 4
619
proc FigCalculateSizes uses eax ebx ecx edi esi, pfig:dword, opt_calc:dword
620
	mov ebx,[pfig]
621
	or ebx,ebx
622
	jz .end_f
623
624
 
625
	bt dword[opt_calc],0
626
	jnc .calc_scale
627
628
 
629
	mov esi,[ebx+Figure.PoiData]
630
	or esi,esi
631
	jz .end_f
632
633
 
634
	lea edi,[ebx+Figure.MinX]
635
	movsd
636
	movsd ;Figure.MinX = Point[0].CoordX
637
	sub esi,8
638
	lea edi,[ebx+Figure.SizeX]
639
	movsd
640
	movsd ;Figure.SizeX = Point[0].CoordX
641
	mov esi,[ebx+Figure.PoiData]
642
	lea esi,[esi+Point.CoordY]
643
	lea edi,[ebx+Figure.MinY]
644
	movsd
645
	movsd ;Figure.MinY = Point[0].CoordY
646
	sub esi,8
647
	lea edi,[ebx+Figure.SizeY]
648
	movsd
649
	movsd ;Figure.SizeY = Point[0].CoordY
650
651
 
652
	mov ecx,[ebx+Figure.PoiCount]
653
	jecxz .cycle2end
654
	mov edi,[ebx+Figure.PoiData]
655
align 4
656
	.cycle2:
657
		fld qword[edi+Point.CoordX]
658
		fcomp qword[ebx+Figure.MinX]
659
		fstsw ax
660
		sahf
661
		ja @f
662
			push edi esi
663
			lea esi,[edi+Point.CoordX]
664
			lea edi,[ebx+Figure.MinX]
665
			movsd
666
			movsd
667
			pop esi edi
668
		@@:
669
		add edi,sizeof.Point
670
	loop .cycle2
671
	.cycle2end:
672
673
 
674
	mov ecx,[ebx+Figure.PoiCount]
675
	jecxz .cycle3end
676
	mov edi,[ebx+Figure.PoiData]
677
align 4
678
	.cycle3:
679
		fld qword[edi+Point.CoordY]
680
		fcomp qword[ebx+Figure.MinY]
681
		fstsw ax
682
		sahf
683
		ja @f
684
			push edi esi
685
			lea esi,[edi+Point.CoordY]
686
			lea edi,[ebx+Figure.MinY]
687
			movsd
688
			movsd
689
			pop esi edi
690
		@@:
691
		add edi,sizeof.Point
692
	loop .cycle3
693
	.cycle3end:
694
695
 
696
	mov ecx,[ebx+Figure.PoiCount]
697
	jecxz .cycle4end
698
	mov edi,[ebx+Figure.PoiData]
699
align 4
700
	.cycle4:
701
		fld qword[edi+Point.CoordX]
702
		fcomp qword[ebx+Figure.SizeX]
703
		fstsw ax
704
		sahf
705
		jbe @f
706
			push edi esi
707
			lea esi,[edi+Point.CoordX]
708
			lea edi,[ebx+Figure.SizeX]
709
			movsd
710
			movsd
711
			pop esi edi
712
		@@:
713
		add edi,sizeof.Point
714
	loop .cycle4
715
	.cycle4end:
716
717
 
718
	mov ecx,[ebx+Figure.PoiCount]
719
	jecxz .cycle5end
720
	mov edi,[ebx+Figure.PoiData]
721
align 4
722
	.cycle5:
723
		fld qword[edi+Point.CoordY]
724
		fcomp qword[ebx+Figure.SizeY]
725
		fstsw ax
726
		sahf
727
		jbe @f
728
			push edi esi
729
			lea esi,[edi+Point.CoordY]
730
			lea edi,[ebx+Figure.SizeY]
731
			movsd
732
			movsd
733
			pop esi edi
734
		@@:
735
		add edi,sizeof.Point
736
	loop .cycle5
737
	.cycle5end:
738
739
 
740
	fld qword[ebx+Figure.SizeX]
741
	fsub qword[ebx+Figure.MinX]
742
	fstp qword[ebx+Figure.SizeX]
743
	;found size Y
744
	fld qword[ebx+Figure.SizeY]
745
	fsub qword[ebx+Figure.MinY]
746
	fstp qword[ebx+Figure.SizeY]
747
748
 
749
align 4
750
	.calc_scale:
751
	mov dword[ebx+Figure.MCentrX],0
752
	mov dword[ebx+Figure.MCentrY],0
753
	fld1
754
	fst qword[ebx+Figure.MScale] ;???
755
	fstp qword[ebx+Figure.WScale] ;set default scale
756
757
 
758
	ftst
759
	fstsw ax
760
	sahf
761
	jne .els_0 ;if (SizeX == 0.0)
762
		ffree st0
763
		fincstp
764
		jmp .els_1
765
	.els_0: ;else if (SizeX != 0.0)
766
		fild dword[buf_0.w]
767
		fisub dword[graf_margin_left]
768
		fisub dword[graf_margin_right]
769
		fxch st1
770
		fdivp
771
		fstp qword[ebx+Figure.WScale]
772
	.els_1:
773
774
 
775
	ftst
776
	fstsw ax
777
	sahf
778
	jne .els_2 ;if (SizeY == 0.0)
779
		ffree st0
780
		fincstp
781
		jmp .els_3
782
	.els_2: ;else if (SizeY != 0.0)
783
		fild dword[buf_0.h]
784
		fisub dword[graf_margin_top]
785
		fisub dword[graf_margin_bot]
786
		fxch st1
787
		fdivp
788
		fcom qword[ebx+Figure.WScale]
789
		fstsw ax
790
		sahf
791
		jbe @f
792
			ffree st0
793
			fincstp
794
			jmp .els_3
795
		@@:
796
		fstp qword[ebx+Figure.WScale]
797
	.els_3:
798
799
 
800
	ret
801
endp
802
803
 
804
; esi - input description text
805
; ppoi - pointer to point struct
806
;output:
807
; eax - 0 (if error init) or 1
808
; esi - output description text
809
align 4
810
proc PointInit uses ebx ecx edi, ppoi:dword
811
	mov	ecx,64 ;защита от зацикливания
812
	@@:
813
		lodsb
814
		cmp	al,' '
815
		jne	@f
816
		loop @b
817
	@@:
818
	dec esi
819
	cmp byte[esi],'X'
820
	jne .err_init
821
		inc esi
822
		stdcall conv_str_to_int, esi
823
		mov ebx,[ppoi]
824
825
 
826
		push esi
827
			mov ecx,32
828
			mov edi,esi
829
			@@:
830
				lodsb
831
				or al,al
832
				jz @f
833
				cmp al,' '
834
				je @f
835
				cmp al,13
836
				je @f
837
				loop @b
838
			@@:
839
			mov esi,edi
840
			sub ecx,32
841
			neg ecx
842
			mov edi,Data_String
843
			rep movsb
844
			mov byte[edi],0
845
		pop esi
846
		stdcall String_to_DoubleFloat
847
		;Data_Double -> Point.CoordX
848
		push esi
849
			mov esi,Data_Double
850
			lea edi,[ebx+Point.CoordX]
851
			movsd
852
			movsd
853
		pop esi
854
855
 
856
		mov al,'Y'
857
		mov ecx,80
858
		mov edi,esi
859
		repne scasb
860
		mov esi,edi
861
		pop edi
862
		;Data_String <- esi
863
		push esi
864
			mov ecx,32
865
			mov edi,esi
866
			@@:
867
				lodsb
868
				or al,al
869
				jz @f
870
				cmp al,' '
871
				je @f
872
				cmp al,13
873
				je @f
874
				loop @b
875
			@@:
876
			mov esi,edi
877
			sub ecx,32
878
			neg ecx
879
			mov edi,Data_String
880
			rep movsb
881
			mov byte[edi],0
882
		pop esi
883
		stdcall String_to_DoubleFloat
884
		;Data_Double -> Point.CoordY
885
		push esi
886
			mov esi,Data_Double
887
			lea edi,[ebx+Point.CoordY]
888
			movsd
889
			movsd
890
		pop esi
891
892
 
893
		jmp @f
894
	.err_init:
895
		xor eax,eax
896
		jmp .end_f
897
	@@:
898
		xor eax,eax
899
		inc eax
900
	.end_f:
901
	ret
902
endp
903
904
 
905
; icon - номер иконки
906
; level - уровень вложенности узла
907
; buffer - добавляемые данные
908
; pfig - указатель на добавленную фигуру (для контроля со стороны родительского объекта)
909
;output:
910
; eax - object data pointer
911
align 4
912
proc add_object_in_list uses ebx, icon:dword,level:dword,buffer:dword, pfig:dword
913
	mov ax,word[icon]
914
	shl eax,16
915
	mov ax,word[level]
916
917
 
918
	stdcall [tl_node_get_data],tree1
919
	mov ebx,[pfig]
920
	or ebx,ebx
921
	jz @f
922
		mov [ebx],eax
923
	@@:
924
	stdcall [tl_cur_next], tree1
925
	ret
926
endp
927
928
 
929
proc clear_object_in_list uses eax, buffer:dword
930
	mov eax,[buffer]
931
	cmp dword[eax+Object.FigCount],0 ;or Figure.PoiCount
932
	je .end_f
933
		stdcall mem.Free,[eax+Object.FigData] ;or Figure.PoiData
934
	.end_f:
935
	ret
936
endp
937
938
 
939
; функция для рисования выбранного объекта
940
align 4
941
proc draw_obj2d, pobj:dword
942
locals
943
	CentrX dd ?
944
	CentrY dd ?
945
endl
946
pushad
947
	mov ebx,[pobj]
948
	stdcall [buf2d_clear], buf_0, [buf_0.color]
949
	mov ecx,[ebx+Object.FigCount]
950
	or ecx,ecx
951
	jz .end_f
952
	;;jecxz .end_f
953
		mov edi,[ebx+Object.FigData]
954
		finit
955
		fld qword[ebx+Object.SizeY]
956
		fmul qword[ebx+Object.WScale]
957
		fmul qword[ebx+Object.MScale]
958
		fchs
959
		fistp dword[CentrY]
960
		mov eax,[CentrY]
961
		sub eax,[graf_margin_top]
962
		sub eax,[graf_margin_bot]
963
		add eax,[buf_0.h]
964
		sar eax,1
965
		add eax,[graf_margin_bot] ;_bot а не _top - в связи с тем что коорд. Y перевернута
966
		add eax,[ebx+Object.MCentrY]
967
		mov [CentrY],eax
968
		fld qword[ebx+Object.SizeX]
969
		fmul qword[ebx+Object.WScale]
970
		fmul qword[ebx+Object.MScale]
971
		fchs
972
		fistp dword[CentrX]
973
		mov edx,[CentrX]
974
		sub edx,[graf_margin_left]
975
		sub edx,[graf_margin_right]
976
		add edx,[buf_0.w]
977
		sar edx,1
978
		add edx,[graf_margin_left]
979
		add edx,[ebx+Object.MCentrX]
980
		mov [CentrX],edx
981
align 4
982
		.cycle0:
983
			stdcall draw_fig2d_litl, buf_0,ebx,[edi],0,edx,eax
984
			add edi,4
985
			loop .cycle0
986
		stdcall [buf2d_flip_v], buf_0
987
988
 
989
	jnc .end_f
990
		; draw min & sizes
991
		mov word[NumberSymbolsAD],8
992
		stdcall mem_copy, txt_buf,txt_size_x,20
993
		fld qword[ebx+Object.SizeX]
994
		fstp qword[Data_Double]
995
		call DoubleFloat_to_String
996
		call String_crop_0
997
		stdcall str_cat,txt_buf,Data_String
998
		stdcall str_cat,txt_buf,txt_n
999
		stdcall str_cat,txt_buf,txt_size_y
1000
		fld qword[ebx+Object.SizeY]
1001
		fstp qword[Data_Double]
1002
		call DoubleFloat_to_String
1003
		call String_crop_0
1004
		stdcall str_cat,txt_buf,Data_String
1005
		stdcall [buf2d_draw_text], buf_0, buf_1,txt_buf,3,23,0
1006
1007
 
1008
		fstp qword[Data_Double]
1009
		stdcall mem_copy, txt_buf,txt_min_x,20
1010
		call DoubleFloat_to_String
1011
		call String_crop_0
1012
		stdcall str_cat,txt_buf,Data_String
1013
		stdcall str_cat,txt_buf,txt_n
1014
		stdcall str_cat,txt_buf,txt_min_y
1015
		fld qword[ebx+Object.MinY]
1016
		fstp qword[Data_Double]
1017
		call DoubleFloat_to_String
1018
		call String_crop_0
1019
		stdcall str_cat,txt_buf,Data_String
1020
		stdcall [buf2d_draw_text], buf_0, buf_1,txt_buf,3,3,0
1021
	.end_f:
1022
popad
1023
	ret
1024
endp
1025
1026
 
1027
proc draw_obj2d_png uses eax ebx ecx edi esi, pobj:dword
1028
	mov ebx,[pobj]
1029
	mov ecx,[ebx+Object.FigCount]
1030
	cmp dword[ebx+Object.FigCount],0
1031
	or ecx,ecx
1032
	jz .end_f
1033
	;;jecxz .end_f
1034
		mov edi,[ebx+Object.FigData]
1035
		stdcall [buf2d_delete], buf_png
1036
		finit
1037
		fld qword[ebx+Object.SizeY]
1038
		fmul qword[Scale1mm]
1039
		fiadd dword[graf_margin_top]
1040
		fiadd dword[graf_margin_bot]
1041
		fistp dword[buf_png.h]
1042
		fld qword[ebx+Object.SizeX]
1043
		fmul qword[Scale1mm]
1044
		fiadd dword[graf_margin_left]
1045
		fiadd dword[graf_margin_right]
1046
		fistp dword[buf_png.w]
1047
		stdcall [buf2d_create], buf_png
1048
align 4
1049
		.cycle0:
1050
			stdcall draw_fig2d_litl, buf_png,ebx,[edi],Scale1mm,[graf_margin_left],[graf_margin_bot] ;_bot а не _top - в связи с тем что коорд. Y перевернута
1051
			add edi,4
1052
			loop .cycle0
1053
		stdcall [buf2d_flip_v], buf_png
1054
	.end_f:
1055
	ret
1056
endp
1057
1058
 
1059
; pbuf - pointer to buffer 2d
1060
;description:
1061
; функция для рисования объекта по частям
1062
align 4
1063
proc draw_fig2d_litl, pbuf:dword, pobj:dword, pfig:dword, Scale:dword, CentrX:dword, CentrY:dword
1064
locals
1065
	PervX dd 0 ;pervios point coord X
1066
	PervY dd 0 ;pervios point coord Y
1067
	GrafX dd ? ;active point coord X
1068
	GrafY dd ? ;active point coord Y
1069
endl
1070
pushad
1071
	mov ebx,[pfig]
1072
	test ebx,ebx
1073
	jz .end_f
1074
	mov ecx,[ebx+Figure.PoiCount]
1075
	;;jecxz .end_f
1076
	test ecx,ecx
1077
	jz .end_f
1078
	mov edi,[ebx+Figure.PoiData]
1079
	mov edx,[pobj]
1080
1081
 
1082
	mov eax,[Scale]
1083
	or eax,eax
1084
	jnz @f
1085
		lea eax,[edx+Object.MScale]
1086
		fmul qword[eax]
1087
		lea eax,[edx+Object.WScale]
1088
	@@:
1089
	fmul qword[eax]
1090
align 4
1091
	.cycle0:
1092
		fld qword[edi+Point.CoordX]
1093
		fsub qword[edx+Object.MinX]
1094
		fmul st0,st1
1095
		fiadd dword[CentrX]
1096
		fistp dword[ebp-8]
1097
		fld qword[edi+Point.CoordY]
1098
		fsub qword[edx+Object.MinY]
1099
		fmul st0,st1
1100
		fiadd dword[CentrY]
1101
		fistp dword[ebp-4]
1102
		stdcall [buf2d_set_pixel], [pbuf], [GrafX],[GrafY], 0xff0000
1103
		cmp ecx,[ebx+Figure.PoiCount]
1104
		je @f
1105
			stdcall [buf2d_line_sm], [pbuf], [PervX],[PervY], [GrafX],[GrafY], 0x80
1106
			;sub esp,24
1107
			;call [buf2d_line]
1108
			stdcall [buf2d_line], [pbuf], [PervX],[PervY], [GrafX],[GrafY], 0x80
1109
		@@:
1110
		mov eax,[GrafX]
1111
		mov [PervX],eax
1112
		mov eax,[GrafY]
1113
		mov [PervY],eax
1114
		add edi,sizeof.Point
1115
	;;loop .cycle0
1116
		dec ecx
1117
	jnz .cycle0
1118
	ffree st0
1119
	fincstp
1120
1121
 
1122
popad
1123
	ret
1124
endp
1125
1126
 
1127
; функция для рисования выбранной фигуры
1128
align 4
1129
proc draw_fig2d, pfig:dword
1130
locals
1131
	n dd 0
1132
	col_lin dd 0 ;цвет линий фигуры
1133
	CentrX dd ?
1134
	CentrY dd ?
1135
	PervX dd 0 ;pervios point coord X
1136
	PervY dd 0 ;pervios point coord Y
1137
	GrafX dd ? ;active point coord X
1138
	GrafY dd ? ;active point coord Y
1139
	old_tl dd 0 ;old text coord X0
1140
	old_tt dd 0 ;old text coord Y0
1141
	old_tw dd 0 ;old text coord X1
1142
	old_th dd 0 ;old text coord Y1
1143
	new_tl dd 0 ;new text coord X0
1144
	;new_tt dd 0 ;new text coord Y0
1145
	new_tw dd 0 ;new text coord X1
1146
	;new_th dd 0 ;new text coord Y1
1147
endl
1148
pushad
1149
	stdcall [buf2d_clear], buf_0, [buf_0.color]
1150
	mov ebx,[pfig]
1151
	test ebx,ebx
1152
	jz .end_f
1153
	mov ecx,[ebx+Figure.PoiCount]
1154
	;;jecxz .end_f
1155
	test ecx,ecx
1156
	jz .end_f
1157
	mov edi,[ebx+Figure.PoiData]
1158
	finit
1159
	fld qword[ebx+Figure.SizeY]
1160
	fmul qword[ebx+Figure.WScale]
1161
	fmul qword[ebx+Figure.MScale]
1162
	fchs
1163
	fistp dword[CentrY]
1164
	mov eax,[CentrY]
1165
	sub eax,[graf_margin_top]
1166
	sub eax,[graf_margin_bot]
1167
	add eax,[buf_0.h]
1168
	sar eax,1
1169
	add eax,[graf_margin_bot]
1170
	add eax,[ebx+Figure.MCentrY]
1171
	mov [CentrY],eax
1172
	;CentrY = (-(Figure.SizeY * Figure.WScale) - graf_margin_top - graf_margin_bot + buf_0.h) / 2 + graf_margin_bot
1173
	fld qword[ebx+Figure.SizeX]
1174
	fmul qword[ebx+Figure.WScale]
1175
	fmul qword[ebx+Figure.MScale]
1176
	fchs
1177
	fistp dword[CentrX]
1178
	mov eax,[CentrX]
1179
	sub eax,[graf_margin_left]
1180
	sub eax,[graf_margin_right]
1181
	add eax,[buf_0.w]
1182
	sar eax,1
1183
	add eax,[graf_margin_left]
1184
	add eax,[ebx+Figure.MCentrX]
1185
	mov [CentrX],eax
1186
	;CentrX = (-(Figure.SizeX * Figure.WScale) - graf_margin_left - graf_margin_right + buf_0.w) / 2 + graf_margin_left
1187
1188
 
1189
	.cycle0:
1190
		fld qword[edi+Point.CoordX]
1191
		fsub qword[ebx+Figure.MinX]
1192
		fmul qword[ebx+Figure.WScale]
1193
		fmul qword[ebx+Figure.MScale]
1194
		fiadd dword[CentrX]
1195
		fistp dword[GrafX]
1196
		;GrafX = (Point.CoordX - Figure.MinX) * Figure.WScale + CentrX
1197
		fld qword[edi+Point.CoordY]
1198
		fsub qword[ebx+Figure.MinY]
1199
		fmul qword[ebx+Figure.WScale]
1200
		fmul qword[ebx+Figure.MScale]
1201
		fiadd dword[CentrY]
1202
		fisub dword[buf_0.h] ;invert coord Y
1203
		fchs
1204
		fistp dword[GrafY]
1205
		;GrafY = -((Point.CoordY - Figure.MinY) * Figure.WScale + CentrY - buf_0.h)
1206
1207
 
1208
		mov dword[col_lin],0x80
1209
		bt dword[edi+Point.Prop],PROP_BIT_SELECT
1210
		jnc @f
1211
			stdcall [buf2d_circle], buf_0, [GrafX],[GrafY], 3, 0xff0000
1212
		@@:
1213
		cmp ecx,[ebx+Figure.PoiCount]
1214
		je @f
1215
			stdcall [buf2d_line_sm], buf_0, [PervX],[PervY], [GrafX],[GrafY], [col_lin]
1216
			stdcall [buf2d_line], buf_0, [PervX],[PervY], [GrafX],[GrafY], [col_lin]
1217
		@@:
1218
		mov eax,[GrafX]
1219
		mov [PervX],eax
1220
		mov edx,[GrafY]
1221
		mov [PervY],edx
1222
		add edi,sizeof.Point
1223
1224
 
1225
		jnc .end0
1226
		; draw number points
1227
		;mov eax,[GrafX]
1228
		;mov edx,[GrafY]
1229
		add eax,2
1230
		add edx,2
1231
		push eax edi
1232
			mov eax,[n]
1233
			mov edi,txt_buf
1234
			stdcall convert_int_to_str,20
1235
		pop edi eax
1236
1237
 
1238
		;calculate new text coords
1239
		mov [new_tl],eax
1240
		mov esi,eax
1241
		stdcall str_len,txt_buf
1242
		imul eax,[buf_1.w]
1243
		add eax,esi
1244
		mov [new_tw],eax
1245
		;rect compare coords
1246
		cmp [old_tl],eax
1247
		jg .no_comp
1248
		cmp [old_tw],esi
1249
		jl .no_comp
1250
			;calculate new text coord Y1
1251
			mov esi,edx
1252
			add esi,[font_h]
1253
		cmp [old_tt],esi
1254
		jg .no_comp
1255
		cmp [old_th],edx
1256
		;jl .no_comp
1257
			;jmp .end0
1258
		jge .end0
1259
		.no_comp:
1260
			mov eax,[new_tl]
1261
			mov [old_tl],eax
1262
			mov eax,[new_tw]
1263
			mov [old_tw],eax
1264
			mov [old_tt],edx
1265
			add edx,[font_h]
1266
			mov [old_th],edx
1267
			stdcall [buf2d_draw_text], buf_0, buf_1,txt_buf,[old_tl],[old_tt],0x000000
1268
		.end0:
1269
		dec ecx
1270
	jnz .cycle0
1271
1272
 
1273
	or eax,eax
1274
	jz .no_point
1275
		stdcall mem_copy, txt_buf,txt_poi_sel,txt_poi_sel.end-txt_poi_sel
1276
		mov edi,txt_buf+txt_poi_sel.end-txt_poi_sel
1277
		stdcall convert_int_to_str, 20
1278
		mov word[NumberSymbolsAD],8
1279
		cmp eax,1
1280
		jne @f
1281
			;если выбрана одна точка, то по ней вывод более детальной информации
1282
			stdcall sel_points_get_first,[pfig]
1283
			stdcall str_cat,txt_buf,txt_ls
1284
			fld qword[eax+Point.CoordX]
1285
			fstp qword[Data_Double]
1286
			call DoubleFloat_to_String
1287
			call String_crop_0
1288
			stdcall str_cat,txt_buf,Data_String
1289
			stdcall str_cat,txt_buf,txt_coma
1290
			fld qword[eax+Point.CoordY]
1291
			fstp qword[Data_Double]
1292
			call DoubleFloat_to_String
1293
			call String_crop_0
1294
			stdcall str_cat,txt_buf,Data_String
1295
			stdcall str_cat,txt_buf,txt_rs
1296
			jmp .end1
1297
		@@:
1298
		cmp eax,2
1299
		jne .end1
1300
			;если выбрано 2 точки
1301
			stdcall sel_points_get_first,[pfig]
1302
			fld qword[eax+Point.CoordX]
1303
			fld qword[eax+Point.CoordY]
1304
			stdcall sel_points_get_last,[pfig]
1305
			fsub qword[eax+Point.CoordY]
1306
			fmul st0,st0
1307
			fxch st1
1308
			fsub qword[eax+Point.CoordX]
1309
			fmul st0,st0
1310
			faddp st1,st0
1311
			fsqrt
1312
			fstp qword[Data_Double]
1313
			call DoubleFloat_to_String
1314
			call String_crop_0
1315
			stdcall str_cat,txt_buf,txt_len
1316
			stdcall str_cat,txt_buf,Data_String
1317
		.end1:
1318
		stdcall [buf2d_draw_text], buf_0, buf_1,txt_buf,3,3,0
1319
		jmp .end_f ;не выводим информацию о размерах
1320
	.no_point:
1321
1322
 
1323
	jnc .end_f
1324
		; draw min & sizes
1325
		mov word[NumberSymbolsAD],8
1326
		stdcall mem_copy, txt_buf,txt_size_x,20
1327
		fld qword[ebx+Figure.SizeX]
1328
		fstp qword[Data_Double]
1329
		call DoubleFloat_to_String
1330
		call String_crop_0
1331
		stdcall str_cat,txt_buf,Data_String
1332
		stdcall str_cat,txt_buf,txt_n
1333
		stdcall str_cat,txt_buf,txt_size_y
1334
		fld qword[ebx+Figure.SizeY]
1335
		fstp qword[Data_Double]
1336
		call DoubleFloat_to_String
1337
		call String_crop_0
1338
		stdcall str_cat,txt_buf,Data_String
1339
		stdcall [buf2d_draw_text], buf_0, buf_1,txt_buf,3,23,0
1340
1341
 
1342
		fstp qword[Data_Double]
1343
		stdcall mem_copy, txt_buf,txt_min_x,20
1344
		call DoubleFloat_to_String
1345
		call String_crop_0
1346
		stdcall str_cat,txt_buf,Data_String
1347
		stdcall str_cat,txt_buf,txt_n
1348
		stdcall str_cat,txt_buf,txt_min_y
1349
		fld qword[ebx+Figure.MinY]
1350
		fstp qword[Data_Double]
1351
		call DoubleFloat_to_String
1352
		call String_crop_0
1353
		stdcall str_cat,txt_buf,Data_String
1354
		stdcall [buf2d_draw_text], buf_0, buf_1,txt_buf,3,3,0
1355
	.end_f:
1356
popad
1357
	ret
1358
endp
1359
1360
 
1361
; pnode - указатель на данные узла
1362
align 4
1363
proc get_object_data, pnode:dword
1364
	mov ecx,[pnode]
1365
	cmp [ecx+Object.OType],'Obj'
1366
	jne .end0
1367
		mov ecx,ObjData
1368
		jmp .end_f
1369
	.end0:
1370
		xor ecx,ecx
1371
	.end_f:
1372
	ret
1373
endp
1374
1375
 
1376
; pfig - pointer to figure
1377
;output:
1378
; eax - указатель на родительский объект или 0 если не найдено
1379
; ecx - номер фигуры внутри объекта
1380
align 4
1381
proc found_parent_obj uses ebx edx edi, pfig:dword
1382
	mov eax,ObjData
1383
	mov edx,[eax+Object.FigCount]
1384
	or edx,edx
1385
	jz .cycle1end
1386
	mov edi,[eax+Object.FigData]
1387
	xor ecx,ecx
1388
	.cycle1: ;цикл по фигурам
1389
		mov ebx,[edi]
1390
		cmp ebx,[pfig]
1391
		je .end_f ;если найдено
1392
		add edi,4
1393
		inc ecx
1394
		dec edx
1395
		jnz .cycle1
1396
	.cycle1end:
1397
	xor eax,eax
1398
	.end_f:
1399
	ret
1400
endp
1401
1402
 
1403
; считает колличество выделенных точек
1404
align 4
1405
proc sel_points_get_count uses ebx ecx, pFig:dword
1406
	xor eax,eax
1407
	mov ebx,[pFig]
1408
	mov ecx,[ebx+Figure.PoiCount]
1409
	or ecx,ecx
1410
	jz .no_point
1411
	mov ebx,[ebx+Figure.PoiData]
1412
	.cycle0:
1413
		bt dword[ebx+Point.Prop],PROP_BIT_SELECT
1414
		jnc @f
1415
			inc eax
1416
		@@:
1417
		add ebx,sizeof.Point
1418
		loop .cycle0
1419
	.no_point:
1420
	ret
1421
endp
1422
1423
 
1424
; берет указатель на первую выделенную точку
1425
;output:
1426
; eax - указатель на точку или 0 если не выделенно
1427
align 4
1428
proc sel_points_get_first uses ecx, pFig:dword
1429
	mov eax,[pFig]
1430
	mov ecx,[eax+Figure.PoiCount]
1431
	or ecx,ecx
1432
	jz .no_point
1433
	mov eax,[eax+Figure.PoiData]
1434
	.cycle0:
1435
		bt dword[eax+Point.Prop],PROP_BIT_SELECT
1436
		jc .end_f
1437
		add eax,sizeof.Point
1438
		loop .cycle0
1439
	.no_point:
1440
	xor eax,eax
1441
	.end_f:
1442
	ret
1443
endp
1444
1445
 
1446
; pObj - указатель на объект
1447
; FigN - номер комманды
1448
;description:
1449
; пересчет фигур после обновления координат точки
1450
align 4
1451
proc figure_update_coords uses eax ecx edx, pObj:dword, FigN:dword
1452
	mov eax,[pObj]
1453
	mov ecx,[eax+Object.FigCount]
1454
	mov eax,[eax+Object.FigData]
1455
	mov edx,[FigN]
1456
	cmp ecx,edx
1457
	jle @f
1458
		stdcall FigCalculateSizes,[eax+4*edx],1
1459
		stdcall ObjCalculateScale,[pObj]
1460
	@@:
1461
	ret
1462
endp
1463
1464
 
1465
; берет указатель на последнюю выделенную точку
1466
align 4
1467
proc sel_points_get_last uses ebx ecx, pFig:dword
1468
	mov ebx,[pFig]
1469
	mov ecx,[ebx+Figure.PoiCount]
1470
	or ecx,ecx
1471
	jz .no_point
1472
	mov eax,ecx
1473
	dec eax
1474
	imul eax,sizeof.Point
1475
	add eax,[ebx+Figure.PoiData]
1476
	.cycle0:
1477
		bt dword[eax+Point.Prop],PROP_BIT_SELECT
1478
		jc .end_f
1479
		sub eax,sizeof.Point
1480
		loop .cycle0
1481
	.no_point:
1482
	xor eax,eax
1483
	.end_f:
1484
	ret
1485
endp
1486
1487
 
1488
; снимает выделение с точек
1489
align 4
1490
proc sel_points_clear uses ebx ecx, pFig:dword
1491
	mov ebx,[pFig]
1492
	mov ecx,[ebx+Figure.PoiCount]
1493
	or ecx,ecx
1494
	jz .no_point
1495
	mov ebx,[ebx+Figure.PoiData]
1496
	.cycle0:
1497
		btr dword[ebx+Point.Prop],PROP_BIT_SELECT
1498
		add ebx,sizeof.Point
1499
		loop .cycle0
1500
	.no_point:
1501
	ret
1502
endp
1503
1504
 
1505
; инвертирует указанный бит в свойствах выделенных точек
1506
align 4
1507
proc sel_points_invert_bit uses eax ebx ecx, pFig:dword, iBit:dword
1508
	mov ecx,[iBit]
1509
	xor eax,eax
1510
	inc eax
1511
	shl eax,cl
1512
	mov ebx,[pFig]
1513
	mov ecx,[ebx+Figure.PoiCount]
1514
	or ecx,ecx
1515
	jz .no_point
1516
	mov ebx,[ebx+Figure.PoiData]
1517
	.cycle0:
1518
		bt dword[ebx+Point.Prop],PROP_BIT_SELECT
1519
		jnc @f
1520
			xor dword[ebx+Point.Prop],eax
1521
		@@:
1522
		add ebx,sizeof.Point
1523
		loop .cycle0
1524
	.no_point:
1525
	ret
1526
endp
1527
1528
 
7663 IgorA 1529
; оптимизация фигуры, выделяет лишние точки (1-я и последняя точки не учитываются)
1530
align 4
1531
proc points_optimize uses eax ebx ecx, pFig:dword
1532
	mov ebx,[pFig]
1533
	mov ecx,[ebx+Figure.PoiCount]
1534
	cmp ecx,3
1535
	jl .no_point
1536
	sub ecx,2 ;отнимаем точки которые не учитываются
1537
	stdcall sel_points_clear,ebx
1538
	mov ebx,[ebx+Figure.PoiData]
1539
	finit
1540
	.cycle0:
1541
		;calc (x0-x1)/(x0-x2)
1542
		fld qword[ebx+Point.CoordX]
1543
		add ebx,sizeof.Point
1544
		fcom qword[ebx+Point.CoordX]
1545
		fstsw ax
1546
		sahf
1547
		jne @f
1548
			fcomp qword[ebx+sizeof.Point+Point.CoordX]
1549
			fstsw ax
1550
			sahf
1551
			jne .no_sel ;if( (x0==x1) && (x0!=x2) )
1552
			jmp .sel    ;if( x0==x1==x2 )
1553
		@@:
1554
		fld st0
1555
		fsub qword[ebx+Point.CoordX]
1556
		fxch st1
1557
		fsub qword[ebx+sizeof.Point+Point.CoordX]
1558
		fdivp
1559
1560
 
1561
		fld qword[ebx-sizeof.Point+Point.CoordY]
1562
		fcom qword[ebx+Point.CoordY]
1563
		fstsw ax
1564
		sahf
1565
		jne @f
1566
			fcomp qword[ebx+sizeof.Point+Point.CoordY]
1567
			fstsw ax
1568
			ffree st0 ;free (x0-x1)/(x0-x2)
1569
			fincstp
1570
			sahf
1571
			jne .no_sel ;if( (y0==y1) && (y0!=y2) )
1572
			jmp .sel    ;if( y0==y1==y2 )
1573
		@@:
1574
		fld st0
1575
		fsub qword[ebx+Point.CoordY]
1576
		fxch st1
1577
		fsub qword[ebx+sizeof.Point+Point.CoordY]
1578
		fdivp
1579
1580
 
1581
		fabs
1582
		fcomp qword[opt_koef] ;if( abs((x0-x1)/(x0-x2)-(y0-y1)/(y0-y2)) > 0.02)
1583
		fstsw ax
1584
		sahf
1585
		jae .no_sel
1586
		.sel:
1587
			bts dword[ebx+Point.Prop],PROP_BIT_SELECT
1588
		.no_sel:
1589
		loop .cycle0
1590
	.no_point:
1591
	ret
1592
endp
1593
1594
 
7360 IgorA 1595
; pPoi - указатель на данные точки
1596
align 4
1597
proc point_move_up, pObj:dword,pFig:dword,idFig:dword,pPoi:dword
1598
pushad
1599
	;изменение ссылок на точки
1600
	mov eax,[pObj]
1601
	mov ecx,[idFig]
1602
	mov edx,[eax+Object.FigCount]
1603
	or edx,edx
1604
	jz .end_f
1605
	mov edi,[eax+Object.FigData]
1606
1607
 
1608
	mov ecx,sizeof.Point
1609
	mov esi,[pPoi]
1610
	sub esi,ecx
1611
	mov edi,PoiData
1612
	rep movsb ;p(-1) > p_s
1613
	mov ecx,sizeof.Point
1614
	mov edi,[pPoi]
1615
	sub edi,ecx
1616
	rep movsb ;p(0) > p(-1)
1617
	mov esi,PoiData
1618
	mov ecx,sizeof.Point
1619
	rep movsb ;p_s > p(0)
1620
	.end_f:
1621
popad
1622
	ret
1623
endp
1624
1625
 
1626
proc mouse_left_d uses eax ebx
1627
	stdcall [tl_node_get_data],tree1
1628
	or eax,eax
1629
	jz .end_f
1630
1631
 
1632
	je @f
1633
	cmp [eax+Figure.OType],'Obj'
1634
	jne .end_f
7663 IgorA 1635
		mov eax,ObjData
7360 IgorA 1636
	@@:
1637
	call buf_get_mouse_coord
1638
	cmp eax,-1
1639
	je .end_f
1640
		mov [mouse_down_x],eax
1641
		mov [mouse_down_y],ebx
1642
	.end_f:
1643
	ret
1644
endp
1645
1646
 
1647
proc mouse_left_u uses eax ebx ecx
1648
	stdcall [tl_node_get_data],tree1
1649
	or eax,eax
1650
	jz .end_f
1651
1652
 
1653
	je @f
1654
	cmp [eax+Figure.OType],'Obj'
1655
	jne .end_f
7663 IgorA 1656
		mov eax,ObjData
7360 IgorA 1657
	@@:
1658
	mov ecx,eax
1659
1660
 
1661
	cmp eax,-1
1662
	je .end_f
1663
		sub eax,[mouse_down_x]
1664
		sub ebx,[mouse_down_y]
1665
		add [ecx+Figure.MCentrX],eax
1666
		sub [ecx+Figure.MCentrY],ebx
1667
		mov dword[offs_last_timer],0
1668
	.end_f:
1669
	ret
1670
endp
1671
1672
 
1673
; eax, ebx - портятся
1674
align 4
1675
proc mouse_right_d uses ecx edx edi
1676
locals
1677
	BufX dd ?
1678
	BufY dd ?
1679
	CentrX dd ?
1680
	CentrY dd ?
1681
	GrafX dd ? ;active point coord X
1682
	GrafY dd ? ;active point coord Y
1683
endl
1684
	call buf_get_mouse_coord
1685
	cmp eax,-1
1686
	je .end_f
1687
	mov [BufX],eax
1688
	mov [BufY],ebx
1689
1690
 
1691
	stdcall [tl_node_get_data],tree1
1692
	or eax,eax
1693
	jz .end_f
1694
1695
 
1696
	jne .end_fblo
1697
1698
 
1699
	mcall SF_KEYBOARD,SSF_GET_CONTROL_KEYS ;проверка Shift
1700
	bt eax,0
1701
	jc @f
1702
	bt eax,1
1703
	jc @f
1704
		;если не нажат Shift
1705
		stdcall sel_points_clear,ecx
1706
	@@:
1707
	mov ebx,ecx
1708
	mov ecx,[ebx+Figure.PoiCount]
1709
	;;jecxz .end_f
1710
	test ecx,ecx
1711
	jz .end_f
1712
1713
 
1714
	finit
1715
	fld qword[ebx+Figure.SizeY]
1716
	fmul qword[ebx+Figure.WScale]
1717
	fmul qword[ebx+Figure.MScale]
1718
	fchs
1719
	fistp dword[CentrY]
1720
	mov eax,[CentrY]
1721
	sub eax,[graf_margin_top]
1722
	sub eax,[graf_margin_bot]
1723
	add eax,[buf_0.h]
1724
	sar eax,1
1725
	add eax,[graf_margin_bot]
1726
	add eax,[ebx+Figure.MCentrY]
1727
	mov [CentrY],eax
1728
	fld qword[ebx+Figure.SizeX]
1729
	fmul qword[ebx+Figure.WScale]
1730
	fmul qword[ebx+Figure.MScale]
1731
	fchs
1732
	fistp dword[CentrX]
1733
	mov eax,[CentrX]
1734
	sub eax,[graf_margin_left]
1735
	sub eax,[graf_margin_right]
1736
	add eax,[buf_0.w]
1737
	sar eax,1
1738
	add eax,[graf_margin_left]
1739
	add eax,[ebx+Figure.MCentrX]
1740
	mov [CentrX],eax
1741
1742
 
1743
	.cycle0:
1744
		fld qword[edi+Point.CoordX]
1745
		fsub qword[ebx+Figure.MinX]
1746
		fmul qword[ebx+Figure.WScale]
1747
		fmul qword[ebx+Figure.MScale]
1748
		fiadd dword[CentrX]
1749
		fistp dword[GrafX]
1750
		fld qword[edi+Point.CoordY]
1751
		fsub qword[ebx+Figure.MinY]
1752
		fmul qword[ebx+Figure.WScale]
1753
		fmul qword[ebx+Figure.MScale]
1754
		fiadd dword[CentrY]
1755
		fisub dword[buf_0.h] ;invert coord Y
1756
		fchs
1757
		fistp dword[GrafY]
1758
1759
 
1760
		sub eax,[BufX]
1761
		bt eax,31
1762
		jnc @f
1763
			neg eax
1764
		@@:
1765
		mov edx,[GrafY]
1766
		sub edx,[BufY]
1767
		bt edx,31
1768
		jnc @f
1769
			neg edx
1770
		@@:
1771
		add eax,edx
1772
		cmp eax,7 ;приблизительное расстояние до точки
1773
		jg @f
1774
			;выделяем или снимаем выделение с точек
1775
			xor dword[edi+Point.Prop],(1 shl PROP_BIT_SELECT)
1776
		@@:
1777
1778
 
1779
		dec ecx
1780
	jnz .cycle0
1781
1782
 
1783
		;jmp .end_f
1784
	.end_fblo:
1785
1786
 
1787
	ret
1788
endp
1789