Subversion Repositories Kolibri OS

Rev

Rev 7663 | 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
		@@:
1107
		mov eax,[GrafX]
1108
		mov [PervX],eax
1109
		mov eax,[GrafY]
1110
		mov [PervY],eax
1111
		add edi,sizeof.Point
1112
	;;loop .cycle0
1113
		dec ecx
1114
	jnz .cycle0
1115
	ffree st0
1116
	fincstp
1117
1118
 
1119
popad
1120
	ret
1121
endp
1122
1123
 
1124
; функция для рисования выбранной фигуры
1125
align 4
1126
proc draw_fig2d, pfig:dword
1127
locals
1128
	n dd 0
1129
	col_lin dd 0 ;цвет линий фигуры
1130
	CentrX dd ?
1131
	CentrY dd ?
1132
	PervX dd 0 ;pervios point coord X
1133
	PervY dd 0 ;pervios point coord Y
1134
	GrafX dd ? ;active point coord X
1135
	GrafY dd ? ;active point coord Y
1136
	old_tl dd 0 ;old text coord X0
1137
	old_tt dd 0 ;old text coord Y0
1138
	old_tw dd 0 ;old text coord X1
1139
	old_th dd 0 ;old text coord Y1
1140
	new_tl dd 0 ;new text coord X0
1141
	;new_tt dd 0 ;new text coord Y0
1142
	new_tw dd 0 ;new text coord X1
1143
	;new_th dd 0 ;new text coord Y1
1144
endl
1145
pushad
1146
	stdcall [buf2d_clear], buf_0, [buf_0.color]
1147
	mov ebx,[pfig]
1148
	test ebx,ebx
1149
	jz .end_f
1150
	mov ecx,[ebx+Figure.PoiCount]
1151
	;;jecxz .end_f
1152
	test ecx,ecx
1153
	jz .end_f
1154
	mov edi,[ebx+Figure.PoiData]
1155
	finit
1156
	fld qword[ebx+Figure.SizeY]
1157
	fmul qword[ebx+Figure.WScale]
1158
	fmul qword[ebx+Figure.MScale]
1159
	fchs
1160
	fistp dword[CentrY]
1161
	mov eax,[CentrY]
1162
	sub eax,[graf_margin_top]
1163
	sub eax,[graf_margin_bot]
1164
	add eax,[buf_0.h]
1165
	sar eax,1
1166
	add eax,[graf_margin_bot]
1167
	add eax,[ebx+Figure.MCentrY]
1168
	mov [CentrY],eax
1169
	;CentrY = (-(Figure.SizeY * Figure.WScale) - graf_margin_top - graf_margin_bot + buf_0.h) / 2 + graf_margin_bot
1170
	fld qword[ebx+Figure.SizeX]
1171
	fmul qword[ebx+Figure.WScale]
1172
	fmul qword[ebx+Figure.MScale]
1173
	fchs
1174
	fistp dword[CentrX]
1175
	mov eax,[CentrX]
1176
	sub eax,[graf_margin_left]
1177
	sub eax,[graf_margin_right]
1178
	add eax,[buf_0.w]
1179
	sar eax,1
1180
	add eax,[graf_margin_left]
1181
	add eax,[ebx+Figure.MCentrX]
1182
	mov [CentrX],eax
1183
	;CentrX = (-(Figure.SizeX * Figure.WScale) - graf_margin_left - graf_margin_right + buf_0.w) / 2 + graf_margin_left
1184
1185
 
1186
	.cycle0:
1187
		fld qword[edi+Point.CoordX]
1188
		fsub qword[ebx+Figure.MinX]
1189
		fmul qword[ebx+Figure.WScale]
1190
		fmul qword[ebx+Figure.MScale]
1191
		fiadd dword[CentrX]
1192
		fistp dword[GrafX]
1193
		;GrafX = (Point.CoordX - Figure.MinX) * Figure.WScale + CentrX
1194
		fld qword[edi+Point.CoordY]
1195
		fsub qword[ebx+Figure.MinY]
1196
		fmul qword[ebx+Figure.WScale]
1197
		fmul qword[ebx+Figure.MScale]
1198
		fiadd dword[CentrY]
1199
		fisub dword[buf_0.h] ;invert coord Y
1200
		fchs
1201
		fistp dword[GrafY]
1202
		;GrafY = -((Point.CoordY - Figure.MinY) * Figure.WScale + CentrY - buf_0.h)
1203
1204
 
1205
		mov dword[col_lin],0x80
1206
		bt dword[edi+Point.Prop],PROP_BIT_SELECT
1207
		jnc @f
1208
			stdcall [buf2d_circle], buf_0, [GrafX],[GrafY], 3, 0xff0000
1209
		@@:
1210
		cmp ecx,[ebx+Figure.PoiCount]
1211
		je @f
1212
			stdcall [buf2d_line_sm], buf_0, [PervX],[PervY], [GrafX],[GrafY], [col_lin]
1213
		@@:
1214
		mov eax,[GrafX]
1215
		mov [PervX],eax
1216
		mov edx,[GrafY]
1217
		mov [PervY],edx
1218
		add edi,sizeof.Point
1219
1220
 
1221
		jnc .end0
1222
		; draw number points
1223
		;mov eax,[GrafX]
1224
		;mov edx,[GrafY]
1225
		add eax,2
1226
		add edx,2
1227
		push eax edi
1228
			mov eax,[n]
1229
			mov edi,txt_buf
1230
			stdcall convert_int_to_str,20
1231
		pop edi eax
1232
1233
 
1234
		;calculate new text coords
1235
		mov [new_tl],eax
1236
		mov esi,eax
1237
		stdcall str_len,txt_buf
1238
		imul eax,[buf_1.w]
1239
		add eax,esi
1240
		mov [new_tw],eax
1241
		;rect compare coords
1242
		cmp [old_tl],eax
1243
		jg .no_comp
1244
		cmp [old_tw],esi
1245
		jl .no_comp
1246
			;calculate new text coord Y1
1247
			mov esi,edx
1248
			add esi,[font_h]
1249
		cmp [old_tt],esi
1250
		jg .no_comp
1251
		cmp [old_th],edx
1252
		;jl .no_comp
1253
			;jmp .end0
1254
		jge .end0
1255
		.no_comp:
1256
			mov eax,[new_tl]
1257
			mov [old_tl],eax
1258
			mov eax,[new_tw]
1259
			mov [old_tw],eax
1260
			mov [old_tt],edx
1261
			add edx,[font_h]
1262
			mov [old_th],edx
1263
			stdcall [buf2d_draw_text], buf_0, buf_1,txt_buf,[old_tl],[old_tt],0x000000
1264
		.end0:
1265
		dec ecx
1266
	jnz .cycle0
1267
1268
 
1269
	or eax,eax
1270
	jz .no_point
1271
		stdcall mem_copy, txt_buf,txt_poi_sel,txt_poi_sel.end-txt_poi_sel
1272
		mov edi,txt_buf+txt_poi_sel.end-txt_poi_sel
1273
		stdcall convert_int_to_str, 20
1274
		mov word[NumberSymbolsAD],8
1275
		cmp eax,1
1276
		jne @f
1277
			;если выбрана одна точка, то по ней вывод более детальной информации
1278
			stdcall sel_points_get_first,[pfig]
1279
			stdcall str_cat,txt_buf,txt_ls
1280
			fld qword[eax+Point.CoordX]
1281
			fstp qword[Data_Double]
1282
			call DoubleFloat_to_String
1283
			call String_crop_0
1284
			stdcall str_cat,txt_buf,Data_String
1285
			stdcall str_cat,txt_buf,txt_coma
1286
			fld qword[eax+Point.CoordY]
1287
			fstp qword[Data_Double]
1288
			call DoubleFloat_to_String
1289
			call String_crop_0
1290
			stdcall str_cat,txt_buf,Data_String
1291
			stdcall str_cat,txt_buf,txt_rs
1292
			jmp .end1
1293
		@@:
1294
		cmp eax,2
1295
		jne .end1
1296
			;если выбрано 2 точки
1297
			stdcall sel_points_get_first,[pfig]
1298
			fld qword[eax+Point.CoordX]
1299
			fld qword[eax+Point.CoordY]
1300
			stdcall sel_points_get_last,[pfig]
1301
			fsub qword[eax+Point.CoordY]
1302
			fmul st0,st0
1303
			fxch st1
1304
			fsub qword[eax+Point.CoordX]
1305
			fmul st0,st0
1306
			faddp st1,st0
1307
			fsqrt
1308
			fstp qword[Data_Double]
1309
			call DoubleFloat_to_String
1310
			call String_crop_0
1311
			stdcall str_cat,txt_buf,txt_len
1312
			stdcall str_cat,txt_buf,Data_String
1313
		.end1:
1314
		stdcall [buf2d_draw_text], buf_0, buf_1,txt_buf,3,3,0
1315
		jmp .end_f ;не выводим информацию о размерах
1316
	.no_point:
1317
1318
 
1319
	jnc .end_f
1320
		; draw min & sizes
1321
		mov word[NumberSymbolsAD],8
1322
		stdcall mem_copy, txt_buf,txt_size_x,20
1323
		fld qword[ebx+Figure.SizeX]
1324
		fstp qword[Data_Double]
1325
		call DoubleFloat_to_String
1326
		call String_crop_0
1327
		stdcall str_cat,txt_buf,Data_String
1328
		stdcall str_cat,txt_buf,txt_n
1329
		stdcall str_cat,txt_buf,txt_size_y
1330
		fld qword[ebx+Figure.SizeY]
1331
		fstp qword[Data_Double]
1332
		call DoubleFloat_to_String
1333
		call String_crop_0
1334
		stdcall str_cat,txt_buf,Data_String
1335
		stdcall [buf2d_draw_text], buf_0, buf_1,txt_buf,3,23,0
1336
1337
 
1338
		fstp qword[Data_Double]
1339
		stdcall mem_copy, txt_buf,txt_min_x,20
1340
		call DoubleFloat_to_String
1341
		call String_crop_0
1342
		stdcall str_cat,txt_buf,Data_String
1343
		stdcall str_cat,txt_buf,txt_n
1344
		stdcall str_cat,txt_buf,txt_min_y
1345
		fld qword[ebx+Figure.MinY]
1346
		fstp qword[Data_Double]
1347
		call DoubleFloat_to_String
1348
		call String_crop_0
1349
		stdcall str_cat,txt_buf,Data_String
1350
		stdcall [buf2d_draw_text], buf_0, buf_1,txt_buf,3,3,0
1351
	.end_f:
1352
popad
1353
	ret
1354
endp
1355
1356
 
1357
; pnode - указатель на данные узла
1358
align 4
1359
proc get_object_data, pnode:dword
1360
	mov ecx,[pnode]
1361
	cmp [ecx+Object.OType],'Obj'
1362
	jne .end0
1363
		mov ecx,ObjData
1364
		jmp .end_f
1365
	.end0:
1366
		xor ecx,ecx
1367
	.end_f:
1368
	ret
1369
endp
1370
1371
 
1372
; pfig - pointer to figure
1373
;output:
1374
; eax - указатель на родительский объект или 0 если не найдено
1375
; ecx - номер фигуры внутри объекта
1376
align 4
1377
proc found_parent_obj uses ebx edx edi, pfig:dword
1378
	mov eax,ObjData
1379
	mov edx,[eax+Object.FigCount]
1380
	or edx,edx
1381
	jz .cycle1end
1382
	mov edi,[eax+Object.FigData]
1383
	xor ecx,ecx
1384
	.cycle1: ;цикл по фигурам
1385
		mov ebx,[edi]
1386
		cmp ebx,[pfig]
1387
		je .end_f ;если найдено
1388
		add edi,4
1389
		inc ecx
1390
		dec edx
1391
		jnz .cycle1
1392
	.cycle1end:
1393
	xor eax,eax
1394
	.end_f:
1395
	ret
1396
endp
1397
1398
 
1399
; считает колличество выделенных точек
1400
align 4
1401
proc sel_points_get_count uses ebx ecx, pFig:dword
1402
	xor eax,eax
1403
	mov ebx,[pFig]
1404
	mov ecx,[ebx+Figure.PoiCount]
1405
	or ecx,ecx
1406
	jz .no_point
1407
	mov ebx,[ebx+Figure.PoiData]
1408
	.cycle0:
1409
		bt dword[ebx+Point.Prop],PROP_BIT_SELECT
1410
		jnc @f
1411
			inc eax
1412
		@@:
1413
		add ebx,sizeof.Point
1414
		loop .cycle0
1415
	.no_point:
1416
	ret
1417
endp
1418
1419
 
1420
; берет указатель на первую выделенную точку
1421
;output:
1422
; eax - указатель на точку или 0 если не выделенно
1423
align 4
1424
proc sel_points_get_first uses ecx, pFig:dword
1425
	mov eax,[pFig]
1426
	mov ecx,[eax+Figure.PoiCount]
1427
	or ecx,ecx
1428
	jz .no_point
1429
	mov eax,[eax+Figure.PoiData]
1430
	.cycle0:
1431
		bt dword[eax+Point.Prop],PROP_BIT_SELECT
1432
		jc .end_f
1433
		add eax,sizeof.Point
1434
		loop .cycle0
1435
	.no_point:
1436
	xor eax,eax
1437
	.end_f:
1438
	ret
1439
endp
1440
1441
 
1442
; pObj - указатель на объект
1443
; FigN - номер комманды
1444
;description:
1445
; пересчет фигур после обновления координат точки
1446
align 4
1447
proc figure_update_coords uses eax ecx edx, pObj:dword, FigN:dword
1448
	mov eax,[pObj]
1449
	mov ecx,[eax+Object.FigCount]
1450
	mov eax,[eax+Object.FigData]
1451
	mov edx,[FigN]
1452
	cmp ecx,edx
1453
	jle @f
1454
		stdcall FigCalculateSizes,[eax+4*edx],1
1455
		stdcall ObjCalculateScale,[pObj]
1456
	@@:
1457
	ret
1458
endp
1459
1460
 
1461
; берет указатель на последнюю выделенную точку
1462
align 4
1463
proc sel_points_get_last uses ebx ecx, pFig:dword
1464
	mov ebx,[pFig]
1465
	mov ecx,[ebx+Figure.PoiCount]
1466
	or ecx,ecx
1467
	jz .no_point
1468
	mov eax,ecx
1469
	dec eax
1470
	imul eax,sizeof.Point
1471
	add eax,[ebx+Figure.PoiData]
1472
	.cycle0:
1473
		bt dword[eax+Point.Prop],PROP_BIT_SELECT
1474
		jc .end_f
1475
		sub eax,sizeof.Point
1476
		loop .cycle0
1477
	.no_point:
1478
	xor eax,eax
1479
	.end_f:
1480
	ret
1481
endp
1482
1483
 
1484
; снимает выделение с точек
1485
align 4
1486
proc sel_points_clear uses ebx ecx, pFig:dword
1487
	mov ebx,[pFig]
1488
	mov ecx,[ebx+Figure.PoiCount]
1489
	or ecx,ecx
1490
	jz .no_point
1491
	mov ebx,[ebx+Figure.PoiData]
1492
	.cycle0:
1493
		btr dword[ebx+Point.Prop],PROP_BIT_SELECT
1494
		add ebx,sizeof.Point
1495
		loop .cycle0
1496
	.no_point:
1497
	ret
1498
endp
1499
1500
 
1501
; инвертирует указанный бит в свойствах выделенных точек
1502
align 4
1503
proc sel_points_invert_bit uses eax ebx ecx, pFig:dword, iBit:dword
1504
	mov ecx,[iBit]
1505
	xor eax,eax
1506
	inc eax
1507
	shl eax,cl
1508
	mov ebx,[pFig]
1509
	mov ecx,[ebx+Figure.PoiCount]
1510
	or ecx,ecx
1511
	jz .no_point
1512
	mov ebx,[ebx+Figure.PoiData]
1513
	.cycle0:
1514
		bt dword[ebx+Point.Prop],PROP_BIT_SELECT
1515
		jnc @f
1516
			xor dword[ebx+Point.Prop],eax
1517
		@@:
1518
		add ebx,sizeof.Point
1519
		loop .cycle0
1520
	.no_point:
1521
	ret
1522
endp
1523
1524
 
7663 IgorA 1525
; оптимизация фигуры, выделяет лишние точки (1-я и последняя точки не учитываются)
1526
align 4
1527
proc points_optimize uses eax ebx ecx, pFig:dword
1528
	mov ebx,[pFig]
1529
	mov ecx,[ebx+Figure.PoiCount]
1530
	cmp ecx,3
1531
	jl .no_point
1532
	sub ecx,2 ;отнимаем точки которые не учитываются
1533
	stdcall sel_points_clear,ebx
1534
	mov ebx,[ebx+Figure.PoiData]
1535
	finit
1536
	.cycle0:
1537
		;calc (x0-x1)/(x0-x2)
1538
		fld qword[ebx+Point.CoordX]
1539
		add ebx,sizeof.Point
1540
		fcom qword[ebx+Point.CoordX]
1541
		fstsw ax
1542
		sahf
1543
		jne @f
1544
			fcomp qword[ebx+sizeof.Point+Point.CoordX]
1545
			fstsw ax
1546
			sahf
1547
			jne .no_sel ;if( (x0==x1) && (x0!=x2) )
1548
			jmp .sel    ;if( x0==x1==x2 )
1549
		@@:
1550
		fld st0
1551
		fsub qword[ebx+Point.CoordX]
1552
		fxch st1
1553
		fsub qword[ebx+sizeof.Point+Point.CoordX]
1554
		fdivp
1555
1556
 
1557
		fld qword[ebx-sizeof.Point+Point.CoordY]
1558
		fcom qword[ebx+Point.CoordY]
1559
		fstsw ax
1560
		sahf
1561
		jne @f
1562
			fcomp qword[ebx+sizeof.Point+Point.CoordY]
1563
			fstsw ax
1564
			ffree st0 ;free (x0-x1)/(x0-x2)
1565
			fincstp
1566
			sahf
1567
			jne .no_sel ;if( (y0==y1) && (y0!=y2) )
1568
			jmp .sel    ;if( y0==y1==y2 )
1569
		@@:
1570
		fld st0
1571
		fsub qword[ebx+Point.CoordY]
1572
		fxch st1
1573
		fsub qword[ebx+sizeof.Point+Point.CoordY]
1574
		fdivp
1575
1576
 
1577
		fabs
1578
		fcomp qword[opt_koef] ;if( abs((x0-x1)/(x0-x2)-(y0-y1)/(y0-y2)) > 0.02)
1579
		fstsw ax
1580
		sahf
1581
		jae .no_sel
1582
		.sel:
1583
			bts dword[ebx+Point.Prop],PROP_BIT_SELECT
1584
		.no_sel:
1585
		loop .cycle0
1586
	.no_point:
1587
	ret
1588
endp
1589
1590
 
7360 IgorA 1591
; pPoi - указатель на данные точки
1592
align 4
1593
proc point_move_up, pObj:dword,pFig:dword,idFig:dword,pPoi:dword
1594
pushad
1595
	;изменение ссылок на точки
1596
	mov eax,[pObj]
1597
	mov ecx,[idFig]
1598
	mov edx,[eax+Object.FigCount]
1599
	or edx,edx
1600
	jz .end_f
1601
	mov edi,[eax+Object.FigData]
1602
1603
 
1604
	mov ecx,sizeof.Point
1605
	mov esi,[pPoi]
1606
	sub esi,ecx
1607
	mov edi,PoiData
1608
	rep movsb ;p(-1) > p_s
1609
	mov ecx,sizeof.Point
1610
	mov edi,[pPoi]
1611
	sub edi,ecx
1612
	rep movsb ;p(0) > p(-1)
1613
	mov esi,PoiData
1614
	mov ecx,sizeof.Point
1615
	rep movsb ;p_s > p(0)
1616
	.end_f:
1617
popad
1618
	ret
1619
endp
1620
1621
 
1622
proc mouse_left_d uses eax ebx
1623
	stdcall [tl_node_get_data],tree1
1624
	or eax,eax
1625
	jz .end_f
1626
1627
 
1628
	je @f
1629
	cmp [eax+Figure.OType],'Obj'
1630
	jne .end_f
7663 IgorA 1631
		mov eax,ObjData
7360 IgorA 1632
	@@:
1633
	call buf_get_mouse_coord
1634
	cmp eax,-1
1635
	je .end_f
1636
		mov [mouse_down_x],eax
1637
		mov [mouse_down_y],ebx
1638
	.end_f:
1639
	ret
1640
endp
1641
1642
 
1643
proc mouse_left_u uses eax ebx ecx
1644
	stdcall [tl_node_get_data],tree1
1645
	or eax,eax
1646
	jz .end_f
1647
1648
 
1649
	je @f
1650
	cmp [eax+Figure.OType],'Obj'
1651
	jne .end_f
7663 IgorA 1652
		mov eax,ObjData
7360 IgorA 1653
	@@:
1654
	mov ecx,eax
1655
1656
 
1657
	cmp eax,-1
1658
	je .end_f
1659
		sub eax,[mouse_down_x]
1660
		sub ebx,[mouse_down_y]
1661
		add [ecx+Figure.MCentrX],eax
1662
		sub [ecx+Figure.MCentrY],ebx
1663
		mov dword[offs_last_timer],0
1664
	.end_f:
1665
	ret
1666
endp
1667
1668
 
1669
; eax, ebx - портятся
1670
align 4
1671
proc mouse_right_d uses ecx edx edi
1672
locals
1673
	BufX dd ?
1674
	BufY dd ?
1675
	CentrX dd ?
1676
	CentrY dd ?
1677
	GrafX dd ? ;active point coord X
1678
	GrafY dd ? ;active point coord Y
1679
endl
1680
	call buf_get_mouse_coord
1681
	cmp eax,-1
1682
	je .end_f
1683
	mov [BufX],eax
1684
	mov [BufY],ebx
1685
1686
 
1687
	stdcall [tl_node_get_data],tree1
1688
	or eax,eax
1689
	jz .end_f
1690
1691
 
1692
	jne .end_fblo
1693
1694
 
1695
	mcall SF_KEYBOARD,SSF_GET_CONTROL_KEYS ;проверка Shift
1696
	bt eax,0
1697
	jc @f
1698
	bt eax,1
1699
	jc @f
1700
		;если не нажат Shift
1701
		stdcall sel_points_clear,ecx
1702
	@@:
1703
	mov ebx,ecx
1704
	mov ecx,[ebx+Figure.PoiCount]
1705
	;;jecxz .end_f
1706
	test ecx,ecx
1707
	jz .end_f
1708
1709
 
1710
	finit
1711
	fld qword[ebx+Figure.SizeY]
1712
	fmul qword[ebx+Figure.WScale]
1713
	fmul qword[ebx+Figure.MScale]
1714
	fchs
1715
	fistp dword[CentrY]
1716
	mov eax,[CentrY]
1717
	sub eax,[graf_margin_top]
1718
	sub eax,[graf_margin_bot]
1719
	add eax,[buf_0.h]
1720
	sar eax,1
1721
	add eax,[graf_margin_bot]
1722
	add eax,[ebx+Figure.MCentrY]
1723
	mov [CentrY],eax
1724
	fld qword[ebx+Figure.SizeX]
1725
	fmul qword[ebx+Figure.WScale]
1726
	fmul qword[ebx+Figure.MScale]
1727
	fchs
1728
	fistp dword[CentrX]
1729
	mov eax,[CentrX]
1730
	sub eax,[graf_margin_left]
1731
	sub eax,[graf_margin_right]
1732
	add eax,[buf_0.w]
1733
	sar eax,1
1734
	add eax,[graf_margin_left]
1735
	add eax,[ebx+Figure.MCentrX]
1736
	mov [CentrX],eax
1737
1738
 
1739
	.cycle0:
1740
		fld qword[edi+Point.CoordX]
1741
		fsub qword[ebx+Figure.MinX]
1742
		fmul qword[ebx+Figure.WScale]
1743
		fmul qword[ebx+Figure.MScale]
1744
		fiadd dword[CentrX]
1745
		fistp dword[GrafX]
1746
		fld qword[edi+Point.CoordY]
1747
		fsub qword[ebx+Figure.MinY]
1748
		fmul qword[ebx+Figure.WScale]
1749
		fmul qword[ebx+Figure.MScale]
1750
		fiadd dword[CentrY]
1751
		fisub dword[buf_0.h] ;invert coord Y
1752
		fchs
1753
		fistp dword[GrafY]
1754
1755
 
1756
		sub eax,[BufX]
1757
		bt eax,31
1758
		jnc @f
1759
			neg eax
1760
		@@:
1761
		mov edx,[GrafY]
1762
		sub edx,[BufY]
1763
		bt edx,31
1764
		jnc @f
1765
			neg edx
1766
		@@:
1767
		add eax,edx
1768
		cmp eax,7 ;приблизительное расстояние до точки
1769
		jg @f
1770
			;выделяем или снимаем выделение с точек
1771
			xor dword[edi+Point.Prop],(1 shl PROP_BIT_SELECT)
1772
		@@:
1773
1774
 
1775
		dec ecx
1776
	jnz .cycle0
1777
1778
 
1779
		;jmp .end_f
1780
	.end_fblo:
1781
1782
 
1783
	ret
1784
endp
1785