2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 //-----------------------------------------------------------------------------
25 // implementation of isurfaceplugin-interface specifics
29 void QERApp_GetTwoSelectedPatch( patchMesh_t **p1, patchMesh_t **p2 )
31 *p1 = NULL; *p2 = NULL;
32 for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
46 Sys_Printf("WARNING: QERApp_GetTwoSelectedPatch failed (did not find two patches)\n");
51 // Nurail: The following functions are used by the Surface Inspector module
53 // Queries the number of faces from selected brushes
54 int SI_GetSelectedFaceCountfromBrushes(void)
60 if(selected_brushes.next == &selected_brushes)
63 for(b=selected_brushes.next; b!=&selected_brushes; b=b->next)
65 for(f=b->brush_faces; f ; f=f->next, num_of_faces++);
70 void SI_GetSelFacesTexdef(texdef_to_face_t *allocd_block_texdef)
75 texdef_to_face_t *position, *prev_pos;
77 if(selected_brushes.next != &selected_brushes)
79 prev_pos = position = allocd_block_texdef;
80 for(b=selected_brushes.next; b!=&selected_brushes; b=b->next)
82 if ( !(b->patchBrush) )
84 for(f=b->brush_faces; f ; f = f->next)
88 position->texdef = f->texdef;
89 position->orig_texdef = f->texdef;
90 prev_pos->next = position;
94 prev_pos->next = NULL;
98 else if(g_ptrSelectedFaces.GetSize() != 0)
100 f = (face_t *) g_ptrSelectedFaces.GetAt(0);
101 b = (brush_t *) g_ptrSelectedFaceBrushes.GetAt(0);
102 position = (texdef_to_face_t*) allocd_block_texdef;
105 position->texdef = f->texdef;
106 position->orig_texdef = f->texdef;
108 for(i=1; i<g_ptrSelectedFaces.GetSize(); i++)
110 f = (face_t *) g_ptrSelectedFaces.GetAt(i);
111 b = (brush_t *) g_ptrSelectedFaceBrushes.GetAt(i);
112 position = allocd_block_texdef + i;
115 position->texdef = f->texdef;
116 position->orig_texdef = f->texdef;
117 prev_pos->next = position;
120 position->next = NULL;
128 This doesn't mess with CONTENTS_DETAIL needed for Quake2 content flag
131 void SetFaceTexdef_Q2 (face_t *f, texdef_t *texdef, bool bFitScale)
134 if(strcmp(f->texdef.GetName(), texdef->GetName()) != 0) // set shader here instead of Brush_Build
135 Face_SetShader(f, texdef->GetName());
140 // fit the scaling of the texture on the actual plane
141 vec3_t p1,p2,p3; // absolute coordinates
142 // compute absolute coordinates
143 ComputeAbsolute(f,p1,p2,p3);
146 VectorSubtract(p2,p1,vx);
147 VectorNormalize(vx, vx);
148 VectorSubtract(p3,p1,vy);
149 VectorNormalize(vy, vy);
151 VectorScale(vx,texdef->scale[0],vx);
152 VectorScale(vy,texdef->scale[1],vy);
155 // compute back shift scale rot
156 AbsoluteToLocal(f->plane,f,p1,p2,p3);
166 void SI_SetTexdef_FaceList(texdef_to_face_t* texdef_face_list, bool b_SetUndoPoint, bool bFit_to_Scale)
168 texdef_to_face_t* texdef_to_face;
171 if ( ( g_pGameDescription->quake2 ) || ( g_pGameDescription->mGameFile == "q2.game" ) || ( g_pGameDescription->mGameFile == "heretic2.game" ) )
176 if (!texdef_face_list)
181 if(g_ptrSelectedFaces.GetSize() > 1)
182 Sys_FPrintf(SYS_WRN, "WARNING: Undo NOT supported for multiple face selections\n");
183 else if( (selected_brushes.next != &selected_brushes) || (g_ptrSelectedFaces.GetSize() == 1))
185 // Give something to undo to
186 for(texdef_to_face = texdef_face_list; texdef_to_face; texdef_to_face = texdef_to_face->next)
188 SetFaceTexdef_Q2(texdef_to_face->face, &texdef_to_face->orig_texdef, bFit_to_Scale);
190 SetFaceTexdef(texdef_to_face->face, &texdef_to_face->orig_texdef, NULL);
192 Undo_Start("set facelist texdefs");
194 if( selected_brushes.next != &selected_brushes )
195 Undo_AddBrushList(&selected_brushes);
197 Undo_AddBrush(texdef_face_list->brush);
202 for(texdef_to_face = texdef_face_list; texdef_to_face; texdef_to_face = texdef_to_face->next)
205 SetFaceTexdef_Q2(texdef_to_face->face, &texdef_to_face->texdef, bFit_to_Scale);
207 SetFaceTexdef(texdef_to_face->face, &texdef_to_face->texdef, NULL , bFit_to_Scale);
208 Brush_Build(texdef_to_face->brush);
210 texdef_to_face->texdef = texdef_to_face->face->texdef;
213 if ( b_SetUndoPoint )
215 if( (selected_brushes.next != &selected_brushes) || (g_ptrSelectedFaces.GetSize() == 1) )
217 if(selected_brushes.next != &selected_brushes)
218 Undo_EndBrushList(&selected_brushes);
220 Undo_EndBrush(texdef_face_list->brush);
223 // Over-write the orig_texdef list, cementing the change.
224 for(texdef_to_face = texdef_face_list; texdef_to_face; texdef_to_face = texdef_to_face->next)
225 texdef_to_face->orig_texdef = texdef_to_face->texdef;
229 Sys_UpdateWindows (W_ALL);
232 void SI_FaceList_FitTexture(texdef_to_face_t* si_texdef_face_list, int nHeight, int nWidth)
234 texdef_to_face_t* temp_texdef_face_list;
236 if (!si_texdef_face_list)
239 for (temp_texdef_face_list = si_texdef_face_list; temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
241 Face_FitTexture(temp_texdef_face_list->face, nHeight, nWidth);
242 Brush_Build(temp_texdef_face_list->brush,true,true,false,false);
243 // Write changes to our working Texdef list
244 temp_texdef_face_list->texdef = temp_texdef_face_list->face->texdef;
247 Sys_UpdateWindows (W_CAMERA);
251 GtkWindow* SI_GetMainWindow(void)
253 return GTK_WINDOW(g_qeglobals_gui.d_main_window);
256 void SI_SetWinPos_from_Prefs(GtkWidget *win)
258 load_window_pos (win, g_PrefsDlg.mWindowInfo.posSurfaceWnd);