/* ============ 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_t*>(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_t brushprimit_texdef; ConvertTexMatWithQTexture ( &t.face->brushprimit_texdef, t.face->d_texture, &brushprimit_texdef, NULL ); Texture_SetTexture ( &t.face->texdef, &brushprimit_texdef, false, GETPLUGINTEXDEF(t.face), 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); }
// will free all GL binded qtextures and shaders // NOTE: doesn't make much sense out of Radiant exit or called during a reload void WINAPI QERApp_FreeShaders() { int i; brush_t *b; // store the shader names used by the patches for(i=0; i<PatchShaders.GetSize(); i++) delete PatchShaders.GetAt(i); PatchShaders.RemoveAll(); for (b=active_brushes.next ; b != NULL && b != &active_brushes ; b=b->next) { if (b->patchBrush) PushPatch(b->pPatch); } for (b=selected_brushes.next ; b != NULL && b != &selected_brushes ; b=b->next) { if (b->patchBrush) PushPatch(b->pPatch); } // reload shaders // empty the actives shaders list g_ActiveShaders.ReleaseAll(); g_Shaders.ReleaseAll(); // empty the main g_qeglobals.d_qtextures list // FIXME: when we reload later on, we need to have the shader names // for brushes it's stored in the texdef // but patches don't have texdef // see bug 104655 for details // so the solution, build an array of patchMesh_t* and their shader names #ifdef _DEBUG Sys_Printf("FIXME: bug 104655 workaround\n"); #endif // NOTE: maybe before we'd like to set all qtexture_t in the shaders list to notex? // NOTE: maybe there are some qtexture_t we don't want to erase? For plain color faces maybe? // NOTE: the GL textures are freed later on if (g_qeglobals.d_qtextures) { qtexture_t* pTex = g_qeglobals.d_qtextures->next; while (pTex != NULL && pTex != g_qeglobals.d_qtextures) { qtexture_t* pNextTex = pTex->next; if (g_qeglobals.bSurfacePropertiesPlugin) { // Timo // Surface properties plugin #ifdef _DEBUG if ( !pTex->pData ) Sys_Printf("WARNING: found a qtexture_t* with no IPluginQTexture\n"); #endif if ( pTex->pData ) GETPLUGINTEXDEF(pTex)->DecRef(); } free(pTex); pTex = pNextTex; } } // free GL bindings GLuint* pGln = new GLuint[texture_extension_number-1]; qglGenTextures(texture_extension_number-1, pGln); QE_CheckOpenGLForErrors(); qglDeleteTextures(texture_extension_number-1, pGln); QE_CheckOpenGLForErrors(); delete []pGln; texture_extension_number = 1; g_qeglobals.d_qtextures = NULL; // free the map g_qeglobals.d_qtexmap->RemoveAll(); }
/* =========== 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; } }