fix: opening a doc async did not update the layers list, added on_complete callback to update the layers panel
This commit is contained in:
@@ -121,12 +121,16 @@ void App::dialog_browse()
|
||||
{
|
||||
canvas->reset_camera();
|
||||
layers->clear();
|
||||
canvas->m_canvas->project_open(dialog->selected_path);
|
||||
doc_name = dialog->selected_name;
|
||||
if (auto docname = layout[main_id]->find<NodeText>("txt-docname"))
|
||||
docname->set_text(("Panodoc: " + doc_name).c_str());
|
||||
for (auto& i : canvas->m_canvas->m_order)
|
||||
layers->add_layer(canvas->m_canvas->m_layers[i].m_name.c_str());
|
||||
canvas->m_canvas->project_open(dialog->selected_path, [this] {
|
||||
// on complete
|
||||
async_start();
|
||||
if (auto docname = layout[main_id]->find<NodeText>("txt-docname"))
|
||||
docname->set_text(("Panodoc: " + doc_name).c_str());
|
||||
for (auto& i : canvas->m_canvas->m_order)
|
||||
layers->add_layer(canvas->m_canvas->m_layers[i].m_name.c_str());
|
||||
async_end();
|
||||
});
|
||||
dialog->destroy();
|
||||
ActionManager::clear();
|
||||
};
|
||||
|
||||
@@ -1241,22 +1241,23 @@ void ui::Canvas::project_save_thread(std::string file_path)
|
||||
App::I.async_end();
|
||||
}
|
||||
|
||||
void ui::Canvas::project_open(std::string file_path)
|
||||
void ui::Canvas::project_open(std::string file_path, std::function<void()> on_complete)
|
||||
{
|
||||
std::thread t(&ui::Canvas::project_open_thread, this, file_path);
|
||||
std::thread t([=] {
|
||||
project_open_thread(file_path);
|
||||
if (on_complete)
|
||||
on_complete();
|
||||
});
|
||||
t.detach();
|
||||
//project_open_thread(data_path);
|
||||
}
|
||||
|
||||
void ui::Canvas::project_open_thread(std::string file_path)
|
||||
{
|
||||
// static char name[128];
|
||||
// sprintf(name, "%s/latlong.pano", data_path.c_str());
|
||||
FILE* fp = fopen(file_path.c_str(), "rb");
|
||||
if (!fp)
|
||||
{
|
||||
LOG("cannot write project to %s", file_path.c_str());
|
||||
return;
|
||||
return; // should probably return a bool
|
||||
}
|
||||
|
||||
gl_state gl;
|
||||
@@ -1306,6 +1307,9 @@ void ui::Canvas::project_open_thread(std::string file_path)
|
||||
m_order.clear();
|
||||
App::I.async_end();
|
||||
|
||||
std::vector<int> tmp_order;
|
||||
std::vector<Layer> tmp_layers;
|
||||
|
||||
for (int i = 0; i < n_layers; i++)
|
||||
{
|
||||
int n_order;
|
||||
@@ -1354,13 +1358,16 @@ void ui::Canvas::project_open_thread(std::string file_path)
|
||||
}
|
||||
|
||||
App::I.async_start();
|
||||
m_layers.emplace_back();
|
||||
m_layers.back().create(m_width, m_height, name.c_str());
|
||||
m_layers.back().restore(snap);
|
||||
m_order.push_back(n_order);
|
||||
tmp_layers.emplace_back();
|
||||
tmp_layers.back().create(m_width, m_height, name.c_str());
|
||||
tmp_layers.back().restore(snap);
|
||||
tmp_order.push_back(n_order);
|
||||
App::I.async_end();
|
||||
}
|
||||
|
||||
std::swap(tmp_order, m_order);
|
||||
std::swap(tmp_layers, m_layers);
|
||||
|
||||
fclose(fp);
|
||||
LOG("project restore from %s", file_path.c_str());
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ public:
|
||||
void export_anim(std::string data_path);
|
||||
void project_save(std::string file_path);
|
||||
void project_save_thread(std::string file_path);
|
||||
void project_open(std::string file_path);
|
||||
void project_open(std::string file_path, std::function<void()> on_complete = nullptr);
|
||||
void project_open_thread(std::string file_path);
|
||||
void inject_xmp(std::string jpg_path);
|
||||
ui::Image thumbnail_generate(int w, int h);
|
||||
|
||||
@@ -562,7 +562,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
pt.y = GET_Y_LPARAM(lp);
|
||||
ScreenToClient(hWnd, &pt);
|
||||
App::I.mouse_scroll((float)pt.x, (float)pt.y,
|
||||
(float)GET_WHEEL_DELTA_WPARAM(wp) / (float)WHEEL_DELTA);
|
||||
(float)GET_WHEEL_DELTA_WPARAM(wp) / (float)WHEEL_DELTA * 10.f);
|
||||
break;
|
||||
}
|
||||
case WM_POINTERUPDATE:
|
||||
|
||||
@@ -43,7 +43,7 @@ void NodeDialogCloud::loaded()
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<std::string> split(const std::string& subject, char d)
|
||||
std::vector<std::string> split(const std::string& subject, char d, int max_split = 0)
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
int start = 0;
|
||||
@@ -52,6 +52,8 @@ std::vector<std::string> split(const std::string& subject, char d)
|
||||
{
|
||||
ret.push_back(subject.substr(start, n - start));
|
||||
start = n + 1;
|
||||
if (max_split && ret.size() == max_split)
|
||||
break;
|
||||
n = subject.find_first_of(d, start);
|
||||
}
|
||||
ret.push_back(subject.substr(start));
|
||||
@@ -77,7 +79,7 @@ void NodeDialogCloud::load_thumbs_thread()
|
||||
std::string url = "http://omigamedev.ddns.net:8080/panoview/cloud-info.php?file=" + n;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
auto err = curl_easy_perform(curl);
|
||||
auto info = split(res, ',');
|
||||
auto info = split(res, ',', 3);
|
||||
int width = atoi(info[0].c_str());
|
||||
int height = atoi(info[1].c_str());
|
||||
int comp = atoi(info[2].c_str());
|
||||
|
||||
@@ -241,4 +241,5 @@ void NodePanelLayer::clear()
|
||||
{
|
||||
m_layers_container->remove_all_children();
|
||||
m_layers.clear();
|
||||
m_current_layer = nullptr;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
bool create(const ui::Image& img);
|
||||
void assign(GLuint tex, int w = -1, int h = -1, GLuint internal_format = GL_RGBA8, GLuint format = GL_RGBA);
|
||||
bool load(std::string filename);
|
||||
void destroy() { LOG("TEX destroy %d", m_tex); glDeleteTextures(1, &m_tex); }
|
||||
void destroy() { if (m_tex) LOG("TEX destroy %d", m_tex); glDeleteTextures(1, &m_tex); }
|
||||
void bind() const { glBindTexture(GL_TEXTURE_2D, m_tex); }
|
||||
void unbind() const { glBindTexture(GL_TEXTURE_2D, 0); }
|
||||
void update(const uint8_t* data);
|
||||
|
||||
Reference in New Issue
Block a user