]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - contrib/camera/funchandlers.cpp
Revert partially (auto) "reformat code! now the code is only ugly on the *inside*"
[xonotic/netradiant.git] / contrib / camera / funchandlers.cpp
index a0b9d756536d07bfa918ab95b7c90dd20604aa8d..5d72242b5eb48654cd2e96b6d990632feb75c5be 100644 (file)
 
 extern GtkWidget *g_pEditModeAddRadioButton;
 
-char *Q_realpath(const char *path, char *resolved_path, size_t size)
-{
+char* Q_realpath( const char *path, char *resolved_path, size_t size ){
 #if GDEF_OS_POSIX
-    return realpath( path, resolved_path );
+       return realpath( path, resolved_path );
 #elif GDEF_OS_WINDOWS
-    return _fullpath( resolved_path, path, size );
+       return _fullpath( resolved_path, path, size );
 #else
 #error "unsupported platform"
 #endif
 }
 
-static void DoNewCamera(idCameraPosition::positionType type)
-{
-    CCamera *cam = AllocCam();
+static void DoNewCamera( idCameraPosition::positionType type ){
+       CCamera *cam = AllocCam();
 
-    if (cam) {
-        char buf[128];
-        sprintf(buf, "camera%i", cam->GetCamNum());
+       if ( cam ) {
+               char buf[128];
+               sprintf( buf, "camera%i", cam->GetCamNum() );
 
-        cam->GetCam()->startNewCamera(type);
-        cam->GetCam()->setName(buf);
-        cam->GetCam()->buildCamera();
+               cam->GetCam()->startNewCamera( type );
+               cam->GetCam()->setName( buf );
+               cam->GetCam()->buildCamera();
 
-        sprintf(buf, "Unsaved Camera %i", cam->GetCamNum());
-        cam->SetFileName(buf, false);
+               sprintf( buf, "Unsaved Camera %i", cam->GetCamNum() );
+               cam->SetFileName( buf, false );
 
-        SetCurrentCam(cam);
-        RefreshCamListCombo();
+               SetCurrentCam( cam );
+               RefreshCamListCombo();
 
-        // Go to editmode Add
-        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_pEditModeAddRadioButton), TRUE);
+               // Go to editmode Add
+               gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( g_pEditModeAddRadioButton ), TRUE );
 
-        // Show the camera inspector
-        DoCameraInspector();
+               // Show the camera inspector
+               DoCameraInspector();
 
-        // Start edit mode (if not initiated by DoCameraInspector)
-        if (!g_bEditOn) {
-            DoStartEdit(GetCurrentCam());
-        }
-    } else {
-        g_FuncTable.m_pfnMessageBox((GtkWidget *) g_pRadiantWnd, "No free cameras available.", "Create Camera Error",
-                                    eMB_OK);
-    }
+               // Start edit mode (if not initiated by DoCameraInspector)
+               if ( !g_bEditOn ) {
+                       DoStartEdit( GetCurrentCam() );
+               }
+       }
+       else {
+               g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, "No free cameras available.", "Create Camera Error", eMB_OK );
+       }
 }
 
-void DoNewFixedCamera()
-{
-    DoNewCamera(idCameraPosition::FIXED);
+void DoNewFixedCamera(){
+       DoNewCamera( idCameraPosition::FIXED );
 }
 
-void DoNewInterpolatedCamera()
-{
-    DoNewCamera(idCameraPosition::INTERPOLATED);
+void DoNewInterpolatedCamera(){
+       DoNewCamera( idCameraPosition::INTERPOLATED );
 }
 
-void DoNewSplineCamera()
-{
-    DoNewCamera(idCameraPosition::SPLINE);
+void DoNewSplineCamera(){
+       DoNewCamera( idCameraPosition::SPLINE );
 }
 
-void DoCameraInspector()
-{
-    g_pCameraInspectorWnd.show();
+void DoCameraInspector(){
+       g_pCameraInspectorWnd.show();
 }
 
-void DoPreviewCamera()
-{
-    if (GetCurrentCam()) {
-        g_iPreviewRunning = 1;
-        g_FuncTable.m_pfnSysUpdateWindows(W_XY_OVERLAY | W_CAMERA);
-    }
+void DoPreviewCamera(){
+       if ( GetCurrentCam() ) {
+               g_iPreviewRunning = 1;
+               g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
+       }
 }
 
-void DoLoadCamera()
-{
-    char basepath[PATH_MAX];
-
-    if (firstCam && firstCam->HasBeenSaved()) {
-        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");
-
-    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", eMB_OK);
-                    //g_free( filename );
-                    return;
-                }
-                checkCam = checkCam->GetNext();
-            }
-
-            if (loadCamera(cam->GetCamNum(), fullpathtofile)) {
-                cam->GetCam()->buildCamera();
-                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", eMB_OK);
-            }
-
-            //g_free( filename );
-        } else {
-            g_FuncTable.m_pfnMessageBox((GtkWidget *) g_pRadiantWnd, "No free camera slots available", "Load error",
-                                        eMB_OK);
-        }
-    }
+void DoLoadCamera(){
+       char basepath[PATH_MAX];
+
+       if ( firstCam && firstCam->HasBeenSaved() ) {
+               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" );
+
+       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", eMB_OK );
+                                       //g_free( filename );
+                                       return;
+                               }
+                               checkCam = checkCam->GetNext();
+                       }
+
+                       if ( loadCamera( cam->GetCamNum(), fullpathtofile ) ) {
+                               cam->GetCam()->buildCamera();
+                               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", eMB_OK );
+                       }
+
+                       //g_free( filename );
+               }
+               else {
+                       g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, "No free camera slots available", "Load error", eMB_OK );
+               }
+       }
 }
 
-void DoSaveCamera()
-{
-    char basepath[PATH_MAX];
-
-    if (!GetCurrentCam()) {
-        return;
-    }
-
-    if (GetCurrentCam()->GetFileName()[0]) {
-        ExtractFilePath(GetCurrentCam()->GetFileName(), basepath);
-    } else {
-        strcpy(basepath, g_FuncTable.m_pfnGetGamePath());
-    }
-
-    const gchar *filename = g_FuncTable.m_pfnFileDialog(g_pRadiantWnd, FALSE, "Save Camera File", basepath, "camera");
-
-    if (filename) {
-        char fullpathtofile[PATH_MAX + 8];
-
-        Q_realpath(filename, fullpathtofile, PATH_MAX);
-
-        // 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
-        if (strcmp(fullpathtofile + (strlen(fullpathtofile) - 7), ".camera")) {
-            strcat(fullpathtofile, ".camera");
-
-            if (FileExists(fullpathtofile)) {
-                if (g_FuncTable.m_pfnMessageBox((GtkWidget *) g_pRadiantWnd, "File already exists.\nOverwrite?",
-                                                "Save Camera File", eMB_YESNO) == eIDNO) {
-                    return;
-                }
-            }
-        }
-
-        // 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
-                    break;
-                }
-            } else if (!strcmp(fullpathtofile, checkCam->GetFileName())) {
-                char error[PATH_MAX + 64];
-                sprintf(error,
-                        "Camera file \'%s\' is currently loaded by NetRadiant.\nPlease select a different filename.",
-                        fullpathtofile);
-                g_FuncTable.m_pfnMessageBox((GtkWidget *) g_pRadiantWnd, error, "Save error", eMB_OK);
-                return;
-            }
-            checkCam = checkCam->GetNext();
-        }
-
-        // FIXME: check for existing directory
-
-        GetCurrentCam()->GetCam()->save(fullpathtofile);
-        GetCurrentCam()->SetFileName(fullpathtofile, true);
-        RefreshCamListCombo();
-    }
+void DoSaveCamera() {
+       char basepath[PATH_MAX];
+
+       if ( !GetCurrentCam() ) {
+               return;
+       }
+
+       if ( GetCurrentCam()->GetFileName()[0] ) {
+               ExtractFilePath( GetCurrentCam()->GetFileName(), basepath );
+       }
+       else{
+               strcpy( basepath, g_FuncTable.m_pfnGetGamePath() );
+       }
+
+       const gchar *filename = g_FuncTable.m_pfnFileDialog( g_pRadiantWnd, FALSE, "Save Camera File", basepath, "camera" );
+
+       if ( filename ) {
+               char fullpathtofile[PATH_MAX + 8];
+
+               Q_realpath( filename, fullpathtofile, PATH_MAX );
+
+               // 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
+               if ( strcmp( fullpathtofile + ( strlen( fullpathtofile ) - 7 ), ".camera" ) ) {
+                       strcat( fullpathtofile, ".camera" );
+
+                       if ( FileExists( fullpathtofile ) ) {
+                               if ( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, "File already exists.\nOverwrite?", "Save Camera File", eMB_YESNO ) == eIDNO ) {
+                                       return;
+                               }
+                       }
+               }
+
+               // 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
+                                       break;
+                               }
+                       }
+                       else if ( !strcmp( fullpathtofile, checkCam->GetFileName() ) ) {
+                               char error[PATH_MAX + 64];
+                               sprintf( error, "Camera file \'%s\' is currently loaded by NetRadiant.\nPlease select a different filename.", fullpathtofile );
+                               g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, error, "Save error", eMB_OK );
+                               return;
+                       }
+                       checkCam = checkCam->GetNext();
+               }
+
+               // FIXME: check for existing directory
+
+               GetCurrentCam()->GetCam()->save( fullpathtofile );
+               GetCurrentCam()->SetFileName( fullpathtofile, true );
+               RefreshCamListCombo();
+       }
 }
 
-void DoUnloadCamera()
-{
-    if (!GetCurrentCam()) {
-        return;
-    }
-
-    if (!GetCurrentCam()->HasBeenSaved()) {
-        char buf[PATH_MAX + 64];
-        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", eMB_YESNO) == eIDYES) {
-            DoSaveCamera();
-        }
-    } else if (GetCurrentCam()->HasBeenSaved() == 2) {
-        char buf[PATH_MAX + 64];
-        sprintf(buf, "Do you want to save the changes made to camera file '%s'?", GetCurrentCam()->GetFileName());
-        if (g_FuncTable.m_pfnMessageBox((GtkWidget *) g_pRadiantWnd, buf, "Warning", eMB_YESNO) == eIDYES) {
-            DoSaveCamera();
-        }
-    }
-
-    if (g_pCurrentEditCam) {
-        DoStopEdit();
-        g_pCurrentEditCam = NULL;
-    }
-
-    FreeCam(GetCurrentCam());
-    SetCurrentCam(NULL);
-    RefreshCamListCombo();
+void DoUnloadCamera() {
+       if ( !GetCurrentCam() ) {
+               return;
+       }
+
+       if ( !GetCurrentCam()->HasBeenSaved() ) {
+               char buf[PATH_MAX + 64];
+               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", eMB_YESNO ) == eIDYES ) {
+                       DoSaveCamera();
+               }
+       }
+       else if ( GetCurrentCam()->HasBeenSaved() == 2 ) {
+               char buf[PATH_MAX + 64];
+               sprintf( buf, "Do you want to save the changes made to camera file '%s'?", GetCurrentCam()->GetFileName() );
+               if ( g_FuncTable.m_pfnMessageBox( (GtkWidget *)g_pRadiantWnd, buf, "Warning", eMB_YESNO ) == eIDYES ) {
+                       DoSaveCamera();
+               }
+       }
+
+       if ( g_pCurrentEditCam ) {
+               DoStopEdit();
+               g_pCurrentEditCam = NULL;
+       }
+
+       FreeCam( GetCurrentCam() );
+       SetCurrentCam( NULL );
+       RefreshCamListCombo();
 }
 
 CCamera *g_pCurrentEditCam = NULL;
 
-void DoStartEdit(CCamera *cam)
-{
-    if (g_pCurrentEditCam) {
-        DoStopEdit();
-        g_pCurrentEditCam = NULL;
-    }
+void DoStartEdit( CCamera *cam ) {
+       if ( g_pCurrentEditCam ) {
+               DoStopEdit();
+               g_pCurrentEditCam = NULL;
+       }
 
-    if (cam) {
-        g_bEditOn = true;
+       if ( cam ) {
+               g_bEditOn = true;
 
-        if (!Listener) {
-            Listener = new CListener;
-        }
+               if ( !Listener ) {
+                       Listener = new CListener;
+               }
 
-        cam->GetCam()->startEdit(g_iActiveTarget < 0 ? true : false);
+               cam->GetCam()->startEdit( g_iActiveTarget < 0 ? true : false );
 
-        g_pCurrentEditCam = cam;
+               g_pCurrentEditCam = cam;
 
-        g_FuncTable.m_pfnSysUpdateWindows(W_XY_OVERLAY | W_CAMERA);
-    }
+               g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
+       }
 }
 
-void DoStopEdit(void)
-{
-    g_bEditOn = false;
+void DoStopEdit( void ) {
+       g_bEditOn = false;
 
-    if (Listener) {
-        delete Listener;
-        Listener = NULL;
-    }
+       if ( Listener ) {
+               delete Listener;
+               Listener = NULL;
+       }
 
-    if (g_pCurrentEditCam) {
-        // stop editing on the current cam
-        g_pCurrentEditCam->GetCam()->stopEdit();
-        g_pCurrentEditCam = NULL;
+       if ( g_pCurrentEditCam ) {
+               // stop editing on the current cam
+               g_pCurrentEditCam->GetCam()->stopEdit();
+               g_pCurrentEditCam = NULL;
 
-        g_FuncTable.m_pfnSysUpdateWindows(W_XY_OVERLAY | W_CAMERA);
-    }
+               g_FuncTable.m_pfnSysUpdateWindows( W_XY_OVERLAY | W_CAMERA );
+       }
 }