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
23 Camera plugin for GtkRadiant
24 Copyright (C) 2002 Splash Damage Ltd.
29 extern GtkWidget *g_pEditModeAddRadioButton;
31 char* Q_realpath(const char *path, char *resolved_path, size_t size)
33 #if defined (__linux__) || defined (__APPLE__)
34 return realpath(path, resolved_path);
36 return _fullpath(resolved_path, path, size);
40 static void DoNewCamera( idCameraPosition::positionType type )
42 CCamera *cam = AllocCam();
46 sprintf( buf, "camera%i", cam->GetCamNum() );
48 cam->GetCam()->startNewCamera( type );
49 cam->GetCam()->setName( buf );
50 cam->GetCam()->buildCamera();
52 sprintf( buf, "Unsaved Camera %i", cam->GetCamNum() );
53 cam->SetFileName( buf, false );
56 RefreshCamListCombo();
59 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(g_pEditModeAddRadioButton), TRUE );
61 // Show the camera inspector
64 // Start edit mode (if not initiated by DoCameraInspector)
66 DoStartEdit( GetCurrentCam() );
68 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, "No free cameras available.", "Create Camera Error", MB_OK, NULL );
72 void DoNewFixedCamera()
74 DoNewCamera( idCameraPosition::FIXED );
77 void DoNewInterpolatedCamera()
79 DoNewCamera( idCameraPosition::INTERPOLATED );
82 void DoNewSplineCamera()
84 DoNewCamera( idCameraPosition::SPLINE );
87 void DoCameraInspector()
89 gtk_widget_show( g_pCameraInspectorWnd );
92 void DoPreviewCamera()
94 if( GetCurrentCam() ) {
95 g_iPreviewRunning = 1;
96 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
102 char basepath[PATH_MAX];
104 if( firstCam && firstCam->HasBeenSaved() )
105 ExtractFilePath( firstCam->GetFileName(), basepath );
107 strcpy( basepath, g_FuncTable.m_pfnGetGamePath() );
109 const gchar *filename = g_FuncTable.m_pfnFileDialog( (GtkWidget *)g_pRadiantWnd, TRUE, "Open Camera File", basepath, "camera");
113 CCamera *cam = AllocCam();
114 char fullpathtofile[PATH_MAX];
117 Q_realpath(filename, fullpathtofile, PATH_MAX);
119 // see if this camera file was already loaded
120 CCamera *checkCam = firstCam->GetNext(); // not the first one as we just allocated it
122 if( !strcmp( fullpathtofile, checkCam->GetFileName() ) ) {
123 char error[PATH_MAX+64];
125 sprintf( error, "Camera file \'%s\' is already loaded", fullpathtofile );
126 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Load error", MB_OK, NULL );
127 //g_free( filename );
130 checkCam = checkCam->GetNext();
133 if( loadCamera( cam->GetCamNum(), fullpathtofile ) ) {
134 cam->GetCam()->buildCamera();
135 cam->SetFileName( filename, true );
136 SetCurrentCam( cam );
137 RefreshCamListCombo();
138 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
140 char error[PATH_MAX+64];
142 sprintf( error, "An error occured during the loading of \'%s\'", fullpathtofile );
143 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Load error", MB_OK, NULL );
146 //g_free( filename );
148 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, "No free camera slots available", "Load error", MB_OK, NULL );
153 void DoSaveCamera() {
154 char basepath[PATH_MAX];
156 if( !GetCurrentCam() )
159 if( GetCurrentCam()->GetFileName()[0] )
160 ExtractFilePath( GetCurrentCam()->GetFileName(), basepath );
162 strcpy( basepath, g_FuncTable.m_pfnGetGamePath() );
164 const gchar *filename = g_FuncTable.m_pfnFileDialog( (void *)g_pRadiantWnd, FALSE, "Save Camera File", basepath, "camera");
167 char fullpathtofile[PATH_MAX + 8];
169 Q_realpath(filename, fullpathtofile, PATH_MAX);
171 // File dialog from windows (and maybe the gtk one from radiant) doesn't handle default extensions properly.
172 // Add extension and check again if file exists
173 if( strcmp( fullpathtofile + (strlen(fullpathtofile) - 7), ".camera" ) ) {
174 strcat( fullpathtofile, ".camera" );
176 if( FileExists( fullpathtofile ) ) {
177 if ( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, "File already exists.\nOverwrite?", "Save Camera File", MB_YESNO, NULL ) == IDNO ) {
183 // see if this camera file was already loaded
184 CCamera *checkCam = firstCam;
186 if( checkCam == GetCurrentCam() ) {
187 checkCam = checkCam->GetNext();
188 if( !checkCam ) // we only have one camera file opened so no need to check further
190 } else if( !strcmp( fullpathtofile, checkCam->GetFileName() ) ) {
191 char error[PATH_MAX+64];
192 sprintf( error, "Camera file \'%s\' is currently loaded by GtkRadiant.\nPlease select a different filename.", fullpathtofile );
193 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Save error", MB_OK, NULL );
196 checkCam = checkCam->GetNext();
199 // FIXME: check for existing directory
201 GetCurrentCam()->GetCam()->save( fullpathtofile );
202 GetCurrentCam()->SetFileName( fullpathtofile, true );
203 RefreshCamListCombo();
207 void DoUnloadCamera() {
208 if( !GetCurrentCam() )
211 if( !GetCurrentCam()->HasBeenSaved() ) {
212 char buf[PATH_MAX+64];
213 sprintf( buf, "Do you want to save the changes for camera '%s'?", GetCurrentCam()->GetCam()->getName() );
214 if ( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, buf, "Warning", MB_YESNO, NULL ) == IDYES ) {
217 } else if( GetCurrentCam()->HasBeenSaved() == 2 ) {
218 char buf[PATH_MAX+64];
219 sprintf( buf, "Do you want to save the changes made to camera file '%s'?", GetCurrentCam()->GetFileName() );
220 if( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, buf, "Warning", MB_YESNO, NULL ) == IDYES ) {
225 if( g_pCurrentEditCam ) {
227 g_pCurrentEditCam = NULL;
230 FreeCam( GetCurrentCam() );
231 SetCurrentCam( NULL );
232 RefreshCamListCombo();
235 CCamera *g_pCurrentEditCam = NULL;
237 void DoStartEdit( CCamera *cam ) {
238 if( g_pCurrentEditCam ) {
240 g_pCurrentEditCam = NULL;
247 Listener = new CListener;
249 cam->GetCam()->startEdit( g_iActiveTarget < 0 ? true : false );
251 g_pCurrentEditCam = cam;
253 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
257 void DoStopEdit( void ) {
265 if( g_pCurrentEditCam ) {
266 // stop editing on the current cam
267 g_pCurrentEditCam->GetCam()->stopEdit();
268 g_pCurrentEditCam = NULL;
270 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );