2 ===========================================================================
3 Copyright (C) 1997-2006 Id Software, Inc.
5 This file is part of Quake 2 Tools source code.
7 Quake 2 Tools source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
12 Quake 2 Tools source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Quake 2 Tools source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
27 drag either multiple brushes, or select plane points from
36 static int buttonstate;
37 static int pressx, pressy;
38 static vec3_t pressdelta;
39 static int buttonx, buttony;
42 //int num_move_points;
43 //float *move_points[1024];
50 void AxializeVector (vec3_t v)
65 if (a[0] > a[1] && a[0] > a[2])
67 else if (a[1] > a[0] && a[1] > a[2])
73 VectorCopy (vec3_origin, v);
87 void Drag_Setup (int x, int y, int buttons,
88 vec3_t xaxis, vec3_t yaxis,
89 vec3_t origin, vec3_t dir)
94 if (selected_brushes.next == &selected_brushes)
96 Sys_Status("No selection to drag\n", 0);
101 g_qeglobals.d_num_move_points = 0;
102 VectorCopy (vec3_origin, pressdelta);
106 VectorCopy (xaxis, drag_xvec);
107 AxializeVector (drag_xvec);
108 VectorCopy (yaxis, drag_yvec);
109 AxializeVector (drag_yvec);
111 if (g_qeglobals.d_select_mode == sel_vertex)
113 SelectVertexByRay (origin, dir);
114 if (g_qeglobals.d_num_move_points)
120 if (g_qeglobals.d_select_mode == sel_edge)
122 SelectEdgeByRay (origin, dir);
123 if (g_qeglobals.d_num_move_points)
132 // check for direct hit first
134 t = Test_Ray (origin, dir, true);
139 if (buttons == (MK_LBUTTON|MK_CONTROL) )
141 Sys_Printf ("Shear dragging face\n");
142 Brush_SelectFaceForDragging (t.brush, t.face, true);
144 else if (buttons == (MK_LBUTTON|MK_CONTROL|MK_SHIFT) )
146 Sys_Printf ("Sticky dragging brush\n");
147 for (f=t.brush->brush_faces ; f ; f=f->next)
148 Brush_SelectFaceForDragging (t.brush, f, false);
151 Sys_Printf ("Dragging entire selection\n");
156 if (g_qeglobals.d_select_mode == sel_vertex || g_qeglobals.d_select_mode == sel_edge)
160 // check for side hit
162 if (selected_brushes.next->next != &selected_brushes)
164 Sys_Printf ("Click isn't inside multiple selection\n");
168 if (selected_brushes.next->owner->eclass->fixedsize)
170 Sys_Printf ("Can't stretch fixed size entities\n");
175 if (buttons & MK_CONTROL)
176 Brush_SideSelect (selected_brushes.next, origin, dir, true);
178 Brush_SideSelect (selected_brushes.next, origin, dir, false);
181 Sys_Printf ("Side stretch\n");
187 void UpdateTarget(vec3_t origin, vec3_t dir)
194 t = Test_Ray (origin, dir, 0);
204 // is this the first?
208 // Get the target id from out current target
209 // if there is no id, make one
211 i = IntForKey(pe, "target");
214 i = GetUniqueTargetId(1);
215 sprintf(sz, "%d", i);
217 SetKeyValue(pe, "target", sz);
220 // set the target # into our src
222 sprintf(sz, "%d", i);
223 SetKeyValue(peLink, "targetname", sz);
225 Sys_UpdateWindows(W_ENTITY);
229 // promote the target to the src
240 void Drag_Begin (int x, int y, int buttons,
241 vec3_t xaxis, vec3_t yaxis,
242 vec3_t origin, vec3_t dir)
247 VectorCopy (vec3_origin, pressdelta);
252 // shift LBUTTON = select entire brush
253 if (buttons == (MK_LBUTTON | MK_SHIFT))
255 if (!dir[0] && !dir[1])
256 Select_Ray (origin, dir, SF_ENTITIES_FIRST); // hack for XY
258 Select_Ray (origin, dir, 0);
262 // ctrl-shift LBUTTON = select single face
263 if (buttons == (MK_LBUTTON | MK_CONTROL | MK_SHIFT))
266 Select_Ray (origin, dir, SF_SINGLEFACE);
270 // LBUTTON + all other modifiers = manipulate selection
271 if (buttons & MK_LBUTTON)
273 Drag_Setup (x, y, buttons, xaxis, yaxis, origin, dir);
277 // middle button = grab texture
278 if (buttons == MK_MBUTTON)
280 t = Test_Ray (origin, dir, false);
283 g_qeglobals.d_new_brush_bottom_z = t.brush->mins[2];
284 g_qeglobals.d_new_brush_top_z = t.brush->maxs[2];
285 Texture_SetTexture (&t.face->texdef);
288 Sys_Printf ("Did not select a texture\n");
292 // ctrl-middle button = set entire brush to texture
293 if (buttons == (MK_MBUTTON|MK_CONTROL) )
295 t = Test_Ray (origin, dir, false);
298 if (t.brush->brush_faces->texdef.name[0] == '(')
299 Sys_Printf ("Can't change an entity texture\n");
302 Brush_SetTexture (t.brush, &g_qeglobals.d_texturewin.texdef);
303 Sys_UpdateWindows (W_ALL);
307 Sys_Printf ("Didn't hit a btrush\n");
311 // ctrl-shift-middle button = set single face to texture
312 if (buttons == (MK_MBUTTON|MK_SHIFT|MK_CONTROL) )
314 t = Test_Ray (origin, dir, false);
317 if (t.brush->brush_faces->texdef.name[0] == '(')
318 Sys_Printf ("Can't change an entity texture\n");
321 t.face->texdef = g_qeglobals.d_texturewin.texdef;
322 Brush_Build( t.brush );
323 Sys_UpdateWindows (W_ALL);
327 Sys_Printf ("Didn't hit a btrush\n");
339 void MoveSelection (vec3_t move)
344 if (!move[0] && !move[1] && !move[2])
347 Sys_UpdateWindows (W_XY|W_CAMERA);
350 // dragging only a part of the selection
352 if (g_qeglobals.d_num_move_points)
354 for (i=0 ; i<g_qeglobals.d_num_move_points ; i++)
355 VectorAdd (g_qeglobals.d_move_points[i], move, g_qeglobals.d_move_points[i]);
357 for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
360 for (i=0 ; i<3 ; i++)
361 if (b->mins[i] > b->maxs[i]
362 || b->maxs[i] - b->mins[i] > 4096)
363 break; // dragged backwards or fucked up
368 // if any of the brushes were crushed out of existance
369 // calcel the entire move
370 if (b != &selected_brushes)
372 Sys_Printf ("Brush dragged backwards, move canceled\n");
373 for (i=0 ; i<g_qeglobals.d_num_move_points ; i++)
374 VectorSubtract (g_qeglobals.d_move_points[i], move, g_qeglobals.d_move_points[i]);
376 for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
384 // if there are lots of brushes selected, just translate instead
385 // of rebuilding the brushes
387 if (drag_yvec[2] == 0 && selected_brushes.next->next != &selected_brushes)
389 VectorAdd (g_qeglobals.d_select_translate, move, g_qeglobals.d_select_translate);
403 void Drag_MouseMoved (int x, int y, int buttons)
407 char movestring[128];
417 // clear along one axis
418 if (buttons & MK_SHIFT)
421 if (abs(x-pressx) > abs(y-pressy))
428 for (i=0 ; i<3 ; i++)
430 move[i] = drag_xvec[i]*(x - pressx)
431 + drag_yvec[i]*(y - pressy);
432 move[i] = floor(move[i]/g_qeglobals.d_gridsize+0.5)*g_qeglobals.d_gridsize;
435 sprintf (movestring, "drag (%i %i %i)", (int)move[0], (int)move[1], (int)move[2]);
436 Sys_Status (movestring, 0);
438 VectorSubtract (move, pressdelta, delta);
439 MoveSelection (delta);
440 VectorCopy (move, pressdelta);
448 void Drag_MouseUp (void)
450 Sys_Status ("drag completed.", 0);
451 if (g_qeglobals.d_select_translate[0] || g_qeglobals.d_select_translate[1] || g_qeglobals.d_select_translate[2])
453 Select_Move (g_qeglobals.d_select_translate);
454 VectorCopy (vec3_origin, g_qeglobals.d_select_translate);
455 Sys_UpdateWindows (W_CAMERA);