pen state and buttons color when active
This commit is contained in:
@@ -468,41 +468,43 @@ void App::initLayout()
|
||||
if (auto* button = layout[main_id]->find<NodeButton>("btn-pen"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
canvas->m_canvas->m_erase = false;
|
||||
layout[main_id]->find<NodeButton>("btn-pen")->set_color(color_button_hlight);
|
||||
layout[main_id]->find<NodeButton>("btn-erase")->set_color(color_button_normal);
|
||||
layout[main_id]->find<NodeButton>("btn-line")->set_color(color_button_normal);
|
||||
layout[main_id]->find<NodeButton>("btn-cam")->set_color(color_button_normal);
|
||||
Canvas::I->m_state = Canvas::kPenState::Draw;
|
||||
};
|
||||
layout[main_id]->find<NodeButton>("btn-pen")->set_color(color_button_hlight);
|
||||
Canvas::I->m_state = Canvas::kPenState::Draw;
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButton>("btn-erase"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
canvas->m_canvas->m_erase = true;
|
||||
layout[main_id]->find<NodeButton>("btn-pen")->set_color(color_button_normal);
|
||||
layout[main_id]->find<NodeButton>("btn-erase")->set_color(color_button_hlight);
|
||||
layout[main_id]->find<NodeButton>("btn-line")->set_color(color_button_normal);
|
||||
layout[main_id]->find<NodeButton>("btn-cam")->set_color(color_button_normal);
|
||||
Canvas::I->m_state = Canvas::kPenState::Erase;
|
||||
};
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButton>("btn-line"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
canvas->m_canvas->m_erase = true;
|
||||
layout[main_id]->find<NodeButton>("btn-pen")->set_color(color_button_normal);
|
||||
layout[main_id]->find<NodeButton>("btn-erase")->set_color(color_button_normal);
|
||||
layout[main_id]->find<NodeButton>("btn-line")->set_color(color_button_hlight);
|
||||
layout[main_id]->find<NodeButton>("btn-cam")->set_color(color_button_normal);
|
||||
Canvas::I->m_state = Canvas::kPenState::Line;
|
||||
};
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButton>("btn-cam"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
canvas->m_canvas->m_erase = true;
|
||||
layout[main_id]->find<NodeButton>("btn-pen")->set_color(color_button_normal);
|
||||
layout[main_id]->find<NodeButton>("btn-erase")->set_color(color_button_normal);
|
||||
layout[main_id]->find<NodeButton>("btn-line")->set_color(color_button_normal);
|
||||
layout[main_id]->find<NodeButton>("btn-cam")->set_color(color_button_hlight);
|
||||
Canvas::I->m_state = Canvas::kPenState::Camera;
|
||||
};
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-bucket"))
|
||||
@@ -513,26 +515,30 @@ void App::initLayout()
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-stroke"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
button->on_click = [this, button](Node*) {
|
||||
panels->get_child_index(stroke.get()) == -1 ? panels->add_child(stroke) : panels->remove_child(stroke.get());
|
||||
button->set_color(panels->get_child_index(stroke.get()) == -1 ? color_button_normal : color_button_hlight);
|
||||
};
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-brush"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
button->on_click = [this, button](Node*) {
|
||||
panels->get_child_index(brushes.get()) == -1 ? panels->add_child(brushes) : panels->remove_child(brushes.get());
|
||||
button->set_color(panels->get_child_index(brushes.get()) == -1 ? color_button_normal : color_button_hlight);
|
||||
};
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-color"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
button->on_click = [this, button](Node*) {
|
||||
panels->get_child_index(color.get()) == -1 ? panels->add_child(color) : panels->remove_child(color.get());
|
||||
button->set_color(panels->get_child_index(color.get()) == -1 ? color_button_normal : color_button_hlight);
|
||||
};
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-layer"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
button->on_click = [this, button](Node*) {
|
||||
panels->get_child_index(layers.get()) == -1 ? panels->add_child(layers) : panels->remove_child(layers.get());
|
||||
button->set_color(panels->get_child_index(layers.get()) == -1 ? color_button_normal : color_button_hlight);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -563,6 +569,7 @@ void App::initLayout()
|
||||
|
||||
open_dialog->btn_ok->on_click = [this,open_dialog](Node*)
|
||||
{
|
||||
layers->clear();
|
||||
canvas->m_canvas->project_open(data_path);
|
||||
for (auto& i : canvas->m_canvas->m_order)
|
||||
layers->add_layer(canvas->m_canvas->m_layers[i].m_name.c_str());
|
||||
|
||||
@@ -88,7 +88,7 @@ void ui::Canvas::stroke_draw()
|
||||
else
|
||||
{
|
||||
glDisable(GL_BLEND);
|
||||
if (m_erase)
|
||||
if (m_state == kPenState::Erase)
|
||||
{
|
||||
ShaderManager::use(ui::kShader::StrokeErase);
|
||||
//ShaderManager::u_vec4(kShaderUniform::Col, m_brush.m_tip_color);
|
||||
@@ -275,7 +275,7 @@ void ui::Canvas::stroke_commit()
|
||||
m_tex2[i].bind();
|
||||
m_sampler.bind(0);
|
||||
m_sampler_bg.bind(1);
|
||||
if (m_erase)
|
||||
if (m_state == kPenState::Erase)
|
||||
{
|
||||
ShaderManager::use(ui::kShader::Texture);
|
||||
}
|
||||
@@ -324,7 +324,7 @@ void ui::Canvas::stroke_start(glm::vec2 point, float pressure, const ui::Brush&
|
||||
m_dirty_box[i] = glm::vec4(m_width, m_height, 0, 0); // reset bounding box
|
||||
m_dirty_face[i] = false;
|
||||
|
||||
if (m_erase)
|
||||
if (m_state == kPenState::Erase)
|
||||
{
|
||||
m_layers[m_current_layer_idx].m_rtt[i].bindFramebuffer();
|
||||
m_tmp[i].bindTexture();
|
||||
|
||||
@@ -40,7 +40,6 @@ class Canvas
|
||||
bool m_dirty = false;
|
||||
public:
|
||||
static Canvas* I;
|
||||
bool m_erase = false;
|
||||
bool m_alpha_lock = false;
|
||||
glm::mat4 m_mv;
|
||||
glm::mat4 m_proj;
|
||||
@@ -67,6 +66,8 @@ public:
|
||||
Sampler m_sampler_mask;
|
||||
glm::vec2 m_cam_rot;
|
||||
float m_cam_fov = 85;
|
||||
enum class kPenState { Draw, Erase, Line, Camera };
|
||||
kPenState m_state{ kPenState::Draw };
|
||||
|
||||
GLuint cube_id;
|
||||
RTT m_latlong;
|
||||
|
||||
@@ -845,6 +845,11 @@ public:
|
||||
m_color = color_normal;
|
||||
m_mouse_ignore = false;
|
||||
}
|
||||
void set_color(const glm::vec4& c)
|
||||
{
|
||||
color_normal = c;
|
||||
m_color = color_normal;
|
||||
}
|
||||
virtual kEventResult handle_event(Event* e) override
|
||||
{
|
||||
NodeBorder::handle_event(e);
|
||||
@@ -1489,6 +1494,11 @@ public:
|
||||
if (on_layer_change)
|
||||
on_layer_change(this, -1, m_layers_container->get_child_index(m_current_layer));
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
m_layers_container->remove_all_children();
|
||||
m_layers.clear();
|
||||
}
|
||||
};
|
||||
|
||||
class NodeButtonBrush : public NodeButtonCustom
|
||||
@@ -1771,6 +1781,7 @@ public:
|
||||
init_controls();
|
||||
if (m_size.x > 0 && m_size.y > 0)
|
||||
m_rtt.create(m_size.x, m_size.y);
|
||||
draw_stroke();
|
||||
}
|
||||
virtual void clear_context() override
|
||||
{
|
||||
@@ -2043,7 +2054,8 @@ public:
|
||||
ui::ShaderManager::u_mat4(kShaderUniform::MVP, plane_mvp);
|
||||
for (auto layer_index : m_canvas->m_order)
|
||||
{
|
||||
if (!(m_canvas->m_erase && m_canvas->m_show_tmp && m_canvas->m_current_layer_idx == layer_index))
|
||||
if (!(m_canvas->m_state == ui::Canvas::kPenState::Erase &&
|
||||
m_canvas->m_show_tmp && m_canvas->m_current_layer_idx == layer_index))
|
||||
{
|
||||
ui::ShaderManager::u_float(kShaderUniform::Alpha, m_canvas->m_layers[layer_index].m_opacity);
|
||||
m_canvas->m_layers[layer_index].m_rtt[plane_index].bindTexture();
|
||||
@@ -2130,7 +2142,7 @@ public:
|
||||
break;
|
||||
case kEventType::KeyDown:
|
||||
if (ke->m_key == kKey::KeyE)
|
||||
m_canvas->m_erase = true;
|
||||
m_canvas->m_state = ui::Canvas::kPenState::Erase;
|
||||
if (ke->m_key == kKey::KeySpacebar)
|
||||
m_canvas->m_alpha_lock = true;
|
||||
if (ke->m_key == kKey::AndroidVolumeUp)
|
||||
@@ -2140,7 +2152,7 @@ public:
|
||||
break;
|
||||
case kEventType::KeyUp:
|
||||
if (ke->m_key == kKey::KeyE)
|
||||
m_canvas->m_erase = false;
|
||||
m_canvas->m_state = ui::Canvas::kPenState::Draw;
|
||||
if (ke->m_key == kKey::KeySpacebar)
|
||||
m_canvas->m_alpha_lock = false;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user