/
FUSIONView.cpp
2448 lines (2075 loc) · 55.7 KB
/
FUSIONView.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
/****************************************************************************************/
/* FusionView.cpp */
/* */
/* Author: Jim Mischel, Ken Baird, Jeff Lomax, John Moore */
/* Description: MFC view stuff... Alot of the editor UI functionality is here */
/* */
/* The contents of this file are subject to the Genesis3D Public License */
/* Version 1.01 (the "License"); you may not use this file except in */
/* compliance with the License. You may obtain a copy of the License at */
/* http://www.genesis3d.com */
/* */
/* Software distributed under the License is distributed on an "AS IS" */
/* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See */
/* the License for the specific language governing rights and limitations */
/* under the License. */
/* */
/* The Original Code is Genesis3D, released March 25, 1999. */
/*Genesis3D Version 1.1 released November 15, 1999 */
/* Copyright (C) 1999 WildTangent, Inc. All Rights Reserved */
/* */
/****************************************************************************************/
#include "stdafx.h"
#include "FUSIONView.h"
#include "FUSIONDoc.h"
#include "KeyEditDlg.h"
#include <assert.h>
#include "FusionTabControls.h"
#include "BrushEntityDialog.h"
#include "units.h"
#include "face.h"
#include "ram.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define AXIS_X 0x1
#define AXIS_Y 0x2
#define AXIS_Z 0x4
#define MAX_PIXEL_DRAG_START_DIST (12.0f)
int CFusionView::mCY_DRAG = 2 ;
int CFusionView::mCX_DRAG = 2 ;
IMPLEMENT_DYNCREATE(CFusionView, CView)
BEGIN_MESSAGE_MAP(CFusionView, CView)
ON_MESSAGE(WM_USER_COMPILE_MSG, OnCompileMessage)
ON_MESSAGE(WM_USER_COMPILE_ERR, OnCompileError)
ON_MESSAGE(WM_USER_COMPILE_DONE, OnCompileDone)
//{{AFX_MSG_MAP(CFusionView)
ON_WM_SIZE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_TOOLS_CAMERA, OnToolsCamera)
ON_UPDATE_COMMAND_UI(ID_TOOLS_CAMERA, OnUpdateToolsCamera)
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_COMMAND(ID_AXIS_X, OnAxisX)
ON_UPDATE_COMMAND_UI(ID_AXIS_X, OnUpdateAxisX)
ON_COMMAND(ID_AXIS_Y, OnAxisY)
ON_UPDATE_COMMAND_UI(ID_AXIS_Y, OnUpdateAxisY)
ON_COMMAND(ID_AXIS_Z, OnAxisZ)
ON_UPDATE_COMMAND_UI(ID_AXIS_Z, OnUpdateAxisZ)
ON_COMMAND(ID_TOOLS_BRUSH_MOVEROTATEBRUSH, OnToolsBrushMoverotatebrush)
ON_UPDATE_COMMAND_UI(ID_TOOLS_BRUSH_MOVEROTATEBRUSH, OnUpdateToolsBrushMoverotatebrush)
ON_COMMAND(ID_TOOLS_BRUSH_SCALEBRUSH, OnToolsBrushScalebrush)
ON_UPDATE_COMMAND_UI(ID_TOOLS_BRUSH_SCALEBRUSH, OnUpdateToolsBrushScalebrush)
ON_COMMAND(ID_TOOLS_BRUSH_SHOWBRUSH, OnToolsBrushShowbrush)
ON_UPDATE_COMMAND_UI(ID_TOOLS_BRUSH_SHOWBRUSH, OnUpdateToolsBrushShowbrush)
ON_WM_ERASEBKGND()
ON_COMMAND(ID_TOOLS_BRUSH_SHEARBRUSH, OnToolsBrushShearbrush)
ON_UPDATE_COMMAND_UI(ID_TOOLS_BRUSH_SHEARBRUSH, OnUpdateToolsBrushShearbrush)
ON_UPDATE_COMMAND_UI(ID_GROUPS_MAKENEWGROUP, OnUpdateBrushGroupsMakenewgroup)
ON_UPDATE_COMMAND_UI(ID_BRUSH_GROUPS_ADDTOGROUP, OnUpdateBrushGroupsAddtogroup)
ON_COMMAND(ID_TOOLS_BRUSH_ROTATE90, OnToolsBrushRotate45)
ON_COMMAND(ID_TOOLS_BRUSH_MOVESELECTEDBRUSHES, OnToolsBrushMoveselectedbrushes)
ON_UPDATE_COMMAND_UI(ID_TOOLS_BRUSH_MOVESELECTEDBRUSHES, OnUpdateToolsBrushMoveselectedbrushes)
ON_COMMAND(ID_TOOLS_TEMPLATE, OnToolsTemplate)
ON_UPDATE_COMMAND_UI(ID_TOOLS_TEMPLATE, OnUpdateToolsTemplate)
ON_UPDATE_COMMAND_UI(ID_TOOLS_BRUSH_ROTATE90, OnUpdateToolsBrushRotate45)
ON_COMMAND(ID_BRUSH_REMOVESELECTEDFROMGROUP, OnBrushRemoveselectedfromgroup)
ON_UPDATE_COMMAND_UI(ID_BRUSH_REMOVESELECTEDFROMGROUP, OnUpdateBrushRemoveselectedfromgroup)
ON_COMMAND(ID_BRUSH_GROUPS_ADDTOGROUP, OnBrushGroupsAddtogroup)
ON_COMMAND(ID_DESELECTALL, OnDeselectall)
ON_UPDATE_COMMAND_UI(ID_DESELECTALL, OnUpdateDeselectall)
ON_COMMAND(ID_SELECTALL, OnSelectall)
ON_UPDATE_COMMAND_UI(ID_SELECTALL, OnUpdateSelectall)
ON_COMMAND(ID_TOOLS_SCALEWORLD, OnToolsScaleworld)
ON_COMMAND(ID_TOOLS_BRUSH_MAKENEWEST, OnToolsBrushMakenewest)
ON_COMMAND(ID_TOOLS_SETTEXTURESCALE, OnToolsSettexturescale)
ON_COMMAND(ID_TOOLS_NEXTBRUSH, OnToolsNextbrush)
ON_COMMAND(ID_TOOLS_PREVBRUSH, OnToolsPrevbrush)
ON_COMMAND(ID_TOOLS_ADDTOLEVEL, OnToolsAddtolevel)
ON_UPDATE_COMMAND_UI(ID_TOOLS_ADDTOLEVEL, OnUpdateToolsAddtolevel)
ON_COMMAND(ID_VIEW_ZOOMIN, OnViewZoomin)
ON_UPDATE_COMMAND_UI(ID_VIEW_ZOOMIN, OnUpdateViewZoomin)
ON_COMMAND(ID_VIEW_ZOOMOUT, OnViewZoomout)
ON_UPDATE_COMMAND_UI(ID_VIEW_ZOOMOUT, OnUpdateViewZoomout)
ON_COMMAND(ID_CENTERTHING, OnCenterthing)
ON_UPDATE_COMMAND_UI(ID_CENTERTHING, OnUpdateCenterthing)
ON_COMMAND(ID_QUICK_BACKUP, OnQuickBackup)
ON_WM_MBUTTONUP()
ON_COMMAND(ID_QUICK_RESTORE, OnQuickRestore)
//}}AFX_MSG_MAP
ON_COMMAND_RANGE( ID_VIEW_3DWIREFRAME, ID_VIEW_TEXTUREVIEW, OnViewType)
ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_3DWIREFRAME, ID_VIEW_TEXTUREVIEW, OnViewTypeCmdUi)
END_MESSAGE_MAP()
#define SIDE_LEFT 1
#define SIDE_RIGHT 2
#define SIDE_TOP 4
#define SIDE_BOTTOM 8
void CFusionView::OnUpdateCenterthing(CCmdUI* pCmdUI)
{
CFusionDoc *pDoc = GetDocument ();
if ((pDoc->mModeTool == ID_TOOLS_TEMPLATE) &&
((mViewType == ID_VIEW_TOPVIEW) || (mViewType == ID_VIEW_SIDEVIEW) || (mViewType == ID_VIEW_FRONTVIEW)))
{
pCmdUI->Enable (TRUE);
}
else
{
pCmdUI->Enable (FALSE);
}
}
// Center the template brush or entity in the selected view.
// Doesn't work for 3d views...
void CFusionView::OnCenterthing()
{
CFusionDoc *pDoc = GetDocument ();
// only works on templates
if ((pDoc->mModeTool != ID_TOOLS_TEMPLATE) ||
((mViewType != ID_VIEW_TOPVIEW) && (mViewType != ID_VIEW_SIDEVIEW) && (mViewType != ID_VIEW_FRONTVIEW)))
{
return;
}
geVec3d NewWorldPos = Render_GetViewCenter (VCam);
// Get the current thing's position...
geVec3d CurrentThingPos;
if (pDoc->TempEnt)
{
CurrentThingPos = pDoc->mRegularEntity.mOrigin;
}
else
{
if (pDoc->CurBrush == NULL)
{
return;
}
Brush_Center (pDoc->CurBrush, &CurrentThingPos);
}
// Compute delta required to get thing to NewWorldPos.
// One dimension won't be changed (i.e. in the top view, the Y won't be modified)
geVec3d MoveDelta;
geVec3d_Subtract (&NewWorldPos, &CurrentThingPos, &MoveDelta);
switch (mViewType)
{
case ID_VIEW_TOPVIEW :
MoveDelta.Y = 0.0f;
break;
case ID_VIEW_SIDEVIEW :
MoveDelta.X = 0.0f;
break;
case ID_VIEW_FRONTVIEW :
MoveDelta.Z = 0.0f;
break;
default :
// don't do nothin!
assert (0);
}
// We've computed the delta, so move the thing...
pDoc->MoveTemplateBrush (&MoveDelta);
pDoc->UpdateAllViews( UAV_ALL3DVIEWS, NULL );
}
static geBoolean IsKeyDown (int Key)
{
int KeyState;
KeyState = ::GetAsyncKeyState (Key);
return (KeyState & 0x8000);
}
// Prevent axis movement. View space clipping.
void CFusionView::LockAxisView (int *dx, int *dy)
{
CFusionDoc *pDoc = GetDocument ();
int mLockAxis = pDoc->GetLockAxis ();
switch (mViewType)
{
case ID_VIEW_TOPVIEW :
if (mLockAxis & AXIS_X) *dx = 0;
if (mLockAxis & AXIS_Z) *dy = 0;
break;
case ID_VIEW_SIDEVIEW :
if (mLockAxis & AXIS_X) *dx = 0;
if (mLockAxis & AXIS_Y) *dy = 0;
break;
case ID_VIEW_FRONTVIEW :
if (mLockAxis & AXIS_Z) *dx = 0;
if (mLockAxis & AXIS_Y) *dy = 0;
break;
}
}
// Prevent axis movement. World space clipping.
void CFusionView::LockAxis( geVec3d * pWP )
{
int mLockAxis ;
CFusionDoc* pDoc = GetDocument();
mLockAxis = pDoc->GetLockAxis() ;
if( mLockAxis & AXIS_X ) pWP->X = 0.0f ;
if( mLockAxis & AXIS_Y ) pWP->Y = 0.0f ;
if( mLockAxis & AXIS_Z ) pWP->Z = 0.0f ;
}/* CFusionView::LockAxis */
void CFusionView::OnToolsBrushRotate45()
{
geVec3d rp;
CFusionDoc* pDoc = GetDocument();
geVec3d_Clear (&rp);
switch (mViewType)
{
case ID_VIEW_TOPVIEW:
rp.Y = -(M_PI/4.0f);
break;
case ID_VIEW_FRONTVIEW :
rp.Z = -(M_PI/4.0f);
break;
case ID_VIEW_SIDEVIEW:
rp.X = (M_PI/4.0f);
break;
default :
return;
}
if(GetModeTool()!=ID_GENERALSELECT)
{
pDoc->RotateTemplateBrush(&rp);
pDoc->UpdateSelected();
pDoc->UpdateAllViews(UAV_ALL3DVIEWS, NULL);
}
else
{
pDoc->RotateSelectedBrushesDirect (&rp);
pDoc->UpdateAllViews(UAV_ALL3DVIEWS | REBUILD_QUICK, NULL);
}
}
int CFusionView::GetCursorBoxPos (const POINT *ptMousePos)
{
CFusionDoc *pDoc;
const Box3d *pBrushBox;
POINT ptMin, ptMax;
int dx, dy;
int x, y;
int horiz, vert;
int lookup[4] = {1, 2, 2, 3};
/*
Split the box up into 3 sections vertically and 3 horizontally.
The center sections are 1/2 the width and height, and the end sections are
each 1/4 of width and height.
What we're creating is:
0 1 2 3 4
------------------------
| | | |
5 | 6 | 7 | 8 | 9
------------------------
| | | |
| | | |
10 | 11 | 12 | 13 | 14
| | | |
------------------------
| | | |
15 | 16 | 17 | 18 | 19
------------------------
20 21 22 23 24
Then we determine which of the sections the cursor is closest to,
and return that index.
*/
pDoc = GetDocument ();
pBrushBox = Brush_GetBoundingBox (pDoc->CurBrush);
// obtain screen coordinates for bounding box min and max points
ptMin = Render_OrthoWorldToView (VCam, &pBrushBox->Min);
ptMax = Render_OrthoWorldToView (VCam, &pBrushBox->Max);
// make sure the min and max points are correct...
if (ptMin.x > ptMax.x)
{
int temp;
temp = ptMin.x;
ptMin.x = ptMax.x;
ptMax.x = temp;
}
if (ptMin.y > ptMax.y)
{
int temp;
temp = ptMin.y;
ptMin.y = ptMax.y;
ptMax.y = temp;
}
// compute horizontal first
x = ptMousePos->x - ptMin.x;
dx = (ptMax.x - ptMin.x);
if (dx == 0) horiz = 0; else horiz = (4*x) / dx;
if (horiz < 0) horiz = 0;
else if (horiz > 3) horiz = 4;
else horiz = lookup[horiz];
// and vertical
y = ptMousePos->y - ptMin.y;
dy = (ptMax.y - ptMin.y);
if (dy == 0) vert = 0; else vert = (4*y)/dy;
if (vert < 0) vert = 0;
else if (vert > 3) vert = 3;
else vert = lookup[vert];
// return index...
return (vert * 5) + horiz;
}
void CFusionView::SetEditCursor (int Tool, const POINT *pMousePos)
{
//for sizing stuff
static const char *SizeCursors[25]=
{
IDC_SIZENWSE, IDC_SIZENWSE, IDC_SIZENS, IDC_SIZENESW, IDC_SIZENESW,
IDC_SIZENWSE, IDC_SIZENWSE, IDC_SIZENS, IDC_SIZENESW, IDC_SIZENESW,
IDC_SIZEWE, IDC_SIZEWE, IDC_NO, IDC_SIZEWE, IDC_SIZEWE,
IDC_SIZENESW, IDC_SIZENESW, IDC_SIZENS, IDC_SIZENWSE, IDC_SIZENWSE,
IDC_SIZENESW, IDC_SIZENESW, IDC_SIZENS, IDC_SIZENWSE, IDC_SIZENWSE
};
static const char *ShearCursors[25]=
{
IDC_NO, IDC_SIZEWE, IDC_SIZEWE, IDC_SIZEWE, IDC_NO,
IDC_SIZENS, IDC_NO, IDC_SIZEWE, IDC_NO, IDC_SIZENS,
IDC_SIZENS, IDC_SIZENS, IDC_NO, IDC_SIZENS, IDC_SIZENS,
IDC_SIZENS, IDC_NO, IDC_SIZEWE, IDC_NO, IDC_SIZENS,
IDC_NO, IDC_SIZEWE, IDC_SIZEWE, IDC_SIZEWE, IDC_NO
};
const char *WhichCursor = NULL;
int CursorIndex;
assert ((Tool == ID_TOOLS_BRUSH_SCALEBRUSH) || (Tool == ID_TOOLS_BRUSH_SHEARBRUSH));
// Determine where the cursor is on the box surrounding the selected brush,
// and set the appropriate cursor.
if (pMousePos->x < 0 || pMousePos->y < 0)
{
return;
}
CursorIndex = GetCursorBoxPos (pMousePos);
switch (Tool)
{
case ID_TOOLS_BRUSH_SCALEBRUSH :
// Scaling it's just a simple lookup
WhichCursor = SizeCursors [CursorIndex];
break;
case ID_TOOLS_BRUSH_SHEARBRUSH :
WhichCursor = ShearCursors[CursorIndex];
break;
default :
assert (0);
break;
}
SetCursor (AfxGetApp()->LoadStandardCursor (WhichCursor));
}
void CFusionView::Pan
(
CFusionDoc *pDoc,
int dx, int dy,
const geVec3d *dv,
BOOL LButtonIsDown,
BOOL RButtonIsDown
)
{
if(mViewIs3d)
{
geVec3d MoveVec;
if(LButtonIsDown && RButtonIsDown)
{
geVec3d_Set (&MoveVec, (geFloat)-dx, (geFloat)-dy, 0.0f);
Render_MoveCamPos( VCam, &MoveVec ) ;
pDoc->UpdateCameraEntity( VCam ) ;
}
else if (LButtonIsDown)
{
geVec3d_Set (&MoveVec, 0.0f, 0.0f, (geFloat)-dy);
Render_MoveCamPos( VCam, &MoveVec ) ;
if (Render_UpIsDown (VCam))
{
Render_IncrementYaw (VCam, (geFloat)(-dx));
}
else
{
Render_IncrementYaw(VCam, (geFloat)dx);
}
pDoc->UpdateCameraEntity( VCam ) ;
}
else if (RButtonIsDown)
{
if (Render_UpIsDown (VCam))
{
Render_IncrementYaw (VCam, (geFloat)(-dx));
}
else
{
Render_IncrementYaw(VCam, (geFloat)dx);
}
Render_IncrementPitch(VCam, (geFloat)dy);
pDoc->UpdateCameraEntity( VCam ) ;
}
}
else
{
geVec3d dcamv;
geVec3d_Scale (dv, -1.0f, &dcamv);
if (LButtonIsDown)
{
Render_MoveCamPosOrtho(VCam, &dcamv);
}
else if (RButtonIsDown)
{
Render_ZoomChange(VCam, -(((geFloat)dy) * 0.001f));
pDoc->UpdateGridInformation ();
}
}
}
void CFusionView::ScaleSelected (CFusionDoc *pDoc, int dx, int dy)
{
//smooth out the zoom scale curve with a scalar
geFloat ZoomInv =Render_GetZoom(VCam);
ZoomInv =(ZoomInv > .5)? 0.5f / ZoomInv : 1.0f;
// negated here because Brush_Resize is still thinking weird
pDoc->ResizeSelected (-(((geFloat)dx)*ZoomInv), -(((geFloat)dy)*ZoomInv), sides, Render_GetInidx(VCam));
}
void CFusionView::ShearSelected (CFusionDoc *pDoc, int dx, int dy)
{
//smooth out the zoom scale curve with a scalar
geFloat ZoomInv =Render_GetZoom(VCam);
ZoomInv =(ZoomInv > .5)? 0.5f / ZoomInv : 1.0f;
pDoc->ShearSelected(-(((geFloat)dy)*ZoomInv), -(((geFloat)dx)*ZoomInv), sides, Render_GetInidx(VCam));
}
#pragma warning (disable:4100)
void CFusionView::OnMouseMove (UINT nFlags, CPoint point)
{
int dx, dy;
geVec3d sp, wp, dv;
CFusionDoc *pDoc;
geBoolean ShiftHeld;
geBoolean ControlHeld;
geBoolean LButtonIsDown, RButtonIsDown;
geBoolean SpaceHeld;
BOOL ThisIsCaptured;
int ModeTool, Tool;
fdocAdjustEnum AdjustMode;
BOOL DoRedraw = TRUE;
POINT RealCursorPosition;
pDoc =GetDocument();
ThisIsCaptured = (this == GetCapture ());
ModeTool = GetModeTool ();
Tool = GetTool ();
AdjustMode = GetAdjustMode ();
/*
You'll notice here that we don't use the nFlags parameter to get these
settings. Those flags tell what the state of things was when the
MouseMove message was received, which could have been several seconds
ago (due to delays caused by a mashed key, for example). What we're
really interested is the current state, so we can throw out old messages.
*/
ShiftHeld = IsKeyDown (VK_SHIFT);
ControlHeld = IsKeyDown (VK_CONTROL);
LButtonIsDown = LMouseButtonDown; //IsKeyDown (VK_LBUTTON);
RButtonIsDown = RMouseButtonDown; //IsKeyDown (VK_RBUTTON);
SpaceHeld = IsKeyDown (VK_SPACE);
IsPanning =((SpaceHeld || IsPanning) &&
(LButtonIsDown | RButtonIsDown) && ThisIsCaptured);
if (!ThisIsCaptured)
{
// Mouse isn't captured. So we're just moving the mouse around
// in this view. If we're not in camera mode and not panning,
// then set the cursor accordingly and exit.
if(!((ModeTool == ID_TOOLS_CAMERA) || IsPanning))
{
int Tool;
Tool = GetTool ();
if (mViewIs3d)
{
if (ShiftHeld)
{
SetCursor (AfxGetApp()->LoadCursor (IDC_EYEDROPPER));
}
else
{
SetCursor (AfxGetApp()->LoadStandardCursor (IDC_ARROW));
}
}
else if ((Tool == ID_TOOLS_BRUSH_SCALEBRUSH) || (Tool == ID_TOOLS_BRUSH_SHEARBRUSH))
{
SetEditCursor (Tool, &point);
}
}
return;
}
if(this==GetParentFrame()->GetActiveView())
{
pDoc->mActiveView =mViewType;
}
/*
The point parameter to this message gives us the mouse position when the
message was received. That could be old. We really want the *current*
position, so we get it here and convert it to client coordinates. This
prevents the panning runaway bug that plauged us for so long.
*/
::GetCursorPos (&RealCursorPosition);
ScreenToClient (&RealCursorPosition);
dx = (RealCursorPosition.x - mStartPoint.x);
dy = (RealCursorPosition.y - mStartPoint.y);
if ((dx == 0) && (dy == 0)) // don't do anything if no delta
{
return;
}
Render_ViewToWorld(VCam, mStartPoint.x, mStartPoint.y, &sp);
Render_ViewToWorld(VCam, RealCursorPosition.x, RealCursorPosition.y, &wp);
geVec3d_Subtract(&wp, &sp, &dv); // delta in world space
//camera and space hold panning
if ((ModeTool == ID_TOOLS_CAMERA)||IsPanning)
{
Pan (pDoc, dx, dy, &dv, LButtonIsDown, RButtonIsDown);
}
else if (!mViewIs3d)
// none of this stuff should be available in the 3d view.
{
switch (ModeTool)
{
case ID_GENERALSELECT :
switch (Tool)
{
case CURTOOL_NONE :
// no tool selected. We're doing a drag select or clone operation
if (AdjustMode == ADJUST_MODE_BRUSH)
{
// drag select or cloning
if( IsDragging )
{
mDragCurrentPoint.x += (long)dx ;
mDragCurrentPoint.y += (long)dy ;
}
else if( !IsCopying && !ShiftHeld && !RButtonIsDown )
{
#pragma message ("Logic flawed here when space being held. Don't know exactly what.")
if((abs(dx) > mCX_DRAG) || (abs(dy) > mCY_DRAG))
{
mDragCurrentPoint = RealCursorPosition;
IsDragging = TRUE ;
}
}// Drag Select
else
{ // Begin a copy operation
if((LButtonIsDown && ShiftHeld)&&(!IsCopying))
{
IsCopying =TRUE;
pDoc->CopySelectedBrushes();
if (SelBrushList_GetSize (pDoc->pSelBrushes) > 0)
{
// make current brush point to first brush in list
// so we can snap correctly.
pDoc->CurBrush = SelBrushList_GetBrush (pDoc->pSelBrushes, 0);
}
}
if(IsCopying)
{
LockAxis( &dv ) ;
if(LButtonIsDown)
{
pDoc->MoveSelectedClone(&dv);
}
SetTool(CURTOOL_NONE);
}
}// Not Drag Select
}
break;
case ID_TOOLS_BRUSH_MOVEROTATEBRUSH :
// moving/rotating brushes and entities
SetTool(ID_TOOLS_BRUSH_MOVESELECTEDBRUSHES);
if (LButtonIsDown)
{
LockAxis( &dv ) ;
pDoc->MoveSelectedBrushes(&dv);
}// LButtonDown
if (RButtonIsDown)
{
if( pDoc->GetSelState() == ONEENTITYONLY ) // Angle,Arc,Radius control
{
if( !ShiftHeld && !ControlHeld )
{
pDoc->AdjustEntityAngle( VCam, (geFloat)dx ) ;
}
else if( ShiftHeld && !ControlHeld )
{
pDoc->AdjustEntityArc( VCam, (geFloat)dx ) ;
}
else if( !ShiftHeld && ControlHeld )
{
pDoc->AdjustEntityRadius( &dv ) ;
}
}
else
{
Render_ViewDeltaToRotation (VCam, (geFloat)dx, &dv);
pDoc->RotateSelectedBrushes(&dv);
}
}// RButtonDown
SetTool(ID_TOOLS_BRUSH_MOVEROTATEBRUSH);
break;
case ID_TOOLS_BRUSH_SCALEBRUSH :
if (LButtonIsDown)
{
LockAxisView (&dx, &dy);
ScaleSelected (pDoc, dx, dy);
}
break;
case ID_TOOLS_BRUSH_SHEARBRUSH :
if (LButtonIsDown)
{
LockAxisView (&dx, &dy);
ShearSelected (pDoc, dx, dy);
}
break;
default :
DoRedraw = FALSE;
break;
}
break;
case ID_TOOLS_TEMPLATE :
switch (Tool)
{
case ID_TOOLS_BRUSH_MOVEROTATEBRUSH :
if (LButtonIsDown)
{
LockAxis (&dv);
pDoc->MoveTemplateBrush(&dv);
}
else if (RButtonIsDown)
{
Render_ViewDeltaToRotation (VCam, (geFloat)dx, &dv);
pDoc->RotateTemplateBrush(&dv);
}
break;
case ID_TOOLS_BRUSH_SCALEBRUSH :
if (LButtonIsDown)
{
LockAxisView (&dx, &dy);
ScaleSelected (pDoc, dx, dy);
}
break;
case ID_TOOLS_BRUSH_SHEARBRUSH :
if (LButtonIsDown)
{
LockAxisView (&dx, &dy);
ShearSelected (pDoc, dx, dy);
}
break;
default :
DoRedraw = FALSE;
break;
}
break;
default :
DoRedraw = FALSE;
break;
} // Mode Tool
}// Ortho Views
if (DoRedraw)
{
RedrawWindow();
}
POINT pt = mStartPoint; // The position works on the delta mStartPoint...
ClientToScreen( &pt ) ;
SetCursorPos( pt.x, pt.y );
}
#pragma warning (default:4100)
// Snaps the closest edge to SnapSize.
static geFloat ComputeSnap (geFloat Cur, geFloat Delta, geFloat SnapSize)
{
geFloat Target;
geFloat SnapDelta;
geFloat Remainder;
Target = Cur + Delta;
Remainder = (geFloat)fmod (Target, SnapSize);
if (fabs (Remainder) < (SnapSize / 2.0f))
{
SnapDelta = -Remainder;
}
else
{
if (Target < 0.0f)
{
SnapDelta = -(SnapSize + Remainder);
}
else
{
SnapDelta = SnapSize - Remainder;
}
}
return SnapDelta;
}
static geFloat SnapSide (geFloat CurMin, geFloat CurMax, geFloat Delta, geFloat SnapSize)
{
geFloat MinDelta, MaxDelta;
MinDelta = ComputeSnap (CurMin, Delta, SnapSize);
MaxDelta = ComputeSnap (CurMax, Delta, SnapSize);
return (fabs (MinDelta) < fabs (MaxDelta)) ? MinDelta : MaxDelta;
}
void CFusionView::DoneMovingBrushes ()
{
CFusionDoc *pDoc = GetDocument ();
int ModeTool = GetModeTool ();
if (SelBrushList_GetSize (pDoc->pSelBrushes) > 0 || ModeTool == ID_TOOLS_TEMPLATE)
{
geFloat fSnapSize ;
const geVec3d *vMin, *vMax;
const Box3d *pBox;
geVec3d SnapDelta;
geBoolean SnapX, SnapY, SnapZ;
fSnapSize = 1.0f;
if (Level_UseGrid (pDoc->pLevel))
{
fSnapSize = Level_GetGridSnapSize (pDoc->pLevel);
}
// do the snap thing...
pBox = Brush_GetBoundingBox (pDoc->CurBrush);
vMin = Box3d_GetMin (pBox);
vMax = Box3d_GetMax (pBox);
geVec3d_Clear (&SnapDelta);
/*
In template mode, the brush is moved directly, so we have to snap to
the current position, not current position plus delta. Since we
clear the delta before computing the snap, we have to save these
flags.
*/
SnapX = (pDoc->FinalPos.X != 0.0f);
SnapY = (pDoc->FinalPos.Y != 0.0f);
SnapZ = (pDoc->FinalPos.Z != 0.0f);
if ((ModeTool == ID_TOOLS_TEMPLATE) || IsCopying)
{
geVec3d_Clear (&pDoc->FinalPos);
}
if (SnapX)
{
SnapDelta.X = ::SnapSide (vMin->X, vMax->X, pDoc->FinalPos.X, fSnapSize);
}
if (SnapY)
{
SnapDelta.Y = ::SnapSide (vMin->Y, vMax->Y, pDoc->FinalPos.Y, fSnapSize);
}
if (SnapZ)
{
SnapDelta.Z = ::SnapSide (vMin->Z, vMax->Z, pDoc->FinalPos.Z, fSnapSize);
}
if (ModeTool == ID_TOOLS_TEMPLATE)
{
pDoc->FinalPos = SnapDelta;
}
else
{
geVec3d_Add (&pDoc->FinalPos, &SnapDelta, &pDoc->FinalPos);
}
}
pDoc->DoneMove ();
pDoc->UpdateSelected();
if ((ModeTool == ID_TOOLS_TEMPLATE) ||
((pDoc->GetSelState() & ANYENTITY) && (!(pDoc->GetSelState() & ANYBRUSH))) )
{
pDoc->UpdateAllViews( UAV_ALL3DVIEWS, NULL );
}
else
{
pDoc->UpdateAllViews( UAV_ALL3DVIEWS | REBUILD_QUICK, NULL );
}
}
#pragma warning (disable:4100)
void CFusionView::OnLButtonUp(UINT nFlags, CPoint point)
{
BOOL bWasCaptured = FALSE ;
CFusionDoc* pDoc;
int ModeTool;
int Tool;
fdocAdjustEnum AdjustMode;
ModeTool = GetModeTool ();
Tool = GetTool ();
pDoc = GetDocument ();
AdjustMode = GetAdjustMode ();
LMouseButtonDown = GE_FALSE;
if (!RMouseButtonDown)
{
// right mouse button isn't down
if(this == GetCapture ())
{
bWasCaptured = TRUE ;
ReleaseCapture();
}
if (IsKeyDown (VK_SPACE) || IsPanning || ModeTool == ID_TOOLS_CAMERA)
{
/*
Ok, here's the scoop.
If we're in the middle of a move/rotate and the user mashes the space bar,
we all of a sudden end up in panning mode with no context information to
tell us that we were previously moving/rotating. So we end up with the
original brushes in the world, and the temporary brushes that are selected
and being moved also in the world. So here we do a TempDeleteSelected to
remove those temporary brushes. Otherwise they'd hang around forever.
Ideally, the move/rotate would be separated from the panning so that we could
move and pan at the same time. Of course, I'd like to get rid of the whole
temp selected thing, too, but that'll have to wait...
*/
pDoc->TempDeleteSelected();
IsPanning = FALSE;
ShowTheCursor ();
RedrawWindow();
return;
}
if (mViewIs3d)
{
if(ModeTool==ID_TOOLS_TEMPLATE && pDoc->TempEnt)
{
pDoc->PlaceTemplateEntity3D(point, VCam);
}
else if (IsKeyDown (VK_SHIFT))
{
pDoc->SelectTextureFromFace3D (point, VCam);
}
else
{
switch (AdjustMode)
{
case ADJUST_MODE_BRUSH :
case ADJUST_MODE_FACE :
pDoc->SelectRay (point, VCam);
pDoc->UpdateAllViews (UAV_ALL3DVIEWS, NULL);
break;
default :
break;
}
}
}
else
{
switch (Tool)
{
case CURTOOL_NONE :
if (AdjustMode == ADJUST_MODE_BRUSH)
{
if( IsDragging )
{
pDoc->SelectOrthoRect( mDragStartPoint, mDragCurrentPoint, VCam );
pDoc->UpdateAllViews(UAV_ALL3DVIEWS, NULL);
IsDragging = FALSE ;
}
else if(IsCopying)
{
DoneMovingBrushes ();
IsCopying = FALSE;
}
else
{
pDoc->SelectOrtho(point, VCam);
pDoc->UpdateAllViews( UAV_ALL3DVIEWS, NULL );
}
}
else
{
MessageBeep ((UINT)(-1));
}
break;
case ID_TOOLS_BRUSH_MOVEROTATEBRUSH :
case ID_TOOLS_BRUSH_MOVESELECTEDBRUSHES :
DoneMovingBrushes ();
break;
case ID_TOOLS_BRUSH_SCALEBRUSH :
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
pDoc->SnapScaleNearest(sides, Render_GetInidx(VCam), VCam);
if(pDoc->mLastOp == BRUSH_SCALE)
{
pDoc->DoneResize(sides, Render_GetInidx(VCam));
}
pDoc->UpdateSelected();
if((ModeTool == ID_TOOLS_TEMPLATE) ||
((pDoc->GetSelState() & ANYENTITY) && (!(pDoc->GetSelState() & ANYBRUSH))) )
{
pDoc->UpdateAllViews( UAV_ALL3DVIEWS, NULL );
}
else
{
pDoc->UpdateAllViews( UAV_ALL3DVIEWS | REBUILD_QUICK, NULL );
}
break;