2 Copyright (C) 2003 Reed Mideke.
4 This file is part of GtkRadiant.
6 GtkRadiant is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 GtkRadiant is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GtkRadiant; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 // bkgrnd2d Plugin dialog
24 // Code by reyalP aka Reed Mideke
26 // Based on various other plugins
34 // spaces to make label nice and big
35 #define NO_FILE_MSG " (no file loaded) "
37 static GtkWidget *pDialogWnd;
38 static GtkWidget *pNotebook;
39 static GtkTooltips *pTooltips;
41 class CBackgroundDialogPage
45 GtkWidget *m_pTabLabel;
46 GtkWidget *m_pFileLabel;
47 GtkWidget *m_pPosLabel;
52 CBackgroundImage *m_pImage;
53 CBackgroundDialogPage( VIEWTYPE vt );
54 void Append( GtkWidget *notebook );
58 // ~BackgroundDialogPage();
62 // dialog page callbacks
63 static void browse_callback( GtkWidget *widget, gpointer data ){
64 ( (CBackgroundDialogPage *)data )->Browse();
67 static void reload_callback( GtkWidget *widget, gpointer data ){
68 ( (CBackgroundDialogPage *)data )->Reload();
71 static void size_sel_callback( GtkWidget *widget, gpointer data ){
72 CBackgroundDialogPage *pPage = (CBackgroundDialogPage *)data;
73 if ( pPage->m_pImage->SetExtentsSel() ) {
78 static void size_mm_callback( GtkWidget *widget, gpointer data ){
79 CBackgroundDialogPage *pPage = (CBackgroundDialogPage *)data;
80 if ( pPage->m_pImage->SetExtentsMM() ) {
85 static void alpha_adjust_callback( GtkWidget *widget, gpointer data ){
86 CBackgroundDialogPage *pPage = (CBackgroundDialogPage *)data;
87 pPage->m_pImage->m_alpha = (float)gtk_range_get_value( GTK_RANGE( widget ) );
88 g_FuncTable.m_pfnSysUpdateWindows( W_XY );
91 void CBackgroundDialogPage::Reload(){
93 m_pImage->Load( gtk_label_get_text( GTK_LABEL( m_pFileLabel ) ) );
97 void CBackgroundDialogPage::Browse(){
98 char browsedir[PATH_MAX];
103 //TODO GetMapName saves the map. eeep!
104 //also with no map, returns unnamed.map, otherwise returns full path
105 // Syn_Printf(MSG_PREFIX "GetMapName() %s\n",
106 // g_FuncTable.m_pfnGetMapName());
108 ct = g_FuncTable.m_pfnReadProjectKey( "basepath" );
109 // TODO shouldn't need this stuff
110 if ( !ct || !strlen( ct ) ) {
111 Syn_Printf( MSG_PREFIX "basepath = NULL or empty\n" );
114 Syn_Printf( MSG_PREFIX "basepath: %s\n",ct );
115 if ( strlen( ct ) >= PATH_MAX ) {
116 Syn_Printf( MSG_PREFIX "base game dir too long\n" );
120 strcpy( browsedir,ct );
121 // make sure we have a trailing /
122 if ( browsedir[strlen( browsedir ) - 1] != '/' ) {
123 strcat( browsedir,"/" );
126 //if we dont have a file yet, don't try to use it for default dir
127 if ( m_bValidFile ) {
128 // filename should always be a nice clean unix style relative path
129 ct = gtk_label_get_text( GTK_LABEL( m_pFileLabel ) );
130 strcat( browsedir,ct );
131 Syn_Printf( MSG_PREFIX "full path: %s\n",browsedir );
133 // lop off the file part
134 t = browsedir + strlen( browsedir ) - 1;
135 while ( t != browsedir && *t != '/' )
139 Syn_Printf( MSG_PREFIX "browse directory %s\n",browsedir );
141 //does NOT need freeing contrary to include/qerplugin.h comments
142 //TODO bug/patch for comments
143 //TODO patern gets fucked up sometimes if empty
144 //http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=915
145 newfile = g_FuncTable.m_pfnFileDialog( pDialogWnd,TRUE,
146 "Load Background Image",browsedir,FILETYPE_KEY );
148 Syn_Printf( MSG_PREFIX "newfile = NULL\n" );
151 Syn_Printf( MSG_PREFIX "newfile: %s\n",newfile );
152 newfile = g_FileSystemTable.m_pfnExtractRelativePath( newfile );
155 Syn_Printf( MSG_PREFIX "newfile = NULL\n" );
158 Syn_Printf( MSG_PREFIX "newfile: %s\n",newfile );
160 if ( m_pImage->Load( newfile ) ) {
162 gtk_label_set_text( GTK_LABEL( m_pFileLabel ),newfile );
166 void CBackgroundDialogPage::SetPosLabel(){
168 // TODO no snprintf ?
169 sprintf( s, "Size/Position (%d,%d) (%d,%d)",(int)( m_pImage->m_xmin ),
170 (int)( m_pImage->m_ymin ),(int)( m_pImage->m_xmax ),(int)( m_pImage->m_ymax ) );
171 gtk_label_set_text( GTK_LABEL( m_pPosLabel ),s );
174 CBackgroundDialogPage::CBackgroundDialogPage( VIEWTYPE vt ){
181 m_bValidFile = false;
186 m_pTabLabel = gtk_label_new( "X/Y" );
187 m_pImage = &backgroundXY;
190 m_pTabLabel = gtk_label_new( "X/Z" );
191 m_pImage = &backgroundXZ;
194 m_pTabLabel = gtk_label_new( "Y/Z" );
195 m_pImage = &backgroundYZ;
198 // A vbox to hold everything
199 m_pWidget = gtk_vbox_new( FALSE,0 );
200 // Frame for file row
201 frame = gtk_frame_new( "File" );
202 gtk_box_pack_start( GTK_BOX( m_pWidget ),frame, FALSE, FALSE, 2 );
204 // hbox for first row
205 hbox = gtk_hbox_new( FALSE,5 );
206 gtk_container_set_border_width( GTK_CONTAINER( hbox ),4 );
207 gtk_container_add( GTK_CONTAINER( frame ), hbox );
209 // label to display filename
210 m_pFileLabel = gtk_label_new( NO_FILE_MSG );
211 gtk_label_set_selectable( GTK_LABEL( m_pFileLabel ),TRUE );
212 //TODO set min size ? done with spaces right now
213 gtk_box_pack_start( GTK_BOX( hbox ),m_pFileLabel, TRUE, TRUE, 5 );
215 gtk_widget_show( m_pFileLabel );
217 w = gtk_button_new_with_label( "Browse..." );
218 g_signal_connect( G_OBJECT( w ), "clicked", G_CALLBACK( browse_callback ),
220 gtk_box_pack_start( GTK_BOX( hbox ),w, FALSE, FALSE, 5 );
221 gtk_tooltips_set_tip( pTooltips, w, "Select a file", NULL );
222 gtk_widget_show( w );
224 w = gtk_button_new_with_label( "Reload" );
225 g_signal_connect( G_OBJECT( w ), "clicked", G_CALLBACK( reload_callback ),
227 // TODO disable until we have file
228 // gtk_widget_set_sensitive(w,FALSE);
229 gtk_tooltips_set_tip( pTooltips, w, "Reload current file", NULL );
230 gtk_box_pack_start( GTK_BOX( hbox ),w, FALSE, FALSE, 5 );
231 gtk_widget_show( w );
233 gtk_widget_show( hbox );
234 gtk_widget_show( frame );
236 // second row (rendering options)
237 frame = gtk_frame_new( "Rendering" );
238 gtk_box_pack_start( GTK_BOX( m_pWidget ),frame, FALSE, FALSE, 2 );
240 hbox = gtk_hbox_new( FALSE,5 );
241 gtk_container_set_border_width( GTK_CONTAINER( hbox ),4 );
242 gtk_container_add( GTK_CONTAINER( frame ), hbox );
244 w = gtk_label_new( "Vertex alpha:" );
245 gtk_box_pack_start( GTK_BOX( hbox ),w, FALSE, FALSE, 5 );
246 gtk_widget_show( w );
248 w = gtk_hscale_new_with_range( 0.0,1.0,0.01 );
249 gtk_range_set_value( GTK_RANGE( w ),0.5 );
250 gtk_scale_set_value_pos( GTK_SCALE( w ),GTK_POS_LEFT );
251 g_signal_connect( G_OBJECT( w ), "value-changed",
252 G_CALLBACK( alpha_adjust_callback ), ( gpointer ) this );
253 gtk_box_pack_start( GTK_BOX( hbox ),w, TRUE, TRUE, 5 );
254 gtk_tooltips_set_tip( pTooltips, w, "Set image transparancy", NULL );
255 gtk_widget_show( w );
257 gtk_widget_show( hbox );
258 gtk_widget_show( frame );
259 // Third row (size and position)
260 frame = gtk_frame_new( "Size/Position (undefined)" );
261 m_pPosLabel = gtk_frame_get_label_widget( GTK_FRAME( frame ) );
262 gtk_box_pack_start( GTK_BOX( m_pWidget ), frame, FALSE, FALSE, 2 );
264 hbox = gtk_hbox_new( FALSE,5 );
265 gtk_container_add( GTK_CONTAINER( frame ), hbox );
266 gtk_container_set_border_width( GTK_CONTAINER( hbox ),4 );
268 w = gtk_button_new_with_label( "from selection" );
269 gtk_box_pack_start( GTK_BOX( hbox ),w, TRUE, FALSE, 5 );
270 g_signal_connect( G_OBJECT( w ), "clicked", G_CALLBACK( size_sel_callback ),
272 gtk_tooltips_set_tip( pTooltips, w, "Set the size of the image to the bounding rectangle of all selected brushes and entities", NULL );
273 gtk_widget_show( w );
276 w = gtk_button_new_with_label( "from map mins/maxs" );
277 gtk_box_pack_start( GTK_BOX( hbox ),w, TRUE, FALSE, 2 );
278 g_signal_connect( G_OBJECT( w ), "clicked", G_CALLBACK( size_mm_callback ),
280 gtk_tooltips_set_tip( pTooltips, w, "Set the size of the image using the mapcoordsmins and mapcoordsmaxs keys of the worldspawn entity", NULL );
281 gtk_widget_show( w );
284 gtk_widget_show( hbox );
285 gtk_widget_show( frame );
287 gtk_widget_show( m_pWidget );
290 void CBackgroundDialogPage::Append( GtkWidget *notebook ){
291 gtk_notebook_append_page( GTK_NOTEBOOK( notebook ), m_pWidget, m_pTabLabel );
294 // dialog global callbacks
296 static gint expose_callback( GtkWidget *widget, gpointer data )
302 static void response_callback( GtkWidget *widget, gint response, gpointer data ){
303 if ( response == GTK_RESPONSE_CLOSE ) {
304 gtk_widget_hide( pDialogWnd );
308 static gint close_callback( GtkWidget *widget, gpointer data ){
309 gtk_widget_hide( pDialogWnd );
313 void InitBackgroundDialog(){
314 CBackgroundDialogPage *pPage;
316 pDialogWnd = gtk_dialog_new_with_buttons( "Background Images",
317 GTK_WINDOW( g_pMainWidget ),
318 (GtkDialogFlags)( GTK_DIALOG_DESTROY_WITH_PARENT ),
319 // TODO dialog with no buttons
321 // GTK_RESPONSE_CLOSE,
323 gtk_signal_connect( GTK_OBJECT( pDialogWnd ), "delete_event",
324 GTK_SIGNAL_FUNC( close_callback ), NULL );
325 gtk_signal_connect( GTK_OBJECT( pDialogWnd ), "response",
326 GTK_SIGNAL_FUNC( response_callback ), NULL );
327 // gtk_signal_connect( GTK_OBJECT (pDialogWnd), "expose_event", GTK_SIGNAL_FUNC( ci_expose ), NULL );
329 pTooltips = gtk_tooltips_new();
331 pNotebook = gtk_notebook_new();
332 pPage = new CBackgroundDialogPage( XY );
333 pPage->Append( pNotebook );
334 pPage = new CBackgroundDialogPage( XZ );
335 pPage->Append( pNotebook );
336 pPage = new CBackgroundDialogPage( YZ );
337 pPage->Append( pNotebook );
339 gtk_box_pack_start( GTK_BOX( GTK_DIALOG( pDialogWnd )->vbox ), pNotebook, TRUE, TRUE, 0 );
341 gtk_widget_show( pNotebook );
343 gtk_widget_realize( pDialogWnd );
346 void ShowBackgroundDialog(){
347 gtk_window_present( GTK_WINDOW( pDialogWnd ) );
350 void ShowBackgroundDialogPG( int page ){
351 gtk_notebook_set_current_page( GTK_NOTEBOOK( pNotebook ),page );
352 ShowBackgroundDialog();