68 lines
1.7 KiB
C++
68 lines
1.7 KiB
C++
#include "Animation/ImageScrollerAnimation.h"
|
|
|
|
#include <iostream>
|
|
|
|
ImageScrollerAnimation::ImageScrollerAnimation(Fader *fader, Bitmap *image, uint32_t interval, bool finish_scrolling)
|
|
: Animation(fader),
|
|
m_image(*image),
|
|
m_interval(interval),
|
|
m_finishScrolling(finish_scrolling)
|
|
{
|
|
reset();
|
|
}
|
|
|
|
void ImageScrollerAnimation::loop(uint64_t frame)
|
|
{
|
|
int32_t nled = m_fader->modules_per_strip();
|
|
int32_t nstrip = m_fader->strips();
|
|
|
|
if((frame % m_interval) != 0) {
|
|
return;
|
|
}
|
|
|
|
if(m_stopping && !m_finishScrolling) {
|
|
m_fader->set_fadestep(3);
|
|
m_fader->fade_color(Fader::Color{0, 0, 0, 0});
|
|
|
|
m_running = false;
|
|
return;
|
|
}
|
|
|
|
// blit the image
|
|
m_fader->set_color(Fader::Color{0, 0, 0, 0});
|
|
|
|
for(int32_t strip = 0; strip < nstrip; strip++) {
|
|
for(int32_t led = 0; led < nled; led++) {
|
|
int32_t im_x = m_startIdx - strip;
|
|
int32_t im_y = m_fader->modules_per_strip() - led - 1;
|
|
|
|
if(im_x < 0 || im_x >= m_image.width || im_y < 0 || im_y >= m_image.height) {
|
|
// the current pixel is not inside the shifted image
|
|
continue;
|
|
}
|
|
|
|
int32_t s = (nstrip - strip - 1 + 5) % nstrip;
|
|
m_fader->set_color(s, led, m_image.pixel(im_x, im_y));
|
|
}
|
|
}
|
|
|
|
// move the image around the lamp
|
|
m_startIdx++;
|
|
|
|
if(m_startIdx >= static_cast<int32_t>(nstrip + m_image.width)) {
|
|
if(m_stopping) {
|
|
m_running = false;
|
|
} else {
|
|
reset();
|
|
}
|
|
}
|
|
}
|
|
|
|
void ImageScrollerAnimation::reset(void)
|
|
{
|
|
m_stopping = false;
|
|
m_running = true;
|
|
|
|
m_startIdx = 0;
|
|
}
|