SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLIOWriterBrowserPopup Class Reference

SLIOStream implementation to display PNG files in a browser popup. More...

#include <SLIOBrowserPopup.h>

Inheritance diagram for SLIOWriterBrowserPopup:
[legend]

Public Member Functions

 SLIOWriterBrowserPopup (std::string path)
 
 ~SLIOWriterBrowserPopup ()
 
void flush ()
 
- Public Member Functions inherited from SLIOWriterMemory
 SLIOWriterMemory (std::string path)
 
size_t write (const void *buffer, size_t size)
 
size_t tell ()
 
bool seek (size_t offset, Origin origin)
 
void flush ()
 
- Public Member Functions inherited from SLIOStream
virtual ~SLIOStream ()=default
 
virtual size_t read (void *buffer, size_t size)
 
virtual size_t size ()
 

Additional Inherited Members

- Public Types inherited from SLIOStream
enum  Origin { IOO_beg , IOO_cur , IOO_end }
 
- Protected Attributes inherited from SLIOWriterMemory
std::string _path
 
size_t _position
 

Detailed Description

SLIOStream implementation to display PNG files in a browser popup.

The popup with the PNG image is opened when SLIOWriterBrowserPopup::flush is called. The popup contains a link for the user to download the file.

Definition at line 23 of file SLIOBrowserPopup.h.

Constructor & Destructor Documentation

◆ SLIOWriterBrowserPopup()

SLIOWriterBrowserPopup::SLIOWriterBrowserPopup ( std::string  path)

Definition at line 16 of file SLIOBrowserPopup.cpp.

17  : SLIOWriterMemory(path)
18 {
19  assert(Utils::endsWithString(path, ".png") && "SLIOWriteBrowserDisplay only supports PNG files");
20 }
SLIOWriterMemory(std::string path)
Definition: SLIOMemory.cpp:81
bool endsWithString(const string &container, const string &endStr)
Return true if the container string ends with the endStr.
Definition: Utils.cpp:357

◆ ~SLIOWriterBrowserPopup()

SLIOWriterBrowserPopup::~SLIOWriterBrowserPopup ( )

Definition at line 22 of file SLIOBrowserPopup.cpp.

23 {
25 }
std::string _path
Definition: SLIOMemory.h:52
void clear(std::string path)
Definition: SLIOMemory.cpp:34

Member Function Documentation

◆ flush()

void SLIOWriterBrowserPopup::flush ( )
virtual

Reimplemented from SLIOStream.

Definition at line 27 of file SLIOBrowserPopup.cpp.

28 {
29  std::vector<char>& buffer = SLIOMemory::get(_path);
30  const char* data = buffer.data();
31  size_t length = buffer.size();
32 
33  std::string filename = Utils::getFileName(_path);
34 
35  // clang-format off
36  MAIN_THREAD_EM_ASM({
37  let path = UTF8ToString($0);
38  let section = HEAPU8.subarray($1, $1 + $2);
39  let array = new Uint8Array(section);
40  let blob = new Blob([array], {"type": "image/png"});
41  globalThis.snapshotURL = URL.createObjectURL(blob);
42 
43  let link = document.querySelector("#snapshot-download");
44  link.href = snapshotURL;
45  link.download = path;
46 
47  document.querySelector("#snapshot-image").src = snapshotURL;
48  document.querySelector("#snapshot-overlay").classList.add("visible");
49  }, filename.c_str(), data, length);
50  // clang-format on
51 }
std::vector< char > & get(std::string path)
Definition: SLIOMemory.cpp:24
string getFileName(const string &pathFilename)
Returns the filename of path-filename string.
Definition: Utils.cpp:580

The documentation for this class was generated from the following files: