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.
29 extern GtkWidget *g_pEditModeAddRadioButton;
31 char* Q_realpath( const char *path, char *resolved_path, size_t size ){
33 return realpath( path, resolved_path );
34 #elif defined( WIN32 )
35 return _fullpath( resolved_path, path, size );
37 #error "unsupported platform"
41 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() );
70 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, "No free cameras available.", "Create Camera Error", eMB_OK );
74 void DoNewFixedCamera(){
75 DoNewCamera( idCameraPosition::FIXED );
78 void DoNewInterpolatedCamera(){
79 DoNewCamera( idCameraPosition::INTERPOLATED );
82 void DoNewSplineCamera(){
83 DoNewCamera( idCameraPosition::SPLINE );
86 void DoCameraInspector(){
87 gtk_widget_show( g_pCameraInspectorWnd );
90 void DoPreviewCamera(){
91 if ( GetCurrentCam() ) {
92 g_iPreviewRunning = 1;
93 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
98 char basepath[PATH_MAX];
100 if ( firstCam && firstCam->HasBeenSaved() ) {
101 ExtractFilePath( firstCam->GetFileName(), basepath );
104 strcpy( basepath, g_FuncTable.m_pfnGetGamePath() );
107 const gchar *filename = g_FuncTable.m_pfnFileDialog( (GtkWidget *)g_pRadiantWnd, TRUE, "Open Camera File", basepath, "camera" );
110 CCamera *cam = AllocCam();
111 char fullpathtofile[PATH_MAX];
114 Q_realpath( filename, fullpathtofile, PATH_MAX );
116 // see if this camera file was already loaded
117 CCamera *checkCam = firstCam->GetNext(); // not the first one as we just allocated it
119 if ( !strcmp( fullpathtofile, checkCam->GetFileName() ) ) {
120 char error[PATH_MAX + 64];
122 sprintf( error, "Camera file \'%s\' is already loaded", fullpathtofile );
123 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Load error", eMB_OK );
124 //g_free( filename );
127 checkCam = checkCam->GetNext();
130 if ( loadCamera( cam->GetCamNum(), fullpathtofile ) ) {
131 cam->GetCam()->buildCamera();
132 cam->SetFileName( filename, true );
133 SetCurrentCam( cam );
134 RefreshCamListCombo();
135 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
138 char error[PATH_MAX + 64];
140 sprintf( error, "An error occured during the loading of \'%s\'", fullpathtofile );
141 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Load error", eMB_OK );
144 //g_free( filename );
147 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, "No free camera slots available", "Load error", eMB_OK );
152 void DoSaveCamera() {
153 char basepath[PATH_MAX];
155 if ( !GetCurrentCam() ) {
159 if ( GetCurrentCam()->GetFileName()[0] ) {
160 ExtractFilePath( GetCurrentCam()->GetFileName(), basepath );
163 strcpy( basepath, g_FuncTable.m_pfnGetGamePath() );
166 const gchar *filename = g_FuncTable.m_pfnFileDialog( g_pRadiantWnd, FALSE, "Save Camera File", basepath, "camera" );
169 char fullpathtofile[PATH_MAX + 8];
171 Q_realpath( filename, fullpathtofile, PATH_MAX );
173 // File dialog from windows (and maybe the gtk one from radiant) doesn't handle default extensions properly.
174 // Add extension and check again if file exists
175 if ( strcmp( fullpathtofile + ( strlen( fullpathtofile ) - 7 ), ".camera" ) ) {
176 strcat( fullpathtofile, ".camera" );
178 if ( FileExists( fullpathtofile ) ) {
179 if ( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, "File already exists.\nOverwrite?", "Save Camera File", eMB_YESNO ) == eIDNO ) {
185 // see if this camera file was already loaded
186 CCamera *checkCam = firstCam;
188 if ( checkCam == GetCurrentCam() ) {
189 checkCam = checkCam->GetNext();
190 if ( !checkCam ) { // we only have one camera file opened so no need to check further
194 else if ( !strcmp( fullpathtofile, checkCam->GetFileName() ) ) {
195 char error[PATH_MAX + 64];
196 sprintf( error, "Camera file \'%s\' is currently loaded by NetRadiant.\nPlease select a different filename.", fullpathtofile );
197 g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Save error", eMB_OK );
200 checkCam = checkCam->GetNext();
203 // FIXME: check for existing directory
205 GetCurrentCam()->GetCam()->save( fullpathtofile );
206 GetCurrentCam()->SetFileName( fullpathtofile, true );
207 RefreshCamListCombo();
211 void DoUnloadCamera() {
212 if ( !GetCurrentCam() ) {
216 if ( !GetCurrentCam()->HasBeenSaved() ) {
217 char buf[PATH_MAX + 64];
218 sprintf( buf, "Do you want to save the changes for camera '%s'?", GetCurrentCam()->GetCam()->getName() );
219 if ( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, buf, "Warning", eMB_YESNO ) == eIDYES ) {
223 else if ( GetCurrentCam()->HasBeenSaved() == 2 ) {
224 char buf[PATH_MAX + 64];
225 sprintf( buf, "Do you want to save the changes made to camera file '%s'?", GetCurrentCam()->GetFileName() );
226 if ( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, buf, "Warning", eMB_YESNO ) == eIDYES ) {
231 if ( g_pCurrentEditCam ) {
233 g_pCurrentEditCam = NULL;
236 FreeCam( GetCurrentCam() );
237 SetCurrentCam( NULL );
238 RefreshCamListCombo();
241 CCamera *g_pCurrentEditCam = NULL;
243 void DoStartEdit( CCamera *cam ) {
244 if ( g_pCurrentEditCam ) {
246 g_pCurrentEditCam = NULL;
253 Listener = new CListener;
256 cam->GetCam()->startEdit( g_iActiveTarget < 0 ? true : false );
258 g_pCurrentEditCam = cam;
260 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
264 void DoStopEdit( void ) {
272 if ( g_pCurrentEditCam ) {
273 // stop editing on the current cam
274 g_pCurrentEditCam->GetCam()->stopEdit();
275 g_pCurrentEditCam = NULL;
277 g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );