forked from vpinball/vpinball
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iselect.cpp
348 lines (289 loc) · 8.33 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
#include "stdafx.h"
ISelect::ISelect()
{
m_dragging = false;
m_markedForUndo = false;
m_selectstate = eNotSelected;
m_locked = false;
m_menuid = -1;
m_oldLayerIndex = 0;
m_isVisible = true;
m_vpinball = g_pvp;
}
void ISelect::SetObjectPos()
{
m_vpinball->ClearObjectPosCur();
}
void ISelect::OnLButtonDown(int x, int y)
{
m_dragging = true;
m_markedForUndo = false; // So we will be marked when and if we are dragged
m_ptLast.x = x;
m_ptLast.y = y;
GetPTable()->SetMouseCapture();
SetObjectPos();
}
void ISelect::OnLButtonUp(int x, int y)
{
m_dragging = false;
ReleaseCapture();
if (m_markedForUndo)
{
m_markedForUndo = false;
STOPUNDOSELECT
}
}
void ISelect::OnRButtonDown(int x, int y, HWND hwnd)
{
}
void ISelect::OnRButtonUp(int x, int y)
{
}
void ISelect::OnMouseMove(int x, int y)
{
if ((x == m_ptLast.x) && (y == m_ptLast.y))
return;
if (m_dragging && !GetIEditable()->GetISelect()->m_locked) // For drag points, follow the lock of the parent
{
PinTable * const ptable = GetPTable();
const float inv_zoom = 1.0f / ptable->m_zoom;
if (!m_markedForUndo)
{
m_markedForUndo = true;
STARTUNDOSELECT
}
MoveOffset((float)(x - m_ptLast.x)*inv_zoom, (float)(y - m_ptLast.y)*inv_zoom);
ptable->SetDirtyDraw();
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(CMenu &menu)
{
}
void ISelect::DoCommand(int icmd, int x, int y)
{
IEditable * const piedit = GetIEditable();
if ((icmd & 0x0000FFFF) == ID_SELECT_ELEMENT)
{
const int ksshift = GetKeyState(VK_SHIFT);
//const int ksctrl = GetKeyState(VK_CONTROL);
PinTable * const currentTable = GetPTable();
const int i = (icmd & 0x00FF0000) >> 16;
ISelect * const pisel = currentTable->m_allHitElements[i];
const bool add = ((ksshift & 0x80000000) != 0);
if (pisel == (ISelect *)currentTable && add)
{
// 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, add, true, true);
return;
}
if (((icmd & 0x000FFFFF) >= 0x40000) && ((icmd & 0x000FFFFF) < 0x40020))
{
/*add to collection*/
//const int ksshift = GetKeyState(VK_SHIFT);
//const int ksctrl = GetKeyState(VK_CONTROL);
PinTable * const currentTable = GetPTable();
const int i = icmd & 0x000000FF;
currentTable->UpdateCollection(i);
}
if ((icmd >= ID_ASSIGN_TO_LAYER1) && (icmd <= ID_ASSIGN_TO_LAYER1+NUM_ASSIGN_LAYERS-1))
{
/*add to layer*/
m_vpinball->GetLayersListDialog()->AssignToLayerByIndex(icmd - ID_ASSIGN_TO_LAYER1);
}
switch (icmd)
{
case ID_EDIT_DRAWINGORDER_HIT:
m_vpinball->ShowDrawingOrderDialog(false);
break;
case ID_EDIT_DRAWINGORDER_SELECT:
m_vpinball->ShowDrawingOrderDialog(true);
break;
case ID_ASSIGN_TO_CURRENT_LAYER:
{
m_vpinball->GetLayersListDialog()->OnAssignButton();
break;
}
case ID_DRAWINFRONT:
{
PinTable * const ptable = GetPTable();
RemoveFromVectorSingle(ptable->m_vedit, piedit);
ptable->m_vedit.push_back(piedit);
ptable->SetDirtyDraw();
break;
}
case ID_DRAWINBACK:
{
PinTable * const ptable = GetPTable();
RemoveFromVectorSingle(ptable->m_vedit, piedit);
ptable->m_vedit.insert(ptable->m_vedit.begin(), piedit);
ptable->SetDirtyDraw();
break;
}
case ID_SETASDEFAULT:
piedit->WriteRegDefaults();
break;
case ID_LOCK:
STARTUNDOSELECT
m_locked = !m_locked;
STOPUNDOSELECT
break;
case IDC_COPY:
{
GetPTable()->Copy(x,y);
break;
}
case IDC_PASTE:
{
GetPTable()->Paste(false, x, y);
break;
}
case IDC_PASTEAT:
{
GetPTable()->Paste(true, x, y);
break;
}
/*default:
psel->DoCommand(command, x, y);
break;*/
}
}
#define COLOR_LOCKED RGB(160,160,160)
//GetSysColor(COLOR_GRAYTEXT)
void ISelect::SetSelectFormat(Sur *psur)
{
const DWORD color = m_locked ? m_vpinball->m_elemSelectLockedColor
: m_vpinball->m_elemSelectColor;//GetSysColor(COLOR_HIGHLIGHT);
psur->SetBorderColor(color, false, 4);
psur->SetLineColor(color, false, 4);
}
void ISelect::SetMultiSelectFormat(Sur *psur)
{
const DWORD color = m_locked ?
m_vpinball->m_elemSelectLockedColor :
m_vpinball->m_elemSelectColor;//GetSysColor(COLOR_HIGHLIGHT);
psur->SetBorderColor(color, false, 3);
psur->SetLineColor(color, false, 3);
}
void ISelect::SetLockedFormat(Sur *psur)
{
psur->SetBorderColor(m_vpinball->m_elemSelectLockedColor, false, 1);
psur->SetLineColor(m_vpinball->m_elemSelectLockedColor, false, 1);
}
void ISelect::FlipY(const Vertex2D& pvCenter)
{
GetIEditable()->MarkForUndo(); // Start/EndUndo cycle is around the loop that calls this
Vertex2D vCenter = GetCenter();
const float delta = vCenter.y - pvCenter.y;
vCenter.y -= delta * 2.f;
PutCenter(vCenter);
}
void ISelect::FlipX(const Vertex2D& pvCenter)
{
GetIEditable()->MarkForUndo(); // Start/EndUndo cycle is around the loop that calls this
Vertex2D vCenter = GetCenter();
const float delta = vCenter.x - pvCenter.x;
vCenter.x -= delta * 2.f;
PutCenter(vCenter);
}
void ISelect::Rotate(const float ang, const Vertex2D& pvCenter, const bool useElementCenter)
{
GetIEditable()->MarkForUndo(); // Start/EndUndo cycle is around the loop that calls this
Vertex2D vCenter = GetCenter();
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(const float scalex, const float scaley, const Vertex2D& pvCenter, const bool useElementCenter)
{
GetIEditable()->MarkForUndo(); // Start/EndUndo cycle is around the loop that calls this
Vertex2D vCenter = GetCenter();
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(const Vertex2D &pvOffset)
{
GetIEditable()->MarkForUndo(); // Start/EndUndo cycle is around the loop that calls this
Vertex2D vCenter = GetCenter();
vCenter.x += pvOffset.x;
vCenter.y += pvOffset.y;
PutCenter(vCenter);
}
HRESULT ISelect::GetTypeName(BSTR *pVal)
{
WCHAR buf[256];
GetTypeNameForType(GetItemType(), buf);
*pVal = SysAllocString(buf);
return S_OK;
}
void ISelect::GetTypeNameForType(const ItemTypeEnum type, WCHAR * const buf) const
{
UINT strID;
switch (type)
{
case eItemTable: strID = IDS_TABLE; break;
case eItemLightCenter: strID = IDS_TB_LIGHT; break;
case eItemDragPoint: strID = IDS_CONTROLPOINT; break;
//case eItemLightSeqCenter: strID = IDS_TB_LIGHTSEQ; break;
default:
strID = EditableRegistry::GetTypeNameStringID(type); break;
}
/*const int len =*/ LoadStringW(m_vpinball->theInstance, strID, buf, 256);
}
bool ISelect::LoadToken(const int id, BiffReader * const pbr)
{
switch(id)
{
case FID(LOCK): pbr->GetBool(m_locked); break;
case FID(LAYR):
{
int tmp;
pbr->GetInt(tmp);
m_oldLayerIndex = (unsigned char)tmp;
break;
}
case FID(LANR):
{
pbr->GetString(m_layerName);
break;
}
case FID(LVIS):
{
pbr->GetBool(m_isVisible);
break;
}
}
return true;
}
HRESULT ISelect::SaveData(IStream *pstm, HCRYPTHASH hcrypthash)
{
BiffWriter bw(pstm, hcrypthash);
bw.WriteBool(FID(LOCK), m_locked);
bw.WriteInt(FID(LAYR), m_oldLayerIndex);
bw.WriteString(FID(LANR), m_layerName);
bw.WriteBool(FID(LVIS), m_isVisible);
return S_OK;
}
void ISelect::UpdateStatusBarInfo()
{
m_vpinball->SetStatusBarUnitInfo(string(), false);
}