-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiselect.cpp
375 lines (318 loc) · 8.32 KB
/
iselect.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
#include "StdAfx.h"
// this table must be kept in sync with the ISelectable ItemTypeEnum table
int rgTypeStringIndex[] = {
IDS_TB_WALL, //eItemSurface,
IDS_TB_FLIPPER, //eItemFlipper,
IDS_TB_TIMER, //eItemTimer,
IDS_TB_PLUNGER, //eItemPlunger,
IDS_TB_TEXTBOX, //eItemTextbox,
IDS_TB_BUMPER, //eItemBumper,
IDS_TB_TRIGGER, //eItemTrigger,
IDS_TB_LIGHT, //eItemLight,
IDS_TB_KICKER, //eItemKicker,
IDS_TB_DECAL, //eItemDecal,
IDS_TB_GATE, //eItemGate,
IDS_TB_SPINNER, //eItemSpinner,
IDS_TB_RAMP, //eItemRamp,
IDS_TABLE, //eItemTable,
IDS_TB_LIGHT, //eItemLightCenter,
IDS_CONTROLPOINT, //eItemDragPoint,
IDS_COLLECTION, //eItemCollection,
IDS_TB_DISPREEL, //eItemDispReel,
IDS_TB_LIGHTSEQ, //eItemLightSeq,
IDS_TB_PRIMITIVE, //eItemPrimitive
IDS_TB_FLASHER, //eItemFlasher
IDS_TB_LIGHTSEQ, //light seq center
IDS_TB_COMCONTROL, //eItemComControl
};
ISelect::ISelect()
{
m_fDragging = fFalse;
m_fMarkedForUndo = fFalse;
m_selectstate = eNotSelected;
m_fLocked = fFalse;
m_menuid = -1;
layerIndex=0;
}
void ISelect::SetObjectPos()
{
g_pvp->ClearObjectPosCur();
}
void ISelect::OnLButtonDown(int x, int y)
{
m_fDragging = fTrue;
m_fMarkedForUndo = fFalse; // So we will be marked when and if we are dragged
m_ptLast.x = x;
m_ptLast.y = y;
SetCapture(GetPTable()->m_hwnd);
SetObjectPos();
}
void ISelect::OnLButtonUp(int x, int y)
{
m_fDragging = fFalse;
ReleaseCapture();
if (m_fMarkedForUndo)
{
m_fMarkedForUndo = fFalse;
GetIEditable()->EndUndo();
}
}
void ISelect::OnRButtonDown(int x, int y, HWND hwnd)
{
}
void ISelect::OnRButtonUp(int x, int y)
{
}
void ISelect::OnMouseMove(int x, int y)
{
PinTable * const ptable = GetPTable();
const float inv_zoom = 1.0f/ptable->m_zoom;
if ((x == m_ptLast.x) && (y == m_ptLast.y))
{
return;
}
if (m_fDragging && !GetIEditable()->GetISelect()->m_fLocked) // For drag points, follow the lock of the parent
{
if (!m_fMarkedForUndo)
{
m_fMarkedForUndo = fTrue;
GetIEditable()->BeginUndo();
GetIEditable()->MarkForUndo();
}
MoveOffset((x - m_ptLast.x)*inv_zoom, (y - m_ptLast.y)*inv_zoom);
m_ptLast.x = x;
m_ptLast.y = y;
SetObjectPos();
}
}
void ISelect::MoveOffset(const float dx, const float dy)
{
// Implement in child class to enable dragging
}
void ISelect::EditMenu(HMENU hmenu)
{
}
void ISelect::DoCommand(int icmd, int x, int y)
{
IEditable *piedit = GetIEditable();
if ( (icmd & 0x0000FFFF) == ID_SELECT_ELEMENT )
{
const int ksshift = GetKeyState(VK_SHIFT);
const int ksctrl = GetKeyState(VK_CONTROL);
PinTable *currentTable = GetPTable();
int i = (icmd & 0x00FF0000)>>16;
ISelect * const pisel = currentTable->m_allHitElements.ElementAt(i);
const BOOL fAdd = ((ksshift & 0x80000000) != 0);
if (pisel == (ISelect *)currentTable && fAdd)
{
// Can not include the table in multi-select
// and table will not be unselected, because the
// user might be drawing a box around other objects
// to add them to the selection group
currentTable->OnLButtonDown(x,y); // Start the band select
return;
}
currentTable->AddMultiSel(pisel, fAdd, fTrue);
return;
}
if ( ((icmd & 0x000FFFFF) >= 0x40000 ) && ((icmd & 0x000FFFFF)<0x40020) )
{
const int ksshift = GetKeyState(VK_SHIFT);
const int ksctrl = GetKeyState(VK_CONTROL);
PinTable *currentTable = GetPTable();
int i = icmd & 0x000000FF;
currentTable->AddToCollection(i);
}
switch (icmd)
{
case ID_EDIT_DRAWINGORDER_HIT:
g_pvp->ShowDrawingOrderDialog(false);
break;
case ID_EDIT_DRAWINGORDER_SELECT:
g_pvp->ShowDrawingOrderDialog(true);
break;
case ID_DRAWINFRONT:
GetPTable()->m_vedit.RemoveElement(piedit);
GetPTable()->m_vedit.AddElement(piedit);
GetPTable()->m_layer[ layerIndex ].RemoveElement(piedit);
GetPTable()->m_layer[ layerIndex ].AddElement(piedit);
GetPTable()->SetDirtyDraw();
break;
case ID_DRAWINBACK:
GetPTable()->m_vedit.RemoveElement(piedit);
GetPTable()->m_vedit.InsertElementAt(piedit, 0);
GetPTable()->m_layer[ layerIndex ].RemoveElement(piedit);
GetPTable()->m_layer[ layerIndex ].InsertElementAt(piedit,0);
GetPTable()->SetDirtyDraw();
break;
case ID_SETASDEFAULT:
piedit->WriteRegDefaults();
break;
case ID_LOCK:
GetIEditable()->BeginUndo();
GetIEditable()->MarkForUndo();
m_fLocked = !m_fLocked;
GetIEditable()->EndUndo();
GetPTable()->SetDirtyDraw();
break;
case ID_ASSIGNTO_LAYER1:
{
GetPTable()->AssignToLayer(piedit, 0);
break;
}
case ID_ASSIGNTO_LAYER2:
{
GetPTable()->AssignToLayer(piedit, 1);
break;
}
case ID_ASSIGNTO_LAYER3:
{
GetPTable()->AssignToLayer(piedit, 2);
break;
}
case ID_ASSIGNTO_LAYER4:
{
GetPTable()->AssignToLayer(piedit, 3);
break;
}
case ID_ASSIGNTO_LAYER5:
{
GetPTable()->AssignToLayer(piedit, 4);
break;
}
case ID_ASSIGNTO_LAYER6:
{
GetPTable()->AssignToLayer(piedit, 5);
break;
}
case ID_ASSIGNTO_LAYER7:
{
GetPTable()->AssignToLayer(piedit, 6);
break;
}
case ID_ASSIGNTO_LAYER8:
{
GetPTable()->AssignToLayer(piedit, 7);
break;
}
/*default:
psel->DoCommand(command, x, y);
break;*/
}
}
#define COLOR_LOCKED RGB(160,160,160)
//GetSysColor(COLOR_GRAYTEXT)
void ISelect::SetSelectFormat(Sur *psur)
{
//psur->SetFillColor(RGB(150,200,255));
//psur->SetFillColor(RGB(128,0,0));
DWORD color;
if (m_fLocked)
{
//color = GetSysColor(COLOR_GRAYTEXT);
color = COLOR_LOCKED;
}
else
{
color = GetSysColor(COLOR_HIGHLIGHT);
}
psur->SetBorderColor(color, false, 4);
psur->SetLineColor(color, false, 4);
}
void ISelect::SetMultiSelectFormat(Sur *psur)
{
DWORD color;
if (m_fLocked)
{
color = COLOR_LOCKED;
}
else
{
color = GetSysColor(COLOR_HIGHLIGHT);
}
psur->SetBorderColor(color, false, 3);
psur->SetLineColor(color, false, 3);
}
void ISelect::SetLockedFormat(Sur *psur)
{
psur->SetBorderColor(COLOR_LOCKED, false, 1);
psur->SetLineColor(COLOR_LOCKED, false, 1);
}
void ISelect::FlipY(Vertex2D * const pvCenter)
{
GetIEditable()->MarkForUndo();
Vertex2D vCenter;
GetCenter(&vCenter);
const float delta = vCenter.y - pvCenter->y;
vCenter.y -= delta*2;
PutCenter(&vCenter);
}
void ISelect::FlipX(Vertex2D * const pvCenter)
{
GetIEditable()->MarkForUndo();
Vertex2D vCenter;
GetCenter(&vCenter);
const float delta = vCenter.x - pvCenter->x;
vCenter.x -= delta*2;
PutCenter(&vCenter);
}
void ISelect::Rotate(float ang, Vertex2D *pvCenter)
{
GetIEditable()->MarkForUndo();
Vertex2D vCenter;
GetCenter(&vCenter);
const float sn = sinf(ANGTORAD(ang));
const float cs = cosf(ANGTORAD(ang));
const float dx = vCenter.x - pvCenter->x;
const float dy = vCenter.y - pvCenter->y;
vCenter.x = pvCenter->x + cs*dx - sn*dy;
vCenter.y = pvCenter->y + cs*dy + sn*dx;
PutCenter(&vCenter);
}
void ISelect::Scale(float scalex, float scaley, Vertex2D *pvCenter)
{
GetIEditable()->MarkForUndo();
Vertex2D vCenter;
GetCenter(&vCenter);
const float dx = vCenter.x - pvCenter->x;
const float dy = vCenter.y - pvCenter->y;
vCenter.x = pvCenter->x + dx*scalex;
vCenter.y = pvCenter->y + dy*scaley;
PutCenter(&vCenter);
}
void ISelect::Translate(Vertex2D *pvOffset)
{
GetIEditable()->MarkForUndo();
Vertex2D vCenter;
GetCenter(&vCenter);
vCenter.x += pvOffset->x;
vCenter.y += pvOffset->y;
PutCenter(&vCenter);
}
HRESULT ISelect::GetTypeName(BSTR *pVal)
{
WCHAR wzName[128];
LocalString ls(rgTypeStringIndex[GetItemType()]);
MultiByteToWideChar(CP_ACP, 0, ls.m_szbuffer, -1, wzName, 128);
*pVal = SysAllocString(wzName);
return S_OK;
}
BOOL ISelect::LoadToken(int id, BiffReader *pbr)
{
if (id == FID(LOCK))
{
pbr->GetBool(&m_fLocked);
}
if(id==FID(LAYR))
{
pbr->GetInt(&layerIndex);
}
return fTrue;
}
HRESULT ISelect::SaveData(IStream *pstm, HCRYPTHASH hcrypthash, HCRYPTKEY hcryptkey)
{
BiffWriter bw(pstm, hcrypthash, hcryptkey);
bw.WriteBool(FID(LOCK), m_fLocked);
bw.WriteInt(FID(LAYR), layerIndex );
return S_OK;
}