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 ){
32 #if defined ( __linux__ ) || defined ( __APPLE__ )
33 return realpath( path, resolved_path );
35 return _fullpath( resolved_path, path, size );
39 static void DoNewCamera( idCameraPosition::positionType type ){
40 CCamera *cam = AllocCam();
44 sprintf( buf, "camera%i", cam->GetCamNum() );
46 cam->GetCam()->startNewCamera( type );
47 cam->GetCam()->setName( buf );
48 cam->GetCam()->buildCamera();
50 sprintf( buf, "Unsaved Camera %i", cam->GetCamNum() );
51 cam->SetFileName( buf, false );
54 RefreshCamListCombo();
57 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( g_pEditModeAddRadioButton ), TRUE );
59 // Show the camera inspector
62 // Start edit mode (if not initiated by DoCameraInspector)
64 DoStartEdit( GetCurrentCam() );
68 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, "No free cameras available.", "Create Camera Error", MB_OK, NULL );
72 void DoNewFixedCamera(){
73 DoNewCamera( idCameraPosition::FIXED );
76 void DoNewInterpolatedCamera(){
77 DoNewCamera( idCameraPosition::INTERPOLATED );
80 void DoNewSplineCamera(){
81 DoNewCamera( idCameraPosition::SPLINE );
84 void DoCameraInspector(){
85 gtk_widget_show( g_pCameraInspectorWnd );
88 void DoPreviewCamera(){
89 if ( GetCurrentCam() ) {
90 g_iPreviewRunning = 1;
91 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
96 char basepath[PATH_MAX];
98 if ( firstCam && firstCam->HasBeenSaved() ) {
99 CAMERA_ExtractFilePath( firstCam->GetFileName(), basepath );
102 strcpy( basepath, g_FuncTable.m_pfnGetGamePath() );
105 const gchar *filename = g_FuncTable.m_pfnFileDialog( (GtkWidget *)g_pRadiantWnd, TRUE, "Open Camera File", basepath, "camera", NULL );
108 CCamera *cam = AllocCam();
109 char fullpathtofile[PATH_MAX];
112 Q_realpath( filename, fullpathtofile, PATH_MAX );
114 // see if this camera file was already loaded
115 CCamera *checkCam = firstCam->GetNext(); // not the first one as we just allocated it
117 if ( !strcmp( fullpathtofile, checkCam->GetFileName() ) ) {
118 char error[PATH_MAX + 64];
120 sprintf( error, "Camera file \'%s\' is already loaded", fullpathtofile );
121 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Load error", MB_OK, NULL );
122 //g_free( filename );
125 checkCam = checkCam->GetNext();
128 if ( loadCamera( cam->GetCamNum(), fullpathtofile ) ) {
129 cam->GetCam()->buildCamera();
130 cam->SetFileName( filename, true );
131 SetCurrentCam( cam );
132 RefreshCamListCombo();
133 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
136 char error[PATH_MAX + 64];
138 sprintf( error, "An error occured during the loading of \'%s\'", fullpathtofile );
139 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Load error", MB_OK, NULL );
142 //g_free( filename );
145 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, "No free camera slots available", "Load error", MB_OK, NULL );
150 void DoSaveCamera() {
151 char basepath[PATH_MAX];
153 if ( !GetCurrentCam() ) {
157 if ( GetCurrentCam()->GetFileName()[0] ) {
158 CAMERA_ExtractFilePath( GetCurrentCam()->GetFileName(), basepath );
161 strcpy( basepath, g_FuncTable.m_pfnGetGamePath() );
164 const gchar *filename = g_FuncTable.m_pfnFileDialog( (void *)g_pRadiantWnd, FALSE, "Save Camera File", basepath, "camera", NULL );
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
192 else if ( !strcmp( fullpathtofile, checkCam->GetFileName() ) ) {
193 char error[PATH_MAX + 64];
194 sprintf( error, "Camera file \'%s\' is currently loaded by GtkRadiant.\nPlease select a different filename.", fullpathtofile );
195 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Save error", MB_OK, NULL );
198 checkCam = checkCam->GetNext();
201 // FIXME: check for existing directory
203 GetCurrentCam()->GetCam()->save( fullpathtofile );
204 GetCurrentCam()->SetFileName( fullpathtofile, true );
205 RefreshCamListCombo();
209 void DoUnloadCamera() {
210 if ( !GetCurrentCam() ) {
214 if ( !GetCurrentCam()->HasBeenSaved() ) {
215 char buf[PATH_MAX + 64];
216 sprintf( buf, "Do you want to save the changes for camera '%s'?", GetCurrentCam()->GetCam()->getName() );
217 if ( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, buf, "Warning", MB_YESNO, NULL ) == IDYES ) {
221 else if ( GetCurrentCam()->HasBeenSaved() == 2 ) {
222 char buf[PATH_MAX + 64];
223 sprintf( buf, "Do you want to save the changes made to camera file '%s'?", GetCurrentCam()->GetFileName() );
224 if ( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, buf, "Warning", MB_YESNO, NULL ) == IDYES ) {
229 if ( g_pCurrentEditCam ) {
231 g_pCurrentEditCam = NULL;
234 FreeCam( GetCurrentCam() );
235 SetCurrentCam( NULL );
236 RefreshCamListCombo();
239 CCamera *g_pCurrentEditCam = NULL;
241 void DoStartEdit( CCamera *cam ) {
242 if ( g_pCurrentEditCam ) {
244 g_pCurrentEditCam = NULL;
251 Listener = new CListener;
254 cam->GetCam()->startEdit( g_iActiveTarget < 0 ? true : false );
256 g_pCurrentEditCam = cam;
258 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
262 void DoStopEdit( void ) {
270 if ( g_pCurrentEditCam ) {
271 // stop editing on the current cam
272 g_pCurrentEditCam->GetCam()->stopEdit();
273 g_pCurrentEditCam = NULL;
275 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );