improve text node

This commit is contained in:
2019-11-28 21:01:17 +01:00
parent 41579fa3c6
commit c6173987af
4 changed files with 19 additions and 18 deletions

View File

@@ -691,19 +691,21 @@ void NodeCanvas::set_cursor_visibility(kCursorVisibility mode)
void NodeCanvas::update_cursor()
{
bool visible = true;
if (m_canvas->m_current_mode == kCanvasMode::Draw ||
m_canvas->m_current_mode == kCanvasMode::Erase)
{
if (m_cursor_visibility == kCursorVisibility::Always)
visible = true;
if (m_cursor_visibility == kCursorVisibility::Never)
visible = false;
if (m_cursor_visibility == kCursorVisibility::SmallBrush)
visible = m_canvas->m_current_brush->m_tip_size < 10;
if (m_cursor_visibility == kCursorVisibility::NotPainting &&
m_canvas->m_current_mode == kCanvasMode::Draw ||
m_canvas->m_current_mode == kCanvasMode::Erase)
{
visible = !m_canvas->get_mode<CanvasModePen>()->m_drawing ||
if (m_cursor_visibility == kCursorVisibility::NotPainting)
visible = !m_canvas->get_mode<CanvasModePen>()->m_drawing;
if (App::I->keys[(int)kKey::KeyAlt] ||
m_canvas->get_mode<CanvasModePen>()->m_resizing ||
m_canvas->get_mode<CanvasModePen>()->m_picking;
m_canvas->get_mode<CanvasModePen>()->m_picking)
visible = true;
}
visible ? App::I->show_cursor() : App::I->hide_cursor();
}

View File

@@ -120,6 +120,7 @@ void NodeText::set_text_format(const char* fmt, ...)
void NodeText::update_layout()
{
auto pad = GetPadding();
if (auto_width)
{
YGNodeStyleSetWidth(y_node, m_text_mesh.bb.x);
@@ -131,9 +132,8 @@ void NodeText::update_layout()
m_size.y = m_text_mesh.bb.y;
}
auto pad = GetPadding();
float h = GetHeight() - (pad[1] + pad[3]);
float w = GetWidth() - (pad[0] + pad[2]);
float h = m_size.y - (pad[1] + pad[3]);
float w = m_size.x - (pad[0] + pad[2]);
if (m_text_align_v == TextAlign::Begin)
m_off.y = pad[0];
@@ -152,11 +152,10 @@ void NodeText::update_layout()
void NodeText::draw()
{
glm::mat4 pos = glm::translate(glm::vec3(glm::floor(m_pos), 0));
m_mvp = m_proj * pos;
glm::mat4 pos = glm::translate(glm::vec3(glm::floor(m_pos + m_off), 0));
ShaderManager::use(kShader::Font);
ShaderManager::u_int(kShaderUniform::Tex, 0);
ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp);
ShaderManager::u_mat4(kShaderUniform::MVP, m_proj * pos);
ShaderManager::u_vec4(kShaderUniform::Col, m_color);
glEnable(GL_BLEND);
m_text_mesh.draw();

View File

@@ -19,7 +19,7 @@ public:
kFont font_id;
bool m_multiline = false;
glm::vec2 m_off;
glm::vec2 m_off = { 0, 0 };
TextAlign m_text_align_v = TextAlign::Center;
TextAlign m_text_align_h = TextAlign::Begin;

View File

@@ -23,7 +23,7 @@ public:
bool m_multiline = false;
bool m_cursor_visible = false;
glm::vec2 m_off;
glm::vec2 m_off = { 0, 0 };
TextAlign m_text_align_v = TextAlign::Center;
TextAlign m_text_align_h = TextAlign::Begin;