fix log thread bug, add clean memory button, fix pinch zoom bug, set android back button to undo
This commit is contained in:
@@ -7,7 +7,7 @@ kKey convert_key(int android_key)
|
|||||||
CASE(AKEYCODE_SOFT_LEFT, kKey::Unknown);
|
CASE(AKEYCODE_SOFT_LEFT, kKey::Unknown);
|
||||||
CASE(AKEYCODE_SOFT_RIGHT, kKey::Unknown);
|
CASE(AKEYCODE_SOFT_RIGHT, kKey::Unknown);
|
||||||
CASE(AKEYCODE_HOME, kKey::AndroidHome);
|
CASE(AKEYCODE_HOME, kKey::AndroidHome);
|
||||||
CASE(AKEYCODE_BACK, kKey::Unknown);
|
CASE(AKEYCODE_BACK, kKey::AndroidBack);
|
||||||
CASE(AKEYCODE_CALL, kKey::Unknown);
|
CASE(AKEYCODE_CALL, kKey::Unknown);
|
||||||
CASE(AKEYCODE_ENDCALL, kKey::Unknown);
|
CASE(AKEYCODE_ENDCALL, kKey::Unknown);
|
||||||
CASE(AKEYCODE_0, kKey::Unknown);
|
CASE(AKEYCODE_0, kKey::Unknown);
|
||||||
|
|||||||
@@ -406,8 +406,8 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
|
|||||||
switch (action) {
|
switch (action) {
|
||||||
case AMOTION_EVENT_ACTION_DOWN:
|
case AMOTION_EVENT_ACTION_DOWN:
|
||||||
{
|
{
|
||||||
float y = AMotionEvent_getY(event, 0);
|
|
||||||
float x = AMotionEvent_getX(event, 0);
|
float x = AMotionEvent_getX(event, 0);
|
||||||
|
float y = AMotionEvent_getY(event, 0);
|
||||||
p0.id = AMotionEvent_getPointerId(event, 0);
|
p0.id = AMotionEvent_getPointerId(event, 0);
|
||||||
p0.pos = {x, y};
|
p0.pos = {x, y};
|
||||||
p0.idx = index;
|
p0.idx = index;
|
||||||
@@ -421,15 +421,18 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
|
|||||||
//LOG("pointer down index %d", index);
|
//LOG("pointer down index %d", index);
|
||||||
if (count == 2)
|
if (count == 2)
|
||||||
{
|
{
|
||||||
float y = AMotionEvent_getY(event, 1);
|
|
||||||
float x = AMotionEvent_getX(event, 1);
|
float x = AMotionEvent_getX(event, 1);
|
||||||
|
float y = AMotionEvent_getY(event, 1);
|
||||||
p1.id = AMotionEvent_getPointerId(event, 1);
|
p1.id = AMotionEvent_getPointerId(event, 1);
|
||||||
p1.idx = index;
|
p1.idx = index;
|
||||||
p1.pos = {x, y};
|
p1.pos = {x, y};
|
||||||
tracked = 2;
|
p0.pos.x = AMotionEvent_getX(event, 0);
|
||||||
|
p0.pos.y = AMotionEvent_getY(event, 0);
|
||||||
//LOG("second down");
|
//LOG("second down");
|
||||||
|
if (tracked == 1)
|
||||||
App::I.mouse_cancel(0);
|
App::I.mouse_cancel(0);
|
||||||
App::I.gesture_start(p0.pos, p1.pos);
|
App::I.gesture_start(p0.pos, p1.pos);
|
||||||
|
tracked = 2;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -500,9 +503,19 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
|
|||||||
break;
|
break;
|
||||||
case AINPUT_EVENT_TYPE_KEY:
|
case AINPUT_EVENT_TYPE_KEY:
|
||||||
{
|
{
|
||||||
|
int action = AKeyEvent_getAction(event);
|
||||||
int32_t key_val = AKeyEvent_getKeyCode(event);
|
int32_t key_val = AKeyEvent_getKeyCode(event);
|
||||||
LOG("Received key event: %d\n", key_val);
|
switch (action)
|
||||||
|
{
|
||||||
|
case AKEY_EVENT_ACTION_DOWN:
|
||||||
|
LOG("Received key down event: %d\n", key_val);
|
||||||
App::I.key_down(convert_key(key_val));
|
App::I.key_down(convert_key(key_val));
|
||||||
|
break;
|
||||||
|
case AKEY_EVENT_ACTION_UP:
|
||||||
|
LOG("Received key up event: %d\n", key_val);
|
||||||
|
App::I.key_up(convert_key(key_val));
|
||||||
|
break;
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} // end switch
|
} // end switch
|
||||||
|
|||||||
@@ -333,7 +333,10 @@
|
|||||||
<text text="Layers" font-face="arial" font-size="11"/>
|
<text text="Layers" font-face="arial" font-size="11"/>
|
||||||
</button-custom>
|
</button-custom>
|
||||||
<node height="100%" color="1" grow="1" align="center" justify="flex-end" dir="row">
|
<node height="100%" color="1" grow="1" align="center" justify="flex-end" dir="row">
|
||||||
<text id="txt-memory" text="History memory: 0.0 Kb" font-face="arial" font-size="11" margin="0 20 0 0" color=".6 .6 .6 1"/>
|
<text id="txt-memory" text="History memory: 0.00 Mb" font-face="arial" font-size="11" margin="0 5 0 0" color=".6 .6 .6 1"/>
|
||||||
|
<button-custom id="btn-clean-memory" margin="0 20 0 0">
|
||||||
|
<icon icon="delete" width="20"/>
|
||||||
|
</button-custom>
|
||||||
<text text="PanoPainter 0.1.2 alpha" font-face="arial" font-size="11" margin="0 10 0 0" color=".2 .5 1 1"/>
|
<text text="PanoPainter 0.1.2 alpha" font-face="arial" font-size="11" margin="0 10 0 0" color=".2 .5 1 1"/>
|
||||||
</node>
|
</node>
|
||||||
</border>
|
</border>
|
||||||
|
|||||||
@@ -21,3 +21,12 @@ void ActionManager::undo()
|
|||||||
LOG("History: %.2f KB", I.m_memory / 1024.f);
|
LOG("History: %.2f KB", I.m_memory / 1024.f);
|
||||||
App::I.update_memory_usage(I.m_memory);
|
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;
|
size_t m_memory = 0;
|
||||||
static void add(Action* action);
|
static void add(Action* action);
|
||||||
static void undo();
|
static void undo();
|
||||||
|
static void clear();
|
||||||
static bool empty()
|
static bool empty()
|
||||||
{
|
{
|
||||||
return I.m_actions.empty();
|
return I.m_actions.empty();
|
||||||
|
|||||||
@@ -636,6 +636,12 @@ void App::initLayout()
|
|||||||
ActionManager::undo();
|
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"))
|
if (auto* button = layout[main_id]->find<NodeButton>("btn-clear"))
|
||||||
{
|
{
|
||||||
button->on_click = [this](Node*) {
|
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"))
|
if (auto txt = layout[main_id]->find<NodeText>("txt-memory"))
|
||||||
{
|
{
|
||||||
static char buffer[128];
|
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);
|
txt->set_text(buffer);
|
||||||
layout[main_id]->update();
|
layout[main_id]->update();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,13 @@ void ui::Canvas::stroke_end()
|
|||||||
m_show_tmp = false;
|
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()
|
void ui::Canvas::stroke_draw()
|
||||||
{
|
{
|
||||||
if (!(m_current_stroke && m_current_stroke->has_sample()))
|
if (!(m_current_stroke && m_current_stroke->has_sample()))
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ public:
|
|||||||
void stroke_update(glm::vec2 point, float pressure);
|
void stroke_update(glm::vec2 point, float pressure);
|
||||||
void stroke_draw();
|
void stroke_draw();
|
||||||
void stroke_end();
|
void stroke_end();
|
||||||
|
void stroke_cancel();
|
||||||
void stroke_commit();
|
void stroke_commit();
|
||||||
void clear(const glm::vec4& color = { 1, 1, 1, 0 });
|
void clear(const glm::vec4& color = { 1, 1, 1, 0 });
|
||||||
void snapshot_save(std::string data_path);
|
void snapshot_save(std::string data_path);
|
||||||
@@ -169,8 +170,6 @@ public:
|
|||||||
}
|
}
|
||||||
virtual ~ActionStroke()
|
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);
|
canvas->stroke_update(loc, 1.f);
|
||||||
break;
|
break;
|
||||||
case kEventType::MouseCancel:
|
case kEventType::MouseCancel:
|
||||||
canvas->stroke_end();
|
canvas->stroke_cancel();
|
||||||
m_dragging = false;
|
m_dragging = false;
|
||||||
node->mouse_release();
|
node->mouse_release();
|
||||||
break;
|
break;
|
||||||
@@ -348,11 +348,17 @@ void CanvasModeFill::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
|
|||||||
}
|
}
|
||||||
case kEventType::MouseCancel:
|
case kEventType::MouseCancel:
|
||||||
if (m_dragging)
|
if (m_dragging)
|
||||||
|
{
|
||||||
m_points.pop_back();
|
m_points.pop_back();
|
||||||
|
m_shape.update_vertices(m_points.data(), m_points.size());
|
||||||
|
}
|
||||||
m_dragging = false;
|
m_dragging = false;
|
||||||
node->mouse_release();
|
node->mouse_release();
|
||||||
if (m_points.size() < 4)
|
if (m_points.size() < 4)
|
||||||
|
{
|
||||||
m_points.clear();
|
m_points.clear();
|
||||||
|
m_shape.update_vertices(m_points.data(), m_points.size());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ enum class kKey : uint8_t
|
|||||||
AndroidVolumeUp,
|
AndroidVolumeUp,
|
||||||
AndroidVolumeDown,
|
AndroidVolumeDown,
|
||||||
AndroidHome,
|
AndroidHome,
|
||||||
|
AndroidBack,
|
||||||
KeySpacebar,
|
KeySpacebar,
|
||||||
KeyE,
|
KeyE,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2043,7 +2043,7 @@ public:
|
|||||||
auto blend = glIsEnabled(GL_BLEND);
|
auto blend = glIsEnabled(GL_BLEND);
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glEnable(GL_DEPTH_TEST);
|
//glEnable(GL_DEPTH_TEST);
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
for (int plane_index = 0; plane_index < 6; plane_index++)
|
for (int plane_index = 0; plane_index < 6; plane_index++)
|
||||||
{
|
{
|
||||||
@@ -2144,6 +2144,9 @@ public:
|
|||||||
// m_zoom_canvas *= 0.9f;
|
// m_zoom_canvas *= 0.9f;
|
||||||
// if (ke->m_key == kKey::AndroidVolumeDown)
|
// if (ke->m_key == kKey::AndroidVolumeDown)
|
||||||
// m_zoom_canvas *= 1.1f;
|
// m_zoom_canvas *= 1.1f;
|
||||||
|
if (ke->m_key == kKey::AndroidBack)
|
||||||
|
if (!ActionManager::empty())
|
||||||
|
ActionManager::undo();
|
||||||
break;
|
break;
|
||||||
case kEventType::KeyUp:
|
case kEventType::KeyUp:
|
||||||
// if (ke->m_key == kKey::KeyE)
|
// 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()
|
void LogRemote::start()
|
||||||
{
|
{
|
||||||
if (m_running)
|
if (m_running || m_error)
|
||||||
return; // already running
|
return; // already running
|
||||||
|
|
||||||
m_running = true;
|
m_running = true;
|
||||||
@@ -20,7 +20,7 @@ void LogRemote::start()
|
|||||||
net_init();
|
net_init();
|
||||||
auto session_string = net_request("/start");
|
auto session_string = net_request("/start");
|
||||||
m_session = atoi(session_string.c_str());
|
m_session = atoi(session_string.c_str());
|
||||||
while (m_running)
|
while (m_running && !m_error)
|
||||||
{
|
{
|
||||||
auto m = m_mq.Get();
|
auto m = m_mq.Get();
|
||||||
auto escaped = curl_easy_escape(curl, m.c_str(), (int)m.size());
|
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_request("/log", std::string(data.get(), sz));
|
||||||
}
|
}
|
||||||
net_close();
|
net_close();
|
||||||
|
LOG("NET thread loop exit");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
void LogRemote::net_init()
|
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());
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||||
res = curl_easy_perform(curl);
|
res = curl_easy_perform(curl);
|
||||||
if (res != CURLcode::CURLE_OK)
|
if (res != CURLcode::CURLE_OK)
|
||||||
|
{
|
||||||
|
LOG("NET error, closed");
|
||||||
m_running = false;
|
m_running = false;
|
||||||
|
m_error = true;
|
||||||
|
}
|
||||||
return readBuffer;
|
return readBuffer;
|
||||||
}
|
}
|
||||||
void LogRemote::net_close()
|
void LogRemote::net_close()
|
||||||
@@ -58,6 +63,7 @@ void LogRemote::net_close()
|
|||||||
if (curl)
|
if (curl)
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
curl = nullptr;
|
curl = nullptr;
|
||||||
|
m_running = false;
|
||||||
}
|
}
|
||||||
void LogRemote::log(const char* format, ...)
|
void LogRemote::log(const char* format, ...)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ class LogRemote
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static LogRemote I;
|
static LogRemote I;
|
||||||
bool m_running;
|
bool m_running = false;
|
||||||
|
bool m_error = false;
|
||||||
std::thread m_thread;
|
std::thread m_thread;
|
||||||
ui::BlockingQueue<std::string> m_mq;
|
ui::BlockingQueue<std::string> m_mq;
|
||||||
CURL *curl = nullptr;
|
CURL *curl = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user