improve animation panel
This commit is contained in:
@@ -38,11 +38,17 @@ void NodePanelAnimation::init_controls()
|
||||
btn_prev = find<NodeButtonCustom>("btn-prev");
|
||||
btn_play = find<NodeButtonCustom>("btn-play");
|
||||
m_fps = find<NodeComboBox>("fps");
|
||||
m_onion = find<NodeComboBox>("onion");
|
||||
m_frame_label = find<NodeText>("frame-index");
|
||||
|
||||
btn_add->on_click = [this](Node*) {
|
||||
Canvas::I->layer().add_frame();
|
||||
load_layers();
|
||||
};
|
||||
btn_remove->on_click = [this](Node*) {
|
||||
Canvas::I->layer_with_id(m_selected_frame_layer_id)->remove_frame(m_selected_frame_index);
|
||||
load_layers();
|
||||
};
|
||||
btn_up->on_click = [this](Node*) {
|
||||
if (auto layer = Canvas::I->layer_with_id(m_selected_frame_layer_id))
|
||||
layer->m_frames[m_selected_frame_index].m_duration =
|
||||
@@ -56,12 +62,24 @@ void NodePanelAnimation::init_controls()
|
||||
load_layers();
|
||||
};
|
||||
|
||||
m_onion->on_select = [this] (Node* target, int index) {
|
||||
m_timeline->m_onion_size = m_onion->get_int();
|
||||
};
|
||||
|
||||
m_timeline->on_frame_changed = [this] (NodeAnimationTimeline* target, int frame) {
|
||||
LOG("goto frame %d", frame);
|
||||
Canvas::I->anim_goto_frame(frame);
|
||||
load_layers();
|
||||
};
|
||||
|
||||
btn_next->on_click = [this] (Node* target) {
|
||||
Canvas::I->anim_goto_next();
|
||||
load_layers();
|
||||
};
|
||||
btn_prev->on_click = [this](Node* target) {
|
||||
Canvas::I->anim_goto_prev();
|
||||
load_layers();
|
||||
};
|
||||
btn_play->on_click = [this] (Node* target) {
|
||||
static auto mode = Canvas::I->m_current_mode;
|
||||
auto b = static_cast<NodeButtonCustom*>(target);
|
||||
@@ -90,7 +108,11 @@ void NodePanelAnimation::load_layers()
|
||||
m_frames_container->remove_all_children();
|
||||
auto& layers = Canvas::I->m_layers;
|
||||
m_selected_frame = nullptr;
|
||||
float max_width = 0;
|
||||
|
||||
float max_width = find("hscroll")->GetWidth() - 2;
|
||||
for (int i = 0; i < layers.size(); i++)
|
||||
max_width = glm::max(max_width, layers[i]->total_duration() * 35.f);
|
||||
|
||||
for (int i = 0; i < layers.size(); i++)
|
||||
{
|
||||
auto l = m_layers_container->add_child<NodeAnimationLayer>();
|
||||
@@ -98,8 +120,8 @@ void NodePanelAnimation::load_layers()
|
||||
l->set_selected(Canvas::I->m_current_layer_idx == i);
|
||||
l->set_chekcbox(layers[i]->m_visible);
|
||||
auto film = m_frames_container->add_child_ref<NodeAnimationFilm>();
|
||||
film->SetWidth(layers[i]->total_duration() * 35.f);
|
||||
max_width = glm::max(max_width, layers[i]->total_duration() * 35.f);
|
||||
//film->m_color = glm::vec4(glm::vec3(i % 2 ? .8 : .7), 1);
|
||||
film->SetWidth(max_width - 5);
|
||||
for (int fi = 0; fi < layers[i]->m_frames.size(); fi++)
|
||||
{
|
||||
auto b = film->add_frame(layers[i]->m_frames[fi].m_duration);
|
||||
@@ -118,11 +140,35 @@ void NodePanelAnimation::load_layers()
|
||||
m_selected_frame = frame;
|
||||
m_selected_frame_layer_id = lid;
|
||||
m_selected_frame_index = fi;
|
||||
m_timeline->m_frame = fi;
|
||||
Canvas::I->anim_goto_frame(fi);
|
||||
App::I->layers->handle_layer_selected(App::I->layers->get_layer_at(i));
|
||||
};
|
||||
}
|
||||
}
|
||||
m_timeline->SetWidth(max_width);
|
||||
m_timeline->SetWidth(max_width - 4);
|
||||
m_timeline->m_frame = Canvas::I->m_anim_frame;
|
||||
m_timeline->m_onion_size = m_onion->get_int();
|
||||
update_frames();
|
||||
}
|
||||
|
||||
void NodePanelAnimation::update_frames()
|
||||
{
|
||||
int total_frames = Canvas::I->anim_duration();
|
||||
int digits = (int)floor(glm::log(total_frames));
|
||||
m_frame_label->set_text_format("%0*d/%d", digits, m_timeline->m_frame + 1, total_frames);
|
||||
}
|
||||
|
||||
void NodePanelAnimation::handle_resize(glm::vec2 old_size, glm::vec2 new_size, float zoom)
|
||||
{
|
||||
parent::handle_resize(old_size, new_size, zoom);
|
||||
auto& layers = Canvas::I->m_layers;
|
||||
float max_width = find("hscroll")->GetWidth() - 2;
|
||||
for (int i = 0; i < layers.size(); i++)
|
||||
max_width = glm::max(max_width, layers[i]->total_duration() * 35.f);
|
||||
for (auto& film : m_frames_container->m_children)
|
||||
film->SetWidth(max_width - 5);
|
||||
m_timeline->SetWidth(max_width - 4);
|
||||
}
|
||||
|
||||
void NodePanelAnimation::on_tick(float dt)
|
||||
@@ -136,6 +182,7 @@ void NodePanelAnimation::on_tick(float dt)
|
||||
m_playback_timer = 0;
|
||||
Canvas::I->anim_goto_next();
|
||||
m_timeline->m_frame = Canvas::I->m_anim_frame;
|
||||
update_frames();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,17 +228,12 @@ void NodeAnimationLayer::draw()
|
||||
parent::draw();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void NodeAnimationTimeline::draw()
|
||||
{
|
||||
parent::draw();
|
||||
ShaderManager::use(kShader::Color);
|
||||
ShaderManager::u_vec4(kShaderUniform::Col, m_cursor_color);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
float step = 35.f;
|
||||
@@ -199,21 +241,31 @@ void NodeAnimationTimeline::draw()
|
||||
m_pos.x + step * m_frame + step * 0.5f,
|
||||
m_pos.y + m_size.y * 0.5f
|
||||
};
|
||||
|
||||
ShaderManager::u_vec4(kShaderUniform::Col, glm::vec4(glm::vec3(m_cursor_color) * 0.5f, 1.f));
|
||||
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, m_proj
|
||||
* glm::translate(glm::vec3(cur_pos, 0))
|
||||
* glm::scale(glm::vec3(step * 0.25f, m_size.y * 0.5f, 1))
|
||||
* glm::scale(glm::vec3(step * m_onion_size * 2.f, m_size.y * 0.5f, 1))
|
||||
);
|
||||
m_plane.draw_fill();
|
||||
|
||||
//bool scissor = glIsEnabled(GL_SCISSOR_TEST);
|
||||
//glDisable(GL_SCISSOR_TEST);
|
||||
ShaderManager::u_vec4(kShaderUniform::Col, m_cursor_color);
|
||||
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, m_proj
|
||||
* glm::translate(glm::vec3(cur_pos, 0))
|
||||
* glm::scale(glm::vec3(step * 0.25f, m_size.y * 0.75f, 1))
|
||||
);
|
||||
m_plane.draw_fill();
|
||||
|
||||
/*
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, m_proj
|
||||
* glm::translate(glm::vec3(cur_pos, 0))
|
||||
* glm::scale(glm::vec3(step * 0.15f, m_size.y * 0.5f, 1))
|
||||
* glm::translate(glm::vec3(0, .5, 0))
|
||||
);
|
||||
m_plane.draw_fill();
|
||||
//scissor ? glEnable(GL_SCISSOR_TEST) : glDisable(GL_SCISSOR_TEST);
|
||||
*/
|
||||
}
|
||||
|
||||
kEventResult NodeAnimationTimeline::handle_event(Event* e)
|
||||
|
||||
Reference in New Issue
Block a user