pen state and buttons color when active
This commit is contained in:
@@ -359,8 +359,8 @@
|
|||||||
</button-custom>
|
</button-custom>
|
||||||
<button id="btn-undo" width="50" height="100%" margin="0 5 0 0" text="Undo"/>
|
<button id="btn-undo" width="50" height="100%" margin="0 5 0 0" text="Undo"/>
|
||||||
<button id="btn-pen" width="50" height="100%" margin="0 0 0 0" text="Pen"/>
|
<button id="btn-pen" width="50" height="100%" margin="0 0 0 0" text="Pen"/>
|
||||||
<button id="btn-line" width="50" height="100%" margin="0 0 0 0" text="Line"/>
|
|
||||||
<button id="btn-erase" width="60" height="100%" margin="0 0 0 0" text="Erase"/>
|
<button id="btn-erase" width="60" height="100%" margin="0 0 0 0" text="Erase"/>
|
||||||
|
<button id="btn-line" width="50" height="100%" margin="0 0 0 0" text="Line"/>
|
||||||
<button id="btn-cam" width="70" height="100%" margin="0 0 0 0" text="Camera"/>
|
<button id="btn-cam" width="70" height="100%" margin="0 0 0 0" text="Camera"/>
|
||||||
<!--
|
<!--
|
||||||
<button-custom id="btn-layer" width="50" height="100%" margin="0 5 0 0" thickness="1" border-color="0 0 0 1" pad="6" align="center" justify="center">
|
<button-custom id="btn-layer" width="50" height="100%" margin="0 5 0 0" thickness="1" border-color="0 0 0 1" pad="6" align="center" justify="center">
|
||||||
|
|||||||
@@ -468,41 +468,43 @@ void App::initLayout()
|
|||||||
if (auto* button = layout[main_id]->find<NodeButton>("btn-pen"))
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-pen"))
|
||||||
{
|
{
|
||||||
button->on_click = [this](Node*) {
|
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-pen")->set_color(color_button_hlight);
|
||||||
layout[main_id]->find<NodeButton>("btn-erase")->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-line")->set_color(color_button_normal);
|
||||||
layout[main_id]->find<NodeButton>("btn-cam")->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"))
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-erase"))
|
||||||
{
|
{
|
||||||
button->on_click = [this](Node*) {
|
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-pen")->set_color(color_button_normal);
|
||||||
layout[main_id]->find<NodeButton>("btn-erase")->set_color(color_button_hlight);
|
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-line")->set_color(color_button_normal);
|
||||||
layout[main_id]->find<NodeButton>("btn-cam")->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"))
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-line"))
|
||||||
{
|
{
|
||||||
button->on_click = [this](Node*) {
|
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-pen")->set_color(color_button_normal);
|
||||||
layout[main_id]->find<NodeButton>("btn-erase")->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-line")->set_color(color_button_hlight);
|
||||||
layout[main_id]->find<NodeButton>("btn-cam")->set_color(color_button_normal);
|
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"))
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-cam"))
|
||||||
{
|
{
|
||||||
button->on_click = [this](Node*) {
|
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-pen")->set_color(color_button_normal);
|
||||||
layout[main_id]->find<NodeButton>("btn-erase")->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-line")->set_color(color_button_normal);
|
||||||
layout[main_id]->find<NodeButton>("btn-cam")->set_color(color_button_hlight);
|
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"))
|
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"))
|
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());
|
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"))
|
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());
|
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"))
|
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());
|
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"))
|
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());
|
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*)
|
open_dialog->btn_ok->on_click = [this,open_dialog](Node*)
|
||||||
{
|
{
|
||||||
|
layers->clear();
|
||||||
canvas->m_canvas->project_open(data_path);
|
canvas->m_canvas->project_open(data_path);
|
||||||
for (auto& i : canvas->m_canvas->m_order)
|
for (auto& i : canvas->m_canvas->m_order)
|
||||||
layers->add_layer(canvas->m_canvas->m_layers[i].m_name.c_str());
|
layers->add_layer(canvas->m_canvas->m_layers[i].m_name.c_str());
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ void ui::Canvas::stroke_draw()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
if (m_erase)
|
if (m_state == kPenState::Erase)
|
||||||
{
|
{
|
||||||
ShaderManager::use(ui::kShader::StrokeErase);
|
ShaderManager::use(ui::kShader::StrokeErase);
|
||||||
//ShaderManager::u_vec4(kShaderUniform::Col, m_brush.m_tip_color);
|
//ShaderManager::u_vec4(kShaderUniform::Col, m_brush.m_tip_color);
|
||||||
@@ -275,7 +275,7 @@ void ui::Canvas::stroke_commit()
|
|||||||
m_tex2[i].bind();
|
m_tex2[i].bind();
|
||||||
m_sampler.bind(0);
|
m_sampler.bind(0);
|
||||||
m_sampler_bg.bind(1);
|
m_sampler_bg.bind(1);
|
||||||
if (m_erase)
|
if (m_state == kPenState::Erase)
|
||||||
{
|
{
|
||||||
ShaderManager::use(ui::kShader::Texture);
|
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_box[i] = glm::vec4(m_width, m_height, 0, 0); // reset bounding box
|
||||||
m_dirty_face[i] = false;
|
m_dirty_face[i] = false;
|
||||||
|
|
||||||
if (m_erase)
|
if (m_state == kPenState::Erase)
|
||||||
{
|
{
|
||||||
m_layers[m_current_layer_idx].m_rtt[i].bindFramebuffer();
|
m_layers[m_current_layer_idx].m_rtt[i].bindFramebuffer();
|
||||||
m_tmp[i].bindTexture();
|
m_tmp[i].bindTexture();
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ class Canvas
|
|||||||
bool m_dirty = false;
|
bool m_dirty = false;
|
||||||
public:
|
public:
|
||||||
static Canvas* I;
|
static Canvas* I;
|
||||||
bool m_erase = false;
|
|
||||||
bool m_alpha_lock = false;
|
bool m_alpha_lock = false;
|
||||||
glm::mat4 m_mv;
|
glm::mat4 m_mv;
|
||||||
glm::mat4 m_proj;
|
glm::mat4 m_proj;
|
||||||
@@ -67,6 +66,8 @@ public:
|
|||||||
Sampler m_sampler_mask;
|
Sampler m_sampler_mask;
|
||||||
glm::vec2 m_cam_rot;
|
glm::vec2 m_cam_rot;
|
||||||
float m_cam_fov = 85;
|
float m_cam_fov = 85;
|
||||||
|
enum class kPenState { Draw, Erase, Line, Camera };
|
||||||
|
kPenState m_state{ kPenState::Draw };
|
||||||
|
|
||||||
GLuint cube_id;
|
GLuint cube_id;
|
||||||
RTT m_latlong;
|
RTT m_latlong;
|
||||||
|
|||||||
@@ -845,6 +845,11 @@ public:
|
|||||||
m_color = color_normal;
|
m_color = color_normal;
|
||||||
m_mouse_ignore = false;
|
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
|
virtual kEventResult handle_event(Event* e) override
|
||||||
{
|
{
|
||||||
NodeBorder::handle_event(e);
|
NodeBorder::handle_event(e);
|
||||||
@@ -1489,6 +1494,11 @@ public:
|
|||||||
if (on_layer_change)
|
if (on_layer_change)
|
||||||
on_layer_change(this, -1, m_layers_container->get_child_index(m_current_layer));
|
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
|
class NodeButtonBrush : public NodeButtonCustom
|
||||||
@@ -1771,6 +1781,7 @@ public:
|
|||||||
init_controls();
|
init_controls();
|
||||||
if (m_size.x > 0 && m_size.y > 0)
|
if (m_size.x > 0 && m_size.y > 0)
|
||||||
m_rtt.create(m_size.x, m_size.y);
|
m_rtt.create(m_size.x, m_size.y);
|
||||||
|
draw_stroke();
|
||||||
}
|
}
|
||||||
virtual void clear_context() override
|
virtual void clear_context() override
|
||||||
{
|
{
|
||||||
@@ -2043,7 +2054,8 @@ public:
|
|||||||
ui::ShaderManager::u_mat4(kShaderUniform::MVP, plane_mvp);
|
ui::ShaderManager::u_mat4(kShaderUniform::MVP, plane_mvp);
|
||||||
for (auto layer_index : m_canvas->m_order)
|
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);
|
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();
|
m_canvas->m_layers[layer_index].m_rtt[plane_index].bindTexture();
|
||||||
@@ -2130,7 +2142,7 @@ public:
|
|||||||
break;
|
break;
|
||||||
case kEventType::KeyDown:
|
case kEventType::KeyDown:
|
||||||
if (ke->m_key == kKey::KeyE)
|
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)
|
if (ke->m_key == kKey::KeySpacebar)
|
||||||
m_canvas->m_alpha_lock = true;
|
m_canvas->m_alpha_lock = true;
|
||||||
if (ke->m_key == kKey::AndroidVolumeUp)
|
if (ke->m_key == kKey::AndroidVolumeUp)
|
||||||
@@ -2140,7 +2152,7 @@ public:
|
|||||||
break;
|
break;
|
||||||
case kEventType::KeyUp:
|
case kEventType::KeyUp:
|
||||||
if (ke->m_key == kKey::KeyE)
|
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)
|
if (ke->m_key == kKey::KeySpacebar)
|
||||||
m_canvas->m_alpha_lock = false;
|
m_canvas->m_alpha_lock = false;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user