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