improve quick panel switch state
This commit is contained in:
@@ -34,13 +34,15 @@ int NodePanelQuick::get_selected_brush_index() const
|
||||
return std::distance(m_button_brushes.begin(), it);
|
||||
}
|
||||
|
||||
void NodePanelQuick::set_selected_brush_index(int idx)
|
||||
void NodePanelQuick::set_selected_brush_index(int idx, bool fire_event /*= false*/)
|
||||
{
|
||||
if (m_button_brush_current)
|
||||
m_button_brush_current->set_active(false);
|
||||
m_button_brush_current = m_button_brushes[idx];
|
||||
m_button_brush_current->set_active(true);
|
||||
m_button_brush_current_preview = static_cast<NodeStrokePreview*>(m_button_brush_current->m_children[0].get());
|
||||
if (fire_event && on_brush_change)
|
||||
on_brush_change(this, m_button_brush_current_preview->m_brush);
|
||||
}
|
||||
|
||||
int NodePanelQuick::get_selected_color_index() const
|
||||
@@ -49,13 +51,15 @@ int NodePanelQuick::get_selected_color_index() const
|
||||
return std::distance(m_button_colors.begin(), it);
|
||||
}
|
||||
|
||||
void NodePanelQuick::set_selected_color_index(int idx)
|
||||
void NodePanelQuick::set_selected_color_index(int idx, bool fire_event /*= false*/)
|
||||
{
|
||||
if (m_button_color_current)
|
||||
m_button_color_current->set_active(false);
|
||||
m_button_color_current = m_button_colors[idx];
|
||||
m_button_color_current->set_active(true);
|
||||
m_button_color_current_inner = static_cast<NodeBorder*>(m_button_color_current->m_children[0].get());
|
||||
if (fire_event && on_color_change)
|
||||
on_color_change(this, m_button_color_current_inner->m_color);
|
||||
}
|
||||
|
||||
NodePanelQuick::MiniState NodePanelQuick::get_state() const
|
||||
@@ -71,33 +75,33 @@ NodePanelQuick::MiniState NodePanelQuick::get_state() const
|
||||
return s;
|
||||
}
|
||||
|
||||
void NodePanelQuick::set_state(const MiniState& state)
|
||||
void NodePanelQuick::set_state(const MiniState& state, bool fire_event /*= false*/)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
auto b = static_cast<NodeStrokePreview*>(m_button_brushes[i]->m_children[0].get());
|
||||
b->m_brush = state.brushes[i];
|
||||
b->draw_stroke();
|
||||
auto c = static_cast<NodeBorder*>(m_button_color_current->m_children[0].get());
|
||||
c->m_color = state.colors[i];
|
||||
}
|
||||
set_selected_color_index(state.color_index);
|
||||
set_selected_brush_index(state.brush_index);
|
||||
m_button_brush_current_preview->draw_stroke();
|
||||
set_selected_color_index(state.color_index, fire_event);
|
||||
set_selected_brush_index(state.brush_index, fire_event);
|
||||
}
|
||||
|
||||
void NodePanelQuick::reset_state()
|
||||
void NodePanelQuick::reset_state(bool fire_event /*= false*/)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
auto b = static_cast<NodeStrokePreview*>(m_button_brushes[i]->m_children[0].get());
|
||||
b->m_brush = std::make_shared<Brush>();
|
||||
b->m_brush->load_tip("data/brushes/Round-Hard.png", "data/brushes/thumbs/Round-Hard.png");
|
||||
b->draw_stroke();
|
||||
auto c = static_cast<NodeBorder*>(m_button_color_current->m_children[0].get());
|
||||
c->m_color = glm::vec4(0, 0, 0, 1);
|
||||
}
|
||||
set_selected_brush_index(0);
|
||||
set_selected_color_index(0);
|
||||
m_button_brush_current_preview->draw_stroke();
|
||||
set_selected_brush_index(0, fire_event);
|
||||
set_selected_color_index(0, fire_event);
|
||||
}
|
||||
|
||||
void NodePanelQuick::init_controls()
|
||||
|
||||
Reference in New Issue
Block a user