diff --git a/macosx/CelestiaAppCore.h b/macosx/CelestiaAppCore.h index 16e44540f..749a5bc82 100644 --- a/macosx/CelestiaAppCore.h +++ b/macosx/CelestiaAppCore.h @@ -70,5 +70,8 @@ class CelestiaCore; -(void)showInfoURL; -(void)keyDown:(int)c withModifiers:(int)m; -(void)keyUp:(int)c withModifiers:(int)m; +- (BOOL) captureMovie: (NSString*)filename width: (int)width height: (int)height + frameRate: (float)framerate; + @end diff --git a/macosx/CelestiaAppCore.mm b/macosx/CelestiaAppCore.mm index f1c16ea26..42f2879c3 100644 --- a/macosx/CelestiaAppCore.mm +++ b/macosx/CelestiaAppCore.mm @@ -21,6 +21,7 @@ #import "CelestiaController.h" #include "celestiacore.h" +#include "qtcapture.h" /* void initMovieCapture(MovieCapture *) @@ -676,5 +677,21 @@ static NSMutableDictionary* tagDict; } } +- (BOOL) captureMovie: (NSString*) filename width: (int) width height: (int) height + frameRate: (float) framerate +{ + MovieCapture* movieCapture = new QTCapture(); + + bool success = movieCapture->start([filename cString], width, height, framerate); + if (success) + appCore->initMovieCapture(movieCapture); + else + delete movieCapture; + + return success; + return true; +} + + @end diff --git a/macosx/CelestiaController.h b/macosx/CelestiaController.h index 436502342..8a9473e84 100644 --- a/macosx/CelestiaController.h +++ b/macosx/CelestiaController.h @@ -68,6 +68,8 @@ -(IBAction) showPanel: (id) sender; +- (IBAction) captureMovie: (id) sender; + -(void)addSurfaceMenu:(NSMenu*)contextMenu; -(BOOL)validateMenuItem:(id)item; -(IBAction)activateMenuItem:(id)item; diff --git a/macosx/CelestiaController.m b/macosx/CelestiaController.m index 5793c1a5a..26ed81067 100644 --- a/macosx/CelestiaController.m +++ b/macosx/CelestiaController.m @@ -697,6 +697,38 @@ NSString* fatalErrorMessage; [appCore showInfoURL]; } +- (void) moviePanelDidEnd:(NSSavePanel*)savePanel returnCode: (int) rc contextInfo: (void *) ci +{ +// if (rc == NSOKButton ) + if (rc == 0 ) return; + { + NSString *path; + path = [savePanel filename]; + NSLog(@"Saving movie: %@",path); + [appCore captureMovie: path width: 640 height: 480 frameRate: 30 ]; + } +} + +- (IBAction) captureMovie: (id) sender +{ +// Remove following line to enable movie capture... + NSRunAlertPanel(@"No Movie Capture",@"Movie capture is not available in this version of Celestia.",nil,nil,nil); return; + + NSSavePanel* panel = [[NSSavePanel alloc] init]; + NSString* lastMovie = nil; // temporary; should be saved in defaults + + [panel setRequiredFileType: @"mov"]; + [panel setTitle: @"Capture Movie"]; + [panel setMessage: @"Capture Movie"]; + [ panel beginSheetForDirectory: [lastMovie stringByDeletingLastPathComponent] + file: [lastMovie lastPathComponent] + modalForWindow: [glView window] + modalDelegate: self + didEndSelector: @selector(moviePanelDidEnd:returnCode:contextInfo:) + contextInfo: nil + ]; +} + // GUI Tag Methods ---------------------------------------------------------- - (BOOL) validateMenuItem: (id) item diff --git a/macosx/English.lproj/MainMenu.nib/classes.nib b/macosx/English.lproj/MainMenu.nib/classes.nib index 2bcee39d8..8b7924fae 100644 --- a/macosx/English.lproj/MainMenu.nib/classes.nib +++ b/macosx/English.lproj/MainMenu.nib/classes.nib @@ -10,6 +10,7 @@ ACTIONS = { activateMenuItem = id; back = id; + captureMovie = id; forward = id; openScript = id; rerunScript = id; diff --git a/macosx/English.lproj/MainMenu.nib/info.nib b/macosx/English.lproj/MainMenu.nib/info.nib index 9a5503f93..47641f8eb 100644 --- a/macosx/English.lproj/MainMenu.nib/info.nib +++ b/macosx/English.lproj/MainMenu.nib/info.nib @@ -9,7 +9,7 @@ 242 441 337 270 342 0 0 1152 746 29 - 57 787 721 44 0 0 1280 832 + 90 957 721 44 0 0 1600 1002 296 555 398 170 341 0 0 1280 832 335 @@ -27,12 +27,12 @@ IBOpenObjects - 383 - 21 - 29 1310 + 383 + 29 + 21 IBSystem Version - 7W98 + 7D28 diff --git a/macosx/English.lproj/MainMenu.nib/objects.nib b/macosx/English.lproj/MainMenu.nib/objects.nib index 1058af05e..a2c2b23ef 100644 Binary files a/macosx/English.lproj/MainMenu.nib/objects.nib and b/macosx/English.lproj/MainMenu.nib/objects.nib differ diff --git a/macosx/celestia.xcode/project.pbxproj b/macosx/celestia.xcode/project.pbxproj index dde083dc4..b68c520f5 100644 --- a/macosx/celestia.xcode/project.pbxproj +++ b/macosx/celestia.xcode/project.pbxproj @@ -65,6 +65,59 @@ //082 //083 //084 +//0C0 +//0C1 +//0C2 +//0C3 +//0C4 + 0C76BFC0085215B100D31A90 = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + name = moviecapture.h; + path = ../src/celestia/moviecapture.h; + refType = 2; + sourceTree = SOURCE_ROOT; + }; + 0C76BFC1085215B100D31A90 = { + fileRef = 0C76BFC0085215B100D31A90; + isa = PBXBuildFile; + settings = { + }; + }; + 0C76BFCF08537EDB00D31A90 = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.cpp.cpp; + path = qtcapture.cpp; + refType = 2; + sourceTree = SOURCE_ROOT; + }; + 0C76BFD008537EDB00D31A90 = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = qtcapture.h; + refType = 2; + sourceTree = SOURCE_ROOT; + }; + 0C76BFD108537EDB00D31A90 = { + fileRef = 0C76BFCF08537EDB00D31A90; + isa = PBXBuildFile; + settings = { + }; + }; + 0C76BFD208537EDB00D31A90 = { + fileRef = 0C76BFD008537EDB00D31A90; + isa = PBXBuildFile; + settings = { + }; + }; +//0C0 +//0C1 +//0C2 +//0C3 +//0C4 //100 //101 //102 @@ -567,6 +620,8 @@ E589B6DE078AC511005B8DD9, E589B6E0078AC511005B8DD9, E56A5AEC0848F92200A21D7E, + 0C76BFC1085215B100D31A90, + 0C76BFD208537EDB00D31A90, ); isa = PBXHeadersBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -1544,6 +1599,7 @@ E589B6DF078AC511005B8DD9, E56A3DB80848C19800A21D7E, E56A5AED0848F92200A21D7E, + 0C76BFD108537EDB00D31A90, ); isa = PBXSourcesBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -3229,17 +3285,20 @@ }; F51C6D51029596B4014901DC = { children = ( - E56431450776D52D00E2C4A3, F51C6D8B02959960014901DC, + E56431450776D52D00E2C4A3, F51C6D8C02959960014901DC, F51C6D8D02959960014901DC, F51C6D8E02959960014901DC, + 0C76BFCF08537EDB00D31A90, + F53036BB03D908CE01000002, F51C6D9A02959960014901DC, E56431460776D52D00E2C4A3, F51C6D9B02959960014901DC, F51C6D9C02959960014901DC, F51C6D9D02959960014901DC, - F53036BB03D908CE01000002, + 0C76BFC0085215B100D31A90, + 0C76BFD008537EDB00D31A90, F53036BC03D908CE01000002, ); isa = PBXGroup; diff --git a/macosx/qtcapture.cpp b/macosx/qtcapture.cpp new file mode 100644 index 000000000..709c4637f --- /dev/null +++ b/macosx/qtcapture.cpp @@ -0,0 +1,105 @@ +// qtcapture.cpp +// +// Copyright (C) 2001, Chris Laurel +// +// This program 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. + +#include + +#include "../src/celengine/gl.h" +#include "../src/celengine/glext.h" + +#include +#include "qtcapture.h" + +using namespace std; + + +QTCapture::QTCapture() : + width(-1), + height(-1), + frameRate(30.0f), + frameCounter(0), + capturing(false) +{ +} + + +QTCapture::~QTCapture() +{ + cleanup(); +} + + +bool QTCapture::start(const string& filename, + int w, int h, + float fps) +{ + if (capturing) + return false; + + width = w; + height = h; + frameRate = fps; + + capturing = true; + frameCounter = 0; + + return true; +} + + +bool QTCapture::end() +{ + capturing = false; + cleanup(); + + return true; +} + + +bool QTCapture::captureFrame() +{ + if (!capturing) + return false; + + // Get the dimensions of the current viewport + GLint viewport[4]; + glGetIntegerv(GL_VIEWPORT, viewport); + + int x = viewport[0] + (viewport[2] - width) / 2; + int y = viewport[1] + (viewport[3] - height) / 2; + + frameCounter++; + + return true; +} + + +void QTCapture::cleanup() +{ +} + + +int QTCapture::getWidth() const +{ + return width; +} + +int QTCapture::getHeight() const +{ + return height; +} + +float QTCapture::getFrameRate() const +{ + return frameRate; +} + +int QTCapture::getFrameCount() const +{ + return frameCounter; +} diff --git a/macosx/qtcapture.h b/macosx/qtcapture.h new file mode 100644 index 000000000..b683aa677 --- /dev/null +++ b/macosx/qtcapture.h @@ -0,0 +1,43 @@ +// qtcapture.h +// +// Copyright (C) 2001, Chris Laurel +// +// This program 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. + +#ifndef _QTCAPTURE_H_ +#define _QTCAPTURE_H_ + +// #include +#include "moviecapture.h" + + +class QTCapture : public MovieCapture +{ + public: + QTCapture(); + virtual ~QTCapture(); + + bool start(const std::string& filename, int w, int h, float fps); + bool end(); + bool captureFrame(); + + int getWidth() const; + int getHeight() const; + float getFrameRate() const; + int getFrameCount() const; + + private: + void cleanup(); + + private: + int width; + int height; + float frameRate; + int frameCounter; + bool capturing; +}; + +#endif // _QTCAPTURE_H_