-
Notifications
You must be signed in to change notification settings - Fork 0
/
drag.c
485 lines (409 loc) · 10.2 KB
/
drag.c
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
// drag.c
#include "qe3.h"
/*
drag either multiple brushes, or select plane points from
a single brush.
*/
qboolean drag_ok;
vec3_t drag_xvec;
vec3_t drag_yvec;
static int buttonstate;
static int pressx, pressy;
static vec3_t pressdelta;
static int buttonx, buttony;
//int num_move_points;
//float *move_points[1024];
int lastx, lasty;
qboolean drag_first;
void AxializeVector (vec3_t v)
{
vec3_t a;
float o;
int i;
if (!v[0] && !v[1])
return;
if (!v[1] && !v[2])
return;
if (!v[0] && !v[2])
return;
for (i=0 ; i<3 ; i++)
a[i] = fabs(v[i]);
if (a[0] > a[1] && a[0] > a[2])
i = 0;
else if (a[1] > a[0] && a[1] > a[2])
i = 1;
else
i = 2;
o = v[i];
VectorCopy (vec3_origin, v);
if (o<0)
v[i] = -1;
else
v[i] = 1;
}
/*
===========
Drag_Setup
===========
*/
void Drag_Setup (int x, int y, int buttons,
vec3_t xaxis, vec3_t yaxis,
vec3_t origin, vec3_t dir)
{
trace_t t;
face_t *f;
if (selected_brushes.next == &selected_brushes)
{
Sys_Printf ("No selection to drag\n");
return;
}
drag_first = true;
g_qeglobals.d_num_move_points = 0;
VectorCopy (vec3_origin, pressdelta);
pressx = x;
pressy = y;
VectorCopy (xaxis, drag_xvec);
AxializeVector (drag_xvec);
VectorCopy (yaxis, drag_yvec);
AxializeVector (drag_yvec);
if (g_qeglobals.d_select_mode == sel_vertex)
{
SelectVertexByRay (origin, dir);
if (g_qeglobals.d_num_move_points)
{
drag_ok = true;
return;
}
}
if (g_qeglobals.d_select_mode == sel_edge)
{
SelectEdgeByRay (origin, dir);
if (g_qeglobals.d_num_move_points)
{
drag_ok = true;
return;
}
}
//
// check for direct hit first
//
t = Test_Ray (origin, dir, true);
if (t.selected)
{
drag_ok = true;
if (buttons == (MK_LBUTTON|MK_CONTROL) )
{
Sys_Printf ("Shear dragging face\n");
Brush_SelectFaceForDragging (t.brush, t.face, true);
}
else if (buttons == (MK_LBUTTON|MK_CONTROL|MK_SHIFT) )
{
Sys_Printf ("Sticky dragging brush\n");
for (f=t.brush->brush_faces ; f ; f=f->next)
Brush_SelectFaceForDragging (t.brush, f, false);
}
else
Sys_Printf ("Dragging entire selection\n");
return;
}
if (g_qeglobals.d_select_mode == sel_vertex || g_qeglobals.d_select_mode == sel_edge)
return;
//
// check for side hit
//
/*
if (selected_brushes.next->next != &selected_brushes)
{
Sys_Printf ("Click isn't inside multiple selection\n");
return;
}
*/
if (selected_brushes.next->owner->eclass->fixedsize)
{
Sys_Printf ("Can't stretch fixed size entities\n");
return;
}
if (buttons & MK_CONTROL)
Brush_SideSelect (selected_brushes.next, origin, dir, true);
else
Brush_SideSelect (selected_brushes.next, origin, dir, false);
Sys_Printf ("Side stretch\n");
drag_ok = true;
}
entity_t *peLink;
void UpdateTarget(vec3_t origin, vec3_t dir)
{
trace_t t;
entity_t *pe;
int i;
char sz[128];
t = Test_Ray (origin, dir, 0);
if (!t.brush)
return;
pe = t.brush->owner;
if (pe == NULL)
return;
// is this the first?
if (peLink != NULL)
{
// get the target id from out current target
// if there is no id, make one
i = IntForKey(pe, "target");
if (i <= 0)
{
i = GetUniqueTargetId(1);
sprintf(sz, "%d", i);
SetKeyValue(pe, "target", sz);
}
// set the target # into our src
sprintf(sz, "%d", i);
SetKeyValue(peLink, "targetname", sz);
Sys_UpdateWindows(W_ENTITY);
}
// promote the target to the src
peLink = pe;
}
/*
===========
Drag_Begin
===========
*/
void Drag_Begin (int x, int y, int buttons,
vec3_t xaxis, vec3_t yaxis,
vec3_t origin, vec3_t dir)
{
trace_t t;
qboolean altdown;
int dim1, dim2;
drag_ok = false;
VectorCopy (vec3_origin, pressdelta);
drag_first = true;
peLink = NULL;
altdown = (qboolean)GetAsyncKeyState(VK_MENU);
// shift LBUTTON = select entire brush
if (buttons == (MK_LBUTTON | MK_SHIFT))
{
int flag = altdown ? SF_CYCLE : 0; // single selection cycle (shift+alt+LBUTTON);
if (dir[0] == 0 || dir[1] == 0 || dir[2] == 0) // extremely low chance of this happening from camera
Select_Ray (origin, dir, flag | SF_ENTITIES_FIRST); // hack for XY
else
Select_Ray (origin, dir, flag);
return;
}
// ctrl-alt-LBUTTON = multiple brush select without selecting whole entities
if (buttons == (MK_LBUTTON | MK_CONTROL) && altdown)
{
if (dir[0] == 0 || dir[1] == 0 || dir[2] == 0) // extremely low chance of this happening from camera
Select_Ray (origin, dir, SF_ENTITIES_FIRST); // hack for XY
else
Select_Ray (origin, dir, 0);
return;
}
// ctrl-shift LBUTTON = select single face
if (buttons == (MK_LBUTTON | MK_CONTROL | MK_SHIFT))
{
// if alt pressed, don't deselect selected faces
Select_Deselect (!altdown); // sikk - Multiple Face Selection
Select_Ray (origin, dir, SF_SINGLEFACE);
return;
}
// LBUTTON + all other modifiers = manipulate selection
if (buttons & MK_LBUTTON)
{
Drag_Setup (x, y, buttons, xaxis, yaxis, origin, dir);
return;
}
// middle button = grab texture
if (buttons == MK_MBUTTON)
{
t = Test_Ray (origin, dir, false);
if (t.face)
{
dim1 = (g_qeglobals.d_viewtype == YZ) ? 1 : 0;
dim2 = (g_qeglobals.d_viewtype == XY) ? 1 : 2;
g_qeglobals.d_work_min[dim1] = t.brush->mins[dim1];
g_qeglobals.d_work_max[dim1] = t.brush->maxs[dim1];
g_qeglobals.d_work_min[dim2] = t.brush->mins[dim2];
g_qeglobals.d_work_max[dim2] = t.brush->maxs[dim2];
// g_qeglobals.d_new_brush_bottom_z = t.brush->mins[2];
// g_qeglobals.d_new_brush_top_z = t.brush->maxs[2];
UpdateWorkzone_ForBrush( t.brush );
Texture_SetTexture (&t.face->texdef, true);
}
else
Sys_Printf ("Did not select a texture\n");
return;
}
// ctrl-middle button = set entire brush to texture
if (buttons == (MK_MBUTTON|MK_CONTROL) )
{
t = Test_Ray (origin, dir, false);
if (t.brush)
{
if (t.brush->brush_faces->texdef.name[0] == '(')
Sys_Printf ("Can't change an entity texture\n");
else
{
Brush_SetTexture (t.brush, &g_qeglobals.d_texturewin.texdef);
Sys_UpdateWindows (W_ALL);
}
}
else
Sys_Printf ("Didn't hit a brush\n");
return;
}
// ctrl-shift-middle button = set single face to texture
if (buttons == (MK_MBUTTON|MK_SHIFT|MK_CONTROL) )
{
t = Test_Ray (origin, dir, false);
if (t.brush)
{
if (t.brush->brush_faces->texdef.name[0] == '(')
Sys_Printf ("Can't change an entity texture\n");
else
{
t.face->texdef = g_qeglobals.d_texturewin.texdef;
Brush_Build( t.brush );
Sys_UpdateWindows (W_ALL);
}
}
else
Sys_Printf ("Didn't hit a brush\n");
return;
}
}
/*
===========
MoveSelection
===========
*/
void MoveSelection (vec3_t move)
{
int i;
qboolean success;
brush_t *b;
vec3_t end;
if (!move[0] && !move[1] && !move[2])
return;
// Sys_UpdateWindows (W_XY|W_CAMERA);
Sys_UpdateWindows (W_ALL);
//
// dragging only a part of the selection
//
if (g_qeglobals.d_num_move_points)
{
//vertex selection
if (g_qeglobals.d_select_mode == sel_vertex)
{
success = true;
for (b = selected_brushes.next; b != &selected_brushes; b = b->next)
{
success &= Brush_MoveVertex(b, g_qeglobals.d_move_points[0], move, end);
}
if (success)
VectorCopy(end, g_qeglobals.d_move_points[0]);
return;
}
//all other selection types
for (i=0 ; i<g_qeglobals.d_num_move_points ; i++)
VectorAdd (g_qeglobals.d_move_points[i], move, g_qeglobals.d_move_points[i]);
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
{
Brush_Build( b );
for (i=0 ; i<3 ; i++)
if (b->mins[i] > b->maxs[i]
|| b->maxs[i] - b->mins[i] > MAX_BRUSH_SIZE)
break; // dragged backwards or fucked up
if (i != 3)
break;
}
// if any of the brushes were crushed out of existance
// cancel the entire move
if (b != &selected_brushes)
{
Sys_Printf ("Brush dragged backwards, move canceled\n");
for (i=0 ; i<g_qeglobals.d_num_move_points ; i++)
VectorSubtract (g_qeglobals.d_move_points[i], move, g_qeglobals.d_move_points[i]);
for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
Brush_Build( b );
}
}
else
{
// reset face originals from vertex edit mode
// this is dirty, but unfortunately necessary because Brush_Build
// can remove windings
for (b = selected_brushes.next; b != &selected_brushes; b = b->next)
{
Brush_ResetFaceOriginals(b);
}
//
// if there are lots of brushes selected, just translate instead
// of rebuilding the brushes
//
if (drag_yvec[2] == 0 && selected_brushes.next->next != &selected_brushes)
{
VectorAdd (g_qeglobals.d_select_translate, move, g_qeglobals.d_select_translate);
}
else
{
Select_Move (move);
}
}
}
/*
===========
Drag_MouseMoved
===========
*/
void Drag_MouseMoved (int x, int y, int buttons)
{
vec3_t move, delta;
int i;
char movestring[128];
if (!buttons)
{
drag_ok = false;
return;
}
if (!drag_ok)
return;
// clear along one axis
if (buttons & MK_SHIFT)
{
drag_first = false;
if (abs(x-pressx) > abs(y-pressy))
y = pressy;
else
x = pressx;
}
for (i=0 ; i<3 ; i++)
{
move[i] = drag_xvec[i]*(x - pressx) + drag_yvec[i]*(y - pressy);
if (!g_qeglobals.d_savedinfo.noclamp)
{
move[i] = floor(move[i]/g_qeglobals.d_gridsize+0.5)*g_qeglobals.d_gridsize;
}
}
sprintf (movestring, "Drag: (%i %i %i)", (int)move[0], (int)move[1], (int)move[2]);
Sys_Status (movestring, 0);
VectorSubtract (move, pressdelta, delta);
VectorCopy (move, pressdelta);
MoveSelection (delta);
}
/*
===========
Drag_MouseUp
===========
*/
void Drag_MouseUp (void)
{
if (drag_ok)
Sys_Printf ("Drag completed.\n");
if (g_qeglobals.d_select_translate[0] || g_qeglobals.d_select_translate[1] || g_qeglobals.d_select_translate[2])
{
Select_Move (g_qeglobals.d_select_translate);
VectorCopy (vec3_origin, g_qeglobals.d_select_translate);
Sys_UpdateWindows (W_CAMERA);
}
}