/* ============ Select_Ray If the origin is inside a brush, that brush will be ignored. ============ */ void Select_Ray( vec3_t origin, vec3_t dir, int flags ) { trace_t t; t = Test_Ray( origin, dir, flags ); if ( !t.brush ) return; if ( flags == SF_SINGLEFACE ) { int nCount = g_SelectedFaces.GetSize(); bool bOk = true; for ( int i = 0; i < nCount; i++ ) { if ( t.face == reinterpret_cast<face_s*>( g_SelectedFaces.GetAt( i ) ) ) { bOk = false; // need to move remove i'th entry g_SelectedFaces.RemoveAt( i, 1 ); g_SelectedFaceBrushes.RemoveAt( i, 1 ); } } if ( bOk ) { g_SelectedFaces.Add( t.face ); g_SelectedFaceBrushes.Add( t.brush ); } //selected_face = t.face; //selected_face_brush = t.brush; Sys_UpdateWindows( W_ALL ); clearSelection(); // Texture_SetTexture requires a brushprimit_texdef fitted to the default width=2 height=2 texture brushprimit_texdef_s brushprimit_texdef; ConvertTexMatWithQTexture( &t.face->brushprimit_texdef, t.face->d_texture, &brushprimit_texdef, NULL ); Texture_SetTexture( &t.face->texdef, &brushprimit_texdef, false, false ); UpdateSurfaceDialog(); return; } // move the brush to the other list clearSelection(); if ( t.selected ) { Brush_RemoveFromList( t.brush ); Brush_AddToList( t.brush, &active_brushes ); UpdatePatchInspector(); } else { Select_Brush( t.brush, !( GetKeyState( VK_MENU ) & 0x8000 ) ); } Sys_UpdateWindows( W_ALL ); }
/* ============ Select_Brush ============ */ void Select_Brush( brush_s* brush, bool bComplete, bool bStatus ) { brush_s* b; entity_s* e; g_ptrSelectedFaces.RemoveAll(); g_ptrSelectedFaceBrushes.RemoveAll(); //selected_face = NULL; if ( g_qeglobals.d_select_count < 2 ) g_qeglobals.d_select_order[g_qeglobals.d_select_count] = brush; g_qeglobals.d_select_count++; //if (brush->patchBrush) // Patch_Select(brush->nPatchID); e = brush->owner; if ( e ) { // select complete entity on first click if ( e != world_entity && bComplete == true ) { for ( b = selected_brushes.next ; b != &selected_brushes ; b = b->next ) if ( b->owner == e ) goto singleselect; for ( b = e->brushes.onext ; b != &e->brushes ; b = b->onext ) { Brush_RemoveFromList( b ); Brush_AddToList( b, &selected_brushes ); } } else { singleselect: Brush_RemoveFromList( brush ); Brush_AddToList( brush, &selected_brushes ); UpdateSurfaceDialog(); UpdatePatchInspector(); } if ( e->eclass ) { UpdateEntitySel( brush->owner->eclass ); } } if ( bStatus ) { edVec3_c vMin, vMax, vSize; Select_GetBounds( vMin, vMax ); vSize = vMax - vMin; CString strStatus; strStatus.Format( "Selection X:: %.1f Y:: %.1f Z:: %.1f", vSize[0], vSize[1], vSize[2] ); g_pParentWnd->SetStatusText( 2, strStatus ); } }
/* ======================================================================================================================= ======================================================================================================================= */ void CNewTexWnd::OnLButtonDown(UINT nFlags, CPoint point) { cursor = point; SetFocus(); bool fitScale = Sys_KeyDown(VK_CONTROL); bool edit = Sys_KeyDown(VK_SHIFT) && !fitScale; const idMaterial *mat = getMaterialAtPoint(point); if (mat) { Select_SetDefaultTexture(mat, fitScale, true); } else { Sys_Status("Did not select a texture\n", 0); } // UpdateSurfaceDialog(); UpdatePatchInspector(); }
/* ================ Drag_Begin ================ */ void Drag_Begin( int x, int y, int buttons, const idVec3 &xaxis, const idVec3 &yaxis, const idVec3 &origin, const idVec3 &dir ) { qertrace_t t; drag_ok = false; VectorCopy(vec3_origin, pressdelta); VectorCopy(vec3_origin, vPressStart); drag_first = true; // shift LBUTTON = select entire brush if (buttons == (MK_LBUTTON | MK_SHIFT) && g_qeglobals.d_select_mode != sel_curvepoint) { int nFlag = ( ::GetAsyncKeyState( VK_MENU ) != 0 ) ? 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-shift LBUTTON = select single face if (buttons == (MK_LBUTTON | MK_CONTROL | MK_SHIFT) && g_qeglobals.d_select_mode != sel_curvepoint) { if ( radiant_entityMode.GetBool() ) { return; } // _D3XP disabled //Select_Deselect( ( ::GetAsyncKeyState( VK_MENU ) == 0 ) ); 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; } if ( radiant_entityMode.GetBool() ) { 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 = t.brush->mins; g_qeglobals.d_new_brush_top = t.brush->maxs; // use a local brushprimit_texdef fitted to a default 2x2 texture brushprimit_texdef_t bp_local; if (t.brush && t.brush->pPatch) { texdef_t localtd; memset(&bp_local.coords, 0, sizeof(bp_local.coords)); bp_local.coords[0][0] = 1.0f; bp_local.coords[1][1] = 1.0f; localtd.SetName(t.brush->pPatch->d_texture->GetName()); Texture_SetTexture(&localtd, &bp_local, false, true); Select_CopyPatchTextureCoords ( t.brush->pPatch ); } else { Select_ProjectFaceOntoPatch( t.face ); ConvertTexMatWithQTexture(&t.face->brushprimit_texdef, t.face->d_texture, &bp_local, NULL); Texture_SetTexture(&t.face->texdef, &bp_local, false, true); } UpdateSurfaceDialog(); UpdatePatchInspector(); UpdateLightInspector(); } else { Sys_Status("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_Status("Can't change an entity texture\n"); } else { Brush_SetTexture ( t.brush, &g_qeglobals.d_texturewin.texdef, &g_qeglobals.d_texturewin.brushprimit_texdef, false ); Sys_UpdateWindows(W_ALL); } } else { Sys_Status("Didn't hit a btrush\n"); } return; } // ctrl-shift-middle button = set single face to texture if (buttons == (nMouseButton | MK_SHIFT | MK_CONTROL)) { t = Test_Ray(origin, dir, false); if (t.brush) { if (t.brush->brush_faces->texdef.name[0] == '(') { Sys_Status("Can't change an entity texture\n"); } else { SetFaceTexdef ( t.brush, t.face, &g_qeglobals.d_texturewin.texdef, &g_qeglobals.d_texturewin.brushprimit_texdef ); Brush_Build(t.brush); Sys_UpdateWindows(W_ALL); } } else { Sys_Status("Didn't hit a btrush\n"); } return; } if (buttons == (nMouseButton | MK_SHIFT)) { Sys_Status("Set brush face texture info\n"); t = Test_Ray(origin, dir, false); if (t.brush && !t.brush->owner->eclass->fixedsize) { /* if (t.brush->brush_faces->texdef.name[0] == '(') { if (t.brush->owner->eclass->nShowFlags & ECLASS_LIGHT) { CString strBuff; idMaterial *pTex = declManager->FindMaterial(g_qeglobals.d_texturewin.texdef.name); if (pTex) { idVec3 vColor = pTex->getColor(); float fLargest = 0.0f; for (int i = 0; i < 3; i++) { if (vColor[i] > fLargest) { fLargest = vColor[i]; } } if (fLargest == 0.0f) { vColor[0] = vColor[1] = vColor[2] = 1.0f; } else { float fScale = 1.0f / fLargest; for (int i = 0; i < 3; i++) { vColor[i] *= fScale; } } strBuff.Format("%f %f %f", pTex->getColor().x, pTex->getColor().y, pTex->getColor().z); SetKeyValue(t.brush->owner, "_color", strBuff.GetBuffer(0)); Sys_UpdateWindows(W_ALL); } } else { Sys_Status("Can't select an entity brush face\n"); } } else { */ // strcpy(t.face->texdef.name,g_qeglobals.d_texturewin.texdef.name); t.face->texdef.SetName(g_qeglobals.d_texturewin.texdef.name); Brush_Build(t.brush); Sys_UpdateWindows(W_ALL); // } } else { Sys_Status("Didn't hit a brush\n"); } return; } }
/* =========== 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; drag_ok = false; VectorCopy (vec3_origin, pressdelta); VectorCopy (vec3_origin, vPressStart); drag_first = true; peLink = NULL; // shift LBUTTON = select entire brush if (buttons == (MK_LBUTTON | MK_SHIFT) && g_qeglobals.d_select_mode != sel_curvepoint) { int nFlag = (static_cast<bool>(::GetAsyncKeyState(VK_MENU))) ? 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-shift LBUTTON = select single face if (buttons == (MK_LBUTTON | MK_CONTROL | MK_SHIFT) && g_qeglobals.d_select_mode != sel_curvepoint) { Sys_Printf ("Face Selection?\n"); 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; } // JONATHAN: stuff to add here 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) { //++timo clean #if 0 // g_qeglobals.d_new_brush_bottom_z = t.brush->mins[2]; // g_qeglobals.d_new_brush_top_z = t.brush->maxs[2]; // g_pParentWnd->ActiveXY()->GetViewType() // cf VIEWTYPE definition: enum VIEWTYPE {YZ, XZ, XY}; // we fit our work zone to the brush int nViewType = g_pParentWnd->ActiveXY()->GetViewType(); int nDim1 = (nViewType == YZ) ? 1 : 0; int nDim2 = (nViewType == XY) ? 1 : 2; g_qeglobals.d_work_min[nDim1] = t.brush->mins[nDim1]; g_qeglobals.d_work_max[nDim1] = t.brush->maxs[nDim1]; g_qeglobals.d_work_min[nDim2] = t.brush->mins[nDim2]; g_qeglobals.d_work_max[nDim2] = t.brush->maxs[nDim2]; #endif // JONATHAN:: On ALT-Middle mouse // Fit texture to face SHORT altdown = (GetKeyState(VK_MENU) & 0x8000); if (altdown) { // Fit Texture to brush face Face_FitTexture(t.face, 1, 1); // Build Brush to apply update Brush_Build(t.brush); //? // Update Camera View Sys_UpdateWindows (W_CAMERA); } else { UpdateWorkzone_ForBrush( t.brush ); // 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 { Brush_SetTexture (t.brush, &g_qeglobals.d_texturewin.texdef, &g_qeglobals.d_texturewin.brushprimit_texdef, false, static_cast<IPluginTexdef *>( g_qeglobals.d_texturewin.pTexdef ) ); Sys_UpdateWindows (W_ALL); } } else Sys_Printf ("Didn't hit a btrush\n"); return; } // JONATHAN:HERE // ctrl-shift-middle button = set single face to texture if (buttons == (nMouseButton|MK_SHIFT|MK_CONTROL) ) { t = Test_Ray (origin, dir, false); if (t.brush) { if (t.brush->brush_faces->texdef.name[0] == '(') Sys_Printf ("Can't change an entity texture\n"); else { SetFaceTexdef (t.brush, t.face, &g_qeglobals.d_texturewin.texdef, &g_qeglobals.d_texturewin.brushprimit_texdef); Brush_Build( t.brush ); Sys_UpdateWindows (W_ALL); } } else Sys_Printf ("Didn't hit a btrush\n"); return; } if (buttons == (nMouseButton | MK_SHIFT)) { Sys_Printf("Set brush face texture info\n"); t = Test_Ray (origin, dir, false); if (t.brush) { if (t.brush->brush_faces->texdef.name[0] == '(') { if (t.brush->owner->eclass->nShowFlags & ECLASS_LIGHT) { CString strBuff; qtexture_t* pTex = g_qeglobals.d_texturewin.pShader->getTexture(); if (pTex) { vec3_t vColor; VectorCopy(pTex->color, vColor); float fLargest = 0.0f; for (int i = 0; i < 3; i++) { if (vColor[i] > fLargest) fLargest = vColor[i]; } if (fLargest == 0.0f) { vColor[0] = vColor[1] = vColor[2] = 1.0f; } else { float fScale = 1.0f / fLargest; for (int i = 0; i < 3; i++) { vColor[i] *= fScale; } } strBuff.Format("%f %f %f",pTex->color[0], pTex->color[1], pTex->color[2]); SetKeyValue(t.brush->owner, "_color", strBuff.GetBuffer(0)); Sys_UpdateWindows (W_ALL); } } else { Sys_Printf ("Can't select an entity brush face\n"); } } else { //strcpy(t.face->texdef.name,g_qeglobals.d_texturewin.texdef.name); t.face->texdef.SetName(g_qeglobals.d_texturewin.texdef.name); Brush_Build(t.brush); Sys_UpdateWindows (W_ALL); } } else Sys_Printf ("Didn't hit a brush\n"); return; } }
/* =========== Drag_Begin =========== */ void Drag_Begin (int x, int y, int buttons, vec3_t xaxis, vec3_t yaxis, vec3_t origin, vec3_t dir) { trace_t t; drag_ok = false; VectorCopy (vec3_origin, pressdelta); VectorCopy (vec3_origin, vPressStart); drag_first = true; peLink = NULL; // shift LBUTTON = select entire brush if (buttons == (MK_LBUTTON | MK_SHIFT) && g_qeglobals.d_select_mode != sel_curvepoint) { int nFlag = (static_cast<bool>(::GetAsyncKeyState(VK_MENU))) ? 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-shift LBUTTON = select single face if (buttons == (MK_LBUTTON | MK_CONTROL | MK_SHIFT) && g_qeglobals.d_select_mode != sel_curvepoint) { Select_Deselect (); 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]; Texture_SetTexture (&t.face->texdef); 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 { Brush_SetTexture (t.brush, &g_qeglobals.d_texturewin.texdef, false, false); Sys_UpdateWindows (W_ALL); } } else Sys_Printf ("Didn't hit a btrush\n"); return; } // ctrl-shift-middle button = set single face to texture if (buttons == (nMouseButton|MK_SHIFT|MK_CONTROL) ) { t = Test_Ray (origin, dir, false); if (t.brush) { if (t.brush->brush_faces->texdef.name[0] == '(') Sys_Printf ("Can't change an entity texture\n"); else { SetFaceTexdef (t.brush, t.face, &g_qeglobals.d_texturewin.texdef, false, false); Brush_Build( t.brush ); Sys_UpdateWindows (W_ALL); } } else Sys_Printf ("Didn't hit a btrush\n"); return; } // shift-middle = (if light) // set face texture info (err...whatever), // else // set brush to texture but preserve any system faces // if (buttons == (nMouseButton | MK_SHIFT)) { Sys_Printf("Set brush face texture info\n"); t = Test_Ray (origin, dir, false); if (t.brush) { if (t.brush->brush_faces->texdef.name[0] == '(') { if (strcmpi(t.brush->owner->eclass->name, "light") == 0) { CString strBuff; qtexture_t* pTex = Texture_ForName(g_qeglobals.d_texturewin.texdef.name); if (pTex) { vec3_t vColor; VectorCopy(pTex->color, vColor); float fLargest = 0.0f; for (int i = 0; i < 3; i++) { if (vColor[i] > fLargest) fLargest = vColor[i]; } if (fLargest == 0.0f) { vColor[0] = vColor[1] = vColor[2] = 1.0f; } else { float fScale = 1.0f / fLargest; for (int i = 0; i < 3; i++) { vColor[i] *= fScale; } } strBuff.Format("%f %f %f",pTex->color[0], pTex->color[1], pTex->color[2]); SetKeyValue(t.brush->owner, "_color", strBuff.GetBuffer(0)); Sys_UpdateWindows (W_ALL); } } else { Sys_Printf ("Can't select an entity brush face\n"); } } else { Brush_SetTexture (t.brush, &g_qeglobals.d_texturewin.texdef, false, true); Sys_UpdateWindows (W_ALL); } } else Sys_Printf ("Didn't hit a brush\n"); return; } }