From fda399f7dd4f1fcd478ffc12415ef6349a168502 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Mon, 11 Mar 2019 15:35:59 +0100 Subject: [PATCH] update color at picking and cleanup code from some warnings --- src/abr.cpp | 6 +++--- src/app.cpp | 2 +- src/app_layout.cpp | 4 ++-- src/canvas.cpp | 18 ++++-------------- src/canvas.h | 2 +- src/canvas_modes.cpp | 14 +++++++++----- src/node_combobox.cpp | 1 - src/node_dialog_cloud.cpp | 2 +- src/node_panel_brush.cpp | 8 ++++---- src/node_panel_grid.cpp | 2 +- src/node_panel_layer.cpp | 2 +- src/node_panel_stroke.cpp | 2 +- src/node_stroke_preview.cpp | 6 +++--- src/serializer.h | 10 +++++----- src/util.cpp | 38 ++++++++++++++++++------------------- src/util.h | 2 +- 16 files changed, 56 insertions(+), 63 deletions(-) diff --git a/src/abr.cpp b/src/abr.cpp index a662e71..081363a 100644 --- a/src/abr.cpp +++ b/src/abr.cpp @@ -92,7 +92,7 @@ bool ABR::section_patt() int nc = std::min((int)vm->channels.size(), 3); if (nc != image_mode) { - LOG("PATT: image_mode (%d) and number of channels (%d) not matching\n", + LOG("PATT: image_mode (%d) and number of channels (%ld) not matching\n", image_mode, vm->channels.size()); } if (auto img = vm->image(true, false)) @@ -271,7 +271,7 @@ std::vector> ABR::compute_brushes(const std::string& path std::string blend_mode = p->value("textureBlendMode"); auto bm_it = std::find(modes.begin(), modes.end(), blend_mode); if (bm_it != modes.end()) - b->m_pattern_blend_mode = std::distance(modes.begin(), bm_it); + b->m_pattern_blend_mode = (int)std::distance(modes.begin(), bm_it); b->m_pattern_enabled = p->value("useTexture"); } @@ -342,7 +342,7 @@ std::vector> ABR::compute_brushes(const std::string& path std::string blend_mode = db->value("BlnM"); auto bm_it = std::find(modes.begin(), modes.end(), blend_mode); if (bm_it != modes.end()) - b->m_dual_blend_mode = std::distance(modes.begin(), bm_it); + b->m_dual_blend_mode = (int)std::distance(modes.begin(), bm_it); b->m_dual_enabled = db->value("useDualBrush"); } diff --git a/src/app.cpp b/src/app.cpp index bb409f0..d6b25ec 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -726,7 +726,7 @@ int App::res_from_index(int i) int App::res_to_index(int res) { - return std::distance(res_map.begin(), std::find(res_map.begin(), res_map.end(), res)); + return (int)std::distance(res_map.begin(), std::find(res_map.begin(), res_map.end(), res)); } std::string App::res_to_string(int res) diff --git a/src/app_layout.cpp b/src/app_layout.cpp index 0f62e0e..9eb8bac 100644 --- a/src/app_layout.cpp +++ b/src/app_layout.cpp @@ -871,7 +871,7 @@ void App::init_menu_layer() popup->find("layer-merge")->on_click = [this, popup](Node*) { const auto& order = canvas->m_canvas->m_order; //layers->get_child_index(layers->) - int current_idx_order = std::distance(order.begin(), std::find(order.begin(), order.end(), canvas->m_canvas->m_current_layer_idx)); + int current_idx_order = (int)std::distance(order.begin(), std::find(order.begin(), order.end(), canvas->m_canvas->m_current_layer_idx)); if (current_idx_order > 0) { int dest_layer_idx = order[current_idx_order - 1]; @@ -891,7 +891,7 @@ void App::init_menu_layer() if (layers->m_current_layer) { const auto& order = canvas->m_canvas->m_order; - int current_idx_order = std::distance(order.begin(), std::find(order.begin(), order.end(), canvas->m_canvas->m_current_layer_idx)); + int current_idx_order = (int)std::distance(order.begin(), std::find(order.begin(), order.end(), canvas->m_canvas->m_current_layer_idx)); if (current_idx_order > 0) { int down_layer_idx = order[current_idx_order - 1]; diff --git a/src/canvas.cpp b/src/canvas.cpp index fb72aab..32946a9 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -230,7 +230,7 @@ void Canvas::stroke_draw_mix(const glm::vec2& bb_min, const glm::vec2& bb_sz) !m_layers[layer_index]->m_dirty_face[plane_index]) continue; - glm::mat4 proj = glm::perspective(glm::radians(m_cam_fov), (float)m_mixer.getWidth() / m_mixer.getHeight(), 0.1f, 1000.f); + //glm::mat4 proj = glm::perspective(glm::radians(m_cam_fov), (float)m_mixer.getWidth() / m_mixer.getHeight(), 0.1f, 1000.f); auto plane_mvp_z = glm::scale(glm::vec3(1, -1, 1)) * m_proj * m_mv * @@ -379,12 +379,12 @@ glm::vec4 Canvas::stroke_draw_samples(int i, std::vector& P) } else if (P.size() == 3) { - m_brush_shape.update_vertices(P.data(), P.size()); + m_brush_shape.update_vertices(P.data(), (int)P.size()); } else { P = triangulate_simple(P); - m_brush_shape.update_vertices(P.data(), P.size()); + m_brush_shape.update_vertices(P.data(), (int)P.size()); } m_brush_shape.draw_fill(); @@ -643,18 +643,8 @@ bool Canvas::point_trace_plane(glm::vec2 loc, glm::vec3& hit_pos, glm::vec2& hit bool Canvas::point_trace_plane(glm::vec2 loc, glm::vec3& ray_origin, glm::vec3& ray_dir, glm::vec3& hit_pos, glm::vec3& hit_normal, glm::vec2& hit_fb_pos, int plane_id) { -/* - auto ln = (loc / zw(m_box)) * 2.f - 1.f; - auto p = m_plane_unproject[plane_id] * glm::vec4(ln, 1, 1); - if (p.w <= 0) - { - - return true; - } -*/ point_unproject(loc, { 0, 0, zw(m_box) }, m_mv, m_proj, ray_origin, ray_dir); glm::vec3 hit; - glm::vec2 fb_pos; float hit_t; if (ray_intersect(ray_origin, ray_dir, m_plane_origin[plane_id], m_plane_normal[plane_id], m_plane_tangent[plane_id], hit, hit_t)) @@ -1590,7 +1580,7 @@ void Canvas::export_layers_thread(std::string file_name) App::I.async_update(); } int progress = 0; - int total = (m_order.size() + 1) * 6; + int total = (int)(m_order.size() + 1) * 6; // prepare common states glViewport(0, 0, m_width, m_height); diff --git a/src/canvas.h b/src/canvas.h index f1a3a16..0ab6057 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -70,7 +70,7 @@ public: } } } - glm::vec2 bbsz = bbmax - bbmin; + //glm::vec2 bbsz = bbmax - bbmin; } } }; diff --git a/src/canvas_modes.cpp b/src/canvas_modes.cpp index 4a366cf..0feacd2 100644 --- a/src/canvas_modes.cpp +++ b/src/canvas_modes.cpp @@ -84,12 +84,16 @@ void CanvasModeBasicCamera::on_GestureEvent(GestureEvent* ge) m_camera_fov = Canvas::I->m_cam_fov; break; case kEventType::GestureMove: + { Canvas::I->m_pan = m_pan_start + ge->m_pos_delta * glm::vec2(-1, -1) * 0.3f * (Canvas::I->m_cam_fov / 85.f); Canvas::I->m_cam_fov = m_camera_fov - ge->m_distance_delta * .05f; auto angle = Canvas::I->m_pan * 0.003f; Canvas::I->m_cam_rot = glm::eulerAngleXY(angle.y, angle.x); App::I.brush_update(); break; + } + default: + break; } } @@ -127,7 +131,7 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc) Canvas::I->pick_start(); glm::vec4 pix = Canvas::I->pick_get(loc); Canvas::I->m_current_brush->m_tip_color = pix; - App::I.color->set_color(pix); + App::I.brush_update(); } else { @@ -147,7 +151,7 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc) node->mouse_release(); glm::vec4 pix = Canvas::I->pick_get(loc); Canvas::I->m_current_brush->m_tip_color = pix; - App::I.color->set_color(pix); + App::I.brush_update(); Canvas::I->pick_end(); } m_dragging = false; @@ -179,7 +183,7 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc) { glm::vec4 pix = Canvas::I->pick_get(loc); Canvas::I->m_current_brush->m_tip_color = pix; - App::I.color->set_color(pix); + App::I.brush_update(); } if (m_dragging && m_resizing) { @@ -1017,7 +1021,7 @@ void CanvasModeTransform::enter(kCanvasMode prev) vertex_t(corners[3], { 0, 1 }), }); auto shape3d = triangulate(m_points_face[0]); - m_shape[0].update_vertices(shape3d.data(), shape3d.size()); + m_shape[0].update_vertices(shape3d.data(), (int)shape3d.size()); m_commit_on_leave = true; @@ -1123,7 +1127,7 @@ void CanvasModeTransform::enter(kCanvasMode prev) } auto shape3d = triangulate(m_points_face[plane]); - m_shape[plane].update_vertices(shape3d.data(), shape3d.size()); + m_shape[plane].update_vertices(shape3d.data(), (int)shape3d.size()); Canvas::I->m_layers[Canvas::I->m_current_layer_idx]->m_rtt[plane].bindFramebuffer(); m_tex[plane].create(bb_sz.x, bb_sz.y); diff --git a/src/node_combobox.cpp b/src/node_combobox.cpp index 62ebd59..57165dd 100644 --- a/src/node_combobox.cpp +++ b/src/node_combobox.cpp @@ -30,7 +30,6 @@ void NodeComboBox::loaded() popup->loaded(); root()->add_child(popup); m_items.clear(); - int real_index = 0; for (int i = 0; i < m_data.size(); i++) { if (m_data[i] == "-") diff --git a/src/node_dialog_cloud.cpp b/src/node_dialog_cloud.cpp index 605fe55..e46d3eb 100644 --- a/src/node_dialog_cloud.cpp +++ b/src/node_dialog_cloud.cpp @@ -128,7 +128,7 @@ void NodeDialogCloud::load_thumbs_thread() break; res.clear(); - char* url_escaped = curl_easy_escape(curl, n.c_str(), n.size()); + char* url_escaped = curl_easy_escape(curl, n.c_str(), (int)n.size()); std::string url = std::string("https://panopainter.com/cloud/cloud-info.php?file=") + url_escaped; delete url_escaped; curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); diff --git a/src/node_panel_brush.cpp b/src/node_panel_brush.cpp index 4a55fe9..012915b 100644 --- a/src/node_panel_brush.cpp +++ b/src/node_panel_brush.cpp @@ -298,7 +298,7 @@ bool NodePanelBrush::save() sw.wstring_raw("PPVR"); // magic code sw.wu16(0); // version major sw.wu16(1); // minor - sw.wu32(m_container->m_children.size()); // number of items + sw.wu32((int)m_container->m_children.size()); // number of items for (const auto& child : m_container->m_children) { auto b = std::static_pointer_cast(child); @@ -331,7 +331,7 @@ bool NodePanelBrush::restore() auto vmin = sr.ru16(); if (vmaj != 0 && vmin != 1) { - LOG("unrecognised version %d.$d", vmaj, vmin); + LOG("unrecognised version %d.%d", vmaj, vmin); return false; } @@ -448,7 +448,7 @@ void NodePanelBrushPreset::init() } else { - int next = std::min(m_container->m_children.size() - 1, index); + int next = std::min((int)m_container->m_children.size() - 1, index); m_current = (NodeBrushPresetItem*)m_container->m_children[next].get(); m_current->m_selected = true; } @@ -515,7 +515,7 @@ bool NodePanelBrushPreset::save() sw.wstring_raw("PPVR"); sw.wu16(0); sw.wu16(1); - sw.wu32(m_container->m_children.size()); + sw.wu32((int)m_container->m_children.size()); for (int ci = 0; ci < m_container->m_children.size(); ci++) { auto bpi = static_cast(m_container->get_child_at(ci)); diff --git a/src/node_panel_grid.cpp b/src/node_panel_grid.cpp index b0cfe88..1bff4ba 100644 --- a/src/node_panel_grid.cpp +++ b/src/node_panel_grid.cpp @@ -414,7 +414,7 @@ void NodePanelGrid::bake_uvs() { for (int x = 0; x < fb.getWidth(); x++) { - int i = y * fb.getHeight() + x; + int i = (int)y * fb.getHeight() + x; auto nor = glm::make_vec3(&d_nor[i * 4]); auto pos = glm::make_vec3(&d_pos[i * 4]); auto& out = d_out[i]; diff --git a/src/node_panel_layer.cpp b/src/node_panel_layer.cpp index c03f89d..70a3e60 100644 --- a/src/node_panel_layer.cpp +++ b/src/node_panel_layer.cpp @@ -126,7 +126,7 @@ void NodePanelLayer::init() auto num = m[2].str(); int count = atoi(num.c_str()) + 1; char tmp[128]; - sprintf(tmp, "%s%0*d", m[1].str().c_str(), num.length(), count); + sprintf(tmp, "%s%0*d", m[1].str().c_str(), (int)num.length(), count); next = tmp; } int source_index = m_layers_container->get_child_index(m_current_layer); diff --git a/src/node_panel_stroke.cpp b/src/node_panel_stroke.cpp index b7e6b28..bf0ca30 100644 --- a/src/node_panel_stroke.cpp +++ b/src/node_panel_stroke.cpp @@ -48,7 +48,7 @@ bool NodePanelStroke::import_abr(const std::string& path) abr.open(path); - int tot = abr.m_samples.size() + abr.m_patterns.size() + abr.m_presets.size(); + int tot = (int)(abr.m_samples.size() + abr.m_patterns.size() + abr.m_presets.size()); std::atomic_int count(0); parallel_for(abr.m_samples.size(), [&](size_t i) diff --git a/src/node_stroke_preview.cpp b/src/node_stroke_preview.cpp index dfa97c1..e2d32a7 100644 --- a/src/node_stroke_preview.cpp +++ b/src/node_stroke_preview.cpp @@ -364,7 +364,7 @@ void NodeStrokePreview::draw_stroke_immediate() ShaderManager::u_vec4(kShaderUniform::Col, { 0, 0, 0, 1 }); ShaderManager::u_float(kShaderUniform::Alpha, f.flow); ShaderManager::u_float(kShaderUniform::Opacity, f.opacity); - auto rect = stroke_draw_samples(f.shapes, m_tex_dual); + /*auto rect =*/ stroke_draw_samples(f.shapes, m_tex_dual); } // copy raw stroke to tex @@ -404,7 +404,7 @@ void NodeStrokePreview::draw_stroke_immediate() ShaderManager::u_vec4(kShaderUniform::Col, { 0, 0, 0, 1 } /*f.col*/); ShaderManager::u_float(kShaderUniform::Alpha, glm::max(f.flow, m_min_flow)); ShaderManager::u_float(kShaderUniform::Opacity, f.opacity); - auto rect = stroke_draw_samples(f.shapes, m_tex); + /*auto rect =*/ stroke_draw_samples(f.shapes, m_tex); } glActiveTexture(GL_TEXTURE3); m_rtt_mixer.unbindTexture(); @@ -529,7 +529,7 @@ void NodeStrokePreview::draw() void NodeStrokePreview::handle_resize(glm::vec2 old_size, glm::vec2 new_size) { - if (m_rtt.getWidth() == new_size.x && m_rtt.getHeight() == new_size.y || !m_brush) + if ((m_rtt.getWidth() == new_size.x && m_rtt.getHeight() == new_size.y) || !m_brush) return; new_size *= root()->m_zoom; diff --git a/src/serializer.h b/src/serializer.h index fe13218..45a44c7 100644 --- a/src/serializer.h +++ b/src/serializer.h @@ -68,7 +68,7 @@ public: } virtual void write(BinaryStreamWriter& w) const override { - w.wi32(items.size()); + w.wi32((int)items.size()); for (auto& i : items) i->write(w); } @@ -412,7 +412,7 @@ public: { w.wwstring(name); w.wkey_or_string(class_id); - w.wu32(props.size()); + w.wu32((int)props.size()); for (auto& p : props) { w.wkey_or_string(p.first); @@ -518,7 +518,7 @@ public: auto decoded = r.rrle(sl); data.insert(data.end(), decoded.begin(), decoded.end()); } - auto len = r.pos() - start; + //auto len = r.pos() - start; } else { @@ -541,7 +541,7 @@ public: VMArray(uint32_t version, const Rectangle& rect) : version(version), rect(rect) { } std::shared_ptr image(bool grayscale, bool invert) const { - int nc = channels.size(); + int nc = (int)channels.size(); auto pixels = (channels[0].depth >> 3) * rect.area(); if (nc == 1 || nc >= 3) { @@ -589,7 +589,7 @@ public: } else { - LOG("Error image with %d channels\n", channels.size()); + LOG("Error image with %ld channels\n", channels.size()); } return nullptr; } diff --git a/src/util.cpp b/src/util.cpp index 395f590..0039129 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -369,8 +369,8 @@ std::vector triangulate(const std::vector& points) while (node) { if (outline.empty() || // if empty insert right away - outline.back() != node->a && // insert only if different than the last post - (outline.front() != node->a || !node->end)) // if is the end check against the first one + (outline.back() != node->a && // insert only if different than the last post + (outline.front() != node->a || !node->end))) // if is the end check against the first one { outline.push_back(node->a); } @@ -438,8 +438,8 @@ glm::vec3 convert_rgb2hsv(const glm::vec3 c) std::vector split(const std::string& subject, char d, int max_split/* = 0*/) { std::vector ret; - int start = 0; - int n = subject.find_first_of(d); + size_t start = 0; + size_t n = subject.find_first_of(d); while (n != std::string::npos) { ret.push_back(subject.substr(start, n - start)); @@ -499,10 +499,10 @@ std::string wstr2str(const std::wstring & wstr) bool str_iequals(const std::string& a, const std::string& b) { - unsigned int sz = a.size(); + size_t sz = a.size(); if (b.size() != sz) return false; - for (unsigned int i = 0; i < sz; ++i) + for (size_t i = 0; i < sz; ++i) if (std::tolower(a[i]) != std::tolower(b[i])) return false; return true; @@ -586,25 +586,25 @@ size_t curl_data_write(void *ptr, size_t size, size_t nmemb, FILE *stream) /// @param use_threads : enable / disable threads. /// /// -void parallel_for(unsigned nb_elements, std::function functor, bool use_threads) +void parallel_for(size_t nb_elements, std::function functor, bool use_threads) { // ------- - unsigned nb_threads_hint = std::thread::hardware_concurrency(); - unsigned nb_threads = nb_threads_hint == 0 ? 8 : (nb_threads_hint); + size_t nb_threads_hint = std::thread::hardware_concurrency(); + size_t nb_threads = nb_threads_hint == 0 ? 8 : (nb_threads_hint); - unsigned batch_size = nb_elements / nb_threads; - unsigned batch_remainder = nb_elements % nb_threads; + size_t batch_size = nb_elements / nb_threads; + size_t batch_remainder = nb_elements % nb_threads; std::vector< std::thread > my_threads(nb_threads); if (use_threads) { // Multithread execution - for (unsigned i = 0; i < nb_threads; ++i) + for (size_t i = 0; i < nb_threads; ++i) { - int start = i * batch_size; + size_t start = i * batch_size; my_threads[i] = std::thread([functor, start, batch_size]() { - for (int j = start; j < start + batch_size; j++) + for (size_t j = start; j < start + batch_size; j++) functor(j); }); } @@ -612,16 +612,16 @@ void parallel_for(unsigned nb_elements, std::function functor, bool else { // Single thread execution (for easy debugging) - for (unsigned i = 0; i < nb_threads; ++i) { - int start = i * batch_size; - for (int j = start; j < start + batch_size; j++) + for (size_t i = 0; i < nb_threads; ++i) { + size_t start = i * batch_size; + for (size_t j = start; j < start + batch_size; j++) functor(j); } } // Deform the elements left - int start = nb_threads * batch_size; - for (int j = start; j < start + batch_remainder; j++) + size_t start = nb_threads * batch_size; + for (size_t j = start; j < start + batch_remainder; j++) functor(j); // Wait for the other thread to finish their task diff --git a/src/util.h b/src/util.h index c25161e..a548982 100644 --- a/src/util.h +++ b/src/util.h @@ -87,7 +87,7 @@ inline glm::ivec3 xyz(const glm::ivec4& v) { return glm::ivec3(v.x, v.y, v.z); } inline glm::ivec2 zw(const glm::ivec4& v) { return glm::ivec2(v.z, v.w); } inline glm::vec2 xy(const glm::vec3& v) { return glm::vec2(v.x, v.y); } -void parallel_for(unsigned nb_elements, std::function functor, bool use_threads = true); +void parallel_for(size_t nb_elements, std::function functor, bool use_threads = true); template struct cbuffer {