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;
76 brushprimit_texdef_t bp;
78 if(selected_brushes.next != &selected_brushes)
80 prev_pos = position = allocd_block_texdef;
81 for(b=selected_brushes.next; b!=&selected_brushes; b=b->next)
83 if ( !(b->patchBrush) )
85 for(f=b->brush_faces; f ; f = f->next)
89 position->texdef = f->texdef;
90 if(g_qeglobals.m_bBrushPrimitMode)
92 ConvertTexMatWithQTexture(&f->brushprimit_texdef, QERApp_Shader_ForName( f->texdef.GetName() )->getTexture(), &bp, NULL);
93 TexMatToFakeTexCoords(bp.coords, position->texdef.shift, &position->texdef.rotate, position->texdef.scale);
94 position->orig_bp_texdef = bp;
96 position->orig_texdef = position->texdef;
97 prev_pos->next = position;
101 prev_pos->next = NULL;
105 else if(g_ptrSelectedFaces.GetSize() != 0)
107 f = (face_t *) g_ptrSelectedFaces.GetAt(0);
108 b = (brush_t *) g_ptrSelectedFaceBrushes.GetAt(0);
109 position = (texdef_to_face_t*) allocd_block_texdef;
112 position->texdef = f->texdef;
113 if(g_qeglobals.m_bBrushPrimitMode)
115 ConvertTexMatWithQTexture(&f->brushprimit_texdef, QERApp_Shader_ForName( f->texdef.GetName() )->getTexture(), &bp, NULL);
116 TexMatToFakeTexCoords(bp.coords, position->texdef.shift, &position->texdef.rotate, position->texdef.scale);
117 position->orig_bp_texdef = bp;
119 position->orig_texdef = position->texdef;
121 for(i=1; i<g_ptrSelectedFaces.GetSize(); i++)
123 f = (face_t *) g_ptrSelectedFaces.GetAt(i);
124 b = (brush_t *) g_ptrSelectedFaceBrushes.GetAt(i);
125 position = allocd_block_texdef + i;
128 position->texdef = f->texdef;
129 if(g_qeglobals.m_bBrushPrimitMode)
131 ConvertTexMatWithQTexture(&f->brushprimit_texdef, QERApp_Shader_ForName( f->texdef.GetName() )->getTexture(), &bp, NULL);
132 TexMatToFakeTexCoords(bp.coords, position->texdef.shift, &position->texdef.rotate, position->texdef.scale);
133 position->orig_bp_texdef = bp;
135 position->orig_texdef = position->texdef;
136 prev_pos->next = position;
139 position->next = NULL;
147 This doesn't mess with CONTENTS_DETAIL needed for Quake2 content flag
150 void SetFaceTexdef_Q2 (face_t *f, texdef_t *texdef, bool bFitScale)
153 if(strcmp(f->texdef.GetName(), texdef->GetName()) != 0) // set shader here instead of Brush_Build
154 Face_SetShader(f, texdef->GetName());
159 // fit the scaling of the texture on the actual plane
160 vec3_t p1,p2,p3; // absolute coordinates
161 // compute absolute coordinates
162 ComputeAbsolute(f,p1,p2,p3);
165 VectorSubtract(p2,p1,vx);
166 VectorNormalize(vx, vx);
167 VectorSubtract(p3,p1,vy);
168 VectorNormalize(vy, vy);
170 VectorScale(vx,texdef->scale[0],vx);
171 VectorScale(vy,texdef->scale[1],vy);
174 // compute back shift scale rot
175 AbsoluteToLocal(f->plane,f,p1,p2,p3);
185 void SI_SetTexdef_FaceList(texdef_to_face_t* texdef_face_list, bool b_SetUndoPoint, bool bFit_to_Scale)
187 texdef_to_face_t* texdef_to_face;
190 if (g_pGameDescription->quake2)
195 if (!texdef_face_list)
200 if(g_ptrSelectedFaces.GetSize() > 1)
201 Sys_FPrintf(SYS_WRN, "WARNING: Undo NOT supported for multiple face selections\n");
202 else if( (selected_brushes.next != &selected_brushes) || (g_ptrSelectedFaces.GetSize() == 1))
204 // Give something to undo to
205 for(texdef_to_face = texdef_face_list; texdef_to_face; texdef_to_face = texdef_to_face->next)
207 SetFaceTexdef_Q2(texdef_to_face->face, &texdef_to_face->orig_texdef, bFit_to_Scale);
209 SetFaceTexdef(texdef_to_face->face, &texdef_to_face->orig_texdef, &texdef_to_face->orig_bp_texdef, bFit_to_Scale);
211 Undo_Start("set facelist texdefs");
213 if( selected_brushes.next != &selected_brushes )
214 Undo_AddBrushList(&selected_brushes);
216 Undo_AddBrush(texdef_face_list->brush);
221 for(texdef_to_face = texdef_face_list; texdef_to_face; texdef_to_face = texdef_to_face->next)
224 SetFaceTexdef_Q2(texdef_to_face->face, &texdef_to_face->texdef, bFit_to_Scale);
227 brushprimit_texdef_t brushprimit_texdef;
228 FakeTexCoordsToTexMat(texdef_to_face->texdef.shift, texdef_to_face->texdef.rotate, texdef_to_face->texdef.scale, brushprimit_texdef.coords);
229 SetFaceTexdef(texdef_to_face->face, &texdef_to_face->texdef, &brushprimit_texdef , bFit_to_Scale);
231 Brush_Build(texdef_to_face->brush);
233 texdef_to_face->texdef = texdef_to_face->face->texdef;
236 if ( b_SetUndoPoint )
238 if( (selected_brushes.next != &selected_brushes) || (g_ptrSelectedFaces.GetSize() == 1) )
240 if(selected_brushes.next != &selected_brushes)
241 Undo_EndBrushList(&selected_brushes);
243 Undo_EndBrush(texdef_face_list->brush);
246 // Over-write the orig_texdef list, cementing the change.
247 for(texdef_to_face = texdef_face_list; texdef_to_face; texdef_to_face = texdef_to_face->next)
249 texdef_to_face->orig_texdef = texdef_to_face->texdef;
250 texdef_to_face->orig_bp_texdef = texdef_to_face->face->brushprimit_texdef;
255 Sys_UpdateWindows (W_ALL);
258 void SI_FaceList_FitTexture(texdef_to_face_t* si_texdef_face_list, int nHeight, int nWidth)
260 texdef_to_face_t* temp_texdef_face_list;
261 brushprimit_texdef_t bp;
263 if (!si_texdef_face_list)
266 for (temp_texdef_face_list = si_texdef_face_list; temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
268 Face_FitTexture(temp_texdef_face_list->face, nHeight, nWidth);
269 Brush_Build(temp_texdef_face_list->brush,true,true,false,false);
270 // Write changes to our working Texdef list
272 if(g_qeglobals.m_bBrushPrimitMode)
274 ConvertTexMatWithQTexture(&temp_texdef_face_list->face->brushprimit_texdef, QERApp_Shader_ForName( temp_texdef_face_list->face->texdef.GetName() )->getTexture(), &bp, NULL);
275 TexMatToFakeTexCoords(bp.coords, temp_texdef_face_list->face->texdef.shift, &temp_texdef_face_list->face->texdef.rotate, temp_texdef_face_list->face->texdef.scale);
277 temp_texdef_face_list->texdef = temp_texdef_face_list->face->texdef;
280 Sys_UpdateWindows (W_CAMERA);
284 GtkWindow* SI_GetMainWindow(void)
286 return GTK_WINDOW(g_qeglobals_gui.d_main_window);
289 void SI_SetWinPos_from_Prefs(GtkWidget *win)
291 load_window_pos (win, g_PrefsDlg.mWindowInfo.posSurfaceWnd);