-/*\r
-Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
-For a list of contributors, see the accompanying CONTRIBUTORS file.\r
-\r
-This file is part of GtkRadiant.\r
-\r
-GtkRadiant is free software; you can redistribute it and/or modify\r
-it under the terms of the GNU General Public License as published by\r
-the Free Software Foundation; either version 2 of the License, or\r
-(at your option) any later version.\r
-\r
-GtkRadiant is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-GNU General Public License for more details.\r
-\r
-You should have received a copy of the GNU General Public License\r
-along with GtkRadiant; if not, write to the Free Software\r
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r
-*/\r
-\r
-// select.c\r
-#include "stdafx.h"\r
-#include <assert.h>\r
-#include "filters.h"\r
-\r
-// externs\r
-CPtrArray g_SelectedFaces;\r
-CPtrArray g_SelectedFaceBrushes;\r
-CPtrArray& g_ptrSelectedFaces = g_SelectedFaces;\r
-CPtrArray& g_ptrSelectedFaceBrushes = g_SelectedFaceBrushes;\r
-\r
-/*\r
-===========\r
-Test_Ray\r
-===========\r
-*/\r
-#define DIST_START 999999\r
-trace_t Test_Ray (vec3_t origin, vec3_t dir, int flags)\r
-{\r
- brush_t *brush;\r
- face_t *face;\r
- float dist;\r
- trace_t t;\r
-\r
- memset (&t, 0, sizeof(t));\r
- t.dist = DIST_START;\r
-\r
- if (flags & SF_CYCLE)\r
- {\r
- CPtrArray array;\r
- brush_t *pToSelect = (selected_brushes.next != &selected_brushes) ? selected_brushes.next : NULL;\r
- Select_Deselect();\r
-\r
- // go through active brushes and accumulate all "hit" brushes\r
- for (brush = active_brushes.next ; brush != &active_brushes ; brush=brush->next)\r
- {\r
- //if ( (flags & SF_ENTITIES_FIRST) && brush->owner == world_entity)\r
- // continue;\r
- \r
- if (brush->bFiltered)\r
- continue;\r
-\r
- if (!g_PrefsDlg.m_bSelectCurves && brush->patchBrush)\r
- continue;\r
-\r
- if (!g_PrefsDlg.m_bSelectModels && (brush->owner->eclass->nShowFlags & ECLASS_MISCMODEL))\r
- continue;\r
-\r
- //if (!g_bShowPatchBounds && brush->patchBrush)\r
- // continue;\r
-\r
- face = Brush_Ray (origin, dir, brush, &dist, flags);\r
-\r
- if (face)\r
- array.Add(brush);\r
- }\r
-\r
- int nSize = array.GetSize();\r
- if (nSize > 0)\r
- {\r
- bool bFound = false;\r
- for (int i = 0; i < nSize; i++)\r
- {\r
- brush_t *b = reinterpret_cast<brush_t*>(array.GetAt(i));\r
- // did we hit the last one selected yet ?\r
- if (b == pToSelect)\r
- {\r
- // yes we want to select the next one in the list \r
- int n = (i > 0) ? i-1 : nSize-1;\r
- pToSelect = reinterpret_cast<brush_t*>(array.GetAt(n));\r
- bFound = true;\r
- break;\r
- }\r
- }\r
- if (!bFound)\r
- pToSelect = reinterpret_cast<brush_t*>(array.GetAt(0));\r
- }\r
- if (pToSelect)\r
- {\r
- face = Brush_Ray (origin, dir, pToSelect, &dist, flags);\r
- t.dist = dist;\r
- t.brush = pToSelect;\r
- t.face = face;\r
- t.selected = false;\r
- return t;\r
- }\r
- }\r
-\r
- if (! (flags & SF_SELECTED_ONLY) )\r
- {\r
- for (brush = active_brushes.next ; brush != &active_brushes ; brush=brush->next)\r
- {\r
- if ( (flags & SF_ENTITIES_FIRST) && (brush->owner == world_entity || !brush->owner->eclass->fixedsize))\r
- continue;\r
- \r
- if (brush->bFiltered)\r
- continue;\r
-\r
- if (!g_PrefsDlg.m_bSelectCurves && brush->patchBrush)\r
- continue;\r
-\r
- if (!g_PrefsDlg.m_bSelectModels && (brush->owner->eclass->nShowFlags & ECLASS_MISCMODEL))\r
- continue;\r
-\r
- //if (!g_bShowPatchBounds && brush->patchBrush)\r
- // continue;\r
-\r
- face = Brush_Ray (origin, dir, brush, &dist, flags);\r
- if (face && dist > 0 && dist < t.dist)\r
- {\r
- t.dist = dist;\r
- t.brush = brush;\r
- t.face = face;\r
- t.selected = false;\r
- }\r
- }\r
- }\r
-\r
-\r
- for (brush = selected_brushes.next ; brush != &selected_brushes ; brush=brush->next)\r
- {\r
- if ( (flags & SF_ENTITIES_FIRST) && (brush->owner == world_entity || !brush->owner->eclass->fixedsize))\r
- continue;\r
-\r
- if (brush->bFiltered)\r
- continue;\r
-\r
- if (!g_PrefsDlg.m_bSelectCurves && brush->patchBrush)\r
- continue;\r
-\r
- if (!g_PrefsDlg.m_bSelectModels && (brush->owner->eclass->nShowFlags & ECLASS_MISCMODEL))\r
- continue;\r
-\r
- face = Brush_Ray (origin, dir, brush, &dist, flags);\r
- if (dist > 0 && dist < t.dist)\r
- {\r
- t.dist = dist;\r
- t.brush = brush;\r
- t.face = face;\r
- t.selected = true;\r
- }\r
- }\r
-\r
- // if entites first, but didn't find any, check regular\r
-\r
- if ( (flags & SF_ENTITIES_FIRST) && t.brush == NULL)\r
- return Test_Ray (origin, dir, flags & ~SF_ENTITIES_FIRST);\r
-\r
- return t;\r
-\r
-}\r
-\r
-\r
-/*\r
-============\r
-Select_Brush\r
-\r
-============\r
-*/\r
-void Select_Brush (brush_t *brush, bool bComplete, bool bStatus)\r
-{\r
- brush_t *b;\r
- entity_t *e;\r
-\r
- g_ptrSelectedFaces.RemoveAll();\r
- g_ptrSelectedFaceBrushes.RemoveAll();\r
- if (g_qeglobals.d_select_count < 2)\r
- g_qeglobals.d_select_order[g_qeglobals.d_select_count] = brush;\r
- g_qeglobals.d_select_count++;\r
-\r
- e = brush->owner;\r
- if (e)\r
- {\r
- // select complete entity on first click\r
- if (e != world_entity && bComplete == true)\r
- {\r
- for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)\r
- if (b->owner == e)\r
- goto singleselect;\r
- for (b=e->brushes.onext ; b != &e->brushes ; b=b->onext)\r
- {\r
- if( b == brush ) // make sure we add the actual selected brush last, mainly for cycle select\r
- continue;\r
- Brush_RemoveFromList (b);\r
- Brush_AddToList (b, &selected_brushes);\r
- }\r
- Brush_RemoveFromList (brush);\r
- Brush_AddToList (brush, &selected_brushes);\r
- }\r
- else\r
- {\r
- singleselect:\r
- Brush_RemoveFromList (brush);\r
- Brush_AddToList (brush, &selected_brushes);\r
- UpdatePatchInspector();\r
- }\r
-\r
- if (e->eclass)\r
- {\r
- UpdateEntitySel(brush->owner->eclass);\r
- }\r
-\r
- UpdateSurfaceDialog();\r
- }\r
-\r
- if (bStatus)\r
- {\r
- vec3_t vMin, vMax, vSize;\r
- Select_GetBounds (vMin, vMax);\r
- VectorSubtract(vMax, vMin, vSize);\r
- CString strStatus;\r
- strStatus.Format("Selection X:: %.1f Y:: %.1f Z:: %.1f", vSize[0], vSize[1], vSize[2]);\r
- g_pParentWnd->SetStatusText(2, strStatus);\r
- }\r
-}\r
-\r
-/*\r
-=============\r
-Select_FaceInSelectedBrushes\r
-=============\r
-*/\r
-bool Select_FaceInSelectedBrushes( face_t *face )\r
-{\r
- brush_t *brush;\r
- face_t *tface;\r
-\r
- for(brush = selected_brushes.next; brush != &selected_brushes; brush = brush->next)\r
- {\r
- for(tface = brush->brush_faces; tface; tface = tface->next)\r
- {\r
- if(tface == face)\r
- {\r
- return true;\r
- }\r
- }\r
- }\r
-\r
- return false;\r
-}\r
-\r
-/*\r
-============\r
-Select_Ray\r
-\r
-If the origin is inside a brush, that brush will be ignored.\r
-============\r
-*/\r
-void Select_Ray (vec3_t origin, vec3_t dir, int flags)\r
-{\r
- trace_t t;\r
- face_t *tface;\r
- bool bOk;\r
- static trace_t lastTrace = {\r
- NULL, // brush\r
- NULL, // face\r
- 0, // dist\r
- false // selected\r
- };\r
-\r
- t = Test_Ray (origin, dir, flags);\r
- if (!t.brush)\r
- return;\r
-\r
- if (flags & SF_SINGLEFACE)\r
- {\r
- if( flags & SF_DRAG )\r
- {\r
- if ( t.brush == lastTrace.brush && t.face == lastTrace.face )\r
- return;\r
- }\r
- lastTrace = t;\r
-\r
- if(Select_FaceInSelectedBrushes(t.face))\r
- {\r
- // Deselect the brush\r
- Brush_RemoveFromList (t.brush);\r
- Brush_AddToList (t.brush, &active_brushes);\r
- UpdatePatchInspector();\r
-\r
- // Select all of the brush's faces except the one we are pointing at\r
- for( tface = t.brush->brush_faces; tface; tface = tface->next )\r
- {\r
- if( tface == t.face )\r
- continue;\r
-\r
- bOk = true;\r
- // NOTE: keep the size check in the loop, we remove stuff inside\r
- for (int i = 0; i < g_SelectedFaces.GetSize(); i++)\r
- {\r
- if (tface == reinterpret_cast<face_t*>(g_SelectedFaces.GetAt(i)))\r
- bOk = false;\r
- }\r
-\r
- if(bOk)\r
- {\r
- g_SelectedFaces.Add(tface);\r
- g_SelectedFaceBrushes.Add(t.brush);\r
- }\r
- }\r
- g_qeglobals.d_select_mode = sel_facets_off;\r
- }\r
- else\r
- {\r
- bOk = true;\r
- // NOTE: keep the size check in the loop, we remove stuff inside\r
- for (int i = 0; i < g_SelectedFaces.GetSize(); i++)\r
- {\r
- if (t.face == reinterpret_cast<face_t*>(g_SelectedFaces.GetAt(i)))\r
- {\r
- bOk = false;\r
- if( flags & SF_DRAG_ON )\r
- continue;\r
-\r
- g_qeglobals.d_select_mode = sel_facets_off;\r
- // need to remove i'th entry\r
- g_SelectedFaces.RemoveAt(i, 1);\r
- g_SelectedFaceBrushes.RemoveAt(i, 1);\r
- }\r
- }\r
-\r
- if (bOk && !(flags & SF_DRAG_OFF))\r
- {\r
- g_SelectedFaces.Add(t.face);\r
- g_SelectedFaceBrushes.Add(t.brush);\r
- g_qeglobals.d_select_mode = sel_facets_on;\r
- }\r
- }\r
- UpdateSurfaceDialog();\r
- Sys_UpdateWindows (W_ALL);\r
- //g_qeglobals.d_select_mode = sel_brush;\r
- // Texture_SetTexture requires a brushprimit_texdef fitted to the default width=2 height=2 texture\r
- brushprimit_texdef_t brushprimit_texdef;\r
- ConvertTexMatWithQTexture ( &t.face->brushprimit_texdef, t.face->d_texture, &brushprimit_texdef, NULL );\r
- Texture_SetTexture ( &t.face->texdef, &brushprimit_texdef, false, NULL, false );\r
- return;\r
- }\r
-\r
- // move the brush to the other list\r
- if (t.selected)\r
- {\r
- if( flags & SF_DRAG_ON )\r
- return;\r
- \r
- g_qeglobals.d_select_mode = sel_brush_off;\r
- Brush_RemoveFromList (t.brush);\r
- Brush_AddToList (t.brush, &active_brushes);\r
-\r
- UpdatePatchInspector();\r
- } \r
- else\r
- {\r
- if( flags & SF_DRAG_OFF )\r
- return;\r
-\r
- g_qeglobals.d_select_mode = sel_brush_on;\r
- Select_Brush (t.brush, g_PrefsDlg.m_nCamDragMultiSelect == 1 ? Sys_AltDown () : !Sys_AltDown ());\r
- }\r
- UpdateSurfaceDialog();\r
- Sys_UpdateWindows (W_ALL);\r
-}\r
-\r
-\r
-void Select_Delete (void)\r
-{\r
- brush_t *brush;\r
- entity_t *e;\r
-\r
- g_ptrSelectedFaces.RemoveAll();\r
- g_ptrSelectedFaceBrushes.RemoveAll();\r
-\r
- g_qeglobals.d_select_mode = sel_brush;\r
-\r
- g_qeglobals.d_select_count = 0;\r
- g_qeglobals.d_num_move_points = 0;\r
- while (selected_brushes.next != &selected_brushes)\r
- {\r
- brush = selected_brushes.next;\r
- if (brush->patchBrush)\r
- {\r
- Patch_Delete(brush->pPatch);\r
- }\r
- e = brush->owner;\r
- Brush_Free (brush);\r
- // remove if no brushes\r
- if (e != world_entity && e->brushes.onext == &e->brushes)\r
- Entity_Free(e);\r
- }\r
-\r
- Sys_MarkMapModified ();\r
- UpdateSurfaceDialog();\r
- Sys_UpdateWindows (W_ALL);\r
-}\r
-\r
-// update the workzone to a given brush\r
-void UpdateWorkzone_ForBrush( brush_t* b )\r
-{\r
- VectorCopy( b->mins, g_qeglobals.d_work_min );\r
- VectorCopy( b->maxs, g_qeglobals.d_work_max );\r
- //++timo clean\r
-#if 0\r
- // will update the workzone to the given brush\r
- // g_pParentWnd->ActiveXY()->GetViewType()\r
- // cf VIEWTYPE defintion: enum VIEWTYPE {YZ, XZ, XY};\r
- // we fit our work zone to the last brush on the list (b)\r
- int nViewType = g_pParentWnd->ActiveXY()->GetViewType();\r
- int nDim1 = (nViewType == YZ) ? 1 : 0;\r
- int nDim2 = (nViewType == XY) ? 1 : 2;\r
- g_qeglobals.d_work_min[nDim1] = b->mins[nDim1];\r
- g_qeglobals.d_work_max[nDim1] = b->maxs[nDim1];\r
- g_qeglobals.d_work_min[nDim2] = b->mins[nDim2];\r
- g_qeglobals.d_work_max[nDim2] = b->maxs[nDim2];\r
-#endif\r
-}\r
-\r
-// here to filter new brushes once unselected\r
-extern void PerformFiltering();\r
-\r
-void Select_Deselect (bool bDeselectFaces)\r
-{\r
- brush_t *b;\r
-\r
- Patch_Deselect();\r
-\r
- g_pParentWnd->ActiveXY()->UndoClear();\r
-\r
- g_qeglobals.d_workcount++;\r
- g_qeglobals.d_select_count = 0;\r
- g_qeglobals.d_num_move_points = 0;\r
- b = selected_brushes.next;\r
-\r
- if (b == &selected_brushes)\r
- {\r
- if (bDeselectFaces)\r
- {\r
- g_ptrSelectedFaces.RemoveAll();\r
- g_ptrSelectedFaceBrushes.RemoveAll();\r
- }\r
- PerformFiltering();\r
- UpdateSurfaceDialog();\r
- Sys_UpdateWindows (W_ALL);\r
- return;\r
- }\r
-\r
- if (bDeselectFaces)\r
- {\r
- g_ptrSelectedFaces.RemoveAll();\r
- g_ptrSelectedFaceBrushes.RemoveAll();\r
- }\r
-\r
- g_qeglobals.d_select_mode = sel_brush;\r
-\r
- UpdateWorkzone_ForBrush(b);\r
-\r
- selected_brushes.next->prev = &active_brushes;\r
- selected_brushes.prev->next = active_brushes.next;\r
- active_brushes.next->prev = selected_brushes.prev;\r
- active_brushes.next = selected_brushes.next;\r
- selected_brushes.prev = selected_brushes.next = &selected_brushes;\r
-\r
- // filter newly created stuff once it's unselected\r
- PerformFiltering();\r
- UpdateSurfaceDialog();\r
- Sys_UpdateWindows (W_ALL);\r
-}\r
-\r
-/*\r
-============\r
-Select_Move\r
-============\r
-*/\r
-/*! Moves the currently selected brush/patch\r
- \param delta How far to move the selection (x,y,z)\r
- \param bSnap If the move should snap to grid points\r
-*/\r
-void Select_Move (vec3_t delta, bool bSnap)\r
-{\r
- brush_t *b;\r
-\r
- // actually move the selected brushes\r
- for (b = selected_brushes.next ; b != &selected_brushes ; b=b->next)\r
- Brush_Move (b, delta, bSnap);\r
-\r
- vec3_t vMin, vMax;\r
- Select_GetBounds (vMin, vMax);\r
- CString strStatus;\r
- strStatus.Format("Origin X:: %.1f Y:: %.1f Z:: %.1f", vMin[0], vMax[1], vMax[2]);\r
- g_pParentWnd->SetStatusText(2, strStatus);\r
-\r
- //Sys_UpdateWindows (W_ALL);\r
-}\r
-\r
-/*\r
-=================\r
-Select_NudgeVerts\r
-=================\r
-*/\r
-/*! Moves the currently selected brush/patch vertices\r
- \param delta How far to move the vertices (x,y,z)\r
- \param bSnap If the move should snap to grid points\r
-*/\r
-void Select_NudgePoint(vec3_t delta, qboolean bSnap)\r
-{\r
- if (g_qeglobals.d_select_mode == sel_vertex)\r
- {\r
- // move selected verts\r
- brush_t *b;\r
- vec3_t end;\r
- qboolean success = true;\r
- for (b = selected_brushes.next; b != &selected_brushes; b = b->next)\r
- {\r
- success &= (qboolean)Brush_MoveVertex(b, g_qeglobals.d_move_points[0], delta, end, bSnap);\r
- }\r
- if (success)\r
- VectorCopy(end, g_qeglobals.d_move_points[0]);\r
- }\r
- else if (g_qeglobals.d_select_mode == sel_curvepoint)\r
- {\r
- // move selected patch control points\r
- Patch_UpdateSelected(delta);\r
- }\r
-}\r
-\r
-/*\r
-============\r
-Select_Clone\r
-\r
-Creates an exact duplicate of the selection in place, then moves\r
-the selected brushes off of their old positions\r
-============\r
-*/\r
-void Select_Clone (void)\r
-{\r
- g_bScreenUpdates = false; \r
- g_pParentWnd->Copy();\r
- Select_Deselect();\r
- g_pParentWnd->Paste();\r
- g_pParentWnd->NudgeSelection(2, g_qeglobals.d_gridsize);\r
- g_pParentWnd->NudgeSelection(3, g_qeglobals.d_gridsize);\r
- Undo_Start("clone");\r
- Undo_EndBrushList(&selected_brushes);\r
- Undo_End();\r
- g_bScreenUpdates = true; \r
- Sys_UpdateWindows(W_ALL);\r
-}\r
-\r
-//++timo clean\r
-#if 0\r
-/*\r
-============\r
-Select_SetTexture\r
-Timo : bFitScale to compute scale on the plane and counteract plane / axial plane snapping\r
-Timo : brush primitive texturing\r
- the brushprimit_texdef given must be understood as a qtexture_t width=2 height=2 ( HiRes )\r
-Timo : texture plugin, added an IPluginTexdef* parameter\r
- must be casted to an IPluginTexdef!\r
- if not NULL, get ->Copy() of it into each face or brush ( and remember to hook )\r
- if NULL, means we have no information, ask for a default\r
-TTimo - shader code cleanup\r
- added IShader* parameter\r
-============\r
-*/\r
-void WINAPI Select_SetTexture2 (IShader* pShader, texdef_t *texdef, brushprimit_texdef_t *brushprimit_texdef, bool bFitScale, void* pPlugTexdef )\r
-{\r
- brush_t *b;\r
- int nCount = g_ptrSelectedFaces.GetSize();\r
- if (nCount > 0)\r
- {\r
- Undo_Start("set face textures");\r
- ASSERT(g_ptrSelectedFaces.GetSize() == g_ptrSelectedFaceBrushes.GetSize());\r
- for (int i = 0; i < nCount; i++)\r
- {\r
- face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(i));\r
- brush_t *selBrush = reinterpret_cast<brush_t*>(g_ptrSelectedFaceBrushes.GetAt(i));\r
- Undo_AddBrush(selBrush);\r
- //++timo TODO: propagate the IShader* ..\r
- SetFaceTexdef (selFace, texdef, brushprimit_texdef, bFitScale, static_cast<IPluginTexdef *>(pPlugTexdef) );\r
- Brush_Build(selBrush, bFitScale);\r
- Undo_EndBrush(selBrush);\r
- }\r
- Undo_End();\r
- }\r
- else if (selected_brushes.next != &selected_brushes)\r
- {\r
- Undo_Start("set brush textures");\r
- for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)\r
- if (!b->owner->eclass->fixedsize)\r
- {\r
- Undo_AddBrush(b);\r
- Brush_SetTexture2 (b, pShader, texdef, brushprimit_texdef, bFitScale, static_cast<IPluginTexdef *>(pPlugTexdef) );\r
- Undo_EndBrush(b);\r
- }\r
- Undo_End();\r
- }\r
- Sys_UpdateWindows (W_ALL);\r
-}\r
-#endif\r
-\r
-/*\r
-============\r
-Select_SetTexture\r
-Timo : bFitScale to compute scale on the plane and counteract plane / axial plane snapping\r
-Timo : brush primitive texturing\r
- the brushprimit_texdef given must be understood as a qtexture_t width=2 height=2 ( HiRes )\r
-Timo : texture plugin, added an IPluginTexdef* parameter\r
- must be casted to an IPluginTexdef!\r
- if not NULL, get ->Copy() of it into each face or brush ( and remember to hook )\r
- if NULL, means we have no information, ask for a default\r
-============\r
-*/\r
-void WINAPI Select_SetTexture (texdef_t *texdef, brushprimit_texdef_t *brushprimit_texdef, bool bFitScale, void* pPlugTexdef )\r
-{\r
- /*\r
-#ifdef _DEBUG\r
- static int count = 0;\r
-#endif\r
- */\r
- brush_t *b;\r
- /*\r
-#ifdef _DEBUG\r
- count++;\r
- Sys_Printf("count: %d\n", count);\r
- if(count==4)\r
- Sys_Printf("break!\n");\r
-#endif\r
- */\r
- int nCount = g_ptrSelectedFaces.GetSize();\r
- if (nCount > 0)\r
- {\r
- Undo_Start("set face textures");\r
- assert(g_ptrSelectedFaces.GetSize() == g_ptrSelectedFaceBrushes.GetSize());\r
- for (int i = 0; i < nCount; i++)\r
- {\r
- face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(i));\r
- brush_t *selBrush = reinterpret_cast<brush_t*>(g_ptrSelectedFaceBrushes.GetAt(i));\r
- Undo_AddBrush(selBrush);\r
- SetFaceTexdef (selFace, texdef, brushprimit_texdef, bFitScale, static_cast<IPluginTexdef *>(pPlugTexdef) );\r
- Brush_Build(selBrush, bFitScale);\r
- Undo_EndBrush(selBrush);\r
- }\r
- Undo_End();\r
- }\r
- else if (selected_brushes.next != &selected_brushes)\r
- {\r
- Undo_Start("set brush textures");\r
- for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)\r
- if (!b->owner->eclass->fixedsize)\r
- {\r
- Undo_AddBrush(b);\r
- Brush_SetTexture (b, texdef, brushprimit_texdef, bFitScale, static_cast<IPluginTexdef *>(pPlugTexdef) );\r
- Undo_EndBrush(b);\r
- }\r
- Undo_End();\r
- }\r
- //++timo FIXME: not necessary in every cases, write a message defering / move one level up\r
- Sys_UpdateWindows (W_ALL);\r
-}\r
-\r
-\r
-/*\r
-================================================================\r
-\r
- TRANSFORMATIONS\r
-\r
-================================================================\r
-*/\r
-\r
-void Select_GetBounds (vec3_t mins, vec3_t maxs)\r
-{\r
- brush_t *b;\r
- int i;\r
-\r
- for (i=0 ; i<3 ; i++)\r
- {\r
- mins[i] = 99999;\r
- maxs[i] = -99999;\r
- }\r
-\r
- for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)\r
- {\r
- if (b->owner->eclass->fixedsize)\r
- {\r
- for (i=0 ; i<3 ; i++)\r
- {\r
- if (b->owner->origin[i] < mins[i])\r
- mins[i] = b->owner->origin[i];\r
- if (b->owner->origin[i] > maxs[i])\r
- maxs[i] = b->owner->origin[i];\r
- }\r
- }\r
- else\r
- {\r
- for (i=0 ; i<3 ; i++)\r
- {\r
- if (b->mins[i] < mins[i])\r
- mins[i] = b->mins[i];\r
- if (b->maxs[i] > maxs[i])\r
- maxs[i] = b->maxs[i];\r
- }\r
- }\r
- }\r
-}\r
-\r
-void Select_GetTrueMid (vec3_t mid)\r
-{\r
- vec3_t mins, maxs;\r
- Select_GetBounds (mins, maxs);\r
-\r
- for (int i=0 ; i<3 ; i++)\r
- mid[i] = (mins[i] + ((maxs[i] - mins[i]) / 2));\r
-}\r
-\r
-void Select_GetMid (vec3_t mid)\r
-{\r
- vec3_t mins, maxs;\r
- int i;\r
-\r
- if (g_PrefsDlg.m_bNoClamp)\r
- {\r
- Select_GetTrueMid(mid);\r
- return;\r
- }\r
-\r
- Select_GetBounds (mins, maxs);\r
-\r
- for (i=0 ; i<3 ; i++)\r
- mid[i] = g_qeglobals.d_gridsize*floor ( ( (mins[i] + maxs[i])*0.5 )/g_qeglobals.d_gridsize );\r
-}\r
-\r
-vec3_t select_origin;\r
-vec3_t select_matrix[3];\r
-qboolean select_fliporder;\r
-\r
-// FIXME: bApplyBPrimit is supposed to be temporary\r
-// TODO: manage Brush_Build calls, too many of them with the texture processing\r
-// FIXME: the undo doesn't seem to work correctly on texturing and flip/rotate operations?? this is not supposed to be related to the texture locking code, so what is happening?\r
-// FIXME: ApplyMatrix works on flipping operation, b0rks on Rotations (so does the "regular" rotation code??)\r
-// FIXME: what is getting called in free rotation mode? that used to work right?\r
-void Select_ApplyMatrix (bool bSnap, bool bRotation, int nAxis, float fDeg)//, qboolean bApplyBPrimit)\r
-{\r
- brush_t *b;\r
- face_t *f;\r
- int i, j;\r
- vec3_t temp, tmporigin;\r
-\r
- for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)\r
- {\r
- if(b->owner->eclass->fixedsize)\r
- {\r
- VectorCopy (b->owner->origin, tmporigin);\r
- // transform the origin point\r
- VectorSubtract (b->owner->origin, select_origin, temp);\r
- for (j=0 ; j<3 ; j++)\r
- b->owner->origin[j] = DotProduct(temp, select_matrix[j]) + select_origin[j];\r
- \r
- // update the origin key\r
- char text[64];\r
- sprintf (text, "%i %i %i",\r
- (int)b->owner->origin[0], (int)b->owner->origin[1], (int)b->owner->origin[2]);\r
- SetKeyValue(b->owner, "origin", text);\r
- \r
- /*\todo remove brush-based bounding box for fixedsize entities */\r
- VectorSubtract (b->owner->origin, tmporigin, temp);\r
- for (f=b->brush_faces ; f ; f=f->next)\r
- {\r
- // move fixedsize bbox to new origin\r
- for (i=0 ; i<3 ; i++)\r
- VectorAdd (f->planepts[i], temp, f->planepts[i]);\r
- }\r
- Brush_Build(b, bSnap,true,false,false); // don't filter\r
-\r
- }\r
- else if (b->patchBrush)\r
- {\r
- if (!bRotation && !((g_qeglobals.d_select_mode == sel_curvepoint && g_qeglobals.d_num_move_points != 0) || g_bPatchBendMode))\r
- // invert patch if this is a mirroring operation, unless points are selected or bendmode is active\r
- patchInvert(b->pPatch);\r
- // NOTE: does not clamp points to integers\r
- Patch_ApplyMatrix(b->pPatch, select_origin, select_matrix, false);\r
- }\r
- else\r
- {\r
- for (f=b->brush_faces ; f ; f=f->next)\r
- {\r
- // FIXME: only in BP mode!\r
- // if we are using Brush Primitives texturing, we need to compute the texture matrix after the geometric transformation\r
- // (with the default texturing you don't need to compute anything for flipping and mirroring operations)\r
- // if (bApplyBPrimit) {\r
- // ApplyMatrix_BrushPrimit (f, select_matrix, select_origin, select_fliporder);\r
- // }\r
- for (i=0 ; i<3 ; i++)\r
- {\r
- VectorSubtract (f->planepts[i], select_origin, temp);\r
- for (j=0 ; j<3 ; j++)\r
- f->planepts[i][j] = DotProduct(temp, select_matrix[j]) + select_origin[j];\r
- }\r
- if (select_fliporder)\r
- {\r
- VectorCopy (f->planepts[0], temp);\r
- VectorCopy (f->planepts[2], f->planepts[0]);\r
- VectorCopy (temp, f->planepts[2]);\r
- }\r
- }\r
- Brush_Build(b, bSnap,true,false,false); // don't filter\r
- }\r
- }\r
-}\r
-\r
-void ProjectOnPlane(vec3_t& normal,float dist,vec3_t& ez, vec3_t& p)\r
-{\r
- if (fabs(ez[0]) == 1)\r
- p[0] = (dist - normal[1] * p[1] - normal[2] * p[2]) / normal[0];\r
- else if (fabs(ez[1]) == 1)\r
- p[1] = (dist - normal[0] * p[0] - normal[2] * p[2]) / normal[1];\r
- else\r
- p[2] = (dist - normal[0] * p[0] - normal[1] * p[1]) / normal[2];\r
-}\r
-\r
-void Back(vec3_t& dir, vec3_t& p)\r
-{\r
- if (fabs(dir[0]) == 1)\r
- p[0] = 0;\r
- else if (fabs(dir[1]) == 1)\r
- p[1] = 0;\r
- else p[2] = 0;\r
-}\r
-\r
-\r
-\r
-// using scale[0] and scale[1]\r
-void ComputeScale(vec3_t& rex, vec3_t& rey, vec3_t& p, face_t* f)\r
-{\r
- float px = DotProduct(rex, p);\r
- float py = DotProduct(rey, p);\r
- px *= f->texdef.scale[0];\r
- py *= f->texdef.scale[1];\r
- vec3_t aux;\r
- VectorCopy(rex, aux);\r
- VectorScale(aux, px, aux);\r
- VectorCopy(aux, p);\r
- VectorCopy(rey, aux);\r
- VectorScale(aux, py, aux);\r
- VectorAdd(p, aux, p);\r
-}\r
-\r
-void ComputeAbsolute(face_t* f, vec3_t& p1, vec3_t& p2, vec3_t& p3)\r
-{\r
- vec3_t ex,ey,ez; // local axis base\r
-\r
-#ifdef _DEBUG\r
- if (g_qeglobals.m_bBrushPrimitMode)\r
- Sys_Printf("Warning : illegal call of ComputeAbsolute in brush primitive mode\n");\r
-#endif\r
-\r
- // compute first local axis base\r
- TextureAxisFromPlane(&f->plane, ex, ey);\r
- CrossProduct(ex, ey, ez);\r
- \r
- vec3_t aux;\r
- VectorCopy(ex, aux);\r
- VectorScale(aux, -f->texdef.shift[0], aux);\r
- VectorCopy(aux, p1);\r
- VectorCopy(ey, aux);\r
- VectorScale(aux, -f->texdef.shift[1], aux);\r
- VectorAdd(p1, aux, p1);\r
- VectorCopy(p1, p2);\r
- VectorAdd(p2, ex, p2);\r
- VectorCopy(p1, p3);\r
- VectorAdd(p3, ey, p3);\r
- VectorCopy(ez, aux);\r
- VectorScale(aux, -f->texdef.rotate, aux);\r
- VectorRotate(p1, aux, p1);\r
- VectorRotate(p2, aux, p2);\r
- VectorRotate(p3, aux, p3);\r
- // computing rotated local axis base\r
- vec3_t rex,rey;\r
- VectorCopy(ex, rex);\r
- VectorRotate(rex, aux, rex);\r
- VectorCopy(ey, rey);\r
- VectorRotate(rey, aux, rey);\r
-\r
- ComputeScale(rex,rey,p1,f);\r
- ComputeScale(rex,rey,p2,f);\r
- ComputeScale(rex,rey,p3,f);\r
-\r
- // project on normal plane\r
- // along ez \r
- // assumes plane normal is normalized\r
- ProjectOnPlane(f->plane.normal,f->plane.dist,ez,p1);\r
- ProjectOnPlane(f->plane.normal,f->plane.dist,ez,p2);\r
- ProjectOnPlane(f->plane.normal,f->plane.dist,ez,p3);\r
-};\r
-\r
-\r
-void AbsoluteToLocal(plane_t normal2, face_t* f, vec3_t& p1, vec3_t& p2, vec3_t& p3)\r
-{\r
- vec3_t ex,ey,ez;\r
-\r
-#ifdef _DEBUG\r
- if (g_qeglobals.m_bBrushPrimitMode)\r
- Sys_Printf("Warning : illegal call of AbsoluteToLocal in brush primitive mode\n");\r
-#endif\r
-\r
- // computing new local axis base\r
- TextureAxisFromPlane(&normal2, ex, ey);\r
- CrossProduct(ex, ey, ez);\r
-\r
- // projecting back on (ex,ey)\r
- Back(ez,p1);\r
- Back(ez,p2);\r
- Back(ez,p3);\r
-\r
- vec3_t aux;\r
- // rotation\r
- VectorCopy(p2, aux);\r
- VectorSubtract(aux, p1,aux);\r
- \r
- float x = DotProduct(aux,ex);\r
- float y = DotProduct(aux,ey);\r
- f->texdef.rotate = 180 * atan2(y,x) / Q_PI;\r
-\r
- vec3_t rex,rey;\r
- // computing rotated local axis base\r
- VectorCopy(ez, aux);\r
- VectorScale(aux, f->texdef.rotate, aux);\r
- VectorCopy(ex, rex);\r
- VectorRotate(rex, aux, rex);\r
- VectorCopy(ey, rey);\r
- VectorRotate(rey, aux, rey);\r
-\r
- // scale\r
- VectorCopy(p2, aux);\r
- VectorSubtract(aux, p1, aux);\r
- f->texdef.scale[0] = DotProduct(aux, rex);\r
- VectorCopy(p3, aux);\r
- VectorSubtract(aux, p1, aux);\r
- f->texdef.scale[1] = DotProduct(aux, rey);\r
-\r
- // shift\r
- // only using p1\r
- x = DotProduct(rex,p1);\r
- y = DotProduct(rey,p1); \r
- x /= f->texdef.scale[0];\r
- y /= f->texdef.scale[1];\r
-\r
- VectorCopy(rex, p1);\r
- VectorScale(p1, x, p1);\r
- VectorCopy(rey, aux);\r
- VectorScale(aux, y, aux);\r
- VectorAdd(p1, aux, p1);\r
- VectorCopy(ez, aux);\r
- VectorScale(aux, -f->texdef.rotate, aux);\r
- VectorRotate(p1, aux, p1);\r
- f->texdef.shift[0] = -DotProduct(p1, ex);\r
- f->texdef.shift[1] = -DotProduct(p1, ey);\r
-\r
- // stored rot is good considering local axis base\r
- // change it if necessary\r
- f->texdef.rotate = -f->texdef.rotate;\r
-\r
- Clamp(f->texdef.shift[0], f->d_texture->width);\r
- Clamp(f->texdef.shift[1], f->d_texture->height);\r
- Clamp(f->texdef.rotate, 360);\r
-\r
-}\r
-\r
-void RotateFaceTexture(face_t* f, int nAxis, float fDeg)\r
-{\r
- vec3_t p1,p2,p3, rota; \r
- p1[0] = p1[1] = p1[2] = 0;\r
- VectorCopy(p1, p2);\r
- VectorCopy(p1, p3);\r
- VectorCopy(p1, rota);\r
- ComputeAbsolute(f, p1, p2, p3);\r
- \r
- rota[nAxis] = fDeg;\r
- VectorRotateOrigin (p1, rota, select_origin, p1);\r
- VectorRotateOrigin (p2, rota, select_origin, p2);\r
- VectorRotateOrigin (p3, rota, select_origin, p3);\r
-\r
- plane_t normal2;\r
- vec3_t vNormal;\r
- vNormal[0] = f->plane.normal[0];\r
- vNormal[1] = f->plane.normal[1];\r
- vNormal[2] = f->plane.normal[2];\r
- VectorRotate(vNormal, rota, vNormal);\r
- normal2.normal[0] = vNormal[0];\r
- normal2.normal[1] = vNormal[1];\r
- normal2.normal[2] = vNormal[2];\r
- AbsoluteToLocal(normal2, f, p1, p2 ,p3);\r
-\r
-}\r
-\r
-void RotateTextures(int nAxis, float fDeg, vec3_t vOrigin)\r
-{\r
- for (brush_t* b=selected_brushes.next ; b != &selected_brushes ; b=b->next)\r
- {\r
- for (face_t* f=b->brush_faces ; f ; f=f->next)\r
- {\r
- if (g_qeglobals.m_bBrushPrimitMode)\r
- RotateFaceTexture_BrushPrimit (f, nAxis, fDeg, vOrigin);\r
- else\r
- RotateFaceTexture (f, nAxis, fDeg);\r
- }\r
- Brush_Build(b, false,true,false,false); // don't filter\r
- }\r
-}\r
-\r
-void Select_ApplyMatrix_BrushPrimit()\r
-{\r
- #ifdef _DEBUG\r
- if (!g_qeglobals.m_bBrushPrimitMode) {\r
- Sys_FPrintf(SYS_ERR,"ERROR: Select_ApplyMatrix_BrushPrimit called in non-BP mode\n");\r
- }\r
- #endif\r
- for (brush_t* b=selected_brushes.next ; b != &selected_brushes ; b=b->next)\r
- {\r
- for (face_t* f=b->brush_faces ; f ; f=f->next)\r
- {\r
- ApplyMatrix_BrushPrimit (f, select_matrix, select_origin);\r
- }\r
- }\r
-}\r
-\r
-void Select_FlipAxis (int axis)\r
-{\r
- int i;\r
-\r
- Select_GetMid (select_origin);\r
- for (i=0 ; i<3 ; i++)\r
- {\r
- VectorCopy (vec3_origin, select_matrix[i]);\r
- select_matrix[i][i] = 1;\r
- }\r
- select_matrix[axis][axis] = -1;\r
- select_fliporder = true;\r
-\r
- // texture locking\r
- if (g_PrefsDlg.m_bRotateLock) {\r
- // axis flipping inverts space orientation, we have to use a general texture locking algorithm instead of the RotateFaceTexture\r
- if (g_qeglobals.m_bBrushPrimitMode) {\r
- Select_ApplyMatrix_BrushPrimit();\r
- }\r
- else\r
- {\r
- // there's never been flip locking for non BP mode, this would be tricky to write and there's not much interest for it with the coming of BP format\r
- // what could be done is converting regular to BP, locking, then back to regular :)\r
- Sys_FPrintf(SYS_WRN, "WARNING: regular texturing doesn't have texture lock on flipping operations\n");\r
- }\r
- }\r
- // geometric transformation\r
- Select_ApplyMatrix (true, false, 0, 0);\r
- Sys_UpdateWindows (W_ALL);\r
-}\r
-\r
-\r
-void Select_Scale(float x, float y, float z)\r
-{\r
- Select_GetMid (select_origin);\r
- for (brush_t* b=selected_brushes.next ; b != &selected_brushes ; b=b->next)\r
- {\r
- // ignore fixedsize entities\r
- if(b->owner->eclass->fixedsize) continue;\r
- for (face_t* f=b->brush_faces ; f ; f=f->next)\r
- {\r
- for (int i=0 ; i<3 ; i++)\r
- {\r
- f->planepts[i][0] -= select_origin[0];\r
- f->planepts[i][1] -= select_origin[1];\r
- f->planepts[i][2] -= select_origin[2];\r
- f->planepts[i][0] *= x;\r
- f->planepts[i][1] *= y;\r
- f->planepts[i][2] *= z;\r
- \r
- f->planepts[i][0] += select_origin[0];\r
- f->planepts[i][1] += select_origin[1];\r
- f->planepts[i][2] += select_origin[2];\r
- }\r
- }\r
- Brush_Build(b, false,true,false,false); // don't filter\r
- if (b->patchBrush)\r
- {\r
- vec3_t v;\r
- v[0] = x;\r
- v[1] = y;\r
- v[2] = z;\r
- Patch_Scale(b->pPatch, select_origin, v);\r
- }\r
- }\r
-}\r
-\r
-void Select_RotateAxis (int axis, float deg, bool bPaint, bool bMouse)\r
-{\r
- int i;\r
- vec_t c, s;\r
-\r
- if (deg == 0)\r
- {\r
- return;\r
- }\r
-\r
- if (bMouse)\r
- {\r
- VectorCopy(g_pParentWnd->ActiveXY()->RotateOrigin(), select_origin);\r
- }\r
- else\r
- {\r
- Select_GetMid (select_origin);\r
- }\r
-\r
- /*\r
- if(axis == 2)\r
- {\r
- vec3_t rotation;\r
- VectorSet(rotation, 0, 0, 360 - deg);\r
- for(brush_t *b = selected_brushes.next; b != &selected_brushes; b = b->next)\r
- if(b->owner->model.pEdit)\r
- b->owner->model.pEdit->Rotate(select_origin, rotation);\r
- }\r
- */\r
-\r
- select_fliporder = false;\r
-\r
- // the "90" degrees algorithm is mostly used on axis rotate as a speedup and possibly avoiding rounding errors as much as possible\r
- // previous implementation was doing an indirect-oriented rotation over the plane whereas the general algo below was doing a direct-oriented rotation\r
- // this was confusing the texture locking algorithms, fixed it to be direct-oriented (side consequence is that the axis rotate toolbar button rotates the other way now)\r
- // NOTE: previous algo was using vec3_origin in the matrix computation.. \r
- // I don't see what an origin does in linear transformations (3x3 matrixes always relate to a (0,0,0) origin)\r
- // in Radiant it's initialized as (0,0,0) and never set to another value\r
- // so I got rid of it when it's not used for initialisation tasks (and even if it's not (0,0,0) it should not matter\r
- if (deg == 90)\r
- {\r
- c = 0;\r
- s = 1;\r
- }\r
- else\r
- {\r
- c = cos(deg * Q_PI / 180.0);\r
- s = sin(deg * Q_PI / 180.0);\r
- }\r
-\r
- for (i=0 ; i<3 ; i++)\r
- {\r
- VectorCopy (vec3_origin, select_matrix[i]);\r
- select_matrix[i][i] = 1;\r
- }\r
- \r
- switch (axis)\r
- {\r
- case 0:\r
- select_matrix[1][1] = c;\r
- select_matrix[1][2] = s;\r
- select_matrix[2][1] = -s;\r
- select_matrix[2][2] = c;\r
- break;\r
- case 1:\r
- select_matrix[0][0] = c;\r
- select_matrix[0][2] = s;\r
- select_matrix[2][0] = -s;\r
- select_matrix[2][2] = c;\r
- break;\r
- case 2:\r
- select_matrix[0][0] = c;\r
- select_matrix[0][1] = s;\r
- select_matrix[1][0] = -s;\r
- select_matrix[1][1] = c;\r
- break;\r
- }\r
- \r
-\r
- // texture locking\r
- if (g_PrefsDlg.m_bRotateLock)\r
- {\r
- // Terrible hack, reversing input rotation angle to correct\r
- // texture rotation direction for X and Z axes.\r
- // RotateTextures needs to be changed to fix this properly?\r
- if (axis == 1)\r
- RotateTextures(axis, deg, select_origin);\r
- else\r
- RotateTextures(axis, deg * -1, select_origin);\r
- }\r
- // geometric transformation\r
- Select_ApplyMatrix(!bMouse, true, axis, deg);//, false);\r
-\r
- if (bPaint)\r
- Sys_UpdateWindows (W_ALL);\r
-}\r
-\r
-/*\r
-================================================================\r
-\r
-GROUP SELECTIONS\r
-\r
-================================================================\r
-*/\r
-\r
-void Select_RealCompleteTall(vec3_t mins, vec3_t maxs)\r
-{\r
- brush_t *b, *next;\r
-\r
- int nDim1 = (g_pParentWnd->ActiveXY()->GetViewType() == YZ) ? 1 : 0;\r
- int nDim2 = (g_pParentWnd->ActiveXY()->GetViewType() == XY) ? 1 : 2;\r
-\r
- g_qeglobals.d_select_mode = sel_brush;\r
-\r
- for (b=active_brushes.next ; b != &active_brushes ; b=next)\r
- {\r
- next = b->next;\r
-\r
- if (b->bFiltered)\r
- continue;\r
-\r
- if ( (b->maxs[nDim1] > maxs[nDim1] || b->mins[nDim1] < mins[nDim1]) \r
- || (b->maxs[nDim2] > maxs[nDim2] || b->mins[nDim2] < mins[nDim2]) )\r
- continue;\r
-\r
- Brush_RemoveFromList (b);\r
- Brush_AddToList (b, &selected_brushes);\r
- }\r
-}\r
-\r
-void Select_CompleteTall (void)\r
-{\r
- vec3_t mins, maxs;\r
-\r
- if (!QE_SingleBrush ())\r
- return;\r
-\r
- Undo_Start ("select complete tall");\r
- Undo_AddBrushList (&selected_brushes);\r
- Undo_End();\r
-\r
- VectorCopy (selected_brushes.next->mins, mins);\r
- VectorCopy (selected_brushes.next->maxs, maxs);\r
- Select_Delete ();\r
-\r
- Select_RealCompleteTall(mins, maxs);\r
- Sys_UpdateWindows (W_ALL);\r
-}\r
-\r
-void Select_PartialTall (void)\r
-{\r
- brush_t *b, *next;\r
- vec3_t mins, maxs;\r
-\r
- if (!QE_SingleBrush ())\r
- return;\r
-\r
- Undo_Start ("select complete tall");\r
- Undo_AddBrushList (&selected_brushes);\r
- Undo_End();\r
-\r
- g_qeglobals.d_select_mode = sel_brush;\r
-\r
- VectorCopy (selected_brushes.next->mins, mins);\r
- VectorCopy (selected_brushes.next->maxs, maxs);\r
- Select_Delete ();\r
-\r
- int nDim1 = (g_pParentWnd->ActiveXY()->GetViewType() == YZ) ? 1 : 0;\r
- int nDim2 = (g_pParentWnd->ActiveXY()->GetViewType() == XY) ? 1 : 2;\r
-\r
- for (b=active_brushes.next ; b != &active_brushes ; b=next)\r
- {\r
- next = b->next;\r
-\r
- if (b->bFiltered)\r
- continue;\r
-\r
- if ( (b->mins[nDim1] > maxs[nDim1] || b->maxs[nDim1] < mins[nDim1]) \r
- || (b->mins[nDim2] > maxs[nDim2] || b->maxs[nDim2] < mins[nDim2]) )\r
- continue;\r
-\r
-\r
- Brush_RemoveFromList (b);\r
- Brush_AddToList (b, &selected_brushes);\r
- }\r
-\r
- Sys_UpdateWindows (W_ALL);\r
-}\r
-\r
-void Select_Touching (void)\r
-{\r
- brush_t *b, *next;\r
- int i;\r
- vec3_t mins, maxs;\r
-\r
- if (!QE_SingleBrush ())\r
- return;\r
-\r
- g_qeglobals.d_select_mode = sel_brush;\r
-\r
- VectorCopy (selected_brushes.next->mins, mins);\r
- VectorCopy (selected_brushes.next->maxs, maxs);\r
-\r
- for (b=active_brushes.next ; b != &active_brushes ; b=next)\r
- {\r
- next = b->next;\r
-\r
- if (b->bFiltered)\r
- continue;\r
-\r
- for (i=0 ; i<3 ; i++)\r
- if (b->mins[i] > maxs[i]+1 || b->maxs[i] < mins[i]-1)\r
- break;\r
-\r
- if (i == 3)\r
- {\r
- Brush_RemoveFromList (b);\r
- Brush_AddToList (b, &selected_brushes);\r
- }\r
- }\r
-\r
- Sys_UpdateWindows (W_ALL);\r
-}\r
-\r
-void Select_Inside (void)\r
-{\r
- brush_t *b, *next;\r
- int i;\r
- vec3_t mins, maxs;\r
-\r
- if (!QE_SingleBrush ())\r
- return;\r
-\r
- Undo_Start ("select inside");\r
- Undo_AddBrushList (&selected_brushes);\r
- Undo_End();\r
-\r
- g_qeglobals.d_select_mode = sel_brush;\r
-\r
- VectorCopy (selected_brushes.next->mins, mins);\r
- VectorCopy (selected_brushes.next->maxs, maxs);\r
- Select_Delete ();\r
-\r
- for (b=active_brushes.next ; b != &active_brushes ; b=next)\r
- {\r
- next = b->next;\r
-\r
- if (b->bFiltered)\r
- continue;\r
-\r
- for (i=0 ; i<3 ; i++)\r
- if (b->maxs[i] > maxs[i] || b->mins[i] < mins[i])\r
- break;\r
- if (i == 3)\r
- {\r
- Brush_RemoveFromList (b);\r
- Brush_AddToList (b, &selected_brushes);\r
- }\r
- }\r
-\r
- Sys_UpdateWindows (W_ALL);\r
-}\r
-\r
-void Select_Ungroup(void)\r
-{\r
- int numselectedgroups;\r
- entity_t *e;\r
- brush_t *b,* sb;\r
-\r
- numselectedgroups = 0;\r
- for (sb = selected_brushes.next; sb != &selected_brushes; sb = sb->next)\r
- {\r
- e = sb->owner;\r
-\r
- if (e == world_entity || e->eclass->fixedsize)\r
- {\r
- continue;\r
- }\r
-\r
- for (b = e->brushes.onext; b != &e->brushes; b = e->brushes.onext)\r
- {\r
- Entity_UnlinkBrush (b);\r
- Entity_LinkBrush (world_entity, b);\r
- }\r
- Entity_Free (e);\r
- numselectedgroups++;\r
- }\r
-\r
- if (numselectedgroups <= 0)\r
- {\r
- Sys_Printf("No grouped entities selected.\n");\r
- return;\r
- }\r
- Sys_Printf("Ungrouped %d entit%s.\n", numselectedgroups, (numselectedgroups == 1)?"y":"ies");\r
- Sys_UpdateWindows (W_ALL);\r
-}\r
-\r
-/*!\r
-group selected brushes into specified entity\r
-if an entity is empty afterwards, destroy it\r
-*/\r
-void Select_GroupEntity(entity_t* group)\r
-{\r
- entity_t* e;\r
- brush_t *b;\r
-\r
- if(group->eclass->fixedsize)\r
- {\r
- Sys_FPrintf (SYS_ERR, "Select_GroupEntity: can't group anything to a fixedsize entity\n");\r
- return;\r
- }\r
-\r
- for (b = selected_brushes.next; b != &selected_brushes; b = b->next)\r
- {\r
- if(b->owner->eclass->fixedsize) continue;\r
- e = b->owner; \r
- Entity_UnlinkBrush(b);\r
- Entity_LinkBrush(group, b);\r
- if(e != world_entity && e->brushes.onext == &e->brushes)\r
- {\r
- Undo_AddEntity(e);\r
- Entity_Free(e);\r
- }\r
- }\r
-}\r
-\r
-/*!\r
-merge all selected entities together into the first one selected\r
-NOTE: makes use of order of selected_brushes list\r
-can be used to move world brushes in an entity, or to merge several ents together\r
-NOTE: didn't devise a strategy on the epairs, we merge into the first entity and use those\r
-*/\r
-void Select_MergeEntity()\r
-{\r
- entity_t* e = NULL;\r
- brush_t* b;\r
- for (b = selected_brushes.next; b != &selected_brushes; b = b->next)\r
- {\r
- if(!b->owner->eclass->fixedsize)\r
- {\r
- e = b->owner;\r
- break;\r
- }\r
- }\r
-\r
- if(e != NULL)\r
- {\r
- Select_GroupEntity(e);\r
-\r
- int count = 0;\r
- for(b = e->brushes.onext; b != &e->brushes; b=b->onext)\r
- {\r
- //Brush_RemoveFromList (b);\r
- //Brush_AddToList(b, &active_brushes);\r
- count++;\r
- }\r
- Sys_Printf ("Merged %d brushes into %s entity\n", count, ValueForKey (e, "classname"));\r
- }\r
-}\r
-\r
-/*\r
-====================\r
-Select_Seperate\r
-====================\r
-*/\r
-void Select_Seperate( void ) {\r
- Select_GroupEntity( world_entity );\r
-}\r
-\r
-/*\r
-====================\r
-Select_MakeStructural\r
-====================\r
-*/\r
-void Select_MakeStructural (void)\r
-{\r
- brush_t *b;\r
- face_t *f;\r
-\r
- for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)\r
- {\r
- for (f=b->brush_faces ; f ; f=f->next)\r
- f->texdef.contents &= ~CONTENTS_DETAIL;\r
- b->bFiltered = FilterBrush(b);\r
- }\r
- Select_Deselect ();\r
- Sys_UpdateWindows (W_ALL);\r
-}\r
-\r
-void Select_MakeDetail (void)\r
-{\r
- brush_t *b;\r
- face_t *f;\r
-\r
- for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)\r
- {\r
- for (f=b->brush_faces ; f ; f=f->next)\r
- f->texdef.contents |= CONTENTS_DETAIL;\r
- b->bFiltered = FilterBrush(b);\r
- }\r
- Select_Deselect ();\r
- Sys_UpdateWindows (W_ALL);\r
-}\r
-\r
-// brush primitive texture adjustments, use the camera view to map adjustments\r
-// ShiftTextureRelative_BrushPrimit ( s , t ) will shift relative to the texture\r
-void ShiftTextureRelative_Camera(face_t *f, int x, int y)\r
-{\r
- vec3_t vecS, vecT;\r
- vec_t XY[2]; // the values we are going to send for translation\r
- vec_t sgn[2]; // +1 or -1\r
- int axis[2];\r
- CamWnd* pCam;\r
-\r
- // get the two relative texture axes for the current texturing\r
- BrushPrimit_GetRelativeAxes(f, vecS, vecT);\r
-\r
- // center point of the face, project it on the camera space\r
- vec3_t C;\r
- VectorClear(C);\r
- int i;\r
- for (i=0; i<f->face_winding->numpoints; i++)\r
- {\r
- VectorAdd(C,f->face_winding->points[i],C);\r
- }\r
- VectorScale(C,1.0/f->face_winding->numpoints,C);\r
-\r
- pCam = g_pParentWnd->GetCamWnd();\r
- pCam->MatchViewAxes(C, vecS, axis[0], sgn[0]);\r
- pCam->MatchViewAxes(C, vecT, axis[1], sgn[1]);\r
- \r
- // this happens when the two directions can't be mapped on two different directions on the screen\r
- // then the move will occur against a single axis\r
- // (i.e. the user is not positioned well enough to send understandable shift commands)\r
- // NOTE: in most cases this warning is not very relevant because the user would use one of the two axes\r
- // for which the solution is easy (the other one being unknown)\r
- // so this warning could be removed\r
- if (axis[0] == axis[1])\r
- Sys_FPrintf(SYS_WRN, "Warning: degenerate in ShiftTextureRelative_Camera\n");\r
-\r
- // compute the X Y geometric increments\r
- // those geometric increments will be applied along the texture axes (the ones we computed above)\r
- XY[0] = 0;\r
- XY[1] = 0;\r
- if (x!=0)\r
- {\r
- // moving right/left\r
- XY[axis[0]] += sgn[0]*x;\r
- }\r
- if (y!=0)\r
- {\r
- XY[axis[1]] += sgn[1]*y;\r
- }\r
- // we worked out a move along vecS vecT, and we now it's geometric amplitude\r
- // apply it\r
- ShiftTextureRelative_BrushPrimit(f, XY[0], XY[1]);\r
-}\r
-\r
-void Select_ShiftTexture(int x, int y)\r
-{\r
- brush_t *b;\r
- face_t *f;\r
-\r
- int nFaceCount = g_ptrSelectedFaces.GetSize();\r
-\r
- if(selected_brushes.next == &selected_brushes && nFaceCount == 0)\r
- return;\r
-\r
- for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)\r
- {\r
- for (f=b->brush_faces ; f ; f=f->next)\r
- {\r
- if (g_qeglobals.m_bBrushPrimitMode)\r
- {\r
- ShiftTextureRelative_Camera( f, x, y );\r
- }\r
- else\r
- {\r
- f->texdef.shift[0] += x;\r
- f->texdef.shift[1] += y;\r
- }\r
- }\r
- Brush_Build(b,true,true,false,false); // don't filter\r
- if (b->patchBrush)\r
- {\r
- Patch_ShiftTexture(b->pPatch, x, y);\r
- }\r
- }\r
-\r
- if (nFaceCount > 0)\r
- {\r
- for (int i = 0; i < nFaceCount; i++)\r
- {\r
- face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(i));\r
- brush_t *selBrush = reinterpret_cast<brush_t*>(g_ptrSelectedFaceBrushes.GetAt(i));\r
- if (g_qeglobals.m_bBrushPrimitMode)\r
- {\r
- ShiftTextureRelative_Camera( selFace, x, y );\r
- }\r
- else\r
- {\r
- selFace->texdef.shift[0] += x;\r
- selFace->texdef.shift[1] += y;\r
- }\r
- Brush_Build(selBrush,true,true,false,false); // don't filter\r
- }\r
- }\r
-\r
- Sys_UpdateWindows (W_CAMERA);\r
-}\r
-\r
-// setting float as input\r
-void Select_ScaleTexture(float x, float y)\r
-{\r
- brush_t *b;\r
- face_t *f;\r
-\r
- int nFaceCount = g_ptrSelectedFaces.GetSize();\r
-\r
- if(selected_brushes.next == &selected_brushes && nFaceCount == 0)\r
- {\r
- return;\r
- }\r
-\r
- for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)\r
- {\r
- for (f=b->brush_faces ; f ; f=f->next)\r
- {\r
- if (g_qeglobals.m_bBrushPrimitMode)\r
- {\r
- // apply same scale as the spinner button of the surface inspector\r
- float shift[2];\r
- float rotate;\r
- float scale[2];\r
- brushprimit_texdef_t bp; \r
- // compute normalized texture matrix\r
- ConvertTexMatWithQTexture( &f->brushprimit_texdef, f->d_texture, &bp, NULL );\r
- // compute fake shift scale rot\r
- TexMatToFakeTexCoords( bp.coords, shift, &rotate, scale );\r
- // update\r
- scale[0]+=static_cast<float>(x)*0.1;\r
- scale[1]+=static_cast<float>(y)*0.1;\r
- // compute new normalized texture matrix\r
- FakeTexCoordsToTexMat( shift, rotate, scale, bp.coords );\r
- // apply to face texture matrix\r
- ConvertTexMatWithQTexture( &bp, NULL, &f->brushprimit_texdef, f->d_texture );\r
- }\r
- else\r
- {\r
- f->texdef.scale[0] += x;\r
- f->texdef.scale[1] += y;\r
- }\r
- }\r
- Brush_Build(b,true,true,false,false); // don't filter\r
- if (b->patchBrush)\r
- {\r
- Patch_ScaleTexture(b->pPatch, x, y);\r
- }\r
- }\r
-\r
- if (nFaceCount > 0)\r
- {\r
- for (int i = 0; i < nFaceCount; i++)\r
- {\r
- face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(i));\r
- brush_t *selBrush = reinterpret_cast<brush_t*>(g_ptrSelectedFaceBrushes.GetAt(i));\r
- if (g_qeglobals.m_bBrushPrimitMode)\r
- {\r
- float shift[2];\r
- float rotate;\r
- float scale[2];\r
- brushprimit_texdef_t bp; \r
- ConvertTexMatWithQTexture( &selFace->brushprimit_texdef, selFace->d_texture, &bp, NULL );\r
- TexMatToFakeTexCoords( bp.coords, shift, &rotate, scale );\r
- scale[0]+=static_cast<float>(x)*0.1;\r
- scale[1]+=static_cast<float>(y)*0.1;\r
- FakeTexCoordsToTexMat( shift, rotate, scale, bp.coords );\r
- ConvertTexMatWithQTexture( &bp, NULL, &selFace->brushprimit_texdef, selFace->d_texture );\r
- }\r
- else\r
- {\r
- selFace->texdef.scale[0] += x;\r
- selFace->texdef.scale[1] += y;\r
- }\r
- Brush_Build(selBrush,true,true,false,false); // don't filter\r
- }\r
- }\r
-\r
- Sys_UpdateWindows (W_CAMERA);\r
-}\r
-\r
-void Select_RotateTexture(int amt)\r
-{\r
- brush_t *b;\r
- face_t *f;\r
-\r
- int nFaceCount = g_ptrSelectedFaces.GetSize();\r
-\r
- if(selected_brushes.next == &selected_brushes && nFaceCount == 0)\r
- {\r
- return;\r
- }\r
-\r
- for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)\r
- {\r
- for (f=b->brush_faces ; f ; f=f->next)\r
- {\r
- if (g_qeglobals.m_bBrushPrimitMode)\r
- {\r
- // apply same scale as the spinner button of the surface inspector\r
- float shift[2];\r
- float rotate;\r
- float scale[2];\r
- brushprimit_texdef_t bp; \r
- // compute normalized texture matrix\r
- ConvertTexMatWithQTexture( &f->brushprimit_texdef, f->d_texture, &bp, NULL );\r
- // compute fake shift scale rot\r
- TexMatToFakeTexCoords( bp.coords, shift, &rotate, scale );\r
- // update\r
- rotate += amt;\r
- // compute new normalized texture matrix\r
- FakeTexCoordsToTexMat( shift, rotate, scale, bp.coords );\r
- // apply to face texture matrix\r
- ConvertTexMatWithQTexture( &bp, NULL, &f->brushprimit_texdef, f->d_texture );\r
- }\r
- else\r
- {\r
- f->texdef.rotate += amt;\r
- f->texdef.rotate = static_cast<int>(f->texdef.rotate) % 360;\r
- }\r
- }\r
- Brush_Build(b,true,true,false,false); // don't filter\r
- if (b->patchBrush)\r
- {\r
- //Patch_RotateTexture(b->nPatchID, amt);\r
- Patch_RotateTexture(b->pPatch, amt);\r
- }\r
- }\r
- \r
- if (nFaceCount > 0)\r
- {\r
- for (int i = 0; i < nFaceCount; i++)\r
- {\r
- face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(i));\r
- brush_t *selBrush = reinterpret_cast<brush_t*>(g_ptrSelectedFaceBrushes.GetAt(i));\r
- if (g_qeglobals.m_bBrushPrimitMode)\r
- {\r
- float shift[2];\r
- float rotate;\r
- float scale[2];\r
- brushprimit_texdef_t bp; \r
- ConvertTexMatWithQTexture( &selFace->brushprimit_texdef, selFace->d_texture, &bp, NULL );\r
- TexMatToFakeTexCoords( bp.coords, shift, &rotate, scale );\r
- rotate += amt;\r
- FakeTexCoordsToTexMat( shift, rotate, scale, bp.coords );\r
- ConvertTexMatWithQTexture( &bp, NULL, &selFace->brushprimit_texdef, selFace->d_texture );\r
- }\r
- else\r
- {\r
- selFace->texdef.rotate += amt;\r
- selFace->texdef.rotate = static_cast<int>(selFace->texdef.rotate) % 360;\r
- }\r
- Brush_Build(selBrush,true,true,false,false); // don't filter\r
- }\r
- }\r
-\r
- Sys_UpdateWindows (W_CAMERA);\r
-}\r
-\r
-// TTimo modified to handle shader architecture:\r
-// expects shader names at input, comparison relies on shader names .. texture names no longer relevant\r
-void FindReplaceTextures(const char* pFind, const char* pReplace, bool bSelected, bool bForce, bool bSelectMatchingFaces)\r
-{\r
- // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=391\r
- if (strchr(pFind, ' ') || strchr(pReplace, ' '))\r
- {\r
- Sys_FPrintf(SYS_WRN, "FindReplaceTextures: '%s' or '%s' have spaces, aborted\n", pFind, pReplace);\r
- return;\r
- }\r
- \r
- brush_t* pList = (bSelected) ? &selected_brushes : &active_brushes;\r
- if (!bSelected)\r
- Select_Deselect();\r
-\r
- //++timo BP mode: replacing a texture in BP mode is not that easy, you need to recompute the texture matrix\r
- // if the size of the replacing texture differs, otherwise you get wrong scaling\r
- if (g_qeglobals.m_bBrushPrimitMode)\r
- Sys_Printf("TODO: finalize find/replace code for brush primitives");\r
-\r
- CPtrArray mFaces;\r
- for (brush_t* pBrush = pList->next ; pBrush != pList; pBrush = pBrush->next)\r
- {\r
- if (!bSelectMatchingFaces && pBrush->patchBrush)\r
- {\r
- Patch_FindReplaceTexture(pBrush, pFind, pReplace, bForce);\r
- }\r
- \r
- bool found = false; //spog\r
- for (face_t* pFace = pBrush->brush_faces; pFace; pFace = pFace->next)\r
- {\r
- if(bForce || strcmpi(pFace->pShader->getName(), pFind) == 0)\r
- {\r
- if (!bSelectMatchingFaces) {\r
- pFace->pShader->DecRef();\r
- pFace->pShader = QERApp_Shader_ForName( pReplace );\r
- pFace->pShader->IncRef();\r
- pFace->d_texture = pFace->pShader->getTexture();\r
- pFace->texdef.SetName(pReplace);\r
- found = true;\r
- } else if (bSelectMatchingFaces) {\r
- mFaces.Add(pFace);\r
- }\r
- }\r
- }\r
-\r
- if (found) // spog - speed increase, only build brushes that changed\r
- Brush_Build(pBrush);\r
-\r
- }\r
-\r
- if (bSelectMatchingFaces) {\r
- if (bSelected)\r
- Select_Deselect();\r
-\r
- int nSize = mFaces.GetSize();\r
- for (int i = 0; i < nSize; i++) {\r
- g_SelectedFaces.Add(reinterpret_cast<face_t *>(mFaces.GetAt(i)));\r
- }\r
- }\r
-\r
- Sys_UpdateWindows (W_CAMERA);\r
-}\r
-\r
-void Select_AllOfType()\r
-{\r
- brush_t *b, *next;\r
- entity_t *e;\r
- // if no brush selected, we will select based on texture\r
- // the first selected face's texture if any, or the current texture\r
- // if a brush is selected, we will select entities (first non-worldspawn owner in selected brushes)\r
- if (selected_brushes.next == &selected_brushes)\r
- {\r
-\r
- CString strName;\r
- if (g_ptrSelectedFaces.GetSize() == 0)\r
- {\r
- strName = g_qeglobals.d_texturewin.texdef.GetName();\r
- }\r
- else\r
- {\r
- face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(0));\r
- strName = selFace->texdef.GetName();\r
- }\r
-\r
- Sys_Printf("Selecting all brushes with the texture %s\n", strName.GetBuffer());\r
-\r
- Select_Deselect();\r
- for (b=active_brushes.next ; b != &active_brushes ; b=next)\r
- {\r
- next = b->next;\r
- \r
- if (b->bFiltered)\r
- continue;\r
-\r
- if (b->patchBrush)\r
- {\r
- if (strcmpi(strName, b->pPatch->pShader->getName()) == 0)\r
- {\r
- Brush_RemoveFromList (b);\r
- Brush_AddToList (b, &selected_brushes);\r
- }\r
- }\r
- else\r
- {\r
- for (face_t* pFace = b->brush_faces; pFace; pFace = pFace->next)\r
- {\r
- if (strcmpi(strName, pFace->texdef.GetName()) == 0)\r
- {\r
- Brush_RemoveFromList (b);\r
- Brush_AddToList (b, &selected_brushes);\r
- }\r
- }\r
- }\r
- }\r
- Sys_UpdateWindows(W_ALL);\r
- return;\r
- }\r
-\r
- \r
- b = selected_brushes.next;\r
- e = b->owner;\r
-\r
- if (e != NULL)\r
- {\r
- if (e != world_entity)\r
- {\r
- CString strName = e->eclass->name;\r
- CString strKey, strVal;\r
- bool bCriteria = GetSelectAllCriteria(strKey, strVal);\r
- Sys_Printf("Selecting all %s entities\n", strName.GetBuffer());\r
- Select_Deselect();\r
-\r
- for (b=active_brushes.next ; b != &active_brushes ; b=next)\r
- {\r
- next = b->next;\r
- \r
- if (b->bFiltered)\r
- continue;\r
-\r
- e = b->owner;\r
- if (e != NULL)\r
- {\r
- if (strcmpi(e->eclass->name, strName) == 0)\r
- {\r
- bool doIt = true;\r
- if (bCriteria) {\r
- CString str = ValueForKey (e, strKey);\r
- if (str.CompareNoCase(strVal) != 0) {\r
- doIt = false;\r
- }\r
- }\r
- if (doIt) {\r
- Brush_RemoveFromList (b);\r
- Brush_AddToList (b, &selected_brushes);\r
- }\r
- }\r
- }\r
- }\r
- }\r
- }\r
- Sys_UpdateWindows (W_ALL);\r
-\r
-}\r
-\r
-void Select_Reselect()\r
-{\r
- Select_Brush(selected_brushes.next); \r
- Sys_UpdateWindows (W_ALL);\r
-}\r
-\r
-\r
-void Select_FitTexture(int nHeight, int nWidth)\r
-{\r
- brush_t *b;\r
-\r
- int nFaceCount = g_ptrSelectedFaces.GetSize();\r
-\r
- if(selected_brushes.next == &selected_brushes && nFaceCount == 0)\r
- return;\r
-\r
- for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)\r
- {\r
- Brush_FitTexture(b, nHeight, nWidth);\r
- Brush_Build(b,true,true,false,false); // don't filter\r
- }\r
-\r
- if (nFaceCount > 0)\r
- {\r
- for (int i = 0; i < nFaceCount; i++)\r
- {\r
- face_t *selFace = reinterpret_cast<face_t*>(g_ptrSelectedFaces.GetAt(i));\r
- brush_t *selBrush = reinterpret_cast<brush_t*>(g_ptrSelectedFaceBrushes.GetAt(i));\r
- Face_FitTexture(selFace, nHeight, nWidth);\r
- Brush_Build(selBrush,true,true,false,false); // don't filter\r
- }\r
- }\r
-\r
- Sys_UpdateWindows (W_CAMERA);\r
-}\r
-\r
-void Select_Hide()\r
-{\r
- for (brush_t* b=selected_brushes.next ; b && b != &selected_brushes ; b=b->next)\r
- {\r
- b->hiddenBrush = true;\r
- b->bFiltered = true;\r
- }\r
- Sys_UpdateWindows (W_ALL);\r
-}\r
-\r
-void Select_ShowAllHidden()\r
-{\r
- brush_t* b;\r
- for (b=selected_brushes.next ; b && b != &selected_brushes ; b=b->next)\r
- {\r
- if (b->hiddenBrush)\r
- {\r
- b->hiddenBrush = false;\r
- b->bFiltered = FilterBrush(b);\r
- }\r
- }\r
- for (b=active_brushes.next ; b && b != &active_brushes ; b=b->next)\r
- {\r
- if (b->hiddenBrush)\r
- {\r
- b->hiddenBrush = false;\r
- b->bFiltered = FilterBrush(b);\r
- }\r
- }\r
- Sys_UpdateWindows (W_ALL);\r
-}\r
-\r
-\r
-/*\r
-============\r
-Select_Invert\r
-============\r
-*/\r
-void Select_Invert(void)\r
-{\r
- brush_t *next, *prev, *b;\r
-\r
- Sys_Printf("inverting selection...\n");\r
-\r
- next = active_brushes.next;\r
- prev = active_brushes.prev;\r
- if (selected_brushes.next != &selected_brushes)\r
- {\r
- active_brushes.next = selected_brushes.next;\r
- active_brushes.prev = selected_brushes.prev;\r
- active_brushes.next->prev = &active_brushes;\r
- active_brushes.prev->next = &active_brushes;\r
- }\r
- else\r
- {\r
- active_brushes.next = &active_brushes;\r
- active_brushes.prev = &active_brushes;\r
- }\r
- if (next != &active_brushes)\r
- {\r
- selected_brushes.next = next;\r
- selected_brushes.prev = prev;\r
- selected_brushes.next->prev = &selected_brushes;\r
- selected_brushes.prev->next = &selected_brushes;\r
- }\r
- else\r
- {\r
- selected_brushes.next = &selected_brushes;\r
- selected_brushes.prev = &selected_brushes;\r
- }\r
-\r
- // now check if any hidden brush is selected\r
- for (b = selected_brushes.next; b != &selected_brushes; )\r
- {\r
- if (b->patchBrush)\r
- b->pPatch->bSelected = true;\r
-\r
- if (b->bFiltered)\r
- {\r
- brush_t *pb = b;\r
- b = b->next;\r
- Brush_RemoveFromList (pb);\r
- Brush_AddToList (pb, &active_brushes);\r
- }\r
- else b = b->next;\r
-\r
- }\r
- \r
- for (b = active_brushes.next; b != &active_brushes; b = b->next)\r
- {\r
- if (b->patchBrush)\r
- {\r
- b->pPatch->bSelected = false;\r
- }\r
- }\r
- \r
- // since invert selection only works at the brush level, \r
- // set g_qeglobals.d_select_mode accordingly\r
- g_qeglobals.d_select_mode = sel_brush;\r
-\r
- // since invert selection only works at the brush level,\r
- // set g_qeglobals.d_select_mode accordingly\r
- g_qeglobals.d_select_mode = sel_brush;\r
-\r
- Sys_UpdateWindows(W_ALL);\r
-\r
- Sys_Printf("done.\n");\r
-}\r
-\r
-#ifdef ENABLE_GROUPS\r
-/* \r
-===========\r
-Select_Name\r
-===========\r
-*/\r
-void Select_Name(const char *pName)\r
-{\r
- if (g_qeglobals.m_bBrushPrimitMode)\r
- {\r
- for (brush_t* b=selected_brushes.next ; b && b != &selected_brushes ; b=b->next)\r
- {\r
- Brush_SetEpair(b, "Name", pName);\r
- }\r
- }\r
-}\r
-\r
-/* \r
-=================\r
-Select_AddToGroup\r
-add selected brushes to a group, update the tree\r
-=================\r
-*/\r
-void Select_AddToGroup(const char *pName)\r
-{\r
- if (g_qeglobals.m_bBrushPrimitMode)\r
- {\r
- for (brush_t* b=selected_brushes.next ; b && b != &selected_brushes ; b=b->next)\r
- {\r
- Brush_SetEpair(b, "group", pName);\r
- Group_AddToProperGroup(b);\r
- }\r
- }\r
-}\r
-#endif\r
+/*
+ Copyright (C) 1999-2006 Id Software, Inc. and contributors.
+ For a list of contributors, see the accompanying CONTRIBUTORS file.
+
+ This file is part of GtkRadiant.
+
+ GtkRadiant is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ GtkRadiant is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GtkRadiant; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "select.h"
+
+#include <gtk/gtk.h>
+
+#include "debugging/debugging.h"
+
+#include "ientity.h"
+#include "iselection.h"
+#include "iundo.h"
+
+#include <vector>
+
+#include "stream/stringstream.h"
+#include "signal/isignal.h"
+#include "shaderlib.h"
+#include "scenelib.h"
+
+#include "gtkutil/idledraw.h"
+#include "gtkutil/dialog.h"
+#include "gtkutil/widget.h"
+#include "brushmanip.h"
+#include "brush.h"
+#include "patchmanip.h"
+#include "patchdialog.h"
+#include "selection.h"
+#include "texwindow.h"
+#include "gtkmisc.h"
+#include "mainframe.h"
+#include "grid.h"
+#include "map.h"
+#include "entityinspector.h"
+
+
+
+select_workzone_t g_select_workzone;
+
+
+/**
+ Loops over all selected brushes and stores their
+ world AABBs in the specified array.
+ */
+class CollectSelectedBrushesBounds : public SelectionSystem::Visitor
+{
+AABB* m_bounds; // array of AABBs
+Unsigned m_max; // max AABB-elements in array
+Unsigned& m_count; // count of valid AABBs stored in array
+
+public:
+CollectSelectedBrushesBounds( AABB* bounds, Unsigned max, Unsigned& count )
+ : m_bounds( bounds ),
+ m_max( max ),
+ m_count( count ){
+ m_count = 0;
+}
+
+void visit( scene::Instance& instance ) const {
+ ASSERT_MESSAGE( m_count <= m_max, "Invalid m_count in CollectSelectedBrushesBounds" );
+
+ // stop if the array is already full
+ if ( m_count == m_max ) {
+ return;
+ }
+
+ Selectable* selectable = Instance_getSelectable( instance );
+ if ( ( selectable != 0 )
+ && instance.isSelected() ) {
+ // brushes only
+ if ( Instance_getBrush( instance ) != 0 ) {
+ m_bounds[m_count] = instance.worldAABB();
+ ++m_count;
+ }
+ }
+}
+};
+
+/**
+ Selects all objects that intersect one of the bounding AABBs.
+ The exact intersection-method is specified through TSelectionPolicy
+ */
+template<class TSelectionPolicy>
+class SelectByBounds : public scene::Graph::Walker
+{
+AABB* m_aabbs; // selection aabbs
+Unsigned m_count; // number of aabbs in m_aabbs
+TSelectionPolicy policy; // type that contains a custom intersection method aabb<->aabb
+
+public:
+SelectByBounds( AABB* aabbs, Unsigned count )
+ : m_aabbs( aabbs ),
+ m_count( count ){
+}
+
+bool pre( const scene::Path& path, scene::Instance& instance ) const {
+ Selectable* selectable = Instance_getSelectable( instance );
+
+ // ignore worldspawn
+ Entity* entity = Node_getEntity( path.top() );
+ if ( entity ) {
+ if ( string_equal( entity->getKeyValue( "classname" ), "worldspawn" ) ) {
+ return true;
+ }
+ }
+
+ if ( ( path.size() > 1 ) &&
+ ( !path.top().get().isRoot() ) &&
+ ( selectable != 0 )
+ ) {
+ for ( Unsigned i = 0; i < m_count; ++i )
+ {
+ if ( policy.Evaluate( m_aabbs[i], instance ) ) {
+ selectable->setSelected( true );
+ }
+ }
+ }
+
+ return true;
+}
+
+/**
+ Performs selection operation on the global scenegraph.
+ If delete_bounds_src is true, then the objects which were
+ used as source for the selection aabbs will be deleted.
+ */
+static void DoSelection( bool delete_bounds_src = true ){
+ if ( GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive ) {
+ // we may not need all AABBs since not all selected objects have to be brushes
+ const Unsigned max = (Unsigned)GlobalSelectionSystem().countSelected();
+ AABB* aabbs = new AABB[max];
+
+ Unsigned count;
+ CollectSelectedBrushesBounds collector( aabbs, max, count );
+ GlobalSelectionSystem().foreachSelected( collector );
+
+ // nothing usable in selection
+ if ( !count ) {
+ delete[] aabbs;
+ return;
+ }
+
+ // delete selected objects
+ if ( delete_bounds_src ) { // see deleteSelection
+ UndoableCommand undo( "deleteSelected" );
+ Select_Delete();
+ }
+
+ // select objects with bounds
+ GlobalSceneGraph().traverse( SelectByBounds<TSelectionPolicy>( aabbs, count ) );
+
+ SceneChangeNotify();
+ delete[] aabbs;
+ }
+}
+};
+
+/**
+ SelectionPolicy for SelectByBounds
+ Returns true if box and the AABB of instance intersect
+ */
+class SelectionPolicy_Touching
+{
+public:
+bool Evaluate( const AABB& box, scene::Instance& instance ) const {
+ const AABB& other( instance.worldAABB() );
+ for ( Unsigned i = 0; i < 3; ++i )
+ {
+ if ( fabsf( box.origin[i] - other.origin[i] ) > ( box.extents[i] + other.extents[i] ) ) {
+ return false;
+ }
+ }
+ return true;
+}
+};
+
+/**
+ SelectionPolicy for SelectByBounds
+ Returns true if the AABB of instance is inside box
+ */
+class SelectionPolicy_Inside
+{
+public:
+bool Evaluate( const AABB& box, scene::Instance& instance ) const {
+ const AABB& other( instance.worldAABB() );
+ for ( Unsigned i = 0; i < 3; ++i )
+ {
+ if ( fabsf( box.origin[i] - other.origin[i] ) > ( box.extents[i] - other.extents[i] ) ) {
+ return false;
+ }
+ }
+ return true;
+}
+};
+
+class DeleteSelected : public scene::Graph::Walker
+{
+mutable bool m_remove;
+mutable bool m_removedChild;
+public:
+DeleteSelected()
+ : m_remove( false ), m_removedChild( false ){
+}
+bool pre( const scene::Path& path, scene::Instance& instance ) const {
+ m_removedChild = false;
+
+ Selectable* selectable = Instance_getSelectable( instance );
+ if ( selectable != 0
+ && selectable->isSelected()
+ && path.size() > 1
+ && !path.top().get().isRoot() ) {
+ m_remove = true;
+
+ return false; // dont traverse into child elements
+ }
+ return true;
+}
+void post( const scene::Path& path, scene::Instance& instance ) const {
+
+ if ( m_removedChild ) {
+ m_removedChild = false;
+
+ // delete empty entities
+ Entity* entity = Node_getEntity( path.top() );
+ if ( entity != 0
+ && path.top().get_pointer() != Map_FindWorldspawn( g_map )
+ && Node_getTraversable( path.top() )->empty() ) {
+ Path_deleteTop( path );
+ }
+ }
+
+ // node should be removed
+ if ( m_remove ) {
+ if ( Node_isEntity( path.parent() ) != 0 ) {
+ m_removedChild = true;
+ }
+
+ m_remove = false;
+ Path_deleteTop( path );
+ }
+}
+};
+
+void Scene_DeleteSelected( scene::Graph& graph ){
+ graph.traverse( DeleteSelected() );
+ SceneChangeNotify();
+}
+
+void Select_Delete( void ){
+ Scene_DeleteSelected( GlobalSceneGraph() );
+}
+
+class InvertSelectionWalker : public scene::Graph::Walker
+{
+SelectionSystem::EMode m_mode;
+mutable Selectable* m_selectable;
+public:
+InvertSelectionWalker( SelectionSystem::EMode mode )
+ : m_mode( mode ), m_selectable( 0 ){
+}
+bool pre( const scene::Path& path, scene::Instance& instance ) const {
+ Selectable* selectable = Instance_getSelectable( instance );
+ if ( selectable ) {
+ switch ( m_mode )
+ {
+ case SelectionSystem::eEntity:
+ if ( Node_isEntity( path.top() ) != 0 ) {
+ m_selectable = path.top().get().visible() ? selectable : 0;
+ }
+ break;
+ case SelectionSystem::ePrimitive:
+ m_selectable = path.top().get().visible() ? selectable : 0;
+ break;
+ case SelectionSystem::eComponent:
+ break;
+ }
+ }
+ return true;
+}
+void post( const scene::Path& path, scene::Instance& instance ) const {
+ if ( m_selectable != 0 ) {
+ m_selectable->setSelected( !m_selectable->isSelected() );
+ m_selectable = 0;
+ }
+}
+};
+
+void Scene_Invert_Selection( scene::Graph& graph ){
+ graph.traverse( InvertSelectionWalker( GlobalSelectionSystem().Mode() ) );
+}
+
+void Select_Invert(){
+ Scene_Invert_Selection( GlobalSceneGraph() );
+}
+
+class ExpandSelectionToEntitiesWalker : public scene::Graph::Walker
+{
+mutable std::size_t m_depth;
+NodeSmartReference worldspawn;
+public:
+ExpandSelectionToEntitiesWalker() : m_depth( 0 ), worldspawn( Map_FindOrInsertWorldspawn( g_map ) ){
+}
+bool pre( const scene::Path& path, scene::Instance& instance ) const {
+ ++m_depth;
+
+ // ignore worldspawn
+ NodeSmartReference me( path.top().get() );
+ if ( me == worldspawn ) {
+ return false;
+ }
+
+ if ( m_depth == 2 ) { // entity depth
+ // traverse and select children if any one is selected
+ if ( instance.childSelected() ) {
+ Instance_setSelected( instance, true );
+ }
+ return Node_getEntity( path.top() )->isContainer() && instance.isSelected();
+ }
+ else if ( m_depth == 3 ) { // primitive depth
+ Instance_setSelected( instance, true );
+ return false;
+ }
+ return true;
+}
+void post( const scene::Path& path, scene::Instance& instance ) const {
+ --m_depth;
+}
+};
+
+void Scene_ExpandSelectionToEntities(){
+ GlobalSceneGraph().traverse( ExpandSelectionToEntitiesWalker() );
+}
+
+
+namespace
+{
+void Selection_UpdateWorkzone(){
+ if ( GlobalSelectionSystem().countSelected() != 0 ) {
+ Select_GetBounds( g_select_workzone.d_work_min, g_select_workzone.d_work_max );
+ }
+}
+typedef FreeCaller<void(), Selection_UpdateWorkzone> SelectionUpdateWorkzoneCaller;
+
+IdleDraw g_idleWorkzone = IdleDraw( SelectionUpdateWorkzoneCaller() );
+}
+
+const select_workzone_t& Select_getWorkZone(){
+ g_idleWorkzone.flush();
+ return g_select_workzone;
+}
+
+void UpdateWorkzone_ForSelection(){
+ g_idleWorkzone.queueDraw();
+}
+
+// update the workzone to the current selection
+void UpdateWorkzone_ForSelectionChanged( const Selectable& selectable ){
+ if ( selectable.isSelected() ) {
+ UpdateWorkzone_ForSelection();
+ }
+}
+
+void Select_SetShader( const char* shader ){
+ if ( GlobalSelectionSystem().Mode() != SelectionSystem::eComponent ) {
+ Scene_BrushSetShader_Selected( GlobalSceneGraph(), shader );
+ Scene_PatchSetShader_Selected( GlobalSceneGraph(), shader );
+ }
+ Scene_BrushSetShader_Component_Selected( GlobalSceneGraph(), shader );
+}
+
+void Select_SetTexdef( const TextureProjection& projection ){
+ if ( GlobalSelectionSystem().Mode() != SelectionSystem::eComponent ) {
+ Scene_BrushSetTexdef_Selected( GlobalSceneGraph(), projection );
+ }
+ Scene_BrushSetTexdef_Component_Selected( GlobalSceneGraph(), projection );
+}
+
+void Select_SetFlags( const ContentsFlagsValue& flags ){
+ if ( GlobalSelectionSystem().Mode() != SelectionSystem::eComponent ) {
+ Scene_BrushSetFlags_Selected( GlobalSceneGraph(), flags );
+ }
+ Scene_BrushSetFlags_Component_Selected( GlobalSceneGraph(), flags );
+}
+
+void Select_GetBounds( Vector3& mins, Vector3& maxs ){
+ AABB bounds;
+ Scene_BoundsSelected( GlobalSceneGraph(), bounds );
+ maxs = vector3_added( bounds.origin, bounds.extents );
+ mins = vector3_subtracted( bounds.origin, bounds.extents );
+}
+
+void Select_GetMid( Vector3& mid ){
+ AABB bounds;
+ Scene_BoundsSelected( GlobalSceneGraph(), bounds );
+ mid = vector3_snapped( bounds.origin );
+}
+
+
+void Select_FlipAxis( int axis ){
+ Vector3 flip( 1, 1, 1 );
+ flip[axis] = -1;
+ GlobalSelectionSystem().scaleSelected( flip );
+}
+
+
+void Select_Scale( float x, float y, float z ){
+ GlobalSelectionSystem().scaleSelected( Vector3( x, y, z ) );
+}
+
+enum axis_t
+{
+ eAxisX = 0,
+ eAxisY = 1,
+ eAxisZ = 2,
+};
+
+enum sign_t
+{
+ eSignPositive = 1,
+ eSignNegative = -1,
+};
+
+inline Matrix4 matrix4_rotation_for_axis90( axis_t axis, sign_t sign ){
+ switch ( axis )
+ {
+ case eAxisX:
+ if ( sign == eSignPositive ) {
+ return matrix4_rotation_for_sincos_x( 1, 0 );
+ }
+ else
+ {
+ return matrix4_rotation_for_sincos_x( -1, 0 );
+ }
+ case eAxisY:
+ if ( sign == eSignPositive ) {
+ return matrix4_rotation_for_sincos_y( 1, 0 );
+ }
+ else
+ {
+ return matrix4_rotation_for_sincos_y( -1, 0 );
+ }
+ default: //case eAxisZ:
+ if ( sign == eSignPositive ) {
+ return matrix4_rotation_for_sincos_z( 1, 0 );
+ }
+ else
+ {
+ return matrix4_rotation_for_sincos_z( -1, 0 );
+ }
+ }
+}
+
+inline void matrix4_rotate_by_axis90( Matrix4& matrix, axis_t axis, sign_t sign ){
+ matrix4_multiply_by_matrix4( matrix, matrix4_rotation_for_axis90( axis, sign ) );
+}
+
+inline void matrix4_pivoted_rotate_by_axis90( Matrix4& matrix, axis_t axis, sign_t sign, const Vector3& pivotpoint ){
+ matrix4_translate_by_vec3( matrix, pivotpoint );
+ matrix4_rotate_by_axis90( matrix, axis, sign );
+ matrix4_translate_by_vec3( matrix, vector3_negated( pivotpoint ) );
+}
+
+inline Quaternion quaternion_for_axis90( axis_t axis, sign_t sign ){
+#if 1
+ switch ( axis )
+ {
+ case eAxisX:
+ if ( sign == eSignPositive ) {
+ return Quaternion( c_half_sqrt2f, 0, 0, c_half_sqrt2f );
+ }
+ else
+ {
+ return Quaternion( -c_half_sqrt2f, 0, 0, -c_half_sqrt2f );
+ }
+ case eAxisY:
+ if ( sign == eSignPositive ) {
+ return Quaternion( 0, c_half_sqrt2f, 0, c_half_sqrt2f );
+ }
+ else
+ {
+ return Quaternion( 0, -c_half_sqrt2f, 0, -c_half_sqrt2f );
+ }
+ default: //case eAxisZ:
+ if ( sign == eSignPositive ) {
+ return Quaternion( 0, 0, c_half_sqrt2f, c_half_sqrt2f );
+ }
+ else
+ {
+ return Quaternion( 0, 0, -c_half_sqrt2f, -c_half_sqrt2f );
+ }
+ }
+#else
+ quaternion_for_matrix4_rotation( matrix4_rotation_for_axis90( (axis_t)axis, ( deg > 0 ) ? eSignPositive : eSignNegative ) );
+#endif
+}
+
+void Select_RotateAxis( int axis, float deg ){
+ if ( fabs( deg ) == 90.f ) {
+ GlobalSelectionSystem().rotateSelected( quaternion_for_axis90( (axis_t)axis, ( deg > 0 ) ? eSignPositive : eSignNegative ) );
+ }
+ else
+ {
+ switch ( axis )
+ {
+ case 0:
+ GlobalSelectionSystem().rotateSelected( quaternion_for_matrix4_rotation( matrix4_rotation_for_x_degrees( deg ) ) );
+ break;
+ case 1:
+ GlobalSelectionSystem().rotateSelected( quaternion_for_matrix4_rotation( matrix4_rotation_for_y_degrees( deg ) ) );
+ break;
+ case 2:
+ GlobalSelectionSystem().rotateSelected( quaternion_for_matrix4_rotation( matrix4_rotation_for_z_degrees( deg ) ) );
+ break;
+ }
+ }
+}
+
+
+void Select_ShiftTexture( float x, float y ){
+ if ( GlobalSelectionSystem().Mode() != SelectionSystem::eComponent ) {
+ Scene_BrushShiftTexdef_Selected( GlobalSceneGraph(), x, y );
+ Scene_PatchTranslateTexture_Selected( GlobalSceneGraph(), x, y );
+ }
+ //globalOutputStream() << "shift selected face textures: s=" << x << " t=" << y << '\n';
+ Scene_BrushShiftTexdef_Component_Selected( GlobalSceneGraph(), x, y );
+}
+
+void Select_ScaleTexture( float x, float y ){
+ if ( GlobalSelectionSystem().Mode() != SelectionSystem::eComponent ) {
+ Scene_BrushScaleTexdef_Selected( GlobalSceneGraph(), x, y );
+ Scene_PatchScaleTexture_Selected( GlobalSceneGraph(), x, y );
+ }
+ Scene_BrushScaleTexdef_Component_Selected( GlobalSceneGraph(), x, y );
+}
+
+void Select_RotateTexture( float amt ){
+ if ( GlobalSelectionSystem().Mode() != SelectionSystem::eComponent ) {
+ Scene_BrushRotateTexdef_Selected( GlobalSceneGraph(), amt );
+ Scene_PatchRotateTexture_Selected( GlobalSceneGraph(), amt );
+ }
+ Scene_BrushRotateTexdef_Component_Selected( GlobalSceneGraph(), amt );
+}
+
+// TTimo modified to handle shader architecture:
+// expects shader names at input, comparison relies on shader names .. texture names no longer relevant
+void FindReplaceTextures( const char* pFind, const char* pReplace, bool bSelected ){
+ if ( !texdef_name_valid( pFind ) ) {
+ globalErrorStream() << "FindReplaceTextures: invalid texture name: '" << pFind << "', aborted\n";
+ return;
+ }
+ if ( !texdef_name_valid( pReplace ) ) {
+ globalErrorStream() << "FindReplaceTextures: invalid texture name: '" << pReplace << "', aborted\n";
+ return;
+ }
+
+ StringOutputStream command;
+ command << "textureFindReplace -find " << pFind << " -replace " << pReplace;
+ UndoableCommand undo( command.c_str() );
+
+ if ( bSelected ) {
+ if ( GlobalSelectionSystem().Mode() != SelectionSystem::eComponent ) {
+ Scene_BrushFindReplaceShader_Selected( GlobalSceneGraph(), pFind, pReplace );
+ Scene_PatchFindReplaceShader_Selected( GlobalSceneGraph(), pFind, pReplace );
+ }
+ Scene_BrushFindReplaceShader_Component_Selected( GlobalSceneGraph(), pFind, pReplace );
+ }
+ else
+ {
+ Scene_BrushFindReplaceShader( GlobalSceneGraph(), pFind, pReplace );
+ Scene_PatchFindReplaceShader( GlobalSceneGraph(), pFind, pReplace );
+ }
+}
+
+typedef std::vector<const char*> PropertyValues;
+
+bool propertyvalues_contain( const PropertyValues& propertyvalues, const char *str ){
+ for ( PropertyValues::const_iterator i = propertyvalues.begin(); i != propertyvalues.end(); ++i )
+ {
+ if ( string_equal( str, *i ) ) {
+ return true;
+ }
+ }
+ return false;
+}
+
+class EntityFindByPropertyValueWalker : public scene::Graph::Walker
+{
+const PropertyValues& m_propertyvalues;
+const char *m_prop;
+public:
+EntityFindByPropertyValueWalker( const char *prop, const PropertyValues& propertyvalues )
+ : m_propertyvalues( propertyvalues ), m_prop( prop ){
+}
+bool pre( const scene::Path& path, scene::Instance& instance ) const {
+ Entity* entity = Node_getEntity( path.top() );
+ if ( entity != 0
+ && propertyvalues_contain( m_propertyvalues, entity->getKeyValue( m_prop ) ) ) {
+ Instance_getSelectable( instance )->setSelected( true );
+ }
+ return true;
+}
+};
+
+void Scene_EntitySelectByPropertyValues( scene::Graph& graph, const char *prop, const PropertyValues& propertyvalues ){
+ graph.traverse( EntityFindByPropertyValueWalker( prop, propertyvalues ) );
+}
+
+class EntityGetSelectedPropertyValuesWalker : public scene::Graph::Walker
+{
+PropertyValues& m_propertyvalues;
+const char *m_prop;
+public:
+EntityGetSelectedPropertyValuesWalker( const char *prop, PropertyValues& propertyvalues )
+ : m_propertyvalues( propertyvalues ), m_prop( prop ){
+}
+bool pre( const scene::Path& path, scene::Instance& instance ) const {
+ Selectable* selectable = Instance_getSelectable( instance );
+ if ( selectable != 0
+ && selectable->isSelected() ) {
+ Entity* entity = Node_getEntity( path.top() );
+ if ( entity != 0 ) {
+ if ( !propertyvalues_contain( m_propertyvalues, entity->getKeyValue( m_prop ) ) ) {
+ m_propertyvalues.push_back( entity->getKeyValue( m_prop ) );
+ }
+ }
+ }
+ return true;
+}
+};
+
+void Scene_EntityGetPropertyValues( scene::Graph& graph, const char *prop, PropertyValues& propertyvalues ){
+ graph.traverse( EntityGetSelectedPropertyValuesWalker( prop, propertyvalues ) );
+}
+
+void Select_AllOfType(){
+ if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
+ if ( GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace ) {
+ GlobalSelectionSystem().setSelectedAllComponents( false );
+ Scene_BrushSelectByShader_Component( GlobalSceneGraph(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
+ }
+ }
+ else
+ {
+ PropertyValues propertyvalues;
+ const char *prop = EntityInspector_getCurrentKey();
+ if ( !prop || !*prop ) {
+ prop = "classname";
+ }
+ Scene_EntityGetPropertyValues( GlobalSceneGraph(), prop, propertyvalues );
+ GlobalSelectionSystem().setSelectedAll( false );
+ if ( !propertyvalues.empty() ) {
+ Scene_EntitySelectByPropertyValues( GlobalSceneGraph(), prop, propertyvalues );
+ }
+ else
+ {
+ Scene_BrushSelectByShader( GlobalSceneGraph(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
+ Scene_PatchSelectByShader( GlobalSceneGraph(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
+ }
+ }
+}
+
+void Select_Inside( void ){
+ SelectByBounds<SelectionPolicy_Inside>::DoSelection();
+}
+
+void Select_Touching( void ){
+ SelectByBounds<SelectionPolicy_Touching>::DoSelection( false );
+}
+
+void Select_FitTexture( float horizontal, float vertical ){
+ if ( GlobalSelectionSystem().Mode() != SelectionSystem::eComponent ) {
+ Scene_BrushFitTexture_Selected( GlobalSceneGraph(), horizontal, vertical );
+ }
+ Scene_BrushFitTexture_Component_Selected( GlobalSceneGraph(), horizontal, vertical );
+
+ SceneChangeNotify();
+}
+
+inline void hide_node( scene::Node& node, bool hide ){
+ hide
+ ? node.enable( scene::Node::eHidden )
+ : node.disable( scene::Node::eHidden );
+}
+
+class HideSelectedWalker : public scene::Graph::Walker
+{
+bool m_hide;
+public:
+HideSelectedWalker( bool hide )
+ : m_hide( hide ){
+}
+bool pre( const scene::Path& path, scene::Instance& instance ) const {
+ Selectable* selectable = Instance_getSelectable( instance );
+ if ( selectable != 0
+ && selectable->isSelected() ) {
+ hide_node( path.top(), m_hide );
+ }
+ return true;
+}
+};
+
+void Scene_Hide_Selected( bool hide ){
+ GlobalSceneGraph().traverse( HideSelectedWalker( hide ) );
+}
+
+void Select_Hide(){
+ Scene_Hide_Selected( true );
+ SceneChangeNotify();
+}
+
+void HideSelected(){
+ Select_Hide();
+ GlobalSelectionSystem().setSelectedAll( false );
+}
+
+
+class HideAllWalker : public scene::Graph::Walker
+{
+bool m_hide;
+public:
+HideAllWalker( bool hide )
+ : m_hide( hide ){
+}
+bool pre( const scene::Path& path, scene::Instance& instance ) const {
+ hide_node( path.top(), m_hide );
+ return true;
+}
+};
+
+void Scene_Hide_All( bool hide ){
+ GlobalSceneGraph().traverse( HideAllWalker( hide ) );
+}
+
+void Select_ShowAllHidden(){
+ Scene_Hide_All( false );
+ SceneChangeNotify();
+}
+
+
+
+void Selection_Flipx(){
+ UndoableCommand undo( "mirrorSelected -axis x" );
+ Select_FlipAxis( 0 );
+}
+
+void Selection_Flipy(){
+ UndoableCommand undo( "mirrorSelected -axis y" );
+ Select_FlipAxis( 1 );
+}
+
+void Selection_Flipz(){
+ UndoableCommand undo( "mirrorSelected -axis z" );
+ Select_FlipAxis( 2 );
+}
+
+void Selection_Rotatex(){
+ UndoableCommand undo( "rotateSelected -axis x -angle -90" );
+ Select_RotateAxis( 0,-90 );
+}
+
+void Selection_Rotatey(){
+ UndoableCommand undo( "rotateSelected -axis y -angle 90" );
+ Select_RotateAxis( 1, 90 );
+}
+
+void Selection_Rotatez(){
+ UndoableCommand undo( "rotateSelected -axis z -angle -90" );
+ Select_RotateAxis( 2,-90 );
+}
+
+
+
+void Nudge( int nDim, float fNudge ){
+ Vector3 translate( 0, 0, 0 );
+ translate[nDim] = fNudge;
+
+ GlobalSelectionSystem().translateSelected( translate );
+}
+
+void Selection_NudgeZ( float amount ){
+ StringOutputStream command;
+ command << "nudgeSelected -axis z -amount " << amount;
+ UndoableCommand undo( command.c_str() );
+
+ Nudge( 2, amount );
+}
+
+void Selection_MoveDown(){
+ Selection_NudgeZ( -GetGridSize() );
+}
+
+void Selection_MoveUp(){
+ Selection_NudgeZ( GetGridSize() );
+}
+
+void SceneSelectionChange( const Selectable& selectable ){
+ SceneChangeNotify();
+}
+
+SignalHandlerId Selection_boundsChanged;
+
+void Selection_construct(){
+ typedef FreeCaller<void(const Selectable&), SceneSelectionChange> SceneSelectionChangeCaller;
+ GlobalSelectionSystem().addSelectionChangeCallback( SceneSelectionChangeCaller() );
+ typedef FreeCaller<void(const Selectable&), UpdateWorkzone_ForSelectionChanged> UpdateWorkzoneForSelectionChangedCaller;
+ GlobalSelectionSystem().addSelectionChangeCallback( UpdateWorkzoneForSelectionChangedCaller() );
+ typedef FreeCaller<void(), UpdateWorkzone_ForSelection> UpdateWorkzoneForSelectionCaller;
+ Selection_boundsChanged = GlobalSceneGraph().addBoundsChangedCallback( UpdateWorkzoneForSelectionCaller() );
+}
+
+void Selection_destroy(){
+ GlobalSceneGraph().removeBoundsChangedCallback( Selection_boundsChanged );
+}
+
+
+#include "gtkdlgs.h"
+#include <gdk/gdkkeysyms.h>
+
+
+inline Quaternion quaternion_for_euler_xyz_degrees( const Vector3& eulerXYZ ){
+#if 0
+ return quaternion_for_matrix4_rotation( matrix4_rotation_for_euler_xyz_degrees( eulerXYZ ) );
+#elif 0
+ return quaternion_multiplied_by_quaternion(
+ quaternion_multiplied_by_quaternion(
+ quaternion_for_z( degrees_to_radians( eulerXYZ[2] ) ),
+ quaternion_for_y( degrees_to_radians( eulerXYZ[1] ) )
+ ),
+ quaternion_for_x( degrees_to_radians( eulerXYZ[0] ) )
+ );
+#elif 1
+ double cx = cos( degrees_to_radians( eulerXYZ[0] * 0.5 ) );
+ double sx = sin( degrees_to_radians( eulerXYZ[0] * 0.5 ) );
+ double cy = cos( degrees_to_radians( eulerXYZ[1] * 0.5 ) );
+ double sy = sin( degrees_to_radians( eulerXYZ[1] * 0.5 ) );
+ double cz = cos( degrees_to_radians( eulerXYZ[2] * 0.5 ) );
+ double sz = sin( degrees_to_radians( eulerXYZ[2] * 0.5 ) );
+
+ return Quaternion(
+ cz * cy * sx - sz * sy * cx,
+ cz * sy * cx + sz * cy * sx,
+ sz * cy * cx - cz * sy * sx,
+ cz * cy * cx + sz * sy * sx
+ );
+#endif
+}
+
+struct RotateDialog
+{
+ ui::SpinButton x{ui::null};
+ ui::SpinButton y{ui::null};
+ ui::SpinButton z{ui::null};
+ ui::Window window{ui::null};
+};
+
+static gboolean rotatedlg_apply( ui::Widget widget, RotateDialog* rotateDialog ){
+ Vector3 eulerXYZ;
+
+ eulerXYZ[0] = static_cast<float>( gtk_spin_button_get_value( rotateDialog->x ) );
+ eulerXYZ[1] = static_cast<float>( gtk_spin_button_get_value( rotateDialog->y ) );
+ eulerXYZ[2] = static_cast<float>( gtk_spin_button_get_value( rotateDialog->z ) );
+
+ StringOutputStream command;
+ command << "rotateSelectedEulerXYZ -x " << eulerXYZ[0] << " -y " << eulerXYZ[1] << " -z " << eulerXYZ[2];
+ UndoableCommand undo( command.c_str() );
+
+ GlobalSelectionSystem().rotateSelected( quaternion_for_euler_xyz_degrees( eulerXYZ ) );
+ return TRUE;
+}
+
+static gboolean rotatedlg_cancel( ui::Widget widget, RotateDialog* rotateDialog ){
+ rotateDialog->window.hide();
+
+ gtk_spin_button_set_value( rotateDialog->x, 0.0f ); // reset to 0 on close
+ gtk_spin_button_set_value( rotateDialog->y, 0.0f );
+ gtk_spin_button_set_value( rotateDialog->z, 0.0f );
+
+ return TRUE;
+}
+
+static gboolean rotatedlg_ok( ui::Widget widget, RotateDialog* rotateDialog ){
+ rotatedlg_apply( widget, rotateDialog );
+ rotateDialog->window.hide();
+ return TRUE;
+}
+
+static gboolean rotatedlg_delete( ui::Widget widget, GdkEventAny *event, RotateDialog* rotateDialog ){
+ rotatedlg_cancel( widget, rotateDialog );
+ return TRUE;
+}
+
+RotateDialog g_rotate_dialog;
+void DoRotateDlg(){
+ if ( !g_rotate_dialog.window ) {
+ g_rotate_dialog.window = MainFrame_getWindow().create_dialog_window("Arbitrary rotation", G_CALLBACK(rotatedlg_delete ), &g_rotate_dialog );
+
+ auto accel = ui::AccelGroup(ui::New);
+ g_rotate_dialog.window.add_accel_group( accel );
+
+ {
+ auto hbox = create_dialog_hbox( 4, 4 );
+ g_rotate_dialog.window.add(hbox);
+ {
+ auto table = create_dialog_table( 3, 2, 4, 4 );
+ hbox.pack_start( table, TRUE, TRUE, 0 );
+ {
+ ui::Widget label = ui::Label( " X " );
+ label.show();
+ table.attach(label, {0, 1, 0, 1}, {0, 0});
+ }
+ {
+ ui::Widget label = ui::Label( " Y " );
+ label.show();
+ table.attach(label, {0, 1, 1, 2}, {0, 0});
+ }
+ {
+ ui::Widget label = ui::Label( " Z " );
+ label.show();
+ table.attach(label, {0, 1, 2, 3}, {0, 0});
+ }
+ {
+ auto adj = ui::Adjustment( 0, -359, 359, 1, 10, 0 );
+ auto spin = ui::SpinButton( adj, 1, 0 );
+ spin.show();
+ table.attach(spin, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
+ spin.dimensions(64, -1);
+ gtk_spin_button_set_wrap( spin, TRUE );
+
+ gtk_widget_grab_focus( spin );
+
+ g_rotate_dialog.x = spin;
+ }
+ {
+ auto adj = ui::Adjustment( 0, -359, 359, 1, 10, 0 );
+ auto spin = ui::SpinButton( adj, 1, 0 );
+ spin.show();
+ table.attach(spin, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
+ spin.dimensions(64, -1);
+ gtk_spin_button_set_wrap( spin, TRUE );
+
+ g_rotate_dialog.y = spin;
+ }
+ {
+ auto adj = ui::Adjustment( 0, -359, 359, 1, 10, 0 );
+ auto spin = ui::SpinButton( adj, 1, 0 );
+ spin.show();
+ table.attach(spin, {1, 2, 2, 3}, {GTK_EXPAND | GTK_FILL, 0});
+ spin.dimensions(64, -1);
+ gtk_spin_button_set_wrap( spin, TRUE );
+
+ g_rotate_dialog.z = spin;
+ }
+ }
+ {
+ auto vbox = create_dialog_vbox( 4 );
+ hbox.pack_start( vbox, TRUE, TRUE, 0 );
+ {
+ auto button = create_dialog_button( "OK", G_CALLBACK( rotatedlg_ok ), &g_rotate_dialog );
+ vbox.pack_start( button, FALSE, FALSE, 0 );
+ widget_make_default( button );
+ gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
+ }
+ {
+ auto button = create_dialog_button( "Cancel", G_CALLBACK( rotatedlg_cancel ), &g_rotate_dialog );
+ vbox.pack_start( button, FALSE, FALSE, 0 );
+ gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
+ }
+ {
+ auto button = create_dialog_button( "Apply", G_CALLBACK( rotatedlg_apply ), &g_rotate_dialog );
+ vbox.pack_start( button, FALSE, FALSE, 0 );
+ }
+ }
+ }
+ }
+
+ g_rotate_dialog.window.show();
+}
+
+
+
+
+
+
+
+
+
+struct ScaleDialog
+{
+ ui::Entry x{ui::null};
+ ui::Entry y{ui::null};
+ ui::Entry z{ui::null};
+ ui::Window window{ui::null};
+};
+
+static gboolean scaledlg_apply( ui::Widget widget, ScaleDialog* scaleDialog ){
+ float sx, sy, sz;
+
+ sx = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( scaleDialog->x ) ) ) );
+ sy = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( scaleDialog->y ) ) ) );
+ sz = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( scaleDialog->z ) ) ) );
+
+ StringOutputStream command;
+ command << "scaleSelected -x " << sx << " -y " << sy << " -z " << sz;
+ UndoableCommand undo( command.c_str() );
+
+ Select_Scale( sx, sy, sz );
+
+ return TRUE;
+}
+
+static gboolean scaledlg_cancel( ui::Widget widget, ScaleDialog* scaleDialog ){
+ scaleDialog->window.hide();
+
+ scaleDialog->x.text("1.0");
+ scaleDialog->y.text("1.0");
+ scaleDialog->z.text("1.0");
+
+ return TRUE;
+}
+
+static gboolean scaledlg_ok( ui::Widget widget, ScaleDialog* scaleDialog ){
+ scaledlg_apply( widget, scaleDialog );
+ scaleDialog->window.hide();
+ return TRUE;
+}
+
+static gboolean scaledlg_delete( ui::Widget widget, GdkEventAny *event, ScaleDialog* scaleDialog ){
+ scaledlg_cancel( widget, scaleDialog );
+ return TRUE;
+}
+
+ScaleDialog g_scale_dialog;
+
+void DoScaleDlg(){
+ if ( !g_scale_dialog.window ) {
+ g_scale_dialog.window = MainFrame_getWindow().create_dialog_window("Arbitrary scale", G_CALLBACK(scaledlg_delete ), &g_scale_dialog );
+
+ auto accel = ui::AccelGroup(ui::New);
+ g_scale_dialog.window.add_accel_group( accel );
+
+ {
+ auto hbox = create_dialog_hbox( 4, 4 );
+ g_scale_dialog.window.add(hbox);
+ {
+ auto table = create_dialog_table( 3, 2, 4, 4 );
+ hbox.pack_start( table, TRUE, TRUE, 0 );
+ {
+ ui::Widget label = ui::Label( " X " );
+ label.show();
+ table.attach(label, {0, 1, 0, 1}, {0, 0});
+ }
+ {
+ ui::Widget label = ui::Label( " Y " );
+ label.show();
+ table.attach(label, {0, 1, 1, 2}, {0, 0});
+ }
+ {
+ ui::Widget label = ui::Label( " Z " );
+ label.show();
+ table.attach(label, {0, 1, 2, 3}, {0, 0});
+ }
+ {
+ auto entry = ui::Entry(ui::New);
+ entry.text("1.0");
+ entry.show();
+ table.attach(entry, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
+
+ g_scale_dialog.x = entry;
+ }
+ {
+ auto entry = ui::Entry(ui::New);
+ entry.text("1.0");
+ entry.show();
+ table.attach(entry, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
+
+ g_scale_dialog.y = entry;
+ }
+ {
+ auto entry = ui::Entry(ui::New);
+ entry.text("1.0");
+ entry.show();
+ table.attach(entry, {1, 2, 2, 3}, {GTK_EXPAND | GTK_FILL, 0});
+
+ g_scale_dialog.z = entry;
+ }
+ }
+ {
+ auto vbox = create_dialog_vbox( 4 );
+ hbox.pack_start( vbox, TRUE, TRUE, 0 );
+ {
+ auto button = create_dialog_button( "OK", G_CALLBACK( scaledlg_ok ), &g_scale_dialog );
+ vbox.pack_start( button, FALSE, FALSE, 0 );
+ widget_make_default( button );
+ gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
+ }
+ {
+ auto button = create_dialog_button( "Cancel", G_CALLBACK( scaledlg_cancel ), &g_scale_dialog );
+ vbox.pack_start( button, FALSE, FALSE, 0 );
+ gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
+ }
+ {
+ auto button = create_dialog_button( "Apply", G_CALLBACK( scaledlg_apply ), &g_scale_dialog );
+ vbox.pack_start( button, FALSE, FALSE, 0 );
+ }
+ }
+ }
+ }
+
+ g_scale_dialog.window.show();
+}