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)
35 return realpath( path, resolved_path );
37 return _fullpath( resolved_path, path, size );
39 #error "unsupported platform"
43 static void DoNewCamera(idCameraPosition::positionType type)
45 CCamera *cam = AllocCam();
49 sprintf(buf, "camera%i", cam->GetCamNum());
51 cam->GetCam()->startNewCamera(type);
52 cam->GetCam()->setName(buf);
53 cam->GetCam()->buildCamera();
55 sprintf(buf, "Unsaved Camera %i", cam->GetCamNum());
56 cam->SetFileName(buf, false);
59 RefreshCamListCombo();
62 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_pEditModeAddRadioButton), TRUE);
64 // Show the camera inspector
67 // Start edit mode (if not initiated by DoCameraInspector)
69 DoStartEdit(GetCurrentCam());
72 g_FuncTable.m_pfnMessageBox((GtkWidget *) g_pRadiantWnd, "No free cameras available.", "Create Camera Error",
77 void DoNewFixedCamera()
79 DoNewCamera(idCameraPosition::FIXED);
82 void DoNewInterpolatedCamera()
84 DoNewCamera(idCameraPosition::INTERPOLATED);
87 void DoNewSplineCamera()
89 DoNewCamera(idCameraPosition::SPLINE);
92 void DoCameraInspector()
94 g_pCameraInspectorWnd.show();
97 void DoPreviewCamera()
99 if (GetCurrentCam()) {
100 g_iPreviewRunning = 1;
101 g_FuncTable.m_pfnSysUpdateWindows(W_XY_OVERLAY | W_CAMERA);
107 char basepath[PATH_MAX];
109 if (firstCam && firstCam->HasBeenSaved()) {
110 ExtractFilePath(firstCam->GetFileName(), basepath);
112 strcpy(basepath, g_FuncTable.m_pfnGetGamePath());
115 const gchar *filename = g_FuncTable.m_pfnFileDialog((GtkWidget *) g_pRadiantWnd, TRUE, "Open Camera File", basepath,
119 CCamera *cam = AllocCam();
120 char fullpathtofile[PATH_MAX];
123 Q_realpath(filename, fullpathtofile, PATH_MAX);
125 // see if this camera file was already loaded
126 CCamera *checkCam = firstCam->GetNext(); // not the first one as we just allocated it
128 if (!strcmp(fullpathtofile, checkCam->GetFileName())) {
129 char error[PATH_MAX + 64];
131 sprintf(error, "Camera file \'%s\' is already loaded", fullpathtofile);
132 g_FuncTable.m_pfnMessageBox((GtkWidget *) g_pRadiantWnd, error, "Load error", eMB_OK);
133 //g_free( filename );
136 checkCam = checkCam->GetNext();
139 if (loadCamera(cam->GetCamNum(), fullpathtofile)) {
140 cam->GetCam()->buildCamera();
141 cam->SetFileName(filename, true);
143 RefreshCamListCombo();
144 g_FuncTable.m_pfnSysUpdateWindows(W_XY_OVERLAY | W_CAMERA);
146 char error[PATH_MAX + 64];
148 sprintf(error, "An error occured during the loading of \'%s\'", fullpathtofile);
149 g_FuncTable.m_pfnMessageBox((GtkWidget *) g_pRadiantWnd, error, "Load error", eMB_OK);
152 //g_free( filename );
154 g_FuncTable.m_pfnMessageBox((GtkWidget *) g_pRadiantWnd, "No free camera slots available", "Load error",
162 char basepath[PATH_MAX];
164 if (!GetCurrentCam()) {
168 if (GetCurrentCam()->GetFileName()[0]) {
169 ExtractFilePath(GetCurrentCam()->GetFileName(), basepath);
171 strcpy(basepath, g_FuncTable.m_pfnGetGamePath());
174 const gchar *filename = g_FuncTable.m_pfnFileDialog(g_pRadiantWnd, FALSE, "Save Camera File", basepath, "camera");
177 char fullpathtofile[PATH_MAX + 8];
179 Q_realpath(filename, fullpathtofile, PATH_MAX);
181 // File dialog from windows (and maybe the gtk one from radiant) doesn't handle default extensions properly.
182 // Add extension and check again if file exists
183 if (strcmp(fullpathtofile + (strlen(fullpathtofile) - 7), ".camera")) {
184 strcat(fullpathtofile, ".camera");
186 if (FileExists(fullpathtofile)) {
187 if (g_FuncTable.m_pfnMessageBox((GtkWidget *) g_pRadiantWnd, "File already exists.\nOverwrite?",
188 "Save Camera File", eMB_YESNO) == eIDNO) {
194 // see if this camera file was already loaded
195 CCamera *checkCam = firstCam;
197 if (checkCam == GetCurrentCam()) {
198 checkCam = checkCam->GetNext();
199 if (!checkCam) { // we only have one camera file opened so no need to check further
202 } else if (!strcmp(fullpathtofile, checkCam->GetFileName())) {
203 char error[PATH_MAX + 64];
205 "Camera file \'%s\' is currently loaded by NetRadiant.\nPlease select a different filename.",
207 g_FuncTable.m_pfnMessageBox((GtkWidget *) g_pRadiantWnd, error, "Save error", eMB_OK);
210 checkCam = checkCam->GetNext();
213 // FIXME: check for existing directory
215 GetCurrentCam()->GetCam()->save(fullpathtofile);
216 GetCurrentCam()->SetFileName(fullpathtofile, true);
217 RefreshCamListCombo();
221 void DoUnloadCamera()
223 if (!GetCurrentCam()) {
227 if (!GetCurrentCam()->HasBeenSaved()) {
228 char buf[PATH_MAX + 64];
229 sprintf(buf, "Do you want to save the changes for camera '%s'?", GetCurrentCam()->GetCam()->getName());
230 if (g_FuncTable.m_pfnMessageBox((GtkWidget *) g_pRadiantWnd, buf, "Warning", eMB_YESNO) == eIDYES) {
233 } else if (GetCurrentCam()->HasBeenSaved() == 2) {
234 char buf[PATH_MAX + 64];
235 sprintf(buf, "Do you want to save the changes made to camera file '%s'?", GetCurrentCam()->GetFileName());
236 if (g_FuncTable.m_pfnMessageBox((GtkWidget *) g_pRadiantWnd, buf, "Warning", eMB_YESNO) == eIDYES) {
241 if (g_pCurrentEditCam) {
243 g_pCurrentEditCam = NULL;
246 FreeCam(GetCurrentCam());
248 RefreshCamListCombo();
251 CCamera *g_pCurrentEditCam = NULL;
253 void DoStartEdit(CCamera *cam)
255 if (g_pCurrentEditCam) {
257 g_pCurrentEditCam = NULL;
264 Listener = new CListener;
267 cam->GetCam()->startEdit(g_iActiveTarget < 0 ? true : false);
269 g_pCurrentEditCam = cam;
271 g_FuncTable.m_pfnSysUpdateWindows(W_XY_OVERLAY | W_CAMERA);
275 void DoStopEdit(void)
284 if (g_pCurrentEditCam) {
285 // stop editing on the current cam
286 g_pCurrentEditCam->GetCam()->stopEdit();
287 g_pCurrentEditCam = NULL;
289 g_FuncTable.m_pfnSysUpdateWindows(W_XY_OVERLAY | W_CAMERA);