Add a timer to get the animations going.
This commit is contained in:
parent
78e72d0bcb
commit
88be1a1247
3 changed files with 20 additions and 6 deletions
|
@ -100,7 +100,7 @@ void MemoservWin::open_file_from_dialog() {
|
|||
|
||||
m_memcards.push_back(mc::psx::make_memory_card(file.toStdString()));
|
||||
auto& mc = m_memcards.back();
|
||||
auto grid = std::make_unique<widget::BlockGrid>(this, 3);
|
||||
auto grid = std::make_unique<widget::BlockGrid>(this, 3, g_icon_fps);
|
||||
for (const auto& block : mc) {
|
||||
for (std::size_t n = 0; block.has_magic() and n < block.block_count(); ++n) {
|
||||
grid->emplace_back(make_qt_animation(block, g_icon_size, g_icon_size, g_icon_fps));
|
||||
|
|
|
@ -16,9 +16,8 @@
|
|||
*/
|
||||
|
||||
#include "block_grid.hpp"
|
||||
#include <QGridLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPainter>
|
||||
#include <QTimer>
|
||||
#include <algorithm>
|
||||
|
||||
namespace duck::widget {
|
||||
|
@ -26,10 +25,14 @@ namespace {
|
|||
const constexpr int g_icon_spacing = 3;
|
||||
} //unnamed namespace
|
||||
|
||||
BlockGrid::BlockGrid (QWidget* parent, unsigned int columns) :
|
||||
BlockGrid::BlockGrid (QWidget* parent, unsigned int columns, float fps) :
|
||||
QWidget(parent),
|
||||
m_anim_timer(new QTimer(this)),
|
||||
m_columns(columns)
|
||||
{
|
||||
fps = std::max(fps, 1.0f);
|
||||
m_anim_timer->start(1000.0f / fps);
|
||||
connect(m_anim_timer, &QTimer::timeout, this, &BlockGrid::advance_frame);
|
||||
}
|
||||
|
||||
BlockGrid::~BlockGrid() noexcept = default;
|
||||
|
@ -96,4 +99,11 @@ void BlockGrid::paintEvent (QPaintEvent* event) {
|
|||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
void BlockGrid::advance_frame() {
|
||||
for (auto& ico : m_icons) {
|
||||
ico.advance_frame();
|
||||
}
|
||||
this->update();
|
||||
}
|
||||
} //namespace duck::widget
|
||||
|
|
|
@ -22,13 +22,13 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class QGridLayout;
|
||||
class QTimer;
|
||||
|
||||
namespace duck::widget {
|
||||
class BlockGrid : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit BlockGrid (QWidget* parent=nullptr, unsigned int columns=0);
|
||||
explicit BlockGrid (QWidget* parent=nullptr, unsigned int columns=0, float fps=24.0f);
|
||||
~BlockGrid() noexcept;
|
||||
|
||||
QSize minimumSizeHint() const override;
|
||||
|
@ -43,10 +43,14 @@ public:
|
|||
protected:
|
||||
void paintEvent (QPaintEvent* event) override;
|
||||
|
||||
private slots:
|
||||
void advance_frame();
|
||||
|
||||
private:
|
||||
unsigned int columns() const;
|
||||
|
||||
std::vector<AnimatedPixmap> m_icons;
|
||||
QTimer* m_anim_timer;
|
||||
unsigned int m_columns;
|
||||
};
|
||||
} //namespace duck::widget
|
||||
|
|
Loading…
Add table
Reference in a new issue