]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/patchdialog.cpp
Merge pull request #21 from merlin1991/Q3-gamepack-fix
[xonotic/netradiant.git] / radiant / patchdialog.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 // Patch Dialog
24 //
25 // Leonardo Zide (leo@lokigames.com)
26 //
27
28 #include <gdk/gdkkeysyms.h>
29 #include "stdafx.h"
30 #include "patchdialog.h"
31 #include <glib/gi18n.h>
32
33 PatchDialog g_PatchDialog;
34 // is the patch inspector currently displayed/active?
35 bool l_bIsActive = false;
36 // the increment we are using for the patch inspector (this is saved in the prefs)
37 texdef_t *l_pPIIncrement = &g_qeglobals.d_savedinfo.m_PIIncrement;
38
39 // =============================================================================
40 // static functions
41
42 static void OnDone( GtkWidget *widget, gpointer data ){
43         g_PatchDialog.m_Patch = NULL;
44         g_PatchDialog.HideDlg();
45 }
46
47 // memorize the current state (that is don't try to undo our do before changing something else)
48 static void OnApply( GtkWidget *widget, gpointer data ){
49         g_PatchDialog.UpdateData( TRUE );
50         if ( g_PatchDialog.m_Patch != NULL ) {
51                 int r = g_PatchDialog.m_nRow;
52                 int c = g_PatchDialog.m_nCol;
53                 if ( r >= 0 && r < g_PatchDialog.m_Patch->height && c >= 0 && c < g_PatchDialog.m_Patch->width ) {
54                         if ( g_PatchDialog.m_Patch->pShader ) {
55                                 g_PatchDialog.m_Patch->pShader->DecRef();
56                         }
57                         if ( g_PatchDialog.m_strName.Find( ' ' ) >= 0 ) {
58                                 Sys_FPrintf( SYS_WRN, "WARNING: spaces in shader names are not allowed, dropping '%s'\n", g_PatchDialog.m_strName.GetBuffer() );
59                                 g_PatchDialog.m_strName = SHADER_NOT_FOUND;
60                         }
61                         g_PatchDialog.m_Patch->pShader = QERApp_Shader_ForName( g_PatchDialog.m_strName );
62                         g_PatchDialog.m_Patch->d_texture = g_PatchDialog.m_Patch->pShader->getTexture();
63                         g_PatchDialog.m_Patch->ctrl[c][r].xyz[0] = g_PatchDialog.m_fX;
64                         g_PatchDialog.m_Patch->ctrl[c][r].xyz[1] = g_PatchDialog.m_fY;
65                         g_PatchDialog.m_Patch->ctrl[c][r].xyz[2] = g_PatchDialog.m_fZ;
66                         g_PatchDialog.m_Patch->ctrl[c][r].st[0] = g_PatchDialog.m_fS;
67                         g_PatchDialog.m_Patch->ctrl[c][r].st[1] = g_PatchDialog.m_fT;
68                         g_PatchDialog.m_Patch->bDirty = true;
69                         Sys_UpdateWindows( W_ALL );
70                 }
71         }
72 }
73
74 static void OnSelchangeComboColRow( GtkWidget *widget, gpointer data ){
75         if ( !g_PatchDialog.m_bListenChanged ) {
76                 return;
77         }
78 #ifdef DBG_PI
79         Sys_Printf( "OnSelchangeComboColRow\n" );
80 #endif
81         // retrieve the current m_nRow and m_nCol, other params are not relevant
82         // (NOTE: UpdateData has a mechanism to avoid inifinite looping)
83         g_PatchDialog.UpdateData( TRUE );
84         // read the changed values ourselves
85         g_PatchDialog.UpdateRowColInfo();
86         // now reflect our changes
87         g_PatchDialog.UpdateData( FALSE );
88 }
89
90 static void OnBtnPatchdetails( GtkWidget *widget, gpointer data ){
91         Patch_NaturalizeSelected( true );
92         Sys_UpdateWindows( W_ALL );
93 }
94
95 static void OnBtnPatchfit( GtkWidget *widget, gpointer data ){
96         Patch_ResetTexturing( 1.0, 1.0 );
97         Sys_UpdateWindows( W_ALL );
98 }
99
100 static void OnBtnPatchnatural( GtkWidget *widget, gpointer data ){
101         Patch_NaturalizeSelected();
102         Sys_UpdateWindows( W_ALL );
103 }
104
105 static void OnBtnPatchreset( GtkWidget *widget, gpointer data ){
106         float fx, fy;
107         if ( DoTextureLayout( &fx, &fy ) == IDOK ) {
108                 Patch_ResetTexturing( fx, fy );
109         }
110         Sys_UpdateWindows( W_ALL );
111 }
112
113 static void OnSpinChanged( GtkAdjustment *adj, gpointer data ){
114         texdef_t td;
115
116         td.rotate = 0;
117         td.scale[0] = td.scale[1] = 0;
118         td.shift[0] = td.shift[1] = 0;
119         td.contents = 0;
120         td.flags = 0;
121         td.value = 0;
122
123         if ( adj->value == 0 ) {
124                 return;
125         }
126
127         if ( adj == g_object_get_data( G_OBJECT( g_PatchDialog.GetWidget() ), "hshift_adj" ) ) {
128                 l_pPIIncrement->shift[0] = atof( gtk_entry_get_text( GTK_ENTRY( data ) ) );
129
130                 if ( adj->value > 0 ) {
131                         td.shift[0] = l_pPIIncrement->shift[0];
132                 }
133                 else{
134                         td.shift[0] = -l_pPIIncrement->shift[0];
135                 }
136         }
137         else if ( adj == g_object_get_data( G_OBJECT( g_PatchDialog.GetWidget() ), "vshift_adj" ) ) {
138                 l_pPIIncrement->shift[1] = atof( gtk_entry_get_text( GTK_ENTRY( data ) ) );
139
140                 if ( adj->value > 0 ) {
141                         td.shift[1] = l_pPIIncrement->shift[1];
142                 }
143                 else{
144                         td.shift[1] = -l_pPIIncrement->shift[1];
145                 }
146         }
147         else if ( adj == g_object_get_data( G_OBJECT( g_PatchDialog.GetWidget() ), "hscale_adj" ) ) {
148                 l_pPIIncrement->scale[0] = atof( gtk_entry_get_text( GTK_ENTRY( data ) ) );
149                 if ( l_pPIIncrement->scale[0] == 0.0f ) {
150                         return;
151                 }
152                 // make sure scale factor is always >1 for increases and <1 for decreases
153                 if ( adj->value > 0 ) {
154                         if ( l_pPIIncrement->scale[0] < 1 ) {
155                                 td.scale[0] = l_pPIIncrement->scale[0];
156                         }
157                         else{
158                                 td.scale[0] = 1.0f / l_pPIIncrement->scale[0];
159                         }
160                 }
161                 else
162                 {
163                         if ( l_pPIIncrement->scale[0] < 1 ) {
164                                 td.scale[0] = 1.0f / l_pPIIncrement->scale[0];
165                         }
166                         else{
167                                 td.scale[0] = l_pPIIncrement->scale[0];
168                         }
169                 }
170         }
171         else if ( adj == g_object_get_data( G_OBJECT( g_PatchDialog.GetWidget() ), "vscale_adj" ) ) {
172                 l_pPIIncrement->scale[1] = atof( gtk_entry_get_text( GTK_ENTRY( data ) ) );
173                 if ( l_pPIIncrement->scale[1] == 0.0f ) {
174                         return;
175                 }
176                 // make sure scale factor is always >1 for increases and <1 for decreases
177                 if ( adj->value > 0 ) {
178                         if ( l_pPIIncrement->scale[1] < 1 ) {
179                                 td.scale[1] = l_pPIIncrement->scale[1];
180                         }
181                         else{
182                                 td.scale[1] = 1.0f / l_pPIIncrement->scale[1];
183                         }
184                 }
185                 else
186                 {
187                         if ( l_pPIIncrement->scale[1] < 1 ) {
188                                 td.scale[1] = 1.0f / l_pPIIncrement->scale[1];
189                         }
190                         else{
191                                 td.scale[1] = l_pPIIncrement->scale[1];
192                         }
193                 }
194         }
195         else if ( adj == g_object_get_data( G_OBJECT( g_PatchDialog.GetWidget() ), "rotate_adj" ) ) {
196                 l_pPIIncrement->rotate = atof( gtk_entry_get_text( GTK_ENTRY( data ) ) );
197
198                 if ( adj->value > 0 ) {
199                         td.rotate = l_pPIIncrement->rotate;
200                 }
201                 else{
202                         td.rotate = -l_pPIIncrement->rotate;
203                 }
204         }
205
206         adj->value = 0;
207
208 #ifdef DBG_PI
209         Sys_Printf( "Patch_SetTextureInfo: %g %g %g %g %g\n", td.shift[0], td.shift[1],td.scale[0],td.scale[1],td.rotate );
210 #endif
211         // will scale shift rotate the patch accordingly
212         Patch_SetTextureInfo( &td );
213         // update the point-by-point view
214         OnSelchangeComboColRow( NULL,NULL );
215         Sys_UpdateWindows( W_CAMERA );
216 }
217
218 static gint OnDialogKey( GtkWidget* widget, GdkEventKey* event, gpointer data ){
219 #ifdef DBG_PI
220         Sys_Printf( "OnDialogKey\n" );
221 #endif
222         if ( event->keyval == GDK_Return ) {
223                 OnApply( NULL, NULL );
224                 return TRUE;
225         }
226         else if ( event->keyval == GDK_Escape ) {
227                 OnDone( NULL, NULL );
228                 return TRUE;
229         }
230         return FALSE;
231 }
232
233 // =============================================================================
234 // Global Functions
235
236 void DoPatchInspector(){
237         // do we need to create the dialog?
238         if ( g_PatchDialog.GetWidget() == NULL ) {
239                 g_PatchDialog.Create();
240                 g_PatchDialog.UpdateData( FALSE );
241         }
242         g_PatchDialog.GetPatchInfo();
243         if ( !l_bIsActive ) {
244                 g_PatchDialog.ShowDlg();
245         }
246 }
247
248 void UpdatePatchInspector(){
249         if ( l_bIsActive ) {
250                 g_PatchDialog.GetPatchInfo();
251         }
252 }
253
254 void TogglePatchInspector(){
255         if ( l_bIsActive ) {
256                 OnDone( NULL,NULL );
257         }
258         else{
259                 DoPatchInspector();
260         }
261 }
262
263 // =============================================================================
264 // PatchDialog class
265
266 PatchDialog::PatchDialog (){
267         m_strName = "";
268         m_fS = 0.0f;
269         m_fT = 0.0f;
270         m_fX = 0.0f;
271         m_fY = 0.0f;
272         m_fZ = 0.0f;
273         m_nCol = 0;
274         m_nRow = 0;
275         m_Patch = NULL;
276         m_bListenChanged = true;
277 }
278
279 void PatchDialog::InitDefaultIncrement( texdef_t *tex ){
280         tex->SetName( SHADER_NOT_FOUND );
281         tex->scale[0] = 0.5f;
282         tex->scale[1] = 0.5f;
283         tex->rotate = 45;
284         tex->shift[0] = 8.0f;
285         tex->shift[1] = 8.0f;
286 }
287
288 // we plug into HideDlg and ShowDlg to maintain the l_bIsActive flag
289 void PatchDialog::HideDlg(){
290         l_bIsActive = false;
291         Dialog::HideDlg();
292 }
293
294 void PatchDialog::ShowDlg(){
295         l_bIsActive = true;
296         Dialog::ShowDlg();
297 }
298
299 void PatchDialog::BuildDialog(){
300         GtkWidget *dlg, *vbox, *vbox2, *hbox, *hbox2, *frame, *table, *label;
301         GtkWidget *button, *entry, *spin, *combo;
302         GtkObject *adj;
303         char buf[32];
304
305         dlg = m_pWidget;
306
307         load_window_pos( dlg, g_PrefsDlg.mWindowInfo.posPatchWnd );
308
309         gtk_window_set_title( GTK_WINDOW( dlg ), _( "Patch Properties" ) );
310         gtk_signal_connect( GTK_OBJECT( dlg ), "delete_event", GTK_SIGNAL_FUNC( OnDone ), NULL );
311         // catch 'Esc' and 'Enter'
312         gtk_signal_connect( GTK_OBJECT( dlg ), "key_press_event", GTK_SIGNAL_FUNC( OnDialogKey ), NULL );
313         gtk_window_set_transient_for( GTK_WINDOW( dlg ), GTK_WINDOW( g_pParentWnd->m_pWidget ) );
314
315
316         vbox = gtk_vbox_new( FALSE, 5 );
317         gtk_widget_show( vbox );
318         gtk_container_add( GTK_CONTAINER( dlg ), vbox );
319         gtk_container_set_border_width( GTK_CONTAINER( vbox ), 5 );
320
321         hbox = gtk_hbox_new( FALSE, 5 );
322         gtk_widget_show( hbox );
323         gtk_box_pack_start( GTK_BOX( vbox ), hbox, TRUE, TRUE, 0 );
324
325         frame = gtk_frame_new( _( "Details" ) );
326         gtk_widget_show( frame );
327         gtk_box_pack_start( GTK_BOX( hbox ), frame, TRUE, TRUE, 0 );
328
329         vbox2 = gtk_vbox_new( FALSE, 5 );
330         gtk_widget_show( vbox2 );
331         gtk_container_add( GTK_CONTAINER( frame ), vbox2 );
332         gtk_container_set_border_width( GTK_CONTAINER( vbox2 ), 5 );
333
334         table = gtk_table_new( 2, 2, FALSE );
335         gtk_widget_show( table );
336         gtk_box_pack_start( GTK_BOX( vbox2 ), table, TRUE, TRUE, 0 );
337         gtk_table_set_row_spacings( GTK_TABLE( table ), 5 );
338         gtk_table_set_col_spacings( GTK_TABLE( table ), 5 );
339
340         label = gtk_label_new( _( "Row:" ) );
341         gtk_widget_show( label );
342         gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 0, 1,
343                                           (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
344                                           (GtkAttachOptions) ( 0 ), 0, 0 );
345
346         label = gtk_label_new( _( "Column:" ) );
347         gtk_widget_show( label );
348         gtk_table_attach( GTK_TABLE( table ), label, 1, 2, 0, 1,
349                                           (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
350                                           (GtkAttachOptions) ( 0 ), 0, 0 );
351
352         combo = gtk_combo_new();
353         gtk_widget_show( combo );
354         gtk_table_attach( GTK_TABLE( table ), combo, 0, 1, 1, 2,
355                                           (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
356                                           (GtkAttachOptions) ( 0 ), 0, 0 );
357         gtk_widget_set_usize( combo, 60, -1 );
358         gtk_entry_set_editable( GTK_ENTRY( GTK_COMBO( combo )->entry ), FALSE );
359         gtk_signal_connect( GTK_OBJECT( GTK_COMBO( combo )->entry ), "changed",
360                                                 GTK_SIGNAL_FUNC( OnSelchangeComboColRow ), this );
361         AddDialogData( combo, &m_nRow, DLG_COMBO_INT );
362         m_pRowCombo = combo;
363
364         combo = gtk_combo_new();
365         gtk_widget_show( combo );
366         gtk_table_attach( GTK_TABLE( table ), combo, 1, 2, 1, 2,
367                                           (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
368                                           (GtkAttachOptions) ( 0 ), 0, 0 );
369         gtk_widget_set_usize( combo, 60, -1 );
370         gtk_entry_set_editable( GTK_ENTRY( GTK_COMBO( combo )->entry ), FALSE );
371         gtk_signal_connect( GTK_OBJECT( GTK_COMBO( combo )->entry ), "changed",
372                                                 GTK_SIGNAL_FUNC( OnSelchangeComboColRow ), this );
373         AddDialogData( combo, &m_nCol, DLG_COMBO_INT );
374         m_pColCombo = combo;
375
376         table = gtk_table_new( 5, 2, FALSE );
377         gtk_widget_show( table );
378         gtk_box_pack_start( GTK_BOX( vbox2 ), table, TRUE, TRUE, 0 );
379         gtk_table_set_row_spacings( GTK_TABLE( table ), 5 );
380         gtk_table_set_col_spacings( GTK_TABLE( table ), 5 );
381
382         label = gtk_label_new( _( "X:" ) );
383         gtk_widget_show( label );
384         gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 0, 1,
385                                           (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
386                                           (GtkAttachOptions) ( 0 ), 0, 0 );
387
388         label = gtk_label_new( _( "Y:" ) );
389         gtk_widget_show( label );
390         gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 1, 2,
391                                           (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
392                                           (GtkAttachOptions) ( 0 ), 0, 0 );
393
394         label = gtk_label_new( _( "Z:" ) );
395         gtk_widget_show( label );
396         gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 2, 3,
397                                           (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
398                                           (GtkAttachOptions) ( 0 ), 0, 0 );
399
400         label = gtk_label_new( _( "S:" ) );
401         gtk_widget_show( label );
402         gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 3, 4,
403                                           (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
404                                           (GtkAttachOptions) ( 0 ), 0, 0 );
405
406         label = gtk_label_new( _( "T:" ) );
407         gtk_widget_show( label );
408         gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 4, 5,
409                                           (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
410                                           (GtkAttachOptions) ( 0 ), 0, 0 );
411
412         entry = gtk_entry_new();
413         gtk_widget_show( entry );
414         gtk_table_attach( GTK_TABLE( table ), entry, 1, 2, 0, 1,
415                                           (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
416                                           (GtkAttachOptions) ( 0 ), 0, 0 );
417         AddDialogData( entry, &m_fX, DLG_ENTRY_FLOAT );
418
419         entry = gtk_entry_new();
420         gtk_widget_show( entry );
421         gtk_table_attach( GTK_TABLE( table ), entry, 1, 2, 1, 2,
422                                           (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
423                                           (GtkAttachOptions) ( 0 ), 0, 0 );
424         AddDialogData( entry, &m_fY, DLG_ENTRY_FLOAT );
425
426         entry = gtk_entry_new();
427         gtk_widget_show( entry );
428         gtk_table_attach( GTK_TABLE( table ), entry, 1, 2, 2, 3,
429                                           (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
430                                           (GtkAttachOptions) ( 0 ), 0, 0 );
431         AddDialogData( entry, &m_fZ, DLG_ENTRY_FLOAT );
432
433         entry = gtk_entry_new();
434         gtk_widget_show( entry );
435         gtk_table_attach( GTK_TABLE( table ), entry, 1, 2, 3, 4,
436                                           (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
437                                           (GtkAttachOptions) ( 0 ), 0, 0 );
438         AddDialogData( entry, &m_fS, DLG_ENTRY_FLOAT );
439
440         entry = gtk_entry_new();
441         gtk_widget_show( entry );
442         gtk_table_attach( GTK_TABLE( table ), entry, 1, 2, 4, 5,
443                                           (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
444                                           (GtkAttachOptions) ( 0 ), 0, 0 );
445         AddDialogData( entry, &m_fT, DLG_ENTRY_FLOAT );
446
447         frame = gtk_frame_new( _( "Texturing" ) );
448         gtk_widget_show( frame );
449         gtk_box_pack_start( GTK_BOX( hbox ), frame, TRUE, TRUE, 0 );
450
451         vbox2 = gtk_vbox_new( FALSE, 5 );
452         gtk_widget_show( vbox2 );
453         gtk_container_add( GTK_CONTAINER( frame ), vbox2 );
454         gtk_container_set_border_width( GTK_CONTAINER( vbox2 ), 5 );
455
456         label = gtk_label_new( _( "Name:" ) );
457         gtk_widget_show( label );
458         gtk_box_pack_start( GTK_BOX( vbox2 ), label, TRUE, TRUE, 0 );
459         gtk_label_set_justify( GTK_LABEL( label ), GTK_JUSTIFY_LEFT );
460         gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
461
462         entry = gtk_entry_new();
463 //  gtk_entry_set_editable (GTK_ENTRY (entry), false);
464         gtk_widget_show( entry );
465         gtk_box_pack_start( GTK_BOX( vbox2 ), entry, TRUE, TRUE, 0 );
466         AddDialogData( entry, &m_strName, DLG_ENTRY_TEXT );
467
468         table = gtk_table_new( 5, 3, FALSE );
469         gtk_widget_show( table );
470         gtk_box_pack_start( GTK_BOX( vbox2 ), table, TRUE, TRUE, 0 );
471         gtk_table_set_row_spacings( GTK_TABLE( table ), 5 );
472         gtk_table_set_col_spacings( GTK_TABLE( table ), 5 );
473
474         label = gtk_label_new( _( "Horizontal Shift Step" ) );
475         gtk_widget_show( label );
476         gtk_table_attach( GTK_TABLE( table ), label, 2, 3, 0, 1,
477                                           (GtkAttachOptions) ( GTK_FILL ),
478                                           (GtkAttachOptions) ( 0 ), 0, 0 );
479         gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
480
481         label = gtk_label_new( _( "Vertical Shift Step" ) );
482         gtk_widget_show( label );
483         gtk_table_attach( GTK_TABLE( table ), label, 2, 3, 1, 2,
484                                           (GtkAttachOptions) ( GTK_FILL ),
485                                           (GtkAttachOptions) ( 0 ), 0, 0 );
486         gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
487
488         label = gtk_label_new( _( "Horizontal Stretch Step" ) );
489         gtk_widget_show( label );
490         gtk_table_attach( GTK_TABLE( table ), label, 2, 3, 2, 3,
491                                           (GtkAttachOptions) ( GTK_FILL ),
492                                           (GtkAttachOptions) ( 0 ), 0, 0 );
493         gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
494
495         label = gtk_label_new( _( "Vertical Stretch Step" ) );
496         gtk_widget_show( label );
497         gtk_table_attach( GTK_TABLE( table ), label, 2, 3, 3, 4,
498                                           (GtkAttachOptions) ( GTK_FILL ),
499                                           (GtkAttachOptions) ( 0 ), 0, 0 );
500         gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
501
502         label = gtk_label_new( _( "Rotate Step" ) );
503         gtk_widget_show( label );
504         gtk_table_attach( GTK_TABLE( table ), label, 2, 3, 4, 5,
505                                           (GtkAttachOptions) ( GTK_FILL ),
506                                           (GtkAttachOptions) ( 0 ), 0, 0 );
507         gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
508
509         entry = gtk_entry_new();
510         gtk_widget_show( entry );
511         gtk_table_attach( GTK_TABLE( table ), entry, 0, 1, 0, 1,
512                                           (GtkAttachOptions) ( GTK_FILL ),
513                                           (GtkAttachOptions) ( 0 ), 0, 0 );
514         gtk_widget_set_usize( entry, 50, -2 );
515         g_object_set_data( G_OBJECT( m_pWidget ), "hshift_entry", entry );
516         // we fill in this data, if no patch is selected the widgets are unmodified when the inspector is raised
517         // so we need to have at least one initialisation somewhere
518         sprintf( buf, "%g", l_pPIIncrement->shift[0] );
519         gtk_entry_set_text( GTK_ENTRY( entry ), buf );
520
521         adj = gtk_adjustment_new( 0, -8192, 8192, 1, 1, 1 );
522         gtk_signal_connect( adj, "value_changed", GTK_SIGNAL_FUNC( OnSpinChanged ), entry );
523         g_object_set_data( G_OBJECT( m_pWidget ), "hshift_adj", adj );
524
525         spin = gtk_spin_button_new( GTK_ADJUSTMENT( adj ), 1, 0 );
526         gtk_widget_show( spin );
527         gtk_table_attach( GTK_TABLE( table ), spin, 1, 2, 0, 1,
528                                           (GtkAttachOptions) ( 0 ),
529                                           (GtkAttachOptions) ( 0 ), 0, 0 );
530         gtk_widget_set_usize( spin, 10, -2 );
531
532         entry = gtk_entry_new();
533         gtk_widget_show( entry );
534         gtk_table_attach( GTK_TABLE( table ), entry, 0, 1, 1, 2,
535                                           (GtkAttachOptions) ( GTK_FILL ),
536                                           (GtkAttachOptions) ( 0 ), 0, 0 );
537         gtk_widget_set_usize( entry, 50, -2 );
538         sprintf( buf, "%g", l_pPIIncrement->shift[1] );
539         gtk_entry_set_text( GTK_ENTRY( entry ), buf );
540
541         adj = gtk_adjustment_new( 0, -8192, 8192, 1, 1, 1 );
542         gtk_signal_connect( adj, "value_changed", GTK_SIGNAL_FUNC( OnSpinChanged ), entry );
543         g_object_set_data( G_OBJECT( m_pWidget ), "vshift_adj", adj );
544
545         spin = gtk_spin_button_new( GTK_ADJUSTMENT( adj ), 1, 0 );
546         gtk_widget_show( spin );
547         gtk_table_attach( GTK_TABLE( table ), spin, 1, 2, 1, 2,
548                                           (GtkAttachOptions) ( 0 ),
549                                           (GtkAttachOptions) ( 0 ), 0, 0 );
550         gtk_widget_set_usize( spin, 10, -2 );
551
552         entry = gtk_entry_new();
553         gtk_widget_show( entry );
554         gtk_table_attach( GTK_TABLE( table ), entry, 0, 1, 2, 3,
555                                           (GtkAttachOptions) ( GTK_FILL ),
556                                           (GtkAttachOptions) ( 0 ), 0, 0 );
557         gtk_widget_set_usize( entry, 50, -2 );
558         sprintf( buf, "%g", l_pPIIncrement->scale[0] );
559         gtk_entry_set_text( GTK_ENTRY( entry ), buf );
560
561         adj = gtk_adjustment_new( 0, -1000, 1000, 1, 1, 1 );
562         gtk_signal_connect( adj, "value_changed", GTK_SIGNAL_FUNC( OnSpinChanged ), entry );
563         g_object_set_data( G_OBJECT( m_pWidget ), "hscale_adj", adj );
564
565         spin = gtk_spin_button_new( GTK_ADJUSTMENT( adj ), 1, 0 );
566         gtk_widget_show( spin );
567         gtk_table_attach( GTK_TABLE( table ), spin, 1, 2, 2, 3,
568                                           (GtkAttachOptions) ( 0 ),
569                                           (GtkAttachOptions) ( 0 ), 0, 0 );
570         gtk_widget_set_usize( spin, 10, -2 );
571
572         entry = gtk_entry_new();
573         gtk_widget_show( entry );
574         gtk_table_attach( GTK_TABLE( table ), entry, 0, 1, 3, 4,
575                                           (GtkAttachOptions) ( GTK_FILL ),
576                                           (GtkAttachOptions) ( 0 ), 0, 0 );
577         gtk_widget_set_usize( entry, 50, -2 );
578         sprintf( buf, "%g", l_pPIIncrement->scale[1] );
579         gtk_entry_set_text( GTK_ENTRY( entry ), buf );
580
581         adj = gtk_adjustment_new( 0, -1000, 1000, 1, 1, 1 );
582         gtk_signal_connect( adj, "value_changed", GTK_SIGNAL_FUNC( OnSpinChanged ), entry );
583         g_object_set_data( G_OBJECT( m_pWidget ), "vscale_adj", adj );
584
585         spin = gtk_spin_button_new( GTK_ADJUSTMENT( adj ), 1, 0 );
586         gtk_widget_show( spin );
587         gtk_table_attach( GTK_TABLE( table ), spin, 1, 2, 3, 4,
588                                           (GtkAttachOptions) ( 0 ),
589                                           (GtkAttachOptions) ( 0 ), 0, 0 );
590         gtk_widget_set_usize( spin, 10, -2 );
591
592         entry = gtk_entry_new();
593         gtk_widget_show( entry );
594         gtk_table_attach( GTK_TABLE( table ), entry, 0, 1, 4, 5,
595                                           (GtkAttachOptions) ( GTK_FILL ),
596                                           (GtkAttachOptions) ( 0 ), 0, 0 );
597         gtk_widget_set_usize( entry, 50, -2 );
598         sprintf( buf, "%g", l_pPIIncrement->rotate );
599         gtk_entry_set_text( GTK_ENTRY( entry ), buf );
600
601         adj = gtk_adjustment_new( 0, -1000, 1000, 1, 1, 1 ); // NOTE: Arnout - this really should be 360 but can't change it anymore as it could break existing maps
602         gtk_signal_connect( adj, "value_changed", GTK_SIGNAL_FUNC( OnSpinChanged ), entry );
603         g_object_set_data( G_OBJECT( m_pWidget ), "rotate_adj", adj );
604
605         spin = gtk_spin_button_new( GTK_ADJUSTMENT( adj ), 1, 0 );
606         gtk_widget_show( spin );
607         gtk_table_attach( GTK_TABLE( table ), spin, 1, 2, 4, 5,
608                                           (GtkAttachOptions) ( 0 ),
609                                           (GtkAttachOptions) ( 0 ), 0, 0 );
610         gtk_widget_set_usize( spin, 10, -2 );
611
612         hbox2 = gtk_hbox_new( TRUE, 5 );
613         gtk_widget_show( hbox2 );
614         gtk_box_pack_start( GTK_BOX( vbox2 ), hbox2, TRUE, FALSE, 0 );
615
616         button = gtk_button_new_with_label( _( "CAP" ) );
617         gtk_widget_show( button );
618         gtk_box_pack_end( GTK_BOX( hbox2 ), button, TRUE, FALSE, 0 );
619         gtk_signal_connect( GTK_OBJECT( button ), "clicked", GTK_SIGNAL_FUNC( OnBtnPatchdetails ), NULL );
620         gtk_widget_set_usize( button, 60, -1 );
621
622         button = gtk_button_new_with_label( _( "Set..." ) );
623         gtk_widget_show( button );
624         gtk_box_pack_end( GTK_BOX( hbox2 ), button, TRUE, FALSE, 0 );
625         gtk_signal_connect( GTK_OBJECT( button ), "clicked", GTK_SIGNAL_FUNC( OnBtnPatchreset ), NULL );
626         gtk_widget_set_usize( button, 60, -1 );
627
628         button = gtk_button_new_with_label( _( "Natural" ) );
629         gtk_widget_show( button );
630         gtk_box_pack_end( GTK_BOX( hbox2 ), button, TRUE, FALSE, 0 );
631         gtk_signal_connect( GTK_OBJECT( button ), "clicked", GTK_SIGNAL_FUNC( OnBtnPatchnatural ), NULL );
632         gtk_widget_set_usize( button, 60, -1 );
633
634         button = gtk_button_new_with_label( _( "Fit" ) );
635         gtk_widget_show( button );
636         gtk_box_pack_end( GTK_BOX( hbox2 ), button, TRUE, FALSE, 0 );
637         gtk_signal_connect( GTK_OBJECT( button ), "clicked", GTK_SIGNAL_FUNC( OnBtnPatchfit ), NULL );
638         gtk_widget_set_usize( button, 60, -1 );
639
640         hbox = gtk_hbox_new( FALSE, 5 );
641         gtk_widget_show( hbox );
642         gtk_box_pack_start( GTK_BOX( vbox ), hbox, TRUE, FALSE, 0 );
643
644         button = gtk_button_new_with_label( _( "Done" ) );
645         gtk_widget_show( button );
646         gtk_box_pack_end( GTK_BOX( hbox ), button, FALSE, FALSE, 0 );
647         gtk_signal_connect( GTK_OBJECT( button ), "clicked", GTK_SIGNAL_FUNC( OnDone ), NULL );
648         gtk_widget_set_usize( button, 60, -1 );
649
650         button = gtk_button_new_with_label( _( "Apply" ) );
651         gtk_widget_show( button );
652         gtk_box_pack_end( GTK_BOX( hbox ), button, FALSE, FALSE, 0 );
653         gtk_signal_connect( GTK_OBJECT( button ), "clicked", GTK_SIGNAL_FUNC( OnApply ), NULL );
654         gtk_widget_set_usize( button, 60, -1 );
655 }
656
657 // sync the dialog our internal data structures
658 void PatchDialog::UpdateData( bool retrieve ){
659         if ( m_pWidget == NULL ) {
660                 return;
661         }
662
663         m_bListenChanged = false;
664         Dialog::UpdateData( retrieve );
665         m_bListenChanged = true;
666 }
667
668 // read the map and feed in the stuff to the dialog box
669 void PatchDialog::GetPatchInfo(){
670         m_Patch = SinglePatchSelected();
671         if ( m_Patch != NULL ) {
672                 m_strName = m_Patch->pShader->getName();
673
674                 GList *combo_list = NULL;
675                 int i;
676
677                 // fill in the numbers for Row / Col selection
678                 m_bListenChanged = false;
679
680                 for ( i = 0; i < m_Patch->height; i++ )
681                         combo_list = g_list_append( combo_list, g_strdup_printf( "%i", i ) );  // NOTE: leaving the g_strdup cause we free with g_free later on
682                 gtk_combo_set_popdown_strings( GTK_COMBO( m_pRowCombo ), combo_list );
683                 gtk_entry_set_text( GTK_ENTRY( GTK_COMBO( m_pRowCombo )->entry ), "0" );
684
685                 while ( combo_list )
686                 {
687                         g_free( combo_list->data );
688                         combo_list = g_list_remove( combo_list, combo_list->data );
689                 }
690
691                 for ( i = 0; i < m_Patch->width; i++ )
692                         combo_list = g_list_append( combo_list, g_strdup_printf( "%i", i ) );
693                 gtk_combo_set_popdown_strings( GTK_COMBO( m_pColCombo ), combo_list );
694                 gtk_entry_set_text( GTK_ENTRY( GTK_COMBO( m_pColCombo )->entry ), "0" );
695
696                 while ( combo_list )
697                 {
698                         g_free( combo_list->data );
699                         combo_list = g_list_remove( combo_list, combo_list->data );
700                 }
701
702                 m_bListenChanged = true;
703
704         }
705         else{
706                 Sys_Printf( "WARNING: no patch\n" );
707         }
708         // fill in our internal structs
709         m_nRow = 0; m_nCol = 0;
710         UpdateRowColInfo();
711         // now update the dialog box
712         UpdateData( false );
713 }
714
715 // read the current patch on map and initialize m_fX m_fY accordingly
716 // NOTE: don't call UpdateData in there, it's not meant for
717 void PatchDialog::UpdateRowColInfo(){
718         m_fX = m_fY = m_fZ = m_fS = m_fT = 0.0;
719
720         if ( m_Patch != NULL ) {
721                 // we rely on whatever active row/column has been set before we get called
722                 int r = m_nRow;
723                 int c = m_nCol;
724                 if ( r >= 0 && r < m_Patch->height && c >= 0 && c < m_Patch->width ) {
725                         m_fX = m_Patch->ctrl[c][r].xyz[0];
726                         m_fY = m_Patch->ctrl[c][r].xyz[1];
727                         m_fZ = m_Patch->ctrl[c][r].xyz[2];
728                         m_fS = m_Patch->ctrl[c][r].st[0];
729                         m_fT = m_Patch->ctrl[c][r].st[1];
730                 }
731         }
732 }