forked from vpinball/vpinball
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dragpoint.cpp
1104 lines (933 loc) · 28.5 KB
/
dragpoint.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "stdafx.h"
Vertex3Ds DragPoint::m_copyPoint;
bool DragPoint::m_pointCopied = false;
IHaveDragPoints::IHaveDragPoints()
{
m_propVisuals = nullptr;
m_propPosition = nullptr;
}
IHaveDragPoints::~IHaveDragPoints()
{
for (size_t i = 0; i < m_vdpoint.size(); i++)
m_vdpoint[i]->Release();
}
Vertex2D IHaveDragPoints::GetPointCenter() const
{
float minx = FLT_MAX;
float maxx = -FLT_MAX;
float miny = FLT_MAX;
float maxy = -FLT_MAX;
for (size_t i = 0; i < m_vdpoint.size(); i++)
{
const Vertex3Ds& v = m_vdpoint[i]->m_v;
minx = min(minx, v.x);
maxx = max(maxx, v.x);
miny = min(miny, v.y);
maxy = max(maxy, v.y);
}
return Vertex2D((maxx + minx)*0.5f, (maxy + miny)*0.5f);
}
void IHaveDragPoints::PutPointCenter(const Vertex2D& pv)
{
}
void IHaveDragPoints::FlipPointY(const Vertex2D& pvCenter)
{
STARTUNDOSELECT
Vertex2D newcenter = GetPointCenter();
for (size_t i = 0; i < m_vdpoint.size(); i++)
{
const float deltay = m_vdpoint[i]->m_v.y - pvCenter.y;
m_vdpoint[i]->m_v.y -= deltay*2.0f;
}
const float deltay = newcenter.y - pvCenter.y;
newcenter.y -= deltay*2.0f;
PutPointCenter(newcenter);
ReverseOrder();
STOPUNDOSELECT
}
void IHaveDragPoints::FlipPointX(const Vertex2D& pvCenter)
{
STARTUNDOSELECT
Vertex2D newcenter = GetPointCenter();
for (size_t i = 0; i < m_vdpoint.size(); i++)
{
const float deltax = m_vdpoint[i]->m_v.x - pvCenter.x;
m_vdpoint[i]->m_v.x -= deltax*2.0f;
}
const float deltax = newcenter.x - pvCenter.x;
newcenter.x -= deltax*2.0f;
PutPointCenter(newcenter);
ReverseOrder();
STOPUNDOSELECT
}
void IHaveDragPoints::RotateDialog()
{
DialogBoxParam(g_pvp->theInstance, MAKEINTRESOURCE(IDD_ROTATE),
g_pvp->GetHwnd(), RotateProc, (size_t)this->GetIEditable()->GetISelect());//(long)this);
}
void IHaveDragPoints::ScaleDialog()
{
DialogBoxParam(g_pvp->theInstance, MAKEINTRESOURCE(IDD_SCALE),
g_pvp->GetHwnd(), ScaleProc, (size_t)this->GetIEditable()->GetISelect());
}
void IHaveDragPoints::TranslateDialog()
{
DialogBoxParam(g_pvp->theInstance, MAKEINTRESOURCE(IDD_TRANSLATE),
g_pvp->GetHwnd(), TranslateProc, (size_t)this->GetIEditable()->GetISelect());
}
void IHaveDragPoints::RotatePoints(const float ang, const Vertex2D& pvCenter, const bool useElementCenter)
{
Vertex2D newcenter = GetPointCenter();
STARTUNDOSELECT
if (useElementCenter)
{
/* Don't use the pvCenter anymore! pvCenter is the mouse position when rotating is activated.
Because the mouse position (rotation center) isn't shown in the editor use the element's center returned by GetPointCenter() */
const float centerx = newcenter.x;
const float centery = newcenter.y;
const float sn = sinf(ANGTORAD(ang));
const float cs = cosf(ANGTORAD(ang));
for (size_t i = 0; i < m_vdpoint.size(); i++)
{
DragPoint * const pdp1 = m_vdpoint[i];
const float dx = pdp1->m_v.x - centerx;
const float dy = pdp1->m_v.y - centery;
const float dx2 = cs*dx - sn*dy;
const float dy2 = cs*dy + sn*dx;
pdp1->m_v.x = centerx + dx2;
pdp1->m_v.y = centery + dy2;
}
}
else
{
const float centerx = pvCenter.x;
const float centery = pvCenter.y;
const float sn = sinf(ANGTORAD(ang));
const float cs = cosf(ANGTORAD(ang));
for (size_t i = 0; i < m_vdpoint.size(); i++)
{
DragPoint * const pdp1 = m_vdpoint[i];
const float dx = pdp1->m_v.x - centerx;
const float dy = pdp1->m_v.y - centery;
const float dx2 = cs*dx - sn*dy;
const float dy2 = cs*dy + sn*dx;
pdp1->m_v.x = centerx + dx2;
pdp1->m_v.y = centery + dy2;
}
// Move object center as well (if rotating around object center,
// this will have no effect)
{
const float dx = newcenter.x - centerx;
const float dy = newcenter.y - centery;
const float dx2 = cs*dx - sn*dy;
const float dy2 = cs*dy + sn*dx;
newcenter.x = centerx + dx2;
newcenter.y = centery + dy2;
PutPointCenter(newcenter);
}
}
STOPUNDOSELECT
}
void IHaveDragPoints::ScalePoints(const float scalex, const float scaley, const Vertex2D& pvCenter, const bool useElementCenter)
{
Vertex2D newcenter = GetPointCenter();
STARTUNDOSELECT
if (useElementCenter)
{
/* Don't use the pvCenter anymore! pvCenter is the mouse position when scaling is activated.
Because the mouse position (scaling center) isn't shown in the editor use the element's center returned by GetPointCenter() */
const float centerx = newcenter.x;
const float centery = newcenter.y;
for (size_t i = 0; i < m_vdpoint.size(); i++)
{
DragPoint * const pdp1 = m_vdpoint[i];
const float dx = (pdp1->m_v.x - centerx) * scalex;
const float dy = (pdp1->m_v.y - centery) * scaley;
pdp1->m_v.x = centerx + dx;
pdp1->m_v.y = centery + dy;
}
}
else
{
const float centerx = pvCenter.x;
const float centery = pvCenter.y;
for (size_t i = 0; i < m_vdpoint.size(); i++)
{
DragPoint * const pdp1 = m_vdpoint[i];
const float dx = (pdp1->m_v.x - centerx) * scalex;
const float dy = (pdp1->m_v.y - centery) * scaley;
pdp1->m_v.x = centerx + dx;
pdp1->m_v.y = centery + dy;
}
// Move object center as well (if scaling from object center,
// this will have no effect)
{
const float dx = (newcenter.x - centerx) * scalex;
const float dy = (newcenter.y - centery) * scaley;
newcenter.x = centerx + dx;
newcenter.y = centery + dy;
PutPointCenter(newcenter);
}
}
STOPUNDOSELECT
}
void IHaveDragPoints::TranslatePoints(const Vertex2D &pvOffset)
{
STARTUNDOSELECT
for (size_t i = 0; i < m_vdpoint.size(); i++)
{
DragPoint * const pdp1 = m_vdpoint[i];
pdp1->m_v.x += pvOffset.x;
pdp1->m_v.y += pvOffset.y;
}
Vertex2D newcenter = GetPointCenter();
newcenter.x += pvOffset.x;
newcenter.y += pvOffset.y;
PutPointCenter(newcenter);
STOPUNDOSELECT
}
void IHaveDragPoints::ReverseOrder()
{
if (m_vdpoint.empty())
return;
// Reverse order of points (switches winding, reverses inside/outside)
std::reverse(m_vdpoint.begin(), m_vdpoint.end());
const bool slingshotTemp = m_vdpoint[0]->m_slingshot;
for (size_t i = 0; i < m_vdpoint.size() - 1; i++)
{
DragPoint * const pdp1 = m_vdpoint[i];
const DragPoint * const pdp2 = m_vdpoint[i + 1];
pdp1->m_slingshot = pdp2->m_slingshot;
}
m_vdpoint[m_vdpoint.size() - 1]->m_slingshot = slingshotTemp;
}
//
// license:GPLv3+
// Ported at: VisualPinball.Engine/Math/DragPoint.cs
//
void IHaveDragPoints::GetTextureCoords(const std::vector<RenderVertex> & vv, float **ppcoords)
{
std::vector<int> vitexpoints;
std::vector<int> virenderpoints;
bool noCoords = false;
const int cpoints = (int)vv.size();
int icontrolpoint = 0;
*ppcoords = new float[cpoints];
memset(*ppcoords, 0, sizeof(float)*cpoints);
for (int i = 0; i < cpoints; ++i)
{
const RenderVertex * const prv = &vv[i];
if (prv->controlPoint)
{
if (!m_vdpoint[icontrolpoint]->m_autoTexture)
{
vitexpoints.push_back(icontrolpoint);
virenderpoints.push_back(i);
}
++icontrolpoint;
}
}
if (vitexpoints.empty())
{
// Special case - no texture coordinates were specified
// Make them up starting at point 0
vitexpoints.push_back(0);
virenderpoints.push_back(0);
noCoords = true;
}
// Wrap the array around so we cover the last section
vitexpoints.push_back(vitexpoints[0] + (int)m_vdpoint.size());
virenderpoints.push_back(virenderpoints[0] + cpoints);
for (int i = 0; i < (int)vitexpoints.size() - 1; ++i)
{
const int startrenderpoint = virenderpoints[i] % cpoints;
int endrenderpoint = virenderpoints[(i < cpoints - 1) ? (i + 1) : 0] % cpoints;
float starttexcoord;
float endtexcoord;
if (noCoords)
{
starttexcoord = 0.0f;
endtexcoord = 1.0f;
}
else
{
starttexcoord = m_vdpoint[vitexpoints[i] % m_vdpoint.size()]->m_texturecoord;
endtexcoord = m_vdpoint[vitexpoints[i + 1] % m_vdpoint.size()]->m_texturecoord;
}
const float deltacoord = endtexcoord - starttexcoord;
if (endrenderpoint <= startrenderpoint)
endrenderpoint += cpoints;
float totallength = 0.0f;
for (int l = startrenderpoint; l < endrenderpoint; ++l)
{
const Vertex2D * const pv1 = (Vertex2D *)&vv[l % cpoints];
const Vertex2D * const pv2 = (Vertex2D *)&vv[(l + 1) % cpoints];
const float dx = pv1->x - pv2->x;
const float dy = pv1->y - pv2->y;
const float length = sqrtf(dx*dx + dy*dy);
totallength += length;
}
float partiallength = 0.0f;
for (int l = startrenderpoint; l < endrenderpoint; ++l)
{
const Vertex2D * const pv1 = (Vertex2D *)&vv[l % cpoints];
const Vertex2D * const pv2 = (Vertex2D *)&vv[(l + 1) % cpoints];
const float dx = pv1->x - pv2->x;
const float dy = pv1->y - pv2->y;
const float length = sqrtf(dx*dx + dy*dy);
if (totallength == 0.0f)
totallength = 1.0f;
const float texcoord = partiallength / totallength;
(*ppcoords)[l % cpoints] = (texcoord * deltacoord) + starttexcoord;
partiallength += length;
}
}
}
//
// end of license:GPLv3+, back to 'old MAME'-like
//
void IHaveDragPoints::ClearPointsForOverwrite()
{
for (size_t i = 0; i < m_vdpoint.size(); i++)
{
if (m_vdpoint[i]->m_selectstate != eNotSelected/*GetPTable()->m_pselcur == m_vdpoint[i]*/)
{
//GetPTable()->SetSel(GetPTable());
GetPTable()->AddMultiSel(GetPTable(), false, true, false);
}
m_vdpoint[i]->Release();
}
m_vdpoint.clear();
}
HRESULT IHaveDragPoints::SavePointData(IStream *pstm, HCRYPTHASH hcrypthash)
{
BiffWriter bw(pstm, hcrypthash);
for (size_t i = 0; i < m_vdpoint.size(); i++)
{
bw.WriteTag(FID(DPNT));
CComObject<DragPoint> * const pdp = m_vdpoint[i];
bw.WriteStruct(FID(VCEN), &(pdp->m_v), sizeof(Vertex2D));
bw.WriteFloat(FID(POSZ), pdp->m_v.z);
bw.WriteBool(FID(SMTH), pdp->m_smooth);
bw.WriteBool(FID(SLNG), pdp->m_slingshot);
bw.WriteBool(FID(ATEX), pdp->m_autoTexture);
bw.WriteFloat(FID(TEXC), pdp->m_texturecoord);
((ISelect *)pdp)->SaveData(pstm, hcrypthash);
bw.WriteTag(FID(ENDB));
}
return S_OK;
}
void IHaveDragPoints::LoadPointToken(int id, BiffReader *pbr, int version)
{
if (id == FID(DPNT))
{
CComObject<DragPoint> *pdp;
CComObject<DragPoint>::CreateInstance(&pdp);
if (pdp)
{
pdp->AddRef();
pdp->Init(this, 0.f, 0.f, 0.f, false);
m_vdpoint.push_back(pdp);
BiffReader br(pbr->m_pistream, pdp, nullptr, version, pbr->m_hcrypthash, pbr->m_hcryptkey);
br.Load();
}
}
}
void DragPoint::Init(IHaveDragPoints *pihdp, const float x, const float y, const float z, const bool smooth)
{
m_pihdp = pihdp;
m_smooth = smooth;
m_slingshot = false;
m_v.x = x;
m_v.y = y;
m_v.z = z;
m_calcHeight = 0.0f;
m_autoTexture = true;
m_texturecoord = 0.0f;
m_menuid = (pihdp->GetIEditable()->GetItemType() == eItemRubber) ? IDR_POINTMENU_SMOOTH : IDR_POINTMENU;
}
void DragPoint::OnLButtonDown(int x, int y)
{
ISelect::OnLButtonDown(x, y);
m_pihdp->GetIEditable()->SetDirtyDraw();
}
void DragPoint::OnLButtonUp(int x, int y)
{
ISelect::OnLButtonUp(x, y);
m_pihdp->GetIEditable()->SetDirtyDraw();
}
void DragPoint::SetObjectPos()
{
m_vpinball->SetObjectPosCur(m_v.x, m_v.y);
}
void DragPoint::MoveOffset(const float dx, const float dy)
{
m_v.x += dx;
m_v.y += dy;
}
Vertex2D DragPoint::GetCenter() const
{
return Vertex2D(m_v.x, m_v.y);
}
void DragPoint::PutCenter(const Vertex2D& pv)
{
m_v.x = pv.x;
m_v.y = pv.y;
}
void DragPoint::EditMenu(CMenu &menu)
{
menu.CheckMenuItem(ID_POINTMENU_SMOOTH, MF_BYCOMMAND | (m_smooth ? MF_CHECKED : MF_UNCHECKED));
//EnableMenuItem(hmenu, ID_POINTMENU_SLINGSHOT, MF_BYCOMMAND | (m_fSmooth ? MF_GRAYED : MF_ENABLED));
menu.CheckMenuItem(ID_POINTMENU_SLINGSHOT, MF_BYCOMMAND | ((m_slingshot && !m_smooth) ? MF_CHECKED : MF_UNCHECKED));
}
void DragPoint::Delete()
{
if ((int)m_pihdp->m_vdpoint.size() > m_pihdp->GetMinimumPoints()) // Can't allow less points than the user can recover from
{
m_pihdp->GetIEditable()->BeginUndo();
m_pihdp->GetIEditable()->MarkForUndo();
RemoveFromVectorSingle(m_pihdp->m_vdpoint, (CComObject<DragPoint> *)this);
m_pihdp->GetIEditable()->EndUndo();
m_pihdp->GetIEditable()->SetDirtyDraw();
Release();
}
}
void DragPoint::Uncreate()
{
RemoveFromVectorSingle(m_pihdp->m_vdpoint, (CComObject<DragPoint> *)this);
Release();
}
void DragPoint::DoCommand(int icmd, int x, int y)
{
ISelect::DoCommand(icmd, x, y);
switch (icmd)
{
case ID_POINTMENU_SMOOTH:
{
IEditable * const pedit = m_pihdp->GetIEditable();
pedit->BeginUndo();
pedit->MarkForUndo();
m_smooth = !m_smooth;
const int index2 = (FindIndexOf(m_pihdp->m_vdpoint, (CComObject<DragPoint> *)this) - 1 + (int)m_pihdp->m_vdpoint.size()) % (int)m_pihdp->m_vdpoint.size();
if (m_smooth && m_slingshot)
{
m_slingshot = false;
}
if (m_smooth && m_pihdp->m_vdpoint[index2]->m_slingshot)
{
m_pihdp->m_vdpoint[index2]->m_slingshot = false;
}
pedit->EndUndo();
pedit->SetDirtyDraw();
break;
}
case ID_POINTMENU_SLINGSHOT:
{
IEditable * const pedit = m_pihdp->GetIEditable();
pedit->BeginUndo();
pedit->MarkForUndo();
m_slingshot = !m_slingshot;
if (m_slingshot)
{
m_smooth = false;
const int index2 = (FindIndexOf(m_pihdp->m_vdpoint, (CComObject<DragPoint> *)this) + 1) % m_pihdp->m_vdpoint.size();
m_pihdp->m_vdpoint[index2]->m_smooth = false;
}
pedit->EndUndo();
pedit->SetDirtyDraw();
break;
}
}
}
void DragPoint::SetSelectFormat(Sur *psur)
{
psur->SetFillColor(RGB(150, 200, 255));
}
void DragPoint::SetMultiSelectFormat(Sur *psur)
{
psur->SetFillColor(RGB(200, 225, 255));
}
STDMETHODIMP DragPoint::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_IControlPoint,
};
for (size_t i = 0; i < sizeof(arr) / sizeof(arr[0]); i++)
{
if (InlineIsEqualGUID(*arr[i], riid))
return S_OK;
}
return S_FALSE;
}
bool DragPoint::LoadToken(const int id, BiffReader * const pbr)
{
switch (id)
{
case FID(VCEN): pbr->GetStruct(&m_v, sizeof(Vertex2D)); break;
case FID(POSZ): pbr->GetFloat(m_v.z); break;
case FID(SMTH): pbr->GetBool(m_smooth); break;
case FID(SLNG): pbr->GetBool(m_slingshot); break;
case FID(ATEX): pbr->GetBool(m_autoTexture); break;
case FID(TEXC): pbr->GetFloat(m_texturecoord); break;
default: ISelect::LoadToken(id, pbr); break;
}
return true;
}
void DragPoint::Copy()
{
m_copyPoint = m_v;
m_pointCopied = true;
}
void DragPoint::Paste()
{
if (m_pointCopied)
m_v = m_copyPoint;
}
STDMETHODIMP DragPoint::get_X(float *pVal)
{
*pVal = m_v.x;
return S_OK;
}
STDMETHODIMP DragPoint::put_X(float newVal)
{
STARTUNDOSELECT
m_v.x = newVal;
STOPUNDOSELECT
return S_OK;
}
STDMETHODIMP DragPoint::get_Y(float *pVal)
{
*pVal = m_v.y;
return S_OK;
}
STDMETHODIMP DragPoint::put_Y(float newVal)
{
STARTUNDOSELECT
m_v.y = newVal;
STOPUNDOSELECT
return S_OK;
}
STDMETHODIMP DragPoint::get_Z(float *pVal)
{
*pVal = m_v.z;
return S_OK;
}
STDMETHODIMP DragPoint::put_Z(float newVal)
{
STARTUNDOSELECT
m_v.z = newVal;
STOPUNDOSELECT
return S_OK;
}
STDMETHODIMP DragPoint::get_CalcHeight(float *pVal)
{
*pVal = m_calcHeight;
return S_OK;
}
STDMETHODIMP DragPoint::get_Smooth(VARIANT_BOOL *pVal)
{
*pVal = FTOVB(m_smooth);
return S_OK;
}
STDMETHODIMP DragPoint::put_Smooth(VARIANT_BOOL newVal)
{
STARTUNDOSELECT
m_smooth = VBTOb(newVal);
STOPUNDOSELECT
return S_OK;
}
STDMETHODIMP DragPoint::get_IsAutoTextureCoordinate(VARIANT_BOOL *pVal)
{
*pVal = FTOVB(m_autoTexture);
return S_OK;
}
STDMETHODIMP DragPoint::put_IsAutoTextureCoordinate(VARIANT_BOOL newVal)
{
STARTUNDOSELECT
m_autoTexture = VBTOb(newVal);
STOPUNDOSELECT
return S_OK;
}
STDMETHODIMP DragPoint::get_TextureCoordinateU(float *pVal)
{
*pVal = m_texturecoord;
return S_OK;
}
STDMETHODIMP DragPoint::put_TextureCoordinateU(float newVal)
{
STARTUNDOSELECT
m_texturecoord = newVal;
STOPUNDOSELECT
return S_OK;
}
int rotateApplyCount = 0;
INT_PTR CALLBACK RotateProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
ISelect *psel;
switch (uMsg)
{
case WM_INITDIALOG:
{
rotateApplyCount = 0;
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
psel = (ISelect *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
const float angle = psel->GetRotate();
SendDlgItemMessage(hwndDlg, IDC_CHECK_ROTATE_CENTER, BM_SETCHECK, BST_CHECKED, 0);
string szT;
f2sz(angle, szT);
SetDlgItemText(hwndDlg, IDC_ROTATEBY, szT.c_str());
const Vertex2D v = psel->GetCenter();
f2sz(v.x, szT);
SetDlgItemText(hwndDlg, IDC_CENTERX, szT.c_str());
f2sz(v.y, szT);
SetDlgItemText(hwndDlg, IDC_CENTERY, szT.c_str());
}
return TRUE;
break;
case WM_CLOSE:
EndDialog(hwndDlg, FALSE);
break;
case WM_COMMAND:
psel = (ISelect *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
switch (LOWORD(wParam))
{
case IDC_CHECK_ROTATE_CENTER:
{
switch (HIWORD(wParam))
{
case BN_CLICKED:
{
string szT;
if (!(SendDlgItemMessage(hwndDlg, IDC_CHECK_ROTATE_CENTER, BM_GETCHECK, 0, 0) == BST_CHECKED))
{
f2sz(g_pvp->m_mouseCursorPosition.x, szT);
SetDlgItemText(hwndDlg, IDC_CENTERX, szT.c_str());
f2sz(g_pvp->m_mouseCursorPosition.y, szT);
SetDlgItemText(hwndDlg, IDC_CENTERY, szT.c_str());
}
else
{
const Vertex2D v = psel->GetCenter();
f2sz(v.x, szT);
SetDlgItemText(hwndDlg, IDC_CENTERX, szT.c_str());
f2sz(v.y, szT);
SetDlgItemText(hwndDlg, IDC_CENTERY, szT.c_str());
}
break;
}
default:
break;
}
}
default:
break;
}
switch (HIWORD(wParam))
{
case BN_CLICKED:
switch (LOWORD(wParam))
{
case IDOK:
{
if (rotateApplyCount == 0)
{
char szT[256];
GetDlgItemText(hwndDlg, IDC_ROTATEBY, szT, 255);
const float f = sz2f(szT);
const bool useElementCenter = (SendDlgItemMessage(hwndDlg, IDC_CHECK_ROTATE_CENTER, BM_GETCHECK, 0, 0) == BST_CHECKED);
GetDlgItemText(hwndDlg, IDC_CENTERX, szT, 255);
Vertex2D v;
v.x = sz2f(szT);
GetDlgItemText(hwndDlg, IDC_CENTERY, szT, 255);
v.y = sz2f(szT);
psel->Rotate(f, v, useElementCenter);
}
EndDialog(hwndDlg, TRUE);
break;
}
case IDC_ROTATE_APPLY_BUTTON:
{
rotateApplyCount++;
char szT[256];
GetDlgItemText(hwndDlg, IDC_ROTATEBY, szT, 255);
const float f = sz2f(szT);
const bool useElementCenter = (SendDlgItemMessage(hwndDlg, IDC_CHECK_ROTATE_CENTER, BM_GETCHECK, 0, 0) == BST_CHECKED);
GetDlgItemText(hwndDlg, IDC_CENTERX, szT, 255);
Vertex2D v;
v.x = sz2f(szT);
GetDlgItemText(hwndDlg, IDC_CENTERY, szT, 255);
v.y = sz2f(szT);
psel->Rotate(f, v, useElementCenter);
psel->GetPTable()->SetDirtyDraw();
break;
}
case IDC_ROTATE_UNDO_BUTTON:
{
if (rotateApplyCount > 0)
{
rotateApplyCount--;
psel->GetPTable()->Undo();
psel->GetPTable()->SetDirtyDraw();
}
break;
}
case IDCANCEL:
if (rotateApplyCount > 0)
{
for (int i = 0; i < rotateApplyCount; i++) psel->GetPTable()->Undo();
psel->GetPTable()->SetDirtyDraw();
}
EndDialog(hwndDlg, FALSE);
break;
}
break;
}
break;
}
return FALSE;
}
int scaleApplyCount = 0;
INT_PTR CALLBACK ScaleProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
ISelect *psel;
switch (uMsg)
{
case WM_INITDIALOG:
{
scaleApplyCount = 0;
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
psel = (ISelect *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
Vertex2D v = psel->GetScale();
string szT;
f2sz(v.x, szT);
SetDlgItemText(hwndDlg, IDC_SCALEFACTOR, szT.c_str());
f2sz(v.y, szT);
SetDlgItemText(hwndDlg, IDC_SCALEY, szT.c_str());
v = psel->GetCenter();
SendDlgItemMessage(hwndDlg, IDC_CHECK_SCALE_CENTER, BM_SETCHECK, BST_CHECKED, 0);
f2sz(v.x, szT);
SetDlgItemText(hwndDlg, IDC_CENTERX, szT.c_str());
f2sz(v.y, szT);
SetDlgItemText(hwndDlg, IDC_CENTERY, szT.c_str());
SendDlgItemMessage(hwndDlg, IDC_SQUARE, BM_SETCHECK, TRUE, 0);
EnableWindow(GetDlgItem(hwndDlg, IDC_SCALEY), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC_SCALEY), FALSE);
}
return TRUE;
break;
case WM_CLOSE:
EndDialog(hwndDlg, FALSE);
break;
case WM_COMMAND:
psel = (ISelect *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
switch (LOWORD(wParam))
{
case IDC_CHECK_SCALE_CENTER:
{
switch (HIWORD(wParam))
{
case BN_CLICKED:
{
string szT;
if (!(SendDlgItemMessage(hwndDlg, IDC_CHECK_SCALE_CENTER, BM_GETCHECK, 0, 0) == BST_CHECKED))
{
f2sz(g_pvp->m_mouseCursorPosition.x, szT);
SetDlgItemText(hwndDlg, IDC_CENTERX, szT.c_str());
f2sz(g_pvp->m_mouseCursorPosition.y, szT);
SetDlgItemText(hwndDlg, IDC_CENTERY, szT.c_str());
}
else
{
const Vertex2D v = psel->GetCenter();
f2sz(v.x, szT);
SetDlgItemText(hwndDlg, IDC_CENTERX, szT.c_str());
f2sz(v.y, szT);
SetDlgItemText(hwndDlg, IDC_CENTERY, szT.c_str());
}
break;
}
default:
break;
}
}
default:
break;
}
switch (HIWORD(wParam))
{
case BN_CLICKED:
switch (LOWORD(wParam))
{
case IDOK:
{
if (scaleApplyCount == 0)
{
char szT[256];
GetDlgItemText(hwndDlg, IDC_SCALEFACTOR, szT, 255);
const float fx = sz2f(szT);
const size_t checked = SendDlgItemMessage(hwndDlg, IDC_SQUARE, BM_GETCHECK, 0, 0);
float fy;
if (checked)
{
fy = fx;
}
else
{
GetDlgItemText(hwndDlg, IDC_SCALEY, szT, 255);
fy = sz2f(szT);
}
GetDlgItemText(hwndDlg, IDC_CENTERX, szT, 255);
Vertex2D v;
v.x = sz2f(szT);
GetDlgItemText(hwndDlg, IDC_CENTERY, szT, 255);
v.y = sz2f(szT);
const bool useElementCenter = (SendDlgItemMessage(hwndDlg, IDC_CHECK_SCALE_CENTER, BM_GETCHECK, 0, 0) == BST_CHECKED);
//pihdp->ScalePoints(fx, fy, &v);
psel->Scale(fx, fy, v, useElementCenter);
}
EndDialog(hwndDlg, TRUE);
break;
}
case IDC_SCALE_APPLY_BUTTON:
{
scaleApplyCount++;
char szT[256];
GetDlgItemText(hwndDlg, IDC_SCALEFACTOR, szT, 255);
const float fx = sz2f(szT);
const size_t checked = SendDlgItemMessage(hwndDlg, IDC_SQUARE, BM_GETCHECK, 0, 0);
float fy;
if (checked)
{
fy = fx;
}
else
{
GetDlgItemText(hwndDlg, IDC_SCALEY, szT, 255);
fy = sz2f(szT);
}
GetDlgItemText(hwndDlg, IDC_CENTERX, szT, 255);
Vertex2D v;
v.x = sz2f(szT);
GetDlgItemText(hwndDlg, IDC_CENTERY, szT, 255);
v.y = sz2f(szT);
const bool useElementCenter = (SendDlgItemMessage(hwndDlg, IDC_CHECK_SCALE_CENTER, BM_GETCHECK, 0, 0) == BST_CHECKED);
//pihdp->ScalePoints(fx, fy, &v);
psel->Scale(fx, fy, v, useElementCenter);
psel->GetPTable()->SetDirtyDraw();
break;
}
case IDC_SCALE_UNDO_BUTTON:
{
if (scaleApplyCount > 0)
{
scaleApplyCount--;
psel->GetPTable()->Undo();
psel->GetPTable()->SetDirtyDraw();
}
break;
}
case IDCANCEL:
if (scaleApplyCount > 0)
{
for (int i = 0; i < scaleApplyCount; i++) psel->GetPTable()->Undo();
psel->GetPTable()->SetDirtyDraw();
}
EndDialog(hwndDlg, FALSE);
break;
case IDC_SQUARE:
{