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:
@@ -179,7 +179,7 @@ void App::init_sidebar()
|
||||
};
|
||||
|
||||
layers->on_layer_delete = [this](Node*, int idx) {
|
||||
canvas->m_canvas->layer_remove(canvas->m_canvas->m_order[idx]);
|
||||
canvas->m_canvas->layer_remove(idx);
|
||||
};
|
||||
|
||||
layers->on_layer_opacity_changed = [this](Node*, int idx, float value) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ struct Controller
|
||||
int index = 0;
|
||||
bool active = false;
|
||||
std::map<uint64_t, bool> buttons;
|
||||
std::map<uint8_t, float> buttons_axis;
|
||||
std::map<uint8_t, bool> buttons_axis;
|
||||
uint64_t buttons_bits{ 0 };
|
||||
glm::vec2 axis[5];
|
||||
glm::mat4 xform{ 1 };
|
||||
|
||||
@@ -953,10 +953,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
break;
|
||||
case WM_LBUTTONDOWN:
|
||||
{
|
||||
SetCapture(hWnd);
|
||||
std::lock_guard<std::mutex> lock(task_mutex);
|
||||
auto pt = lastPoint;
|
||||
tasklist.emplace_back([pt, extra, hWnd, p = WacomTablet::I.get_pressure()]{
|
||||
SetCapture(hWnd);
|
||||
kEventSource pointer_source;
|
||||
if (WacomTablet::I.m_ink_pen || WacomTablet::I.m_ink_touch)
|
||||
{
|
||||
@@ -974,11 +974,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
{
|
||||
ReleaseCapture();
|
||||
std::lock_guard<std::mutex> lock(task_mutex);
|
||||
auto pt = lastPoint;
|
||||
tasklist.emplace_back([pt, extra] {
|
||||
WacomTablet::I.reset_pressure();
|
||||
ReleaseCapture();
|
||||
kEventSource pointer_source;
|
||||
if (WacomTablet::I.m_ink_pen || WacomTablet::I.m_ink_touch)
|
||||
{
|
||||
@@ -996,10 +996,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
break;
|
||||
case WM_RBUTTONDOWN:
|
||||
{
|
||||
SetCapture(hWnd);
|
||||
std::lock_guard<std::mutex> lock(task_mutex);
|
||||
auto pt = lastPoint;
|
||||
tasklist.emplace_back([pt, extra, hWnd] {
|
||||
SetCapture(hWnd);
|
||||
kEventSource pointer_source;
|
||||
if (WacomTablet::I.m_ink_pen || WacomTablet::I.m_ink_touch)
|
||||
{
|
||||
@@ -1017,10 +1017,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
break;
|
||||
case WM_RBUTTONUP:
|
||||
{
|
||||
ReleaseCapture();
|
||||
std::lock_guard<std::mutex> lock(task_mutex);
|
||||
auto pt = lastPoint;
|
||||
tasklist.emplace_back([pt, extra] {
|
||||
ReleaseCapture();
|
||||
kEventSource pointer_source;
|
||||
if (WacomTablet::I.m_ink_pen || WacomTablet::I.m_ink_touch)
|
||||
{
|
||||
|
||||
@@ -141,7 +141,7 @@ void NodeCanvas::draw()
|
||||
m_canvas->m_plane_transform[plane_index] *
|
||||
glm::translate(glm::vec3(0, 0, -1));
|
||||
|
||||
if (m_canvas->m_state == ui::Canvas::kCanvasMode::Erase && m_canvas->m_show_tmp && m_canvas->m_current_layer_idx == layer_index)
|
||||
if (m_canvas->m_current_stroke && m_canvas->m_state == ui::Canvas::kCanvasMode::Erase && m_canvas->m_show_tmp && m_canvas->m_current_layer_idx == layer_index)
|
||||
{
|
||||
m_sampler.bind(0);
|
||||
ui::ShaderManager::use(kShader::CompErase);
|
||||
@@ -165,7 +165,7 @@ void NodeCanvas::draw()
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
m_canvas->m_layers[layer_index].m_rtt[plane_index].unbindTexture();
|
||||
}
|
||||
else if(m_canvas->m_show_tmp && m_canvas->m_current_layer_idx == layer_index)
|
||||
else if(m_canvas->m_current_stroke && m_canvas->m_show_tmp && m_canvas->m_current_layer_idx == layer_index)
|
||||
{
|
||||
m_sampler.bind(0);
|
||||
auto& paper = TextureManager::get(const_hash("data/paper.jpg"));
|
||||
|
||||
@@ -198,11 +198,11 @@ void NodePanelLayer::remove_layer(NodeLayer* layer)
|
||||
{
|
||||
auto it = std::find(m_layers.begin(), m_layers.end(), m_current_layer);
|
||||
auto i = m_layers_container->get_child_index(m_current_layer);
|
||||
int old_idx = (int)std::distance(m_layers.begin(), it);
|
||||
int old_idx = i;// (int)std::distance(m_layers.begin(), it);
|
||||
m_layers_container->remove_child(m_current_layer);
|
||||
m_layers.erase(it);
|
||||
i = std::min<int>(i, (int)m_layers.size() - 1);
|
||||
m_current_layer = m_layers[i];
|
||||
m_current_layer = (NodeLayer*)m_layers_container->get_child_at(i);
|
||||
m_current_layer->m_selected = true;
|
||||
if (on_layer_delete)
|
||||
on_layer_delete(this, old_idx);
|
||||
|
||||
Reference in New Issue
Block a user