瀏覽代碼

add make_screenshot_filename()

David Rose 20 年之前
父節點
當前提交
bda902a6d6

+ 25 - 10
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
 //                 %~p - the supplied prefix
 //                 %~f - the frame count
 //                 %~f - the frame count
@@ -439,7 +440,7 @@ output(ostream &out) const {
 //                 All other % strings in strftime().
 //                 All other % strings in strftime().
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 Filename DisplayRegion::
 Filename DisplayRegion::
-save_screenshot_default(const string &prefix) {
+make_screenshot_filename(const string &prefix) {
   time_t now = time(NULL);
   time_t now = time(NULL);
   struct tm *ttm = localtime(&now);
   struct tm *ttm = localtime(&now);
   int frame_count = ClockObject::get_global_clock()->get_frame_count();
   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)) {
   if (save_screenshot(filename)) {
     return filename;
     return filename;
   }
   }

+ 1 - 0
panda/src/display/displayRegion.h

@@ -97,6 +97,7 @@ PUBLISHED:
 
 
   void output(ostream &out) const;
   void output(ostream &out) const;
 
 
+  static Filename make_screenshot_filename(const string &prefix = "screenshot");
   Filename save_screenshot_default(const string &prefix = "screenshot");
   Filename save_screenshot_default(const string &prefix = "screenshot");
   bool save_screenshot(const Filename &filename);
   bool save_screenshot(const Filename &filename);
   bool get_screenshot(PNMImage &image);
   bool get_screenshot(PNMImage &image);

+ 15 - 2
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
 //  Description: Saves a screenshot of the region to a default
 //               filename, and returns the filename, or empty string
 //               filename, and returns the filename, or empty string
 //               if the screenshot failed.  The default filename is
 //               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().
 //                 All other % strings in strftime().
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE Filename GraphicsOutput::
 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) {
 save_screenshot_default(const string &prefix) {
   return _default_display_region->save_screenshot_default(prefix);
   return _default_display_region->save_screenshot_default(prefix);
 }
 }

+ 1 - 0
panda/src/display/graphicsOutput.h

@@ -115,6 +115,7 @@ PUBLISHED:
   GraphicsOutput *make_cube_map(const string &name, int size, bool to_ram,
   GraphicsOutput *make_cube_map(const string &name, int size, bool to_ram,
                                 NodePath &camera_rig, DrawMask camera_mask);
                                 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 Filename save_screenshot_default(const string &prefix = "screenshot");
   INLINE bool save_screenshot(const Filename &filename);
   INLINE bool save_screenshot(const Filename &filename);
   INLINE bool get_screenshot(PNMImage &image);
   INLINE bool get_screenshot(PNMImage &image);