fix log thread bug, add clean memory button, fix pinch zoom bug, set android back button to undo
This commit is contained in:
@@ -21,3 +21,12 @@ void ActionManager::undo()
|
||||
LOG("History: %.2f KB", I.m_memory / 1024.f);
|
||||
App::I.update_memory_usage(I.m_memory);
|
||||
}
|
||||
|
||||
void ActionManager::clear()
|
||||
{
|
||||
while (!I.m_actions.empty())
|
||||
I.m_actions.pop();
|
||||
I.m_memory = 0;
|
||||
LOG("History: %.2f KB", I.m_memory / 1024.f);
|
||||
App::I.update_memory_usage(I.m_memory);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ public:
|
||||
size_t m_memory = 0;
|
||||
static void add(Action* action);
|
||||
static void undo();
|
||||
static void clear();
|
||||
static bool empty()
|
||||
{
|
||||
return I.m_actions.empty();
|
||||
|
||||
@@ -636,6 +636,12 @@ void App::initLayout()
|
||||
ActionManager::undo();
|
||||
};
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-clean-memory"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
ActionManager::clear();
|
||||
};
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButton>("btn-clear"))
|
||||
{
|
||||
button->on_click = [this](Node*) {
|
||||
@@ -961,7 +967,7 @@ void App::update_memory_usage(size_t bytes)
|
||||
if (auto txt = layout[main_id]->find<NodeText>("txt-memory"))
|
||||
{
|
||||
static char buffer[128];
|
||||
sprintf(buffer, "History memory: %.2f Kb", bytes / 1024.f);
|
||||
sprintf(buffer, "History memory: %.2f Mb", bytes / 1024.f / 1024.f);
|
||||
txt->set_text(buffer);
|
||||
layout[main_id]->update();
|
||||
}
|
||||
|
||||
@@ -63,6 +63,13 @@ void ui::Canvas::stroke_end()
|
||||
m_show_tmp = false;
|
||||
}
|
||||
}
|
||||
void ui::Canvas::stroke_cancel()
|
||||
{
|
||||
if (!m_current_stroke)
|
||||
return;
|
||||
m_current_stroke = nullptr;
|
||||
m_show_tmp = false;
|
||||
}
|
||||
void ui::Canvas::stroke_draw()
|
||||
{
|
||||
if (!(m_current_stroke && m_current_stroke->has_sample()))
|
||||
|
||||
@@ -103,6 +103,7 @@ public:
|
||||
void stroke_update(glm::vec2 point, float pressure);
|
||||
void stroke_draw();
|
||||
void stroke_end();
|
||||
void stroke_cancel();
|
||||
void stroke_commit();
|
||||
void clear(const glm::vec4& color = { 1, 1, 1, 0 });
|
||||
void snapshot_save(std::string data_path);
|
||||
@@ -169,8 +170,6 @@ public:
|
||||
}
|
||||
virtual ~ActionStroke()
|
||||
{
|
||||
|
||||
LOG("ActionStroke destroyed: free %zu bytes", memory());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
|
||||
canvas->stroke_update(loc, 1.f);
|
||||
break;
|
||||
case kEventType::MouseCancel:
|
||||
canvas->stroke_end();
|
||||
canvas->stroke_cancel();
|
||||
m_dragging = false;
|
||||
node->mouse_release();
|
||||
break;
|
||||
@@ -348,11 +348,17 @@ void CanvasModeFill::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
|
||||
}
|
||||
case kEventType::MouseCancel:
|
||||
if (m_dragging)
|
||||
{
|
||||
m_points.pop_back();
|
||||
m_shape.update_vertices(m_points.data(), m_points.size());
|
||||
}
|
||||
m_dragging = false;
|
||||
node->mouse_release();
|
||||
if (m_points.size() < 4)
|
||||
{
|
||||
m_points.clear();
|
||||
m_shape.update_vertices(m_points.data(), m_points.size());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -6,6 +6,7 @@ enum class kKey : uint8_t
|
||||
AndroidVolumeUp,
|
||||
AndroidVolumeDown,
|
||||
AndroidHome,
|
||||
AndroidBack,
|
||||
KeySpacebar,
|
||||
KeyE,
|
||||
};
|
||||
|
||||
@@ -2043,7 +2043,7 @@ public:
|
||||
auto blend = glIsEnabled(GL_BLEND);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
//glEnable(GL_DEPTH_TEST);
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
for (int plane_index = 0; plane_index < 6; plane_index++)
|
||||
{
|
||||
@@ -2144,6 +2144,9 @@ public:
|
||||
// m_zoom_canvas *= 0.9f;
|
||||
// if (ke->m_key == kKey::AndroidVolumeDown)
|
||||
// m_zoom_canvas *= 1.1f;
|
||||
if (ke->m_key == kKey::AndroidBack)
|
||||
if (!ActionManager::empty())
|
||||
ActionManager::undo();
|
||||
break;
|
||||
case kEventType::KeyUp:
|
||||
// if (ke->m_key == kKey::KeyE)
|
||||
|
||||
@@ -12,7 +12,7 @@ static size_t data_handler(void *contents, size_t size, size_t nmemb, void *user
|
||||
|
||||
void LogRemote::start()
|
||||
{
|
||||
if (m_running)
|
||||
if (m_running || m_error)
|
||||
return; // already running
|
||||
|
||||
m_running = true;
|
||||
@@ -20,7 +20,7 @@ void LogRemote::start()
|
||||
net_init();
|
||||
auto session_string = net_request("/start");
|
||||
m_session = atoi(session_string.c_str());
|
||||
while (m_running)
|
||||
while (m_running && !m_error)
|
||||
{
|
||||
auto m = m_mq.Get();
|
||||
auto escaped = curl_easy_escape(curl, m.c_str(), (int)m.size());
|
||||
@@ -30,6 +30,7 @@ void LogRemote::start()
|
||||
net_request("/log", std::string(data.get(), sz));
|
||||
}
|
||||
net_close();
|
||||
LOG("NET thread loop exit");
|
||||
});
|
||||
}
|
||||
void LogRemote::net_init()
|
||||
@@ -50,7 +51,11 @@ std::string LogRemote::net_request(std::string cmd, std::string data /*= ""*/)
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
res = curl_easy_perform(curl);
|
||||
if (res != CURLcode::CURLE_OK)
|
||||
{
|
||||
LOG("NET error, closed");
|
||||
m_running = false;
|
||||
m_error = true;
|
||||
}
|
||||
return readBuffer;
|
||||
}
|
||||
void LogRemote::net_close()
|
||||
@@ -58,6 +63,7 @@ void LogRemote::net_close()
|
||||
if (curl)
|
||||
curl_easy_cleanup(curl);
|
||||
curl = nullptr;
|
||||
m_running = false;
|
||||
}
|
||||
void LogRemote::log(const char* format, ...)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,8 @@ class LogRemote
|
||||
{
|
||||
public:
|
||||
static LogRemote I;
|
||||
bool m_running;
|
||||
bool m_running = false;
|
||||
bool m_error = false;
|
||||
std::thread m_thread;
|
||||
ui::BlockingQueue<std::string> m_mq;
|
||||
CURL *curl = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user