2 Copyright (C) 1999-2006 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.
28 #include "globaldefs.h"
30 extern GtkWidget *g_pEditModeAddRadioButton;
32 char* Q_realpath( const char *path, char *resolved_path, size_t size ){
34 return realpath( path, resolved_path );
36 return _fullpath( resolved_path, path, size );
38 #error "unsupported platform"
42 static void DoNewCamera( idCameraPosition::positionType type ){
43 CCamera *cam = AllocCam();
47 sprintf( buf, "camera%i", cam->GetCamNum() );
49 cam->GetCam()->startNewCamera( type );
50 cam->GetCam()->setName( buf );
51 cam->GetCam()->buildCamera();
53 sprintf( buf, "Unsaved Camera %i", cam->GetCamNum() );
54 cam->SetFileName( buf, false );
57 RefreshCamListCombo();
60 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( g_pEditModeAddRadioButton ), TRUE );
62 // Show the camera inspector
65 // Start edit mode (if not initiated by DoCameraInspector)
67 DoStartEdit( GetCurrentCam() );
71 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, "No free cameras available.", "Create Camera Error", eMB_OK );
75 void DoNewFixedCamera(){
76 DoNewCamera( idCameraPosition::FIXED );
79 void DoNewInterpolatedCamera(){
80 DoNewCamera( idCameraPosition::INTERPOLATED );
83 void DoNewSplineCamera(){
84 DoNewCamera( idCameraPosition::SPLINE );
87 void DoCameraInspector(){
88 g_pCameraInspectorWnd.show();
91 void DoPreviewCamera(){
92 if ( GetCurrentCam() ) {
93 g_iPreviewRunning = 1;
94 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
99 char basepath[PATH_MAX];
101 if ( firstCam && firstCam->HasBeenSaved() ) {
102 ExtractFilePath( firstCam->GetFileName(), basepath );
105 strcpy( basepath, g_FuncTable.m_pfnGetGamePath() );
108 const gchar *filename = g_FuncTable.m_pfnFileDialog( (GtkWidget *)g_pRadiantWnd, TRUE, "Open Camera File", basepath, "camera" );
111 CCamera *cam = AllocCam();
112 char fullpathtofile[PATH_MAX];
115 Q_realpath( filename, fullpathtofile, PATH_MAX );
117 // see if this camera file was already loaded
118 CCamera *checkCam = firstCam->GetNext(); // not the first one as we just allocated it
120 if ( !strcmp( fullpathtofile, checkCam->GetFileName() ) ) {
121 char error[PATH_MAX + 64];
123 sprintf( error, "Camera file \'%s\' is already loaded", fullpathtofile );
124 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Load error", eMB_OK );
125 //g_free( filename );
128 checkCam = checkCam->GetNext();
131 if ( loadCamera( cam->GetCamNum(), fullpathtofile ) ) {
132 cam->GetCam()->buildCamera();
133 cam->SetFileName( filename, true );
134 SetCurrentCam( cam );
135 RefreshCamListCombo();
136 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
139 char error[PATH_MAX + 64];
141 sprintf( error, "An error occured during the loading of \'%s\'", fullpathtofile );
142 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Load error", eMB_OK );
145 //g_free( filename );
148 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, "No free camera slots available", "Load error", eMB_OK );
153 void DoSaveCamera() {
154 char basepath[PATH_MAX];
156 if ( !GetCurrentCam() ) {
160 if ( GetCurrentCam()->GetFileName()[0] ) {
161 ExtractFilePath( GetCurrentCam()->GetFileName(), basepath );
164 strcpy( basepath, g_FuncTable.m_pfnGetGamePath() );
167 const gchar *filename = g_FuncTable.m_pfnFileDialog( g_pRadiantWnd, FALSE, "Save Camera File", basepath, "camera" );
170 char fullpathtofile[PATH_MAX + 8];
172 Q_realpath( filename, fullpathtofile, PATH_MAX );
174 // File dialog from windows (and maybe the gtk one from radiant) doesn't handle default extensions properly.
175 // Add extension and check again if file exists
176 if ( strcmp( fullpathtofile + ( strlen( fullpathtofile ) - 7 ), ".camera" ) ) {
177 strcat( fullpathtofile, ".camera" );
179 if ( FileExists( fullpathtofile ) ) {
180 if ( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, "File already exists.\nOverwrite?", "Save Camera File", eMB_YESNO ) == eIDNO ) {
186 // see if this camera file was already loaded
187 CCamera *checkCam = firstCam;
189 if ( checkCam == GetCurrentCam() ) {
190 checkCam = checkCam->GetNext();
191 if ( !checkCam ) { // we only have one camera file opened so no need to check further
195 else if ( !strcmp( fullpathtofile, checkCam->GetFileName() ) ) {
196 char error[PATH_MAX + 64];
197 sprintf( error, "Camera file \'%s\' is currently loaded by NetRadiant.\nPlease select a different filename.", fullpathtofile );
198 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Save error", eMB_OK );
201 checkCam = checkCam->GetNext();
204 // FIXME: check for existing directory
206 GetCurrentCam()->GetCam()->save( fullpathtofile );
207 GetCurrentCam()->SetFileName( fullpathtofile, true );
208 RefreshCamListCombo();
212 void DoUnloadCamera() {
213 if ( !GetCurrentCam() ) {
217 if ( !GetCurrentCam()->HasBeenSaved() ) {
218 char buf[PATH_MAX + 64];
219 sprintf( buf, "Do you want to save the changes for camera '%s'?", GetCurrentCam()->GetCam()->getName() );
220 if ( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, buf, "Warning", eMB_YESNO ) == eIDYES ) {
224 else if ( GetCurrentCam()->HasBeenSaved() == 2 ) {
225 char buf[PATH_MAX + 64];
226 sprintf( buf, "Do you want to save the changes made to camera file '%s'?", GetCurrentCam()->GetFileName() );
227 if ( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, buf, "Warning", eMB_YESNO ) == eIDYES ) {
232 if ( g_pCurrentEditCam ) {
234 g_pCurrentEditCam = NULL;
237 FreeCam( GetCurrentCam() );
238 SetCurrentCam( NULL );
239 RefreshCamListCombo();
242 CCamera *g_pCurrentEditCam = NULL;
244 void DoStartEdit( CCamera *cam ) {
245 if ( g_pCurrentEditCam ) {
247 g_pCurrentEditCam = NULL;
254 Listener = new CListener;
257 cam->GetCam()->startEdit( g_iActiveTarget < 0 ? true : false );
259 g_pCurrentEditCam = cam;
261 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
265 void DoStopEdit( void ) {
273 if ( g_pCurrentEditCam ) {
274 // stop editing on the current cam
275 g_pCurrentEditCam->GetCam()->stopEdit();
276 g_pCurrentEditCam = NULL;
278 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );