OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::AnimatedTexture Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/AnimatedTexture.hpp>

Collaboration diagram for Slic3r::GUI::AnimatedTexture:

Classes

struct  Frame

Public Member Functions

 AnimatedTexture ()=default
 AnimatedTexture (AnimatedTexture &&)=default
AnimatedTexture & operator= (AnimatedTexture &&)=default
 AnimatedTexture (const AnimatedTexture &)=delete
AnimatedTexture & operator= (const AnimatedTexture &)=delete
bool load_from_file (const std::string &path)
void reset ()
bool is_valid () const
bool is_animated () const
int width () const
int height () const
double duration () const
unsigned int texture_id (double time) const

Private Attributes

std::vector< Frame > m_frames
int m_width {0}
int m_height {0}
double m_duration {0.}

Detailed Description


Class Documentation

◆ Slic3r::GUI::AnimatedTexture::Frame

struct Slic3r::GUI::AnimatedTexture::Frame
Collaboration diagram for Slic3r::GUI::AnimatedTexture::Frame:
Class Members
double delay {0.}
double start {0.}
unique_ptr< GLTexture > texture

Constructor & Destructor Documentation

◆ AnimatedTexture() [1/3]

Slic3r::GUI::AnimatedTexture::AnimatedTexture ( )
default

Referenced by AnimatedTexture(), AnimatedTexture(), operator=(), and operator=().

Here is the caller graph for this function:

◆ AnimatedTexture() [2/3]

Slic3r::GUI::AnimatedTexture::AnimatedTexture ( AnimatedTexture && )
default

References AnimatedTexture().

Here is the call graph for this function:

◆ AnimatedTexture() [3/3]

Slic3r::GUI::AnimatedTexture::AnimatedTexture ( const AnimatedTexture & )
delete

References AnimatedTexture().

Here is the call graph for this function:

Member Function Documentation

◆ duration()

double Slic3r::GUI::AnimatedTexture::duration ( ) const
inline
40{ return m_duration; }
double m_duration
Definition AnimatedTexture.hpp:56

References m_duration.

◆ height()

int Slic3r::GUI::AnimatedTexture::height ( ) const
inline
38{ return m_height; }
int m_height
Definition AnimatedTexture.hpp:55

References m_height.

Referenced by load_from_file(), and Slic3r::GUI::GLGizmoTextureDisplacement::render_tip_media().

Here is the caller graph for this function:

◆ is_animated()

bool Slic3r::GUI::AnimatedTexture::is_animated ( ) const
inline
36{ return m_frames.size() > 1; }
std::vector< Frame > m_frames
Definition AnimatedTexture.hpp:53

References m_frames.

Referenced by Slic3r::GUI::GLGizmoTextureDisplacement::render_tip_media().

Here is the caller graph for this function:

◆ is_valid()

bool Slic3r::GUI::AnimatedTexture::is_valid ( ) const
inline
35{ return !m_frames.empty(); }

References m_frames.

Referenced by Slic3r::GUI::GLGizmoTextureDisplacement::render_tip_media().

Here is the caller graph for this function:

◆ load_from_file()

bool Slic3r::GUI::AnimatedTexture::load_from_file ( const std::string & path)
151{
152 reset();
153
154 boost::system::error_code ec;
155 if (!boost::filesystem::is_regular_file(path, ec))
156 return false;
157
158 const std::vector<unsigned char> bytes = read_file_bytes(path);
159 if (bytes.empty())
160 return false;
161
162 std::vector<DecodedFrame> frames;
163 int width = 0, height = 0;
164
165 if (has_gif_signature(bytes)) {
166 if (!decode_gif(bytes, width, height, frames)) {
167 BOOST_LOG_TRIVIAL(error) << "AnimatedTexture: cannot decode GIF " << path;
168 return false;
169 }
170 } else {
171 wxLogNull no_log; // a format wxWidgets cannot read is handled here, not in a dialog
172 wxImage image;
173 wxMemoryInputStream stream(bytes.data(), bytes.size());
174 if (!image.LoadFile(stream, wxBITMAP_TYPE_ANY) || !image.IsOk()) {
175 BOOST_LOG_TRIVIAL(error) << "AnimatedTexture: cannot decode image " << path;
176 return false;
177 }
178 width = image.GetWidth();
179 height = image.GetHeight();
180 frames.push_back({ image_to_rgba(image), 0.0 });
181 }
182
183 m_width = width;
185 m_frames.reserve(frames.size());
186 for (DecodedFrame &frame : frames) {
187 auto texture = std::make_unique<GLTexture>();
188 // Mipmapped: a hint is drawn at whatever width the panel has room for, which is usually
189 // smaller than the source, and an unfiltered downscale of a diagram is all aliasing.
190 if (!texture->load_from_raw_data(std::move(frame.rgba), (unsigned int) width, (unsigned int) height, false,
191 /* use_mipmaps */ true)) {
192 BOOST_LOG_TRIVIAL(error) << "AnimatedTexture: cannot upload " << path;
193 reset();
194 return false;
195 }
196 m_frames.push_back({ std::move(texture), m_duration, frame.delay });
197 m_duration += frame.delay;
198 }
199 return true;
200}
int width() const
Definition AnimatedTexture.hpp:37
int height() const
Definition AnimatedTexture.hpp:38
void reset()
Definition AnimatedTexture.cpp:202
int m_width
Definition AnimatedTexture.hpp:54
bool has_gif_signature(const std::vector< unsigned char > &bytes)
Definition AnimatedTexture.cpp:38
bool decode_gif(const std::vector< unsigned char > &bytes, int &width, int &height, std::vector< DecodedFrame > &out)
Definition AnimatedTexture.cpp:75
std::vector< unsigned char > image_to_rgba(const wxImage &image)
Definition AnimatedTexture.cpp:45
std::vector< unsigned char > read_file_bytes(const std::string &path)
Definition AnimatedTexture.cpp:32

References height(), m_duration, m_frames, m_height, m_width, reset(), and width().

Here is the call graph for this function:

◆ operator=() [1/2]

AnimatedTexture & Slic3r::GUI::AnimatedTexture::operator= ( AnimatedTexture && )
default

References AnimatedTexture().

Here is the call graph for this function:

◆ operator=() [2/2]

AnimatedTexture & Slic3r::GUI::AnimatedTexture::operator= ( const AnimatedTexture & )
delete

References AnimatedTexture().

Here is the call graph for this function:

◆ reset()

void Slic3r::GUI::AnimatedTexture::reset ( )
203{
204 m_frames.clear();
205 m_width = 0;
206 m_height = 0;
207 m_duration = 0.;
208}

References m_duration, m_frames, m_height, and m_width.

Referenced by load_from_file().

Here is the caller graph for this function:

◆ texture_id()

unsigned int Slic3r::GUI::AnimatedTexture::texture_id ( double time) const
211{
212 if (m_frames.empty())
213 return 0;
214 if (m_frames.size() == 1 || m_duration <= 0.)
215 return m_frames.front().texture->get_id();
216
217 const double t = time - m_duration * std::floor(time / m_duration);
218 // Frames are few; a linear walk beats keeping an index around and getting it stale.
219 size_t i = 0;
220 while (i + 1 < m_frames.size() && t >= m_frames[i].start + m_frames[i].delay)
221 ++i;
222 return m_frames[i].texture->get_id();
223}

References m_duration, and m_frames.

Referenced by Slic3r::GUI::GLGizmoTextureDisplacement::render_tip_media().

Here is the caller graph for this function:

◆ width()

int Slic3r::GUI::AnimatedTexture::width ( ) const
inline
37{ return m_width; }

References m_width.

Referenced by load_from_file(), and Slic3r::GUI::GLGizmoTextureDisplacement::render_tip_media().

Here is the caller graph for this function:

Member Data Documentation

◆ m_duration

double Slic3r::GUI::AnimatedTexture::m_duration {0.}
private
56{0.};

Referenced by duration(), load_from_file(), reset(), and texture_id().

◆ m_frames

std::vector<Frame> Slic3r::GUI::AnimatedTexture::m_frames
private

◆ m_height

int Slic3r::GUI::AnimatedTexture::m_height {0}
private
55{0};

Referenced by height(), load_from_file(), and reset().

◆ m_width

int Slic3r::GUI::AnimatedTexture::m_width {0}
private
54{0};

Referenced by load_from_file(), reset(), and width().


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