]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/drag.cpp
* applied patch by StefanV (from mailinglist) that fixes an error in config.py (broke...
[xonotic/netradiant.git] / radiant / drag.cpp
1 /*
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 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.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 #include "stdafx.h"
23 //#include "qe3.h"
24
25 /*
26
27   drag either multiple brushes, or select plane points from
28   a single brush.
29
30 */
31
32 extern int g_nPatchClickedView;
33
34 qboolean        drag_ok;
35 vec3_t  drag_xvec;
36 vec3_t  drag_yvec;
37
38 //static        int     buttonstate;
39 int     pressx, pressy;
40 static  vec3_t pressdelta;
41 static  vec3_t vPressStart;
42 //static        int     buttonx, buttony;
43
44
45 //int           num_move_points;
46 //float *move_points[1024];
47
48 int             lastx, lasty;
49
50 qboolean        drag_first;
51
52
53 void    AxializeVector (vec3_t v)
54 {
55         vec3_t  a;
56         float   o;
57         int             i;
58
59         if (!v[0] && !v[1])
60                 return;
61         if (!v[1] && !v[2])
62                 return;
63         if (!v[0] && !v[2])
64                 return;
65
66         for (i=0 ; i<3 ; i++)
67                 a[i] = fabs(v[i]);
68         if (a[0] > a[1] && a[0] > a[2])
69                 i = 0;
70         else if (a[1] > a[0] && a[1] > a[2])
71                 i = 1;
72         else
73                 i = 2;
74
75         o = v[i];
76         VectorCopy (vec3_origin, v);
77         if (o<0)
78                 v[i] = -1;
79         else
80                 v[i] = 1;
81
82 }
83
84 /*
85 ===========
86 Drag_Setup
87 ===========
88 */
89 extern void SelectCurvePointByRay (vec3_t org, vec3_t dir, int buttons);
90
91 void Drag_Setup (int x, int y, int buttons,
92                  vec3_t xaxis, vec3_t yaxis,
93                  vec3_t origin, vec3_t dir)
94 {
95   trace_t       t;
96   face_t        *f;
97
98   drag_first = true;
99
100   VectorCopy (vec3_origin, pressdelta);
101   pressx = x;
102   pressy = y;
103
104         // snap to nearest axis for camwindow drags
105   VectorCopy (xaxis, drag_xvec);
106   AxializeVector (drag_xvec);
107   VectorCopy (yaxis, drag_yvec);
108   AxializeVector (drag_yvec);
109
110   if (g_qeglobals.d_select_mode == sel_curvepoint)
111   {
112     SelectCurvePointByRay (origin, dir, buttons);
113
114     if(g_qeglobals.d_select_mode == sel_area)
115     {
116       drag_ok = true;
117
118                         if(g_nPatchClickedView == W_CAMERA ) {
119                                 VectorSet( g_qeglobals.d_vAreaTL, x, y, 0 );
120                                 VectorSet( g_qeglobals.d_vAreaBR, x, y, 0 );
121                         }
122     }
123     else if (g_qeglobals.d_num_move_points) // don't add an undo if there are no points selected
124     {
125       drag_ok = true;
126       Sys_UpdateWindows(W_ALL);
127       Undo_Start("drag curve point");
128       Undo_AddBrushList(&selected_brushes);
129     }
130     return;
131   }
132   else
133   {
134     g_qeglobals.d_num_move_points = 0;
135   }
136
137   if (g_qeglobals.d_select_mode == sel_areatall)
138   {
139     VectorCopy(origin, g_qeglobals.d_vAreaTL);
140     VectorCopy(origin, g_qeglobals.d_vAreaBR);
141
142     Sys_UpdateWindows(W_ALL);
143
144     drag_ok = true;
145     return;
146   }
147
148   if (selected_brushes.next == &selected_brushes)
149   {
150     //in this case a new brush is created when the dragging
151     //takes place in the XYWnd, An useless undo is created
152     //when the dragging takes place in the CamWnd
153     Undo_Start("create brush");
154
155     Sys_Status("No selection to drag", 0);
156     return;
157   }
158
159   if (g_qeglobals.d_select_mode == sel_vertex)
160   {
161     SelectVertexByRay (origin, dir);
162     if (g_qeglobals.d_num_move_points)
163     {
164       drag_ok = true;
165       Undo_Start("drag vertex");
166       Undo_AddBrushList(&selected_brushes);
167       // Need an update here for highlighting selected vertices
168       Sys_UpdateWindows(W_XY | W_CAMERA);
169       return;
170     }
171   }
172
173   if (g_qeglobals.d_select_mode == sel_edge)
174   {
175     SelectEdgeByRay (origin, dir);
176     if (g_qeglobals.d_num_move_points)
177     {
178       drag_ok = true;
179       Undo_Start("drag edge");
180       Undo_AddBrushList(&selected_brushes);
181       return;
182     }
183   }
184
185   //
186   // check for direct hit first
187   //
188   t = Test_Ray (origin, dir, true);
189   if (t.selected)
190   {
191     drag_ok = true;
192
193     Undo_Start("drag selection");
194     Undo_AddBrushList(&selected_brushes);
195
196     if (buttons == (MK_LBUTTON|MK_CONTROL) )
197     {
198       Sys_Printf ("Shear dragging face\n");
199       Brush_SelectFaceForDragging (t.brush, t.face, true);
200     }
201     else if (buttons == (MK_LBUTTON|MK_CONTROL|MK_SHIFT) )
202     {
203       Sys_Printf ("Sticky dragging brush\n");
204       for (f=t.brush->brush_faces ; f ; f=f->next)
205         Brush_SelectFaceForDragging (t.brush, f, false);
206     }
207     else
208       Sys_Printf ("Dragging entire selection\n");
209
210     return;
211   }
212
213   if (g_qeglobals.d_select_mode == sel_vertex || g_qeglobals.d_select_mode == sel_edge)
214     return;
215
216   //
217   // check for side hit
218   //
219   // multiple brushes selected?
220   if (selected_brushes.next->next != &selected_brushes)
221   {
222     // yes, special handling
223     bool bOK = (g_PrefsDlg.m_bALTEdge) ? Sys_AltDown() : true;
224     if (bOK)
225     {
226       for (brush_t* pBrush = selected_brushes.next ; pBrush != &selected_brushes ; pBrush = pBrush->next)
227       {
228         if (buttons & MK_CONTROL)
229           Brush_SideSelect (pBrush, origin, dir, true);
230         else
231           Brush_SideSelect (pBrush, origin, dir, false);
232       }
233     }
234     else
235     {
236       Sys_Printf ("press ALT to drag multiple edges\n");
237       return;
238     }
239   }
240   else
241   {
242     // single select.. trying to drag fixed entities handle themselves and just move
243     if (buttons & MK_CONTROL)
244       Brush_SideSelect (selected_brushes.next, origin, dir, true);
245     else
246       Brush_SideSelect (selected_brushes.next, origin, dir, false);
247   }
248
249   Sys_Printf ("Side stretch\n");
250   drag_ok = true;
251
252   Undo_Start("side stretch");
253   Undo_AddBrushList(&selected_brushes);
254 }
255
256 entity_t *peLink;
257
258 void UpdateTarget(vec3_t origin, vec3_t dir)
259 {
260         trace_t t;
261         entity_t *pe;
262         int i;
263         char sz[128];
264
265         t = Test_Ray (origin, dir, 0);
266
267         if (!t.brush)
268                 return;
269
270         pe = t.brush->owner;
271
272         if (pe == NULL)
273                 return;
274
275         // is this the first?
276         if (peLink != NULL)
277         {
278
279                 // Get the target id from out current target
280                 // if there is no id, make one
281
282                 i = IntForKey(pe, "target");
283                 if (i <= 0)
284                 {
285                         i = GetUniqueTargetId(1);
286                         sprintf(sz, "%d", i);
287
288                         SetKeyValue(pe, "target", sz);
289                 }
290
291                 // set the target # into our src
292
293                 sprintf(sz, "%d", i);
294                 SetKeyValue(peLink, "targetname", sz);
295
296                 Sys_UpdateWindows(W_ENTITY);
297
298         }
299
300         // promote the target to the src
301
302         peLink = pe;
303
304 }
305
306 /*
307 ===========
308 Drag_Begin
309 //++timo test three button mouse and three button emulation here ?
310 ===========
311 */
312 void Drag_Begin (int x, int y, int buttons,
313                    vec3_t xaxis, vec3_t yaxis,
314                    vec3_t origin, vec3_t dir, bool sf_camera)
315 {
316         trace_t t;
317   bool altdown;
318   int nFlag;
319
320         drag_ok = false;
321         VectorCopy (vec3_origin, pressdelta);
322         VectorCopy (vec3_origin, vPressStart);
323
324         drag_first = true;
325         peLink = NULL;
326
327   altdown = Sys_AltDown();
328
329         // shift-LBUTTON = select entire brush
330   // shift-alt-LBUTTON = drill select
331         if (buttons == (MK_LBUTTON | MK_SHIFT) && g_qeglobals.d_select_mode != sel_curvepoint)
332         {
333     nFlag = altdown ? SF_CYCLE : 0;
334     if (sf_camera)
335       nFlag |= SF_CAMERA;
336     else
337       nFlag |= SF_ENTITIES_FIRST;
338     Select_Ray(origin, dir, nFlag);
339                 return;
340         }
341
342   // (shift-)alt-LBUTTON = area select completely tall
343   if ( !sf_camera &&
344       ( g_PrefsDlg.m_bALTEdge ? buttons == (MK_LBUTTON | MK_CONTROL | MK_SHIFT) : (buttons == MK_LBUTTON || buttons == (MK_LBUTTON | MK_CONTROL | MK_SHIFT)) ) &&
345       altdown && g_qeglobals.d_select_mode != sel_curvepoint)
346   {
347     if (g_pParentWnd->ActiveXY()->AreaSelectOK())
348     {
349       g_qeglobals.d_select_mode = sel_areatall;
350
351       Drag_Setup (x, y, buttons, xaxis, yaxis, origin, dir);
352       return;
353     }
354   }
355
356         // ctrl-alt-LBUTTON = multiple brush select without selecting whole entities
357         if (buttons == (MK_LBUTTON | MK_CONTROL) && altdown && g_qeglobals.d_select_mode != sel_curvepoint)
358         {
359     nFlag = 0;
360     if (sf_camera)
361       nFlag |= SF_CAMERA;
362     else
363       nFlag |= SF_ENTITIES_FIRST;
364     Select_Ray (origin, dir, nFlag);
365     UpdateSurfaceDialog();
366
367                 return;
368         }
369
370         // ctrl-shift LBUTTON = select single face
371         if (sf_camera && buttons == (MK_LBUTTON | MK_CONTROL | MK_SHIFT) && g_qeglobals.d_select_mode != sel_curvepoint)
372         {
373     if(Sys_AltDown())
374     {
375       brush_t *b;
376       for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
377       {
378         if(b->pPatch)
379           continue;
380
381         for (face_t* pFace = b->brush_faces; pFace; pFace = pFace->next)
382         {
383           g_ptrSelectedFaces.Add(pFace);
384           g_ptrSelectedFaceBrushes.Add(b);
385         }
386       }
387
388       for (b = selected_brushes.next; b != &selected_brushes; )
389       {
390         brush_t *pb = b;
391                           b = b->next;
392         Brush_RemoveFromList (pb);
393         Brush_AddToList (pb, &active_brushes);
394       }
395     }
396     else
397                   Select_Deselect (true);
398
399                 Select_Ray (origin, dir, (SF_SINGLEFACE|SF_CAMERA));
400                 return;
401         }
402
403
404         // LBUTTON + all other modifiers = manipulate selection
405         if (buttons & MK_LBUTTON)
406         {
407                 Drag_Setup (x, y, buttons, xaxis, yaxis, origin, dir);
408                 return;
409         }
410
411         int nMouseButton = g_PrefsDlg.m_nMouseButtons == 2 ? MK_RBUTTON : MK_MBUTTON;
412         // middle button = grab texture
413         if (buttons == nMouseButton)
414         {
415                 t = Test_Ray (origin, dir, false);
416                 if (t.face)
417                 {
418       UpdateWorkzone_ForBrush( t.brush );
419                         // use a local brushprimit_texdef fitted to a default 2x2 texture
420                         brushprimit_texdef_t bp_local;
421                         ConvertTexMatWithQTexture( &t.face->brushprimit_texdef, t.face->d_texture, &bp_local, NULL );
422                         Texture_SetTexture ( &t.face->texdef, &bp_local, false, NULL);
423                         UpdateSurfaceDialog();
424                         UpdatePatchInspector();
425                 }
426                 else
427                         Sys_Printf ("Did not select a texture\n");
428                 return;
429         }
430
431         // ctrl-middle button = set entire brush to texture
432         if (buttons == (nMouseButton|MK_CONTROL) )
433         {
434                 t = Test_Ray (origin, dir, false);
435                 if (t.brush)
436                 {
437                         if (t.brush->brush_faces->texdef.GetName()[0] == '(')
438                                 Sys_Printf ("Can't change an entity texture\n");
439                         else
440                         {
441                                 Brush_SetTexture (t.brush, &g_qeglobals.d_texturewin.texdef, &g_qeglobals.d_texturewin.brushprimit_texdef, false, static_cast<IPluginTexdef *>( g_qeglobals.d_texturewin.pTexdef ) );
442                                 Sys_UpdateWindows (W_ALL);
443                         }
444                 }
445                 else
446                         Sys_Printf ("Didn't hit a btrush\n");
447                 return;
448         }
449
450         // ctrl-shift-middle button = set single face to texture
451         if (buttons == (nMouseButton|MK_SHIFT|MK_CONTROL) )
452         {
453                 t = Test_Ray (origin, dir, false);
454                 if (t.brush)
455                 {
456                         if (t.brush->brush_faces->texdef.GetName()[0] == '(')
457                                 Sys_Printf ("Can't change an entity texture\n");
458                         else
459                         {
460                                 SetFaceTexdef (t.face, &g_qeglobals.d_texturewin.texdef, &g_qeglobals.d_texturewin.brushprimit_texdef);
461                                 Brush_Build( t.brush );
462
463                                 Sys_UpdateWindows (W_ALL);
464                         }
465                 }
466                 else
467                         Sys_Printf ("Didn't hit a btrush\n");
468                 return;
469         }
470
471         if (buttons == (nMouseButton | MK_SHIFT))
472         {
473                 Sys_Printf("Set brush face texture info\n");
474                 t = Test_Ray (origin, dir, false);
475                 if (t.brush)
476                 {
477                         if (t.brush->brush_faces->texdef.GetName()[0] == '(')
478       {
479         if (t.brush->owner->eclass->nShowFlags & ECLASS_LIGHT)
480         {
481           CString strBuff;
482           qtexture_t* pTex = g_qeglobals.d_texturewin.pShader->getTexture();
483           if (pTex)
484           {
485             vec3_t vColor;
486             VectorCopy(pTex->color, vColor);
487
488             float fLargest = 0.0f;
489             for (int i = 0; i < 3; i++)
490             {
491                           if (vColor[i] > fLargest)
492                                   fLargest = vColor[i];
493             }
494
495                         if (fLargest == 0.0f)
496                         {
497               vColor[0] = vColor[1] = vColor[2] = 1.0f;
498             }
499                         else
500                         {
501                                 float fScale = 1.0f / fLargest;
502               for (int i = 0; i < 3; i++)
503               {
504                 vColor[i] *= fScale;
505               }
506             }
507             strBuff.Format("%f %f %f",pTex->color[0], pTex->color[1], pTex->color[2]);
508             SetKeyValue(t.brush->owner, "_color", strBuff.GetBuffer());
509                                     Sys_UpdateWindows (W_ALL);
510           }
511         }
512         else
513         {
514                                   Sys_Printf ("Can't select an entity brush face\n");
515         }
516       }
517                         else
518                         {
519         Face_SetShader(t.face, g_qeglobals.d_texturewin.texdef.GetName());
520                                 Brush_Build(t.brush);
521
522                                 Sys_UpdateWindows (W_ALL);
523                         }
524                 }
525                 else
526                         Sys_Printf ("Didn't hit a brush\n");
527                 return;
528         }
529
530 }
531
532
533 //
534 //===========
535 //MoveSelection
536 //===========
537 //
538 void MoveSelection (vec3_t move)
539 {
540         int             i, success;
541         brush_t *b;
542         CString strStatus;
543         vec3_t vTemp, vTemp2, end;
544
545         if (!move[0] && !move[1] && !move[2])
546   {
547                 return;
548   }
549
550   if (!(g_qeglobals.d_select_mode == sel_area || g_qeglobals.d_select_mode == sel_areatall))
551   {
552     move[0] = (g_nScaleHow & SCALE_X) ? 0 : move[0];
553     move[1] = (g_nScaleHow & SCALE_Y) ? 0 : move[1];
554     move[2] = (g_nScaleHow & SCALE_Z) ? 0 : move[2];
555   }
556
557         if (g_pParentWnd->ActiveXY()->RotateMode() || g_bPatchBendMode)
558         {
559                 float fDeg = -move[2];
560                 float fAdj = move[2];
561                 int nAxis = 0;
562                 if (g_pParentWnd->ActiveXY()->GetViewType() == XY)
563                 {
564                         fDeg = -move[1];
565                         fAdj = move[1];
566                         nAxis = 2;
567                 }
568                 else
569                 if (g_pParentWnd->ActiveXY()->GetViewType() == XZ)
570                 {
571                         fDeg = move[2];
572                         fAdj = move[2];
573                         nAxis = 1;
574                 }
575                 else
576                         nAxis = 0;
577
578                 g_pParentWnd->ActiveXY()->Rotation()[nAxis] += fAdj;
579                 strStatus.Format("%s x:: %.1f  y:: %.1f  z:: %.1f", (g_bPatchBendMode) ? "Bend angle" : "Rotation", g_pParentWnd->ActiveXY()->Rotation()[0], g_pParentWnd->ActiveXY()->Rotation()[1], g_pParentWnd->ActiveXY()->Rotation()[2]);
580                 g_pParentWnd->SetStatusText(2, strStatus);
581
582                 if (g_bPatchBendMode)
583                 {
584                         Patch_SelectBendNormal();
585                         Select_RotateAxis(nAxis, fDeg*2, false, true);
586                         Patch_SelectBendAxis();
587                         Select_RotateAxis(nAxis, fDeg, false, true);
588                 }
589                 else
590                 {
591                         Select_RotateAxis(nAxis, fDeg, false, true);
592                 }
593                 return;
594         }
595
596         if (g_pParentWnd->ActiveXY()->ScaleMode())
597         {
598                 vec3_t v;
599                 v[0] = v[1] = v[2] = 1.0f;
600                 if (move[1] > 0)
601                 {
602                         v[0] = 1.1f;
603                         v[1] = 1.1f;
604                         v[2] = 1.1f;
605                 }
606                 else
607                         if (move[1] < 0)
608                 {
609                         v[0] = 0.9f;
610                         v[1] = 0.9f;
611                         v[2] = 0.9f;
612                 }
613
614                         Select_Scale((g_nScaleHow & SCALE_X) ? 1.0f : v[0],
615                                                                          (g_nScaleHow & SCALE_Y) ? 1.0f : v[1],
616                                                                  (g_nScaleHow & SCALE_Z) ? 1.0f : v[2]);
617       // is that really necessary???
618                 Sys_UpdateWindows (W_ALL);
619                 return;
620         }
621
622
623         vec3_t vDistance;
624         VectorSubtract(pressdelta, vPressStart, vDistance);
625         strStatus.Format("Distance x: %.1f  y: %.1f  z: %.1f", vDistance[0], vDistance[1], vDistance[2]);
626         g_pParentWnd->SetStatusText(3, strStatus);
627
628         //
629         // dragging only a part of the selection
630         //
631
632         // this is fairly crappy way to deal with curvepoint and area selection
633         // but it touches the smallest amount of code this way
634         //
635         if (g_qeglobals.d_num_move_points || g_qeglobals.d_select_mode == sel_vertex || g_qeglobals.d_select_mode == sel_area || g_qeglobals.d_select_mode == sel_areatall)
636         {
637                 //area selection
638     if (g_qeglobals.d_select_mode == sel_area || g_qeglobals.d_select_mode == sel_areatall)
639                 {
640                         VectorAdd(g_qeglobals.d_vAreaBR, move, g_qeglobals.d_vAreaBR);
641                         return;
642                 }
643                 //curve point selection
644                 if (g_qeglobals.d_select_mode == sel_curvepoint)
645                 {
646                         Patch_UpdateSelected(move);
647                         return;
648                 }
649                 //vertex selection
650                 if (g_qeglobals.d_select_mode == sel_vertex && g_PrefsDlg.m_bVertexSplit)
651                 {
652       if(g_qeglobals.d_num_move_points) {
653                           success = true;
654                           for (b = selected_brushes.next; b != &selected_brushes; b = b->next)
655                           {
656                                   success &= Brush_MoveVertex(b, g_qeglobals.d_move_points[0], move, end, true);
657                           }
658                           if (success)
659                                   VectorCopy(end, g_qeglobals.d_move_points[0]);
660       }
661                         return;
662                 }
663                 //all other selection types
664                 for (i=0 ; i<g_qeglobals.d_num_move_points ; i++)
665                         VectorAdd (g_qeglobals.d_move_points[i], move, g_qeglobals.d_move_points[i]);
666                 for (b = selected_brushes.next; b != &selected_brushes; b = b->next)
667                 {
668       bool bMoved = false;
669       for(face_t *f = b->brush_faces; !bMoved && f!=NULL; f=f->next)
670         for(int p=0; !bMoved && p<3; p++)
671           for (i=0 ; !bMoved && i<g_qeglobals.d_num_move_points ; i++)
672                               if(f->planepts[p] == g_qeglobals.d_move_points[i])
673               bMoved = true;
674                   if(!bMoved) continue;
675
676                         VectorCopy(b->maxs, vTemp);
677                         VectorSubtract(vTemp, b->mins, vTemp);
678       Brush_Build(b,true,true,false,false); // don't filter
679                         for (i=0 ; i<3 ; i++)
680                         {
681                                 if (b->mins[i] > b->maxs[i]
682                                 || b->maxs[i] - b->mins[i] > g_MaxBrushSize)
683                                         break;  // dragged backwards or fucked up
684                         }
685                         if (i != 3)
686                                 break;
687                         if (b->patchBrush)
688                         {
689                                 VectorCopy(b->maxs, vTemp2);
690                                 VectorSubtract(vTemp2, b->mins, vTemp2);
691                                 VectorSubtract(vTemp2, vTemp, vTemp2);
692                                 //if (!Patch_DragScale(b->nPatchID, vTemp2, move))
693                                 if (!Patch_DragScale(b->pPatch, vTemp2, move))
694                                 {
695                                         b = NULL;
696                                         break;
697                                 }
698                         }
699                 }
700                 // if any of the brushes were crushed out of existance
701                 // calcel the entire move
702                 if (b != &selected_brushes)
703                 {
704                         Sys_Printf ("Brush dragged backwards, move canceled\n");
705                         for (i=0 ; i<g_qeglobals.d_num_move_points ; i++)
706                                 VectorSubtract (g_qeglobals.d_move_points[i], move, g_qeglobals.d_move_points[i]);
707
708                         for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
709                                 Brush_Build(b,true,true,false,false); // don't filter
710                 }
711
712         }
713         else
714         {
715                 // reset face originals from vertex edit mode
716                 // this is dirty, but unfortunately necessary because Brush_Build
717                 // can remove windings
718                 for (b = selected_brushes.next; b != &selected_brushes; b = b->next)
719                 {
720                         Brush_ResetFaceOriginals(b);
721                 }
722                 //
723                 // if there are lots of brushes selected, just translate instead
724                 // of rebuilding the brushes
725     // NOTE: this is not actually done, but would be a good idea
726                 //
727           Select_Move (move);
728         }
729 }
730
731 /*
732 ===========
733 Drag_MouseMoved
734 ===========
735 */
736 void Drag_MouseMoved (int x, int y, int buttons)
737 {
738   vec3_t        move, delta;
739   int           i;
740
741   if (!buttons)
742   {
743     drag_ok = false;
744     return;
745   }
746   if (!drag_ok)
747     return;
748
749   // clear along one axis
750   if (buttons & MK_SHIFT && (g_PrefsDlg.m_bALTEdge && g_qeglobals.d_select_mode != sel_areatall))
751   {
752     drag_first = false;
753     if (abs(x-pressx) > abs(y-pressy))
754       y = pressy;
755     else
756       x = pressx;
757   }
758
759         if (g_qeglobals.d_select_mode == sel_area && g_nPatchClickedView == W_CAMERA)
760         {
761                 camera_t *m_pCamera = g_pParentWnd->GetCamWnd()->Camera();
762
763                 // snap to window
764                 if( y > m_pCamera->height ) y = m_pCamera->height - 1; else if( y < 0 ) y = 0;
765                 if( x > m_pCamera->width ) x = m_pCamera->width - 1; else if( x < 0 ) x = 0;
766
767                 VectorSet (move, x - pressx, y - pressy, 0);
768         } else
769         {
770                 for (i=0 ; i<3 ; i++)
771                 {
772                         move[i] = drag_xvec[i]*(x - pressx)     + drag_yvec[i]*(y - pressy);
773                         if (g_PrefsDlg.m_bSnap)
774                         {
775                                 move[i] = floor(move[i]/g_qeglobals.d_gridsize+0.5)*g_qeglobals.d_gridsize;
776                         }
777                 }
778         }
779
780   VectorSubtract (move, pressdelta, delta);
781   VectorCopy (move, pressdelta);
782
783   MoveSelection (delta);
784 }
785
786 /*
787 ===========
788 Drag_MouseUp
789 ===========
790 */
791 void Drag_MouseUp (int nButtons)
792 {
793         Sys_Status ("Drag completed.", 0);
794
795   if (g_qeglobals.d_select_mode == sel_area)
796   {
797     Patch_SelectAreaPoints(nButtons & MK_CONTROL); // adds to selection and/or deselects selected points if ctrl is held
798     g_qeglobals.d_select_mode = sel_curvepoint;
799                 Sys_UpdateWindows (W_ALL);
800   }
801
802   if (g_qeglobals.d_select_mode == sel_areatall)
803   {
804     vec3_t mins, maxs;
805
806     int nDim1 = (g_pParentWnd->ActiveXY()->GetViewType() == YZ) ? 1 : 0;
807     int nDim2 = (g_pParentWnd->ActiveXY()->GetViewType() == XY) ? 1 : 2;
808
809                 // get our rectangle
810     mins[nDim1] = MIN( g_qeglobals.d_vAreaTL[nDim1], g_qeglobals.d_vAreaBR[nDim1] );
811     mins[nDim2] = MIN( g_qeglobals.d_vAreaTL[nDim2], g_qeglobals.d_vAreaBR[nDim2] );
812     maxs[nDim1] = MAX( g_qeglobals.d_vAreaTL[nDim1], g_qeglobals.d_vAreaBR[nDim1] );
813     maxs[nDim2] = MAX( g_qeglobals.d_vAreaTL[nDim2], g_qeglobals.d_vAreaBR[nDim2] );
814
815     // deselect current selection
816     if( !(nButtons & (MK_CONTROL|MK_SHIFT)) )
817       Select_Deselect();
818
819     // select new selection
820     Select_RealCompleteTall( mins, maxs );
821
822     Sys_UpdateWindows (W_ALL);
823   }
824
825   if (g_qeglobals.d_select_translate[0] || g_qeglobals.d_select_translate[1] || g_qeglobals.d_select_translate[2])
826         {
827                 Select_Move (g_qeglobals.d_select_translate);
828                 VectorCopy (vec3_origin, g_qeglobals.d_select_translate);
829                 Sys_UpdateWindows (W_CAMERA);
830         }
831
832   /* note: added cleanup here, since an edge drag will leave selected vertices
833            in g_qeglobals.d_num_move_points
834   */
835   if (  g_qeglobals.d_select_mode != sel_vertex &&
836         g_qeglobals.d_select_mode != sel_curvepoint &&
837         g_qeglobals.d_select_mode != sel_edge)
838     g_qeglobals.d_num_move_points = 0;
839
840   g_pParentWnd->SetStatusText(3, "");
841   Undo_EndBrushList(&selected_brushes);
842   Undo_End();
843   UpdateSurfaceDialog();
844 }