From 0f721393bbbd060da61c4e780fe56f89984c8700 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Mon, 29 May 2017 08:47:04 +0100 Subject: [PATCH] added color picking with ALT key, added crash report library for windows --- engine.vcxproj | 18 ++++++------ engine/action.cpp | 6 ++-- engine/app.cpp | 1 + engine/app.h | 1 + engine/app_events.cpp | 2 ++ engine/canvas.cpp | 9 ++++++ engine/canvas_modes.cpp | 59 ++++++++++++++++++++++++++++++++------ engine/canvas_modes.h | 1 + engine/event.h | 1 + engine/keymap.h | 2 +- engine/log.cpp | 23 +++++++++++++++ engine/log.h | 3 ++ engine/main.cpp | 45 +++++++++++++++++++++++++++++ engine/node_canvas.cpp | 2 ++ engine/node_color_quad.cpp | 10 +++---- engine/pch.cpp | 3 ++ engine/pch.h | 3 ++ engine/wacom.cpp | 6 +++- engine/wacom.h | 1 + 19 files changed, 170 insertions(+), 26 deletions(-) diff --git a/engine.vcxproj b/engine.vcxproj index d2540a5..671a321 100644 --- a/engine.vcxproj +++ b/engine.vcxproj @@ -71,23 +71,23 @@ true - libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;$(IncludePath) - libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);$(LibraryPath) + libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;C:\Users\omar\Downloads\BugTrap-master\BugTrap-master\source\Client;$(IncludePath) + libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);C:\Users\omar\Downloads\BugTrap-master\BugTrap-master\bin;$(LibraryPath) true - libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;$(IncludePath) - libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);$(LibraryPath) + libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;C:\Users\omar\Downloads\BugTrap-master\BugTrap-master\source\Client;$(IncludePath) + libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);C:\Users\omar\Downloads\BugTrap-master\BugTrap-master\bin;$(LibraryPath) false - libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;$(IncludePath) - libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);$(LibraryPath) + libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;C:\Users\omar\Downloads\BugTrap-master\BugTrap-master\source\Client;$(IncludePath) + libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);C:\Users\omar\Downloads\BugTrap-master\BugTrap-master\bin;$(LibraryPath) false - libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;$(IncludePath) - libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);$(LibraryPath) + libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;C:\Users\omar\Downloads\BugTrap-master\BugTrap-master\source\Client;$(IncludePath) + libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);C:\Users\omar\Downloads\BugTrap-master\BugTrap-master\bin;$(LibraryPath) @@ -124,6 +124,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) pch.h + MultiThreadedDLL Console @@ -141,6 +142,7 @@ true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) pch.h + MultiThreadedDLL Console diff --git a/engine/action.cpp b/engine/action.cpp index 453a809..bce3942 100644 --- a/engine/action.cpp +++ b/engine/action.cpp @@ -9,7 +9,7 @@ void ActionManager::add(Action *action) { I.m_actions.emplace(action); I.m_memory += action->memory(); - 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); } @@ -18,7 +18,7 @@ void ActionManager::undo() I.m_actions.top()->undo(); I.m_memory -= I.m_actions.top()->memory(); I.m_actions.pop(); - 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); } @@ -27,6 +27,6 @@ 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); + //LOG("History: %.2f KB", I.m_memory / 1024.f); App::I.update_memory_usage(I.m_memory); } diff --git a/engine/app.cpp b/engine/app.cpp index a14fe08..3678be6 100644 --- a/engine/app.cpp +++ b/engine/app.cpp @@ -40,6 +40,7 @@ void App::initAssets() void App::initLog() { LogRemote::I.start(); + LogRemote::I.file_init(); } void App::init() diff --git a/engine/app.h b/engine/app.h index 1734b10..edee05a 100644 --- a/engine/app.h +++ b/engine/app.h @@ -43,6 +43,7 @@ public: const uint16_t main_id = const_hash("main"); float width; float height; + bool keys[256]; glm::vec2 gesture_p0; glm::vec2 gesture_p1; #ifdef __ANDROID__ diff --git a/engine/app_events.cpp b/engine/app_events.cpp index ce4dfb6..97703b6 100644 --- a/engine/app_events.cpp +++ b/engine/app_events.cpp @@ -95,6 +95,7 @@ bool App::gesture_end() } bool App::key_down(kKey key) { + keys[(int)key] = true; KeyEvent e; e.m_type = kEventType::KeyDown; e.m_key = key; @@ -104,6 +105,7 @@ bool App::key_down(kKey key) } bool App::key_up(kKey key) { + keys[(int)key] = false; KeyEvent e; e.m_type = kEventType::KeyUp; e.m_key = key; diff --git a/engine/canvas.cpp b/engine/canvas.cpp index 4da8871..287d032 100644 --- a/engine/canvas.cpp +++ b/engine/canvas.cpp @@ -399,6 +399,15 @@ void ui::Canvas::stroke_update(glm::vec2 point, float pressure) } void ui::Canvas::stroke_start(glm::vec2 point, float pressure, const ui::Brush& brush) { + // need to commit this now before starting a new stroke + if (m_current_stroke && m_commit_delayed) + { + stroke_commit(); + m_current_stroke = nullptr; + m_show_tmp = false; + m_commit_delayed = false; + } + m_current_stroke = std::make_unique(); m_current_stroke->m_camera = { m_cam_rot, m_cam_fov }; m_current_stroke->start(brush); diff --git a/engine/canvas_modes.cpp b/engine/canvas_modes.cpp index 5b79e74..9bc0eac 100644 --- a/engine/canvas_modes.cpp +++ b/engine/canvas_modes.cpp @@ -5,6 +5,7 @@ #include "canvas.h" #include "shader.h" #include "node_canvas.h" +#include "app.h" NodeCanvas* CanvasMode::node; ui::Canvas* CanvasMode::canvas; @@ -71,23 +72,65 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc) switch (me->m_type) { case kEventType::MouseDownL: - canvas->stroke_start(loc, me->m_pressure, node->m_brush); - m_dragging = true; + if (App::I.keys[(int)kKey::KeyAlt]) + { + m_picking = true; + } + else + { + canvas->stroke_start(loc, me->m_pressure, node->m_brush); + m_dragging = true; + } node->mouse_capture(); break; case kEventType::MouseUpL: - canvas->stroke_end(); - m_dragging = false; - node->mouse_release(); + if (m_dragging) + { + canvas->stroke_end(); + m_dragging = false; + node->mouse_release(); + } + if (m_picking) + { + m_picking = false; + node->mouse_release(); + int x = me->m_pos.x; + int y = App::I.height - me->m_pos.y - 1; + float pix[3]; + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glReadPixels(x, y, 1, 1, GL_RGB, GL_FLOAT, pix); + auto hsv = convert_rgb2hsv(glm::vec3(pix[0], pix[1], pix[2])); + App::I.color->m_hue->set_value(hsv.x); + App::I.color->m_quad->set_value(1.f - hsv.y, 1.f - hsv.z); + } break; case kEventType::MouseMove: if (m_dragging) canvas->stroke_update(loc, me->m_pressure); + if (m_picking) + { + int x = me->m_pos.x; + int y = App::I.height - me->m_pos.y - 1; + float pix[3]; + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glReadPixels(x, y, 1, 1, GL_RGB, GL_FLOAT, pix); + auto hsv = convert_rgb2hsv(glm::vec3(pix[0], pix[1], pix[2])); + App::I.color->m_hue->set_value(hsv.x); + App::I.color->m_quad->set_value(1.f - hsv.y, 1.f - hsv.z); + } break; case kEventType::MouseCancel: - canvas->stroke_cancel(); - m_dragging = false; - node->mouse_release(); + if (m_dragging) + { + canvas->stroke_cancel(); + m_dragging = false; + node->mouse_release(); + } + if (m_picking) + { + m_picking = false; + node->mouse_release(); + } break; default: break; diff --git a/engine/canvas_modes.h b/engine/canvas_modes.h index 1655946..3abe67d 100644 --- a/engine/canvas_modes.h +++ b/engine/canvas_modes.h @@ -35,6 +35,7 @@ public: class CanvasModePen : public CanvasMode { bool m_dragging = false; + bool m_picking = false; glm::vec2 m_pan_start; float m_camera_fov; float m_zoom_canvas = 1.f; diff --git a/engine/event.h b/engine/event.h index 77293c8..a5d6341 100644 --- a/engine/event.h +++ b/engine/event.h @@ -9,6 +9,7 @@ enum class kKey : uint8_t AndroidBack, KeySpacebar, KeyE, + KeyAlt }; enum class kEventResult : uint8_t diff --git a/engine/keymap.h b/engine/keymap.h index d76b0c9..029a467 100644 --- a/engine/keymap.h +++ b/engine/keymap.h @@ -248,7 +248,7 @@ kKey convert_key(int key) CASE(VK_RETURN, kKey::Unknown); CASE(VK_SHIFT, kKey::Unknown); CASE(VK_CONTROL, kKey::Unknown); - CASE(VK_MENU, kKey::Unknown); + CASE(VK_MENU, kKey::KeyAlt); CASE(VK_PAUSE, kKey::Unknown); CASE(VK_CAPITAL, kKey::Unknown); CASE(VK_KANA, kKey::Unknown); diff --git a/engine/log.cpp b/engine/log.cpp index dc9ecfc..beb4fc8 100644 --- a/engine/log.cpp +++ b/engine/log.cpp @@ -17,6 +17,7 @@ void LogRemote::start() m_running = true; m_thread = std::thread([&] { + BT_SetTerminate(); net_init(); auto session_string = net_request("/start"); m_session = atoi(session_string.c_str()); @@ -65,6 +66,16 @@ void LogRemote::net_close() curl = nullptr; m_running = false; } +void LogRemote::file_init() +{ + if (!m_logfile.is_open()) + m_logfile.open("log.txt"); +} +void LogRemote::file_close() +{ + if (!m_logfile.is_open()) + m_logfile.close(); +} void LogRemote::log(const char* format, ...) { static char buffer[4096]; @@ -73,6 +84,12 @@ void LogRemote::log(const char* format, ...) int n = vsnprintf(buffer, sizeof(buffer), format, arglist); va_end(arglist); m_mq.Post(std::string(buffer, n)); + if (m_logfile.is_open()) + { + auto line = std::string(buffer, n) + "\n"; + m_logfile.write(line.data(), line.size()); + m_logfile.flush(); + } } void LogRemote::log(const wchar_t* format, ...) { @@ -98,6 +115,12 @@ void LogRemote::log(const wchar_t* format, ...) //std::string converted_str = converter.to_bytes(string_to_convert); m_mq.Post(std::move(converted)); + if (m_logfile.is_open()) + { + auto line = converted + "\n"; + m_logfile.write(line.data(), line.size()); + m_logfile.flush(); + } } LogRemote::~LogRemote() { diff --git a/engine/log.h b/engine/log.h index 640d610..6ffea0b 100644 --- a/engine/log.h +++ b/engine/log.h @@ -23,11 +23,14 @@ public: std::string readBuffer; std::string m_url = "http://omigamedev.ddns.net:8083"; int m_session; + std::ofstream m_logfile; void start(); void net_init(); std::string net_request(std::string cmd, std::string data = ""); void net_close(); + void file_init(); + void file_close(); void log(const char* format, ...); void log(const wchar_t* format, ...); ~LogRemote(); diff --git a/engine/main.cpp b/engine/main.cpp index 96dd0ea..3fd9413 100644 --- a/engine/main.cpp +++ b/engine/main.cpp @@ -478,6 +478,42 @@ int read_WMI_info() return 0; } +INT_PTR g_iLogHandle = -1; +static void SetupExceptionHandler() +{ + // Setup exception handler + BT_SetAppName(_T("PanoPainter")); + //BT_SetSupportEMail(_T("your@email.com")); + BT_SetFlags(BTF_DETAILEDMODE | BTF_ATTACHREPORT | BTF_SCREENCAPTURE); + + // = BugTrapServer =========================================== + BT_SetSupportServer(_T("omigamedev.ddns.net"), 8088); + // - or - + //BT_SetSupportServer(_T("127.0.0.1"), 9999); + + // = BugTrapWebServer ======================================== + //BT_SetSupportServer(_T("http://localhost/BugTrapWebServer/RequestHandler.aspx"), BUGTRAP_HTTP_PORT); + //BT_SetSupportServer(_T("http://omigamedev.ddns.net:8088/source/Server/BugTrapWebServer/RequestHandler.aspx"), BUGTRAP_HTTP_PORT); + + // required for VS 2005 & 2008 + BT_InstallSehFilter(); + + // Add custom log file using default name +// g_iLogHandle = BT_OpenLogFile(NULL, BTLF_TEXT); +// BT_SetLogSizeInEntries(g_iLogHandle, 100); +// BT_SetLogFlags(g_iLogHandle, BTLF_SHOWTIMESTAMP); +// BT_SetLogEchoMode(g_iLogHandle, BTLE_STDERR | BTLE_DBGOUT); +// +// PCTSTR pszLogFileName = BT_GetLogFileName(g_iLogHandle); + TCHAR wpath[1024]; + GetFullPathNameW(L"log.txt", 1024, wpath, nullptr); + BT_AddLogFile(wpath); + + BT_SetPreErrHandler([](INT_PTR){ + LogRemote::I.file_close(); + }, 0); +} + int main() { WNDCLASS wc; @@ -485,6 +521,9 @@ int main() App::I.initLog(); + SetupExceptionHandler(); + BT_SetTerminate(); + read_WMI_info(); App::I.create(); @@ -629,6 +668,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { switch (msg) { + case WM_CREATE: + BT_SetTerminate(); + break; case WM_CLOSE: PostQuitMessage(0); break; @@ -647,10 +689,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) case WT_PACKET: WacomTablet::I.handle_message(hWnd, msg, wp, lp); break; + case WM_SYSKEYDOWN: case WM_KEYDOWN: keys[wp] = true; App::I.key_down(convert_key((int)wp)); break; + case WM_SYSKEYUP: case WM_KEYUP: keys[wp] = false; App::I.key_up(convert_key((int)wp)); @@ -666,6 +710,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) SetCapture(hWnd); break; case WM_LBUTTONUP: + WacomTablet::I.reset_pressure(); App::I.mouse_up(0, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp)); ReleaseCapture(); break; diff --git a/engine/node_canvas.cpp b/engine/node_canvas.cpp index 9a15a16..985b796 100644 --- a/engine/node_canvas.cpp +++ b/engine/node_canvas.cpp @@ -156,6 +156,7 @@ void NodeCanvas::handle_resize(glm::vec2 old_size, glm::vec2 new_size) kEventResult NodeCanvas::handle_event(Event* e) { + static std::vector* old_mode = nullptr; Node::handle_event(e); MouseEvent* me = static_cast(e); KeyEvent* ke = static_cast(e); @@ -186,6 +187,7 @@ kEventResult NodeCanvas::handle_event(Event* e) if (ke->m_key == kKey::AndroidBack) if (!ActionManager::empty()) ActionManager::undo(); + break; case kEventType::KeyUp: // if (ke->m_key == kKey::KeyE) diff --git a/engine/node_color_quad.cpp b/engine/node_color_quad.cpp index 01fab9e..b343a9c 100644 --- a/engine/node_color_quad.cpp +++ b/engine/node_color_quad.cpp @@ -29,7 +29,7 @@ void NodeColorQuad::set_value(float x, float y) { auto sz = GetSize(); auto pos = glm::clamp(glm::vec2(x, y) * sz, { 0, 0 }, sz); - m_picker->SetPosition(pos.x, pos.y); + m_picker->SetPosition(pos - m_picker->GetSize() * .5f); m_value = pos / glm::max({ 1,1 }, sz); // avoid div0 if (on_value_changed) on_value_changed(this, m_value); @@ -45,8 +45,8 @@ kEventResult NodeColorQuad::handle_event(Event* e) dragging = true; mouse_capture(); auto sz = GetSize(); - auto pos = glm::clamp(((MouseEvent*)e)->m_pos - m_pos, { 0, 0 }, sz) - m_picker->GetSize() * .5f; - m_picker->SetPosition(pos.x, pos.y); + auto pos = glm::clamp(((MouseEvent*)e)->m_pos - m_pos, { 0, 0 }, sz); + m_picker->SetPosition(pos - m_picker->GetSize() * .5f); m_value = pos / glm::max({ 1,1 }, sz); // avoid div0 if (on_value_changed) on_value_changed(this, m_value); @@ -60,8 +60,8 @@ kEventResult NodeColorQuad::handle_event(Event* e) if (dragging) { auto sz = GetSize(); - auto pos = glm::clamp(((MouseEvent*)e)->m_pos - m_pos, { 0, 0 }, sz) - m_picker->GetSize() * .5f; - m_picker->SetPosition(pos.x, pos.y); + auto pos = glm::clamp(((MouseEvent*)e)->m_pos - m_pos, { 0, 0 }, sz); + m_picker->SetPosition(pos - m_picker->GetSize() * .5f); m_value = pos / glm::max({ 1,1 }, sz); // avoid div0 if (on_value_changed) on_value_changed(this, m_value); diff --git a/engine/pch.cpp b/engine/pch.cpp index a0859d7..1a1ebab 100644 --- a/engine/pch.cpp +++ b/engine/pch.cpp @@ -13,3 +13,6 @@ #pragma comment (lib, "libcurl.lib") #endif // DEBUG +#ifdef _WIN32 + #pragma comment(lib, "BugTrapU-x64.lib") +#endif // _WIN32 diff --git a/engine/pch.h b/engine/pch.h index b2597bf..ee1823e 100644 --- a/engine/pch.h +++ b/engine/pch.h @@ -45,9 +45,11 @@ #define _SCL_SECURE_NO_WARNINGS #include #include + #include #include #include #include + #include #define SHADER_VERSION "#version 150\n" @@ -68,6 +70,7 @@ #include #include #include +#include #include #include #include diff --git a/engine/wacom.cpp b/engine/wacom.cpp index 98dd1d1..cfe3652 100644 --- a/engine/wacom.cpp +++ b/engine/wacom.cpp @@ -178,5 +178,9 @@ void WacomTablet::handle_message(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lPar float WacomTablet::get_pressure() const { - return m_pen_down ? m_pen_pres : 1.f; + return m_pen_pres; } +void WacomTablet::reset_pressure() +{ + m_pen_pres = 1.f; +} \ No newline at end of file diff --git a/engine/wacom.h b/engine/wacom.h index e61af94..b2769a9 100644 --- a/engine/wacom.h +++ b/engine/wacom.h @@ -26,4 +26,5 @@ public: void handle_message(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam); void set_focus(int activate); float get_pressure() const; + void reset_pressure(); };