fix layer delete order bug, fix and improve brush preview during the stroke, fix windows mouse capture (api works only on the main thread)

This commit is contained in:
2018-11-03 23:44:09 +01:00
parent 3ee10bb88d
commit eb1c8d6b7a
6 changed files with 37 additions and 17 deletions

View File

@@ -91,7 +91,12 @@ void CanvasModeBasicCamera::on_GestureEvent(GestureEvent* ge)
void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
{
#if defined(__IOS__)
m_draw_tip = (me->m_source == kEventSource::Mouse);
#else
m_draw_tip = (me->m_source == kEventSource::Mouse || me->m_source == kEventSource::Stylus);
#endif // _WIN32
if (canvas->m_touch_lock && me->m_source == kEventSource::Touch)
return;
@@ -187,21 +192,35 @@ void CanvasModePen::on_Draw(const glm::mat4& ortho, const glm::mat4& proj, const
{
auto pos = m_resizing ? m_size_pos_start : m_cur_pos;
if (App::I.keys[(int)kKey::KeyAlt] && !m_resizing)
pos.x = pos.x - canvas->m_current_brush.m_tip_size * 500;
pos.x = pos.x - canvas->m_current_brush.m_tip_size * 500.f;
ui::ShaderManager::use(ui::kShader::StrokePreview);
ui::ShaderManager::u_int(ui::kShaderUniform::Tex, 0);
ui::ShaderManager::u_float(ui::kShaderUniform::Alpha, canvas->m_current_brush.m_tip_flow);
float tip_scale_fix = 1.f / glm::tan(glm::radians(ui::Canvas::I->m_cam_fov * 0.5f));
float tip_scale = canvas->m_current_brush.m_tip_size * 800.f * tip_scale_fix;
float tip_angle = canvas->m_current_brush.m_tip_angle * (float)(M_PI * 2.0);
glm::vec2 tip_offset = glm::vec2(0);
auto tip_color = glm::vec4(glm::vec3(canvas->m_current_brush.m_tip_color), 1);
if (canvas->m_current_stroke)
{
const auto& s = canvas->m_current_stroke->m_prev_sample;
if (s.size > 0.f)
{
tip_scale = s.size;
tip_angle = s.angle;
tip_offset = s.pos - s.origin;
tip_color = glm::vec4(s.col, s.flow);
}
}
ui::ShaderManager::u_vec4(ui::kShaderUniform::Col, tip_color);
//ui::ShaderManager::u_int(ui::kShaderUniform::Highlight, 0);
float tip_scale = 1.f / glm::tan(glm::radians(ui::Canvas::I->m_cam_fov * 0.5f));
ui::ShaderManager::u_mat4(ui::kShaderUniform::MVP,
glm::scale(glm::vec3(1, -1, 1)) *
ortho *
glm::translate(glm::vec3(pos, 0)) *
glm::scale(glm::vec3(canvas->m_current_brush.m_tip_size * 800.f * tip_scale)) *
glm::eulerAngleZ(canvas->m_current_brush.m_tip_angle * (float)(M_PI * 2.0))
);
glm::translate(glm::vec3(pos + tip_offset, 0)) *
glm::scale(glm::vec3(tip_scale)) *
glm::eulerAngleZ(tip_angle)
);
bool blend = glIsEnabled(GL_BLEND);
glEnable(GL_BLEND);
glActiveTexture(GL_TEXTURE0);
auto& tex = TextureManager::get(canvas->m_current_brush.m_tex_id);
@@ -209,6 +228,7 @@ void CanvasModePen::on_Draw(const glm::mat4& ortho, const glm::mat4& proj, const
canvas->m_sampler_brush.bind(0);
canvas->m_plane.draw_fill();
tex.unbind();
if (!blend) glDisable(GL_BLEND);
}
}