drag.cpp
来自「quake3工具源码。包括生成bsp文件」· C++ 代码 · 共 714 行 · 第 1/2 页
CPP
714 行
#include "stdafx.h"
#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;
int pressx, pressy;
static vec3_t pressdelta;
static vec3_t vPressStart;
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;
drag_first = true;
VectorCopy (vec3_origin, pressdelta);
pressx = x;
pressy = y;
VectorCopy (xaxis, drag_xvec);
AxializeVector (drag_xvec);
VectorCopy (yaxis, drag_yvec);
AxializeVector (drag_yvec);
extern void SelectCurvePointByRay (vec3_t org, vec3_t dir, int buttons);
if (g_qeglobals.d_select_mode == sel_curvepoint)
{
//if ((buttons == MK_LBUTTON))
// g_qeglobals.d_num_move_points = 0;
SelectCurvePointByRay (origin, dir, buttons);
if (g_qeglobals.d_num_move_points || g_qeglobals.d_select_mode == sel_area)
{
drag_ok = true;
}
Sys_UpdateWindows(W_ALL);
Undo_Start("drag curve point");
Undo_AddBrushList(&selected_brushes);
return;
}
else
{
g_qeglobals.d_num_move_points = 0;
}
if (selected_brushes.next == &selected_brushes)
{
//in this case a new brush is created when the dragging
//takes place in the XYWnd, An useless undo is created
//when the dragging takes place in the CamWnd
Undo_Start("create brush");
Sys_Status("No selection to drag\n", 0);
return;
}
if (g_qeglobals.d_select_mode == sel_vertex)
{
SelectVertexByRay (origin, dir);
if (g_qeglobals.d_num_move_points)
{
drag_ok = true;
Undo_Start("drag vertex");
Undo_AddBrushList(&selected_brushes);
return;
}
}
if (g_qeglobals.d_select_mode == sel_edge)
{
SelectEdgeByRay (origin, dir);
if (g_qeglobals.d_num_move_points)
{
drag_ok = true;
Undo_Start("drag edge");
Undo_AddBrushList(&selected_brushes);
return;
}
}
//
// check for direct hit first
//
t = Test_Ray (origin, dir, true);
if (t.selected)
{
drag_ok = true;
Undo_Start("drag selection");
Undo_AddBrushList(&selected_brushes);
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
//
// multiple brushes selected?
if (selected_brushes.next->next != &selected_brushes)
{
// yes, special handling
bool bOK = (g_PrefsDlg.m_bALTEdge) ? (static_cast<bool>(::GetAsyncKeyState(VK_MENU))) : true;
if (bOK)
{
for (brush_t* pBrush = selected_brushes.next ; pBrush != &selected_brushes ; pBrush = pBrush->next)
{
if (buttons & MK_CONTROL)
Brush_SideSelect (pBrush, origin, dir, true);
else
Brush_SideSelect (pBrush, origin, dir, false);
}
}
else
{
Sys_Printf ("press ALT to drag multiple edges\n");
return;
}
}
else
{
// single select.. trying to drag fixed entities handle themselves and just move
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;
Undo_Start("side stretch");
Undo_AddBrushList(&selected_brushes);
}
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
//++timo test three button mouse and three button emulation here ?
===========
*/
void Drag_Begin (int x, int y, int buttons,
vec3_t xaxis, vec3_t yaxis,
vec3_t origin, vec3_t dir)
{
trace_t t;
bool altdown;
drag_ok = false;
VectorCopy (vec3_origin, pressdelta);
VectorCopy (vec3_origin, vPressStart);
drag_first = true;
peLink = NULL;
altdown = static_cast<bool>(::GetAsyncKeyState(VK_MENU));
// shift-LBUTTON = select entire brush
if (buttons == (MK_LBUTTON | MK_SHIFT) && g_qeglobals.d_select_mode != sel_curvepoint)
{
int nFlag = altdown ? SF_CYCLE : 0;
if (dir[0] == 0 || dir[1] == 0 || dir[2] == 0) // extremely low chance of this happening from camera
Select_Ray (origin, dir, nFlag | SF_ENTITIES_FIRST); // hack for XY
else
Select_Ray (origin, dir, nFlag);
return;
}
// ctrl-alt-LBUTTON = multiple brush select without selecting whole entities
if (buttons == (MK_LBUTTON | MK_CONTROL) && altdown && g_qeglobals.d_select_mode != sel_curvepoint)
{
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) && g_qeglobals.d_select_mode != sel_curvepoint)
{
Select_Deselect (!static_cast<bool>(::GetAsyncKeyState(VK_MENU)));
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;
}
int nMouseButton = g_PrefsDlg.m_nMouseButtons == 2 ? MK_RBUTTON : MK_MBUTTON;
// middle button = grab texture
if (buttons == nMouseButton)
{
t = Test_Ray (origin, dir, false);
if (t.face)
{
g_qeglobals.d_new_brush_bottom_z = t.brush->mins[2];
g_qeglobals.d_new_brush_top_z = t.brush->maxs[2];
// use a local brushprimit_texdef fitted to a default 2x2 texture
brushprimit_texdef_t bp_local;
ConvertTexMatWithQTexture( &t.face->brushprimit_texdef, t.face->d_texture, &bp_local, NULL );
Texture_SetTexture ( &t.face->texdef, &bp_local, false, GETPLUGINTEXDEF(t.face));
UpdateSurfaceDialog();
UpdatePatchInspector();
}
else
Sys_Printf ("Did not select a texture\n");
return;
}
// ctrl-middle button = set entire brush to texture
if (buttons == (nMouseButton|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
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?