add animation playback
This commit is contained in:
@@ -34,6 +34,10 @@ void NodePanelAnimation::init_controls()
|
||||
btn_up = find<NodeButtonCustom>("btn-up");
|
||||
btn_down = find<NodeButtonCustom>("btn-down");
|
||||
btn_duplicate = find<NodeButtonCustom>("btn-duplicate");
|
||||
btn_next = find<NodeButtonCustom>("btn-next");
|
||||
btn_prev = find<NodeButtonCustom>("btn-prev");
|
||||
btn_play = find<NodeButtonCustom>("btn-play");
|
||||
m_fps = find<NodeComboBox>("fps");
|
||||
|
||||
btn_add->on_click = [this](Node*) {
|
||||
Canvas::I->layer().add_frame();
|
||||
@@ -57,6 +61,25 @@ void NodePanelAnimation::init_controls()
|
||||
Canvas::I->anim_goto_frame(frame);
|
||||
load_layers();
|
||||
};
|
||||
|
||||
btn_play->on_click = [this] (Node* target) {
|
||||
static auto mode = Canvas::I->m_current_mode;
|
||||
auto b = static_cast<NodeButtonCustom*>(target);
|
||||
if (b->is_active())
|
||||
{
|
||||
Canvas::set_mode(mode);
|
||||
b->set_active(false);
|
||||
App::I->idle_ms = 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
mode = Canvas::I->m_current_mode;
|
||||
Canvas::set_mode(kCanvasMode::Camera);
|
||||
m_playback_timer = 0;
|
||||
b->set_active(true);
|
||||
App::I->idle_ms = 10;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void NodePanelAnimation::load_layers()
|
||||
@@ -102,6 +125,21 @@ void NodePanelAnimation::load_layers()
|
||||
m_timeline->SetWidth(max_width);
|
||||
}
|
||||
|
||||
void NodePanelAnimation::on_tick(float dt)
|
||||
{
|
||||
parent::on_tick(dt);
|
||||
if (btn_play->is_active())
|
||||
{
|
||||
m_playback_timer += dt;
|
||||
if (m_playback_timer > (1.f / m_fps->get_float()))
|
||||
{
|
||||
m_playback_timer = 0;
|
||||
Canvas::I->anim_goto_next();
|
||||
m_timeline->m_frame = Canvas::I->m_anim_frame;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NodePanelAnimation::added(Node* parent)
|
||||
{
|
||||
parent::added(parent);
|
||||
|
||||
Reference in New Issue
Block a user