2007-11-04 03:51:54 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Camera plugin for GtkRadiant
|
|
|
|
Copyright (C) 2002 Splash Damage Ltd.
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
#include "camera.h"
|
|
|
|
|
|
|
|
extern GtkWidget *g_pEditModeAddRadioButton;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
char* Q_realpath( const char *path, char *resolved_path, size_t size ){
|
2017-08-30 11:07:42 +00:00
|
|
|
#if defined( __linux__ ) || defined( __FreeBSD__ ) || defined( __APPLE__ )
|
2012-03-17 20:01:54 +00:00
|
|
|
return realpath( path, resolved_path );
|
2007-11-04 03:51:54 +00:00
|
|
|
#else
|
2012-03-17 20:01:54 +00:00
|
|
|
return _fullpath( resolved_path, path, size );
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void DoNewCamera( idCameraPosition::positionType type ){
|
2007-11-04 03:51:54 +00:00
|
|
|
CCamera *cam = AllocCam();
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( cam ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
char buf[128];
|
|
|
|
sprintf( buf, "camera%i", cam->GetCamNum() );
|
|
|
|
|
|
|
|
cam->GetCam()->startNewCamera( type );
|
|
|
|
cam->GetCam()->setName( buf );
|
|
|
|
cam->GetCam()->buildCamera();
|
|
|
|
|
|
|
|
sprintf( buf, "Unsaved Camera %i", cam->GetCamNum() );
|
|
|
|
cam->SetFileName( buf, false );
|
|
|
|
|
|
|
|
SetCurrentCam( cam );
|
|
|
|
RefreshCamListCombo();
|
|
|
|
|
|
|
|
// Go to editmode Add
|
2012-03-17 20:01:54 +00:00
|
|
|
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( g_pEditModeAddRadioButton ), TRUE );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
// Show the camera inspector
|
|
|
|
DoCameraInspector();
|
|
|
|
|
|
|
|
// Start edit mode (if not initiated by DoCameraInspector)
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !g_bEditOn ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
DoStartEdit( GetCurrentCam() );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, "No free cameras available.", "Create Camera Error", MB_OK, NULL );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DoNewFixedCamera(){
|
2007-11-04 03:51:54 +00:00
|
|
|
DoNewCamera( idCameraPosition::FIXED );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DoNewInterpolatedCamera(){
|
2007-11-04 03:51:54 +00:00
|
|
|
DoNewCamera( idCameraPosition::INTERPOLATED );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DoNewSplineCamera(){
|
2007-11-04 03:51:54 +00:00
|
|
|
DoNewCamera( idCameraPosition::SPLINE );
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DoCameraInspector(){
|
|
|
|
gtk_widget_show( g_pCameraInspectorWnd );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DoPreviewCamera(){
|
|
|
|
if ( GetCurrentCam() ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
g_iPreviewRunning = 1;
|
|
|
|
g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void DoLoadCamera(){
|
|
|
|
char basepath[PATH_MAX];
|
|
|
|
|
|
|
|
if ( firstCam && firstCam->HasBeenSaved() ) {
|
|
|
|
CAMERA_ExtractFilePath( firstCam->GetFileName(), basepath );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
strcpy( basepath, g_FuncTable.m_pfnGetGamePath() );
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *filename = g_FuncTable.m_pfnFileDialog( (GtkWidget *)g_pRadiantWnd, TRUE, "Open Camera File", basepath, "camera", NULL );
|
|
|
|
|
|
|
|
if ( filename ) {
|
|
|
|
CCamera *cam = AllocCam();
|
|
|
|
char fullpathtofile[PATH_MAX];
|
|
|
|
|
|
|
|
if ( cam ) {
|
|
|
|
Q_realpath( filename, fullpathtofile, PATH_MAX );
|
|
|
|
|
|
|
|
// see if this camera file was already loaded
|
|
|
|
CCamera *checkCam = firstCam->GetNext(); // not the first one as we just allocated it
|
|
|
|
while ( checkCam ) {
|
|
|
|
if ( !strcmp( fullpathtofile, checkCam->GetFileName() ) ) {
|
|
|
|
char error[PATH_MAX + 64];
|
|
|
|
FreeCam( cam );
|
|
|
|
sprintf( error, "Camera file \'%s\' is already loaded", fullpathtofile );
|
|
|
|
g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Load error", MB_OK, NULL );
|
|
|
|
//g_free( filename );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
checkCam = checkCam->GetNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( loadCamera( cam->GetCamNum(), fullpathtofile ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
cam->GetCam()->buildCamera();
|
2012-03-17 20:01:54 +00:00
|
|
|
cam->SetFileName( filename, true );
|
|
|
|
SetCurrentCam( cam );
|
|
|
|
RefreshCamListCombo();
|
|
|
|
g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
char error[PATH_MAX + 64];
|
|
|
|
FreeCam( cam );
|
|
|
|
sprintf( error, "An error occured during the loading of \'%s\'", fullpathtofile );
|
|
|
|
g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Load error", MB_OK, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
//g_free( filename );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, "No free camera slots available", "Load error", MB_OK, NULL );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoSaveCamera() {
|
2012-03-17 20:01:54 +00:00
|
|
|
char basepath[PATH_MAX];
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !GetCurrentCam() ) {
|
|
|
|
return;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( GetCurrentCam()->GetFileName()[0] ) {
|
|
|
|
CAMERA_ExtractFilePath( GetCurrentCam()->GetFileName(), basepath );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
strcpy( basepath, g_FuncTable.m_pfnGetGamePath() );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
const gchar *filename = g_FuncTable.m_pfnFileDialog( (void *)g_pRadiantWnd, FALSE, "Save Camera File", basepath, "camera", NULL );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( filename ) {
|
|
|
|
char fullpathtofile[PATH_MAX + 8];
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Q_realpath( filename, fullpathtofile, PATH_MAX );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
// File dialog from windows (and maybe the gtk one from radiant) doesn't handle default extensions properly.
|
|
|
|
// Add extension and check again if file exists
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strcmp( fullpathtofile + ( strlen( fullpathtofile ) - 7 ), ".camera" ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
strcat( fullpathtofile, ".camera" );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( FileExists( fullpathtofile ) ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
if ( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, "File already exists.\nOverwrite?", "Save Camera File", MB_YESNO, NULL ) == IDNO ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
// see if this camera file was already loaded
|
|
|
|
CCamera *checkCam = firstCam;
|
|
|
|
while ( checkCam ) {
|
|
|
|
if ( checkCam == GetCurrentCam() ) {
|
|
|
|
checkCam = checkCam->GetNext();
|
|
|
|
if ( !checkCam ) { // we only have one camera file opened so no need to check further
|
2007-11-04 03:51:54 +00:00
|
|
|
break;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( !strcmp( fullpathtofile, checkCam->GetFileName() ) ) {
|
|
|
|
char error[PATH_MAX + 64];
|
|
|
|
sprintf( error, "Camera file \'%s\' is currently loaded by GtkRadiant.\nPlease select a different filename.", fullpathtofile );
|
|
|
|
g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Save error", MB_OK, NULL );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
checkCam = checkCam->GetNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: check for existing directory
|
|
|
|
|
|
|
|
GetCurrentCam()->GetCam()->save( fullpathtofile );
|
2007-11-04 03:51:54 +00:00
|
|
|
GetCurrentCam()->SetFileName( fullpathtofile, true );
|
|
|
|
RefreshCamListCombo();
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DoUnloadCamera() {
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !GetCurrentCam() ) {
|
|
|
|
return;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !GetCurrentCam()->HasBeenSaved() ) {
|
|
|
|
char buf[PATH_MAX + 64];
|
2007-11-04 03:51:54 +00:00
|
|
|
sprintf( buf, "Do you want to save the changes for camera '%s'?", GetCurrentCam()->GetCam()->getName() );
|
|
|
|
if ( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, buf, "Warning", MB_YESNO, NULL ) == IDYES ) {
|
|
|
|
DoSaveCamera();
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( GetCurrentCam()->HasBeenSaved() == 2 ) {
|
|
|
|
char buf[PATH_MAX + 64];
|
2007-11-04 03:51:54 +00:00
|
|
|
sprintf( buf, "Do you want to save the changes made to camera file '%s'?", GetCurrentCam()->GetFileName() );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, buf, "Warning", MB_YESNO, NULL ) == IDYES ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
DoSaveCamera();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_pCurrentEditCam ) {
|
|
|
|
DoStopEdit();
|
|
|
|
g_pCurrentEditCam = NULL;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
FreeCam( GetCurrentCam() );
|
|
|
|
SetCurrentCam( NULL );
|
|
|
|
RefreshCamListCombo();
|
|
|
|
}
|
|
|
|
|
|
|
|
CCamera *g_pCurrentEditCam = NULL;
|
|
|
|
|
|
|
|
void DoStartEdit( CCamera *cam ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_pCurrentEditCam ) {
|
|
|
|
DoStopEdit();
|
|
|
|
g_pCurrentEditCam = NULL;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( cam ) {
|
|
|
|
g_bEditOn = true;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !Listener ) {
|
|
|
|
Listener = new CListener;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
cam->GetCam()->startEdit( g_iActiveTarget < 0 ? true : false );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_pCurrentEditCam = cam;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DoStopEdit( void ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
g_bEditOn = false;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( Listener ) {
|
|
|
|
delete Listener;
|
|
|
|
Listener = NULL;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_pCurrentEditCam ) {
|
|
|
|
// stop editing on the current cam
|
|
|
|
g_pCurrentEditCam->GetCam()->stopEdit();
|
|
|
|
g_pCurrentEditCam = NULL;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|