From bda902a6d6f9b05b7f3697f6f62af09cb3beb544 Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 3 Oct 2005 14:34:05 +0000 Subject: [PATCH] add make_screenshot_filename() --- panda/src/display/displayRegion.cxx | 35 ++++++++++++++++++++--------- panda/src/display/displayRegion.h | 1 + panda/src/display/graphicsOutput.I | 17 ++++++++++++-- panda/src/display/graphicsOutput.h | 1 + 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/panda/src/display/displayRegion.cxx b/panda/src/display/displayRegion.cxx index 9ec43ba58e..7b78465150 100644 --- a/panda/src/display/displayRegion.cxx +++ b/panda/src/display/displayRegion.cxx @@ -424,14 +424,15 @@ output(ostream &out) const { } //////////////////////////////////////////////////////////////////// -// Function: DisplayRegion::save_screenshot_default -// Access: Published -// Description: Saves a screenshot of the region to a default -// filename, and returns the filename, or empty string -// if the screenshot failed. The default filename is -// generated from the supplied prefix and from the -// Config variable screenshot-filename, which contains -// the following strings: +// Function: DisplayRegion::make_screenshot_filename +// Access: Published, Static +// Description: Synthesizes a suitable default filename for passing +// to save_screenshot(). +// +// The default filename is generated from the supplied +// prefix and from the Config variable +// screenshot-filename, which contains the following +// strings: // // %~p - the supplied prefix // %~f - the frame count @@ -439,7 +440,7 @@ output(ostream &out) const { // All other % strings in strftime(). //////////////////////////////////////////////////////////////////// Filename DisplayRegion:: -save_screenshot_default(const string &prefix) { +make_screenshot_filename(const string &prefix) { time_t now = time(NULL); struct tm *ttm = localtime(&now); int frame_count = ClockObject::get_global_clock()->get_frame_count(); @@ -496,7 +497,21 @@ save_screenshot_default(const string &prefix) { } } - Filename filename = filename_strm.str(); + return Filename(filename_strm.str()); +} + + +//////////////////////////////////////////////////////////////////// +// Function: DisplayRegion::save_screenshot_default +// Access: Published +// Description: Saves a screenshot of the region to a default +// filename, and returns the filename, or empty string +// if the screenshot failed. The filename is generated +// by make_screenshot_filename(). +//////////////////////////////////////////////////////////////////// +Filename DisplayRegion:: +save_screenshot_default(const string &prefix) { + Filename filename = make_screenshot_filename(prefix); if (save_screenshot(filename)) { return filename; } diff --git a/panda/src/display/displayRegion.h b/panda/src/display/displayRegion.h index 2df1ee9c0b..4f62bd18c4 100644 --- a/panda/src/display/displayRegion.h +++ b/panda/src/display/displayRegion.h @@ -97,6 +97,7 @@ PUBLISHED: void output(ostream &out) const; + static Filename make_screenshot_filename(const string &prefix = "screenshot"); Filename save_screenshot_default(const string &prefix = "screenshot"); bool save_screenshot(const Filename &filename); bool get_screenshot(PNMImage &image); diff --git a/panda/src/display/graphicsOutput.I b/panda/src/display/graphicsOutput.I index 378f25593c..ca63f4ca0b 100644 --- a/panda/src/display/graphicsOutput.I +++ b/panda/src/display/graphicsOutput.I @@ -265,8 +265,8 @@ make_display_region(float l, float r, float b, float t) { } //////////////////////////////////////////////////////////////////// -// Function: GraphicsOutput::save_screenshot_default -// Access: Published +// Function: GraphicsOutput::make_screenshot_filename +// Access: Published, Static // Description: Saves a screenshot of the region to a default // filename, and returns the filename, or empty string // if the screenshot failed. The default filename is @@ -280,6 +280,19 @@ make_display_region(float l, float r, float b, float t) { // All other % strings in strftime(). //////////////////////////////////////////////////////////////////// INLINE Filename GraphicsOutput:: +make_screenshot_filename(const string &prefix) { + return DisplayRegion::make_screenshot_filename(prefix); +} + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsOutput::save_screenshot_default +// Access: Published +// Description: Saves a screenshot of the region to a default +// filename, and returns the filename, or empty string +// if the screenshot failed. The filename is generated +// by make_screenshot_filename(). +//////////////////////////////////////////////////////////////////// +INLINE Filename GraphicsOutput:: save_screenshot_default(const string &prefix) { return _default_display_region->save_screenshot_default(prefix); } diff --git a/panda/src/display/graphicsOutput.h b/panda/src/display/graphicsOutput.h index fef336e83a..bf3d0864a6 100644 --- a/panda/src/display/graphicsOutput.h +++ b/panda/src/display/graphicsOutput.h @@ -115,6 +115,7 @@ PUBLISHED: GraphicsOutput *make_cube_map(const string &name, int size, bool to_ram, NodePath &camera_rig, DrawMask camera_mask); + INLINE static Filename make_screenshot_filename(const string &prefix = "screenshot"); INLINE Filename save_screenshot_default(const string &prefix = "screenshot"); INLINE bool save_screenshot(const Filename &filename); INLINE bool get_screenshot(PNMImage &image);