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