improve quick panel switch state
This commit is contained in:
@@ -722,6 +722,7 @@ void App::terminate()
|
||||
floating_color.reset();
|
||||
floating_layers.reset();
|
||||
floating_picker.reset();
|
||||
quick_mode_state.clear();
|
||||
async_end();
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ public:
|
||||
std::shared_ptr<NodePanelGrid> grid;
|
||||
std::shared_ptr<NodePanelBrushPreset> presets;
|
||||
NodePanelQuick* quick;
|
||||
std::map<kCanvasMode, NodePanelQuick::MiniState> quick_mode_state;
|
||||
Node* floatings_container;
|
||||
std::shared_ptr<NodePanelColor> floating_color;
|
||||
std::shared_ptr<NodeColorPicker> floating_picker;
|
||||
|
||||
@@ -119,12 +119,11 @@ void App::init_sidebar()
|
||||
//presets = find_or_create_panel<NodePanelBrushPreset>(panels);
|
||||
|
||||
canvas->m_canvas->on_mode_changed = [this](kCanvasMode prev, kCanvasMode mode) {
|
||||
static std::map<kCanvasMode, NodePanelQuick::MiniState> mode_state;
|
||||
mode_state[prev] = quick->get_state();
|
||||
if (mode_state.find(mode) != mode_state.end())
|
||||
quick->set_state(mode_state[mode]);
|
||||
quick_mode_state[prev] = quick->get_state();
|
||||
if (quick_mode_state.find(mode) != quick_mode_state.end())
|
||||
quick->set_state(quick_mode_state[mode], true);
|
||||
else
|
||||
quick->reset_state();
|
||||
quick->reset_state(true);
|
||||
brush_update();
|
||||
};
|
||||
color->on_color_changed = [this](Node* target, glm::vec4 color) {
|
||||
|
||||
@@ -268,20 +268,11 @@ void CanvasModePen::on_Draw(const glm::mat4& ortho, const glm::mat4& proj, const
|
||||
|
||||
void CanvasModePen::leave(kCanvasMode next)
|
||||
{
|
||||
*m_brush = *Canvas::I->m_current_brush;
|
||||
}
|
||||
|
||||
void CanvasModePen::enter(kCanvasMode prev)
|
||||
{
|
||||
m_cur_pos = Canvas::I->m_cur_pos;
|
||||
if (!m_brush)
|
||||
{
|
||||
m_brush = std::make_shared<Brush>(*Canvas::I->m_current_brush);
|
||||
m_brush->load_tip("data/brushes/Round-Hard.png", "data/brushes/thumbs/Round-Hard.png");
|
||||
}
|
||||
*Canvas::I->m_current_brush = *m_brush;
|
||||
Canvas::I->m_current_brush->load();
|
||||
App::I.brush_update();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@@ -386,19 +377,10 @@ void CanvasModeLine::init()
|
||||
void CanvasModeLine::enter(kCanvasMode prev)
|
||||
{
|
||||
m_cur_pos = Canvas::I->m_cur_pos;
|
||||
if (!m_brush)
|
||||
{
|
||||
m_brush = std::make_shared<Brush>();
|
||||
m_brush->load_tip("data/brushes/Round-Hard.png", "data/brushes/thumbs/Round-Hard.png");
|
||||
}
|
||||
*Canvas::I->m_current_brush = *m_brush;
|
||||
Canvas::I->m_current_brush->load();
|
||||
App::I.brush_update();
|
||||
}
|
||||
|
||||
void CanvasModeLine::leave(kCanvasMode next)
|
||||
{
|
||||
*m_brush = *Canvas::I->m_current_brush;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -41,12 +41,12 @@ public:
|
||||
|
||||
void set_color(glm::vec3 color);
|
||||
int get_selected_brush_index() const;
|
||||
void set_selected_brush_index(int idx);
|
||||
void set_selected_brush_index(int idx, bool fire_event = false);
|
||||
int get_selected_color_index() const;
|
||||
void set_selected_color_index(int idx);
|
||||
void set_selected_color_index(int idx, bool fire_event = false);
|
||||
MiniState get_state() const;
|
||||
void set_state(const MiniState& state);
|
||||
void reset_state();
|
||||
void set_state(const MiniState& state, bool fire_event = false);
|
||||
void reset_state(bool fire_events = false);
|
||||
|
||||
private:
|
||||
void init_controls();
|
||||
|
||||
@@ -545,7 +545,8 @@ void NodeStrokePreview::draw_stroke()
|
||||
gl.restore();
|
||||
node->app_redraw();
|
||||
node->async_end();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(30));
|
||||
//std::this_thread::sleep_for(std::chrono::milliseconds(30));
|
||||
std::this_thread::yield();
|
||||
}
|
||||
}
|
||||
App::I.async_start();
|
||||
|
||||
Reference in New Issue
Block a user