]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/surfaceplugin.cpp
fix unzip code
[xonotic/netradiant.git] / radiant / surfaceplugin.cpp
1 /*
2    Copyright (C) 1999-2007 id Software, Inc. and contributors.
3    For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5    This file is part of GtkRadiant.
6
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.
11
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.
16
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
20  */
21
22 //-----------------------------------------------------------------------------
23 //
24 // DESCRIPTION:
25 // implementation of isurfaceplugin-interface specifics
26
27 #include "stdafx.h"
28
29 void QERApp_GetTwoSelectedPatch( patchMesh_t **p1, patchMesh_t **p2 ){
30         *p1 = NULL; *p2 = NULL;
31         for ( brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next )
32         {
33                 if ( pb->patchBrush ) {
34                         if ( !( *p1 ) ) {
35                                 *p1 = pb->pPatch;
36                         }
37                         else if ( !( *p2 ) ) {
38                                 *p2 = pb->pPatch;
39                                 return;
40                         }
41                 }
42         }
43 #ifdef _DEBUG
44         Sys_Printf( "WARNING: QERApp_GetTwoSelectedPatch failed (did not find two patches)\n" );
45 #endif
46         return;
47 }
48
49 // Nurail: The following functions are used by the Surface Inspector module
50
51 // Queries the number of faces from selected brushes
52 int SI_GetSelectedFaceCountfromBrushes( void ){
53         face_t    *f;
54         brush_t   *b;
55         int num_of_faces = 0;
56
57         if ( selected_brushes.next == &selected_brushes ) {
58                 return( 0 );
59         }
60
61         for ( b = selected_brushes.next; b != &selected_brushes; b = b->next )
62                 if ( !( b->patchBrush ) ) {
63                         for ( f = b->brush_faces; f ; f = f->next, num_of_faces++ ) ;
64                 }
65
66         return num_of_faces;
67 }
68
69 void SI_GetSelFacesTexdef( texdef_to_face_t *allocd_block_texdef ){
70         int i;
71         face_t    *f;
72         brush_t   *b;
73         texdef_to_face_t *position, *prev_pos;
74         brushprimit_texdef_t bp;
75
76         if ( selected_brushes.next != &selected_brushes ) {
77                 prev_pos = position = allocd_block_texdef;
78                 for ( b = selected_brushes.next; b != &selected_brushes; b = b->next )
79                 {
80                         if ( !( b->patchBrush ) ) {
81                                 for ( f = b->brush_faces; f ; f = f->next )
82                                 {
83                                         position->face = f;
84                                         position->brush = b;
85                                         position->texdef = f->texdef;
86                                         if ( g_qeglobals.m_bBrushPrimitMode ) {
87                                                 ConvertTexMatWithQTexture( &f->brushprimit_texdef, QERApp_Shader_ForName( f->texdef.GetName() )->getTexture(), &bp, NULL );
88                                                 TexMatToFakeTexCoords( bp.coords, position->texdef.shift, &position->texdef.rotate, position->texdef.scale );
89                                                 position->orig_bp_texdef = bp;
90                                         }
91                                         position->orig_texdef = position->texdef;
92                                         prev_pos->next = position;
93                                         prev_pos = position;
94                                         position++;
95                                 }
96                                 prev_pos->next = NULL;
97                         }
98                 }
99         }
100         else if ( g_ptrSelectedFaces.GetSize() != 0 ) {
101                 f = (face_t *) g_ptrSelectedFaces.GetAt( 0 );
102                 b = (brush_t *) g_ptrSelectedFaceBrushes.GetAt( 0 );
103                 position = (texdef_to_face_t*) allocd_block_texdef;
104                 position->face = f;
105                 position->brush = b;
106                 position->texdef = f->texdef;
107                 if ( g_qeglobals.m_bBrushPrimitMode ) {
108                         ConvertTexMatWithQTexture( &f->brushprimit_texdef, QERApp_Shader_ForName( f->texdef.GetName() )->getTexture(), &bp, NULL );
109                         TexMatToFakeTexCoords( bp.coords, position->texdef.shift, &position->texdef.rotate, position->texdef.scale );
110                         position->orig_bp_texdef = bp;
111                 }
112                 position->orig_texdef = position->texdef;
113                 prev_pos = position;
114                 for ( i = 1; i < g_ptrSelectedFaces.GetSize(); i++ )
115                 {
116                         f = (face_t *) g_ptrSelectedFaces.GetAt( i );
117                         b = (brush_t *) g_ptrSelectedFaceBrushes.GetAt( i );
118                         position = allocd_block_texdef + i;
119                         position->face = f;
120                         position->brush = b;
121                         position->texdef = f->texdef;
122                         if ( g_qeglobals.m_bBrushPrimitMode ) {
123                                 ConvertTexMatWithQTexture( &f->brushprimit_texdef, QERApp_Shader_ForName( f->texdef.GetName() )->getTexture(), &bp, NULL );
124                                 TexMatToFakeTexCoords( bp.coords, position->texdef.shift, &position->texdef.rotate, position->texdef.scale );
125                                 position->orig_bp_texdef = bp;
126                         }
127                         position->orig_texdef = position->texdef;
128                         prev_pos->next = position;
129                         prev_pos = position;
130                 }
131                 position->next = NULL;
132         }
133
134 }
135
136 /*
137    SetFaceTexdef_Q2
138
139    This doesn't mess with CONTENTS_DETAIL needed for Quake2 content flag
140
141  */
142 void SetFaceTexdef_Q2( face_t *f, texdef_t *texdef, bool bFitScale ){
143
144         if ( strcmp( f->texdef.GetName(), texdef->GetName() ) != 0 ) { // set shader here instead of Brush_Build
145                 Face_SetShader( f, texdef->GetName() );
146         }
147
148         if ( bFitScale ) {
149                 f->texdef = *texdef;
150                 // fit the scaling of the texture on the actual plane
151                 vec3_t p1,p2,p3;     // absolute coordinates
152                 // compute absolute coordinates
153                 ComputeAbsolute( f,p1,p2,p3 );
154                 // compute the scale
155                 vec3_t vx,vy;
156                 VectorSubtract( p2,p1,vx );
157                 VectorNormalize( vx, vx );
158                 VectorSubtract( p3,p1,vy );
159                 VectorNormalize( vy, vy );
160                 // assign scale
161                 VectorScale( vx,texdef->scale[0],vx );
162                 VectorScale( vy,texdef->scale[1],vy );
163                 VectorAdd( p1,vx,p2 );
164                 VectorAdd( p1,vy,p3 );
165                 // compute back shift scale rot
166                 AbsoluteToLocal( f->plane,f,p1,p2,p3 );
167         }
168         else
169         {
170                 f->texdef = *texdef;
171         }
172 }
173
174
175
176 void SI_SetTexdef_FaceList( texdef_to_face_t* texdef_face_list, bool b_SetUndoPoint, bool bFit_to_Scale ){
177         texdef_to_face_t* texdef_to_face;
178         bool b_isQuake2;
179
180         if ( g_pGameDescription->quake2 ) {
181                 b_isQuake2 = true;
182         }
183         else{
184                 b_isQuake2 = false;
185         }
186
187         if ( !texdef_face_list ) {
188                 return;
189         }
190
191         if ( b_SetUndoPoint ) {
192                 if ( g_ptrSelectedFaces.GetSize() > 1 ) {
193                         Sys_FPrintf( SYS_WRN, "WARNING: Undo NOT supported for multiple face selections\n" );
194                 }
195                 else if ( ( selected_brushes.next != &selected_brushes ) || ( g_ptrSelectedFaces.GetSize() == 1 ) ) {
196                         // Give something to undo to
197                         for ( texdef_to_face = texdef_face_list; texdef_to_face; texdef_to_face = texdef_to_face->next )
198                                 if ( b_isQuake2 ) {
199                                         SetFaceTexdef_Q2( texdef_to_face->face, &texdef_to_face->orig_texdef, bFit_to_Scale );
200                                 }
201                                 else{
202                                         SetFaceTexdef( texdef_to_face->face, &texdef_to_face->orig_texdef, &texdef_to_face->orig_bp_texdef, bFit_to_Scale );
203                                 }
204
205                         Undo_Start( "set facelist texdefs" );
206
207                         if ( selected_brushes.next != &selected_brushes ) {
208                                 Undo_AddBrushList( &selected_brushes );
209                         }
210                         else{
211                                 Undo_AddBrush( texdef_face_list->brush );
212                         }
213
214                 }
215         }
216
217         for ( texdef_to_face = texdef_face_list; texdef_to_face; texdef_to_face = texdef_to_face->next )
218         {
219                 if ( b_isQuake2 ) {
220                         SetFaceTexdef_Q2( texdef_to_face->face, &texdef_to_face->texdef,  bFit_to_Scale );
221                 }
222                 else
223                 {
224                         brushprimit_texdef_t brushprimit_texdef;
225                         FakeTexCoordsToTexMat( texdef_to_face->texdef.shift, texdef_to_face->texdef.rotate, texdef_to_face->texdef.scale, brushprimit_texdef.coords );
226                         SetFaceTexdef( texdef_to_face->face, &texdef_to_face->texdef, &brushprimit_texdef, bFit_to_Scale );
227                 }
228                 Brush_Build( texdef_to_face->brush );
229                 if ( bFit_to_Scale ) {
230                         texdef_to_face->texdef = texdef_to_face->face->texdef;
231                 }
232         }
233
234         if ( b_SetUndoPoint ) {
235                 if ( ( selected_brushes.next != &selected_brushes ) || ( g_ptrSelectedFaces.GetSize() == 1 ) ) {
236                         if ( selected_brushes.next != &selected_brushes ) {
237                                 Undo_EndBrushList( &selected_brushes );
238                         }
239                         else{
240                                 Undo_EndBrush( texdef_face_list->brush );
241                         }
242
243                         Undo_End();
244                         // Over-write the orig_texdef list, cementing the change.
245                         for ( texdef_to_face = texdef_face_list; texdef_to_face; texdef_to_face = texdef_to_face->next )
246                         {
247                                 texdef_to_face->orig_texdef = texdef_to_face->texdef;
248                                 texdef_to_face->orig_bp_texdef = texdef_to_face->face->brushprimit_texdef;
249                         }
250                 }
251         }
252
253         Sys_UpdateWindows( W_ALL );
254 }
255
256 void SI_FaceList_FitTexture( texdef_to_face_t* si_texdef_face_list, int nHeight, int nWidth ){
257         texdef_to_face_t* temp_texdef_face_list;
258         brushprimit_texdef_t bp;
259
260         if ( !si_texdef_face_list ) {
261                 return;
262         }
263
264         for ( temp_texdef_face_list = si_texdef_face_list; temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next )
265         {
266                 Face_FitTexture( temp_texdef_face_list->face, nHeight, nWidth );
267                 Brush_Build( temp_texdef_face_list->brush,true,true,false,false );
268                 // Write changes to our working Texdef list
269
270                 if ( g_qeglobals.m_bBrushPrimitMode ) {
271                         ConvertTexMatWithQTexture( &temp_texdef_face_list->face->brushprimit_texdef, QERApp_Shader_ForName( temp_texdef_face_list->face->texdef.GetName() )->getTexture(), &bp, NULL );
272                         TexMatToFakeTexCoords( bp.coords, temp_texdef_face_list->face->texdef.shift, &temp_texdef_face_list->face->texdef.rotate, temp_texdef_face_list->face->texdef.scale );
273                 }
274                 temp_texdef_face_list->texdef = temp_texdef_face_list->face->texdef;
275         }
276
277         Sys_UpdateWindows( W_CAMERA );
278
279 }
280
281 GtkWindow* SI_GetMainWindow( void ){
282         return GTK_WINDOW( g_qeglobals_gui.d_main_window );
283 }
284
285 void SI_SetWinPos_from_Prefs( GtkWidget *win ){
286         load_window_pos( win, g_PrefsDlg.mWindowInfo.posSurfaceWnd );
287 }