diff --git a/PanoPainter.vcxproj b/PanoPainter.vcxproj index b96e741..7dcc96b 100644 --- a/PanoPainter.vcxproj +++ b/PanoPainter.vcxproj @@ -77,7 +77,7 @@ true - libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;libs\bugtrap-client\include;libs\poly2tri\poly2tri;libs\base64;$(IncludePath) + libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;libs\bugtrap-client\include;libs\poly2tri\poly2tri;libs\base64;libs\sqlite3;$(IncludePath) libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);libs\bugtrap-client\lib;$(LibraryPath) @@ -87,7 +87,7 @@ false - libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;libs\bugtrap-client\include;libs\poly2tri\poly2tri;libs\base64;$(IncludePath) + libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;libs\bugtrap-client\include;libs\poly2tri\poly2tri;libs\base64;libs\sqlite3;$(IncludePath) libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);libs\bugtrap-client\lib;$(LibraryPath) @@ -167,6 +167,10 @@ + + NotUsing + NotUsing + @@ -292,6 +296,8 @@ + + diff --git a/PanoPainter.vcxproj.filters b/PanoPainter.vcxproj.filters index 44b9b38..22a875b 100644 --- a/PanoPainter.vcxproj.filters +++ b/PanoPainter.vcxproj.filters @@ -40,6 +40,9 @@ {e631ac80-1b9b-424f-8adf-e2bab71a566d} + + {ef44d179-f28b-458c-b3df-be2895553149} + @@ -264,6 +267,9 @@ Source Files\ui + + libs\sqlite3 + @@ -473,6 +479,12 @@ Header Files\ui + + libs\sqlite3 + + + libs\sqlite3 + diff --git a/libs/wacom/WinTab/Utils.cpp b/libs/wacom/WinTab/Utils.cpp index 17f3e3a..ed15601 100644 --- a/libs/wacom/WinTab/Utils.cpp +++ b/libs/wacom/WinTab/Utils.cpp @@ -61,7 +61,9 @@ BOOL LoadWintab( void ) { // ghWintab = LoadLibraryA( "C:\\dev\\mainline\\Wacom\\Win\\Win32\\Debug\\Wacom_Tablet.dll" ); // ghWintab = LoadLibraryA( "C:\\dev\\mainline\\Wacom\\Win\\Win32\\Debug\\Wintab32.dll" ); - ghWintab = LoadLibraryA( "Wintab32.dll" ); + LOG("calling LoadLibrary"); + ghWintab = LoadLibrary(L"Wintab32.dll"); + LOG("LoadLibrary called"); if ( !ghWintab ) { @@ -71,6 +73,8 @@ BOOL LoadWintab( void ) return FALSE; } + LOG("WinTab found"); + // Explicitly find the exported Wintab functions in which we are interested. // We are using the ASCII, not unicode versions (where applicable). GETPROCADDRESS( WTOPENA, WTOpenA ); diff --git a/src/app.cpp b/src/app.cpp index 360cd55..8b8c031 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -208,15 +208,13 @@ int progress_callback_upload(void *clientp, curl_off_t dltotal, return 0; } -void App::download(std::string filename, std::function progress) +void App::download(std::string url, std::string dest_filepath, std::function progress) { CURL *curl = curl_easy_init(); if (curl) { - auto dest = data_path + "/" + filename; - FILE* fp = fopen(dest.c_str(), "wb"); - std::string url = "https://panopainter.com/cloud/cloud-dwl.php?file=" + filename; - LOG("download %s to %s", url.c_str(), dest.c_str()); + FILE* fp = fopen(dest_filepath.c_str(), "wb"); + LOG("download %s to %s", url.c_str(), dest_filepath.c_str()); curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_data_write); diff --git a/src/app.h b/src/app.h index 4696718..4b5d169 100644 --- a/src/app.h +++ b/src/app.h @@ -69,6 +69,7 @@ public: std::string doc_path; std::string doc_dir; std::string doc_filename; + bool has_stylus = false; float width; float height; bool keys[256]; @@ -132,6 +133,7 @@ public: bool key_up(kKey key); bool key_char(char key); void toggle_ui(); + void set_stylus(); void message_box(const std::string& title, const std::string& text); void rec_clear(); @@ -165,7 +167,7 @@ public: void cloud_upload_all(); void cloud_browse(); void upload(std::string filename, std::string name = "", std::function progress = nullptr); - void download(std::string filename, std::function progress = nullptr); + void download(std::string url, std::string dest_filepath, std::function progress = nullptr); bool check_license(); std::shared_ptr show_progress(const std::string& title); diff --git a/src/app_cloud.cpp b/src/app_cloud.cpp index 7e23d95..7a778cf 100644 --- a/src/app_cloud.cpp +++ b/src/app_cloud.cpp @@ -146,7 +146,8 @@ void App::cloud_browse() m->m_message->set_text("Download in progress"); async_redraw(); async_end(); - download(dialog->selected_path, [this,m](float p){ + std::string url = "https://panopainter.com/cloud/cloud-dwl.php?file=" + dialog->selected_file; + download(url, dialog->selected_path, [this,m](float p){ static char progress[256]; sprintf(progress, "Download in progress %.2f%%", p * 100.f); async_start(); diff --git a/src/app_events.cpp b/src/app_events.cpp index 76eacf7..9c0a65d 100644 --- a/src/app_events.cpp +++ b/src/app_events.cpp @@ -303,3 +303,10 @@ void App::toggle_ui() m->m_children[i]->m_display = fullscreen; fullscreen = !fullscreen; } + +void App::set_stylus() +{ + has_stylus = true; + if (canvas) + canvas->m_canvas->m_touch_lock = true; +} diff --git a/src/brush.cpp b/src/brush.cpp index 95af37a..9bed6f8 100644 --- a/src/brush.cpp +++ b/src/brush.cpp @@ -207,8 +207,8 @@ void ui::Stroke::add_point(glm::vec2 pos, float pressure) m_curve = glm::min(m_curve + 0.1f, 1.f); //pressure = pressure * glm::pow(m_curve, 2.f); #endif // __IOS__ - m_pressure_buff.add(pressure); - pressure = m_pressure_buff.average(); + //m_pressure_buff.add(pressure); + //pressure = m_pressure_buff.average(); if (m_brush.m_tip_size_pressure) m_step = glm::max(m_brush.m_tip_spacing * m_brush.m_tip_size * pressure * 800.f, 1.f); diff --git a/src/canvas.h b/src/canvas.h index 8f6c1a0..261f618 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -115,7 +115,7 @@ public: static Canvas* I; NodeCanvas* m_node = nullptr; bool m_alpha_lock = false; - bool m_touch_lock = true; + bool m_touch_lock = false; glm::mat4 m_mv{ 1 }; glm::mat4 m_proj{ 1 }; glm::vec4 m_box{ 0 }; diff --git a/src/canvas_modes.cpp b/src/canvas_modes.cpp index b8482d8..81df12f 100644 --- a/src/canvas_modes.cpp +++ b/src/canvas_modes.cpp @@ -16,8 +16,20 @@ void CanvasModeBasicCamera::on_MouseEvent(MouseEvent* me, glm::vec2& loc) switch (me->m_type) { case kEventType::MouseDownL: +// if (canvas->m_touch_lock && me->m_source == kEventSource::Touch) +// { +// m_draggingR = true; +// m_dragR_start = me->m_pos; +// m_pan_start = canvas->m_pan; +// node->mouse_capture(); +// } break; case kEventType::MouseUpL: +// if (canvas->m_touch_lock && me->m_source == kEventSource::Touch) +// { +// m_draggingR = false; +// node->mouse_release(); +// } break; case kEventType::MouseDownR: if (App::I.keys[(int)kKey::KeyAlt]) diff --git a/src/canvas_modes.h b/src/canvas_modes.h index 23c6059..3c6c55e 100644 --- a/src/canvas_modes.h +++ b/src/canvas_modes.h @@ -25,6 +25,7 @@ public: class CanvasModeBasicCamera : public CanvasMode { bool m_draggingR = false; + bool m_draggingT = false; // touch drag glm::vec2 m_dragR_start; glm::vec2 m_pan_start; float m_camera_fov; diff --git a/src/log.cpp b/src/log.cpp index 9bd472b..d6fc094 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -115,7 +115,7 @@ void LogRemote::log(const wchar_t* format, ...) mbstate_t st = {}; std::string converted; - converted.reserve(string_to_convert.size()); + converted.resize(string_to_convert.size()); const wchar_t * wptr = string_to_convert.c_str(); std::wcsrtombs((char*)converted.data(), &wptr, converted.capacity(), &st); diff --git a/src/main.cpp b/src/main.cpp index 40b3b17..4de39a9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,6 +30,9 @@ int gl_count = 0; std::deque> tasklist; std::mutex task_mutex; float timer_stylus = 0; +float timer_ink_touch = 0; +float timer_ink_pen = 0; +bool sandboxed = false; //Returns the last Win32 error, in string format. Returns an empty string if there is no error. std::string GetLastErrorAsString() @@ -184,14 +187,38 @@ int read_WMI_info() auto log_field = [](const wchar_t* section, IWbemClassObject* clsObj, const wchar_t* field) { VARIANT vRet; + CIMTYPE pType; VariantInit(&vRet); - if (SUCCEEDED(clsObj->Get(field, 0, &vRet, NULL, NULL)) && vRet.vt == VT_BSTR) + if (SUCCEEDED(clsObj->Get(field, 0, &vRet, &pType, NULL))) { - LOGW(L"%s %s: %s", section, field, vRet.bstrVal); + if (pType == CIM_STRING && pType != CIM_EMPTY && pType != CIM_ILLEGAL) + { + LOGW(L"%s %s: %s", section, field, vRet.bstrVal); + } + else if (pType == CIM_UINT32 && pType != CIM_EMPTY && pType != CIM_ILLEGAL) + { + LOGW(L"%s %s: %d", section, field, vRet.uintVal); + } + VariantClear(&vRet); } }; + auto get_int = [](IWbemClassObject* clsObj, const wchar_t* field) { + VARIANT vRet; + CIMTYPE pType; + VariantInit(&vRet); + int ret = 0; + if (SUCCEEDED(clsObj->Get(field, 0, &vRet, &pType, NULL))) + { + if (pType == CIM_UINT32 && pType != CIM_EMPTY && pType != CIM_ILLEGAL) + ret = vRet.uintVal; + VariantClear(&vRet); + } + return ret; + }; + + // GET DEVICE INFO { IEnumWbemClassObject* pEnumerator = NULL; @@ -249,7 +276,69 @@ int read_WMI_info() pEnumerator->Release(); } + pService->Release(); + pService = NULL; + if (FAILED(hRes = pLocator->ConnectServer(L"root\\Microsoft\\Windows\\DeviceGuard", NULL, NULL, NULL, WBEM_FLAG_CONNECT_USE_MAX_WAIT, NULL, NULL, &pService))) + { + pLocator->Release(); + LOG("Unable to connect to \"DeviceGuard\": %x", hRes); + return 1; + } + + // GET DEVICE GUARD + { + IEnumWbemClassObject* pEnumerator = NULL; + if (FAILED(hRes = pService->ExecQuery(L"WQL", L"SELECT * FROM Win32_DeviceGuard", WBEM_FLAG_FORWARD_ONLY, NULL, &pEnumerator))) + { + pLocator->Release(); + pService->Release(); + LOG("Unable to retrive desktop monitors: %x", hRes); + return 1; + } + + IWbemClassObject* clsObj = NULL; + int numElems; + while ((hRes = pEnumerator->Next(WBEM_INFINITE, 1, &clsObj, (ULONG*)&numElems)) != WBEM_S_FALSE) + { + if (FAILED(hRes)) + break; + + if (get_int(clsObj, L"CodeIntegrityPolicyEnforcementStatus") > 0) + { + LOG("SANDBOX DETECTED"); + sandboxed = true; + } + + SAFEARRAY *psaNames = NULL; + if (SUCCEEDED(clsObj->GetNames(0, WBEM_FLAG_ALWAYS | WBEM_FLAG_NONSYSTEM_ONLY, 0, &psaNames))) + { + // Get the number of properties. + long lLower, lUpper; + BSTR PropName = NULL; + SafeArrayGetLBound(psaNames, 1, &lLower); + SafeArrayGetUBound(psaNames, 1, &lUpper); + + for (long i = lLower; i <= lUpper; i++) + { + // Get this property. + SafeArrayGetElement(psaNames, &i, &PropName); + + LOGW(L"Prop: %s", PropName); + log_field(L"DeviceGuard", clsObj, PropName); + + SysFreeString(PropName); + } + + SafeArrayDestroy(psaNames); + } + + clsObj->Release(); + } + pEnumerator->Release(); + } + + pLocator->Release(); CoUninitialize(); @@ -261,6 +350,7 @@ static void SetupExceptionHandler() { // Setup exception handler BT_SetAppName(_T("PanoPainter")); + BT_SetAppVersion(g_version_w); //BT_SetSupportEMail(_T("your@email.com")); BT_SetFlags(BTF_DETAILEDMODE | BTF_ATTACHREPORT | BTF_SCREENCAPTURE); @@ -273,6 +363,7 @@ static void SetupExceptionHandler() // = 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); + BT_SetSupportServer(_T("http://panopainter.com/bug/"), BUGTRAP_HTTP_PORT); // required for VS 2005 & 2008 BT_InstallSehFilter(); @@ -284,8 +375,10 @@ static void SetupExceptionHandler() // BT_SetLogEchoMode(g_iLogHandle, BTLE_STDERR | BTLE_DBGOUT); // // PCTSTR pszLogFileName = BT_GetLogFileName(g_iLogHandle); - TCHAR wpath[1024]; - GetFullPathNameW(L"panopainter-log.txt", 1024, wpath, nullptr); + TCHAR wpath[MAX_PATH]; + //GetFullPathNameW(L"panopainter-log.txt", 1024, wpath, nullptr); + auto log_file = App::I.data_path + "/panopainter-log.txt"; + std::mbstowcs(wpath, log_file.c_str(), log_file.size()); BT_AddLogFile(wpath); BT_SetPreErrHandler([](INT_PTR){ @@ -365,10 +458,16 @@ int main(int argc, char** argv) RegisterClass(&wc); + auto monitor = MonitorFromWindow(0, MONITOR_DEFAULTTOPRIMARY); + auto x = unsigned{}; + auto y = unsigned{}; + GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &x, &y); + App::I.zoom = (float)x / 96.f; + AdjustWindowRect(&clientRect, WS_OVERLAPPEDWINDOW, false); - hWnd = CreateWindow(wc.lpszClassName, L"PanoPainter", WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, CW_USEDEFAULT, clientRect.right - clientRect.left, - clientRect.bottom - clientRect.top, 0, 0, hInst, 0); + hWnd = CreateWindow(wc.lpszClassName, L"PanoPainter", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, + (float)(clientRect.right - clientRect.left) * App::I.zoom, + (float)(clientRect.bottom - clientRect.top) * App::I.zoom, 0, 0, hInst, 0); // Setup GL Rendering Context pfd.nSize = sizeof(pfd); @@ -427,9 +526,9 @@ int main(int argc, char** argv) wglDeleteContext(hRC); DestroyWindow(hWnd); - hWnd = CreateWindow(wc.lpszClassName, window_title, WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, CW_USEDEFAULT, clientRect.right - clientRect.left, - clientRect.bottom - clientRect.top, 0, 0, hInst, 0); + hWnd = CreateWindow(wc.lpszClassName, window_title, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, + (float)(clientRect.right - clientRect.left) * App::I.zoom, + (float)(clientRect.bottom - clientRect.top) * App::I.zoom, 0, 0, hInst, 0); hDC = GetDC(hWnd); wglChoosePixelFormatARB(hDC, pixel_attribs, nullptr, 1, &pxfmt, &numFormat); @@ -462,35 +561,38 @@ int main(int argc, char** argv) LOG("RegisterTouchWindow error: %s", GetLastErrorAsString().c_str()); } - auto monitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); - auto x = unsigned{}; - auto y = unsigned{}; - GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &x, &y); - App::I.zoom = (float)x / 96.f; - + LOG("init app"); App::I.init(); + LOG("show main window"); ShowWindow(hWnd, SW_NORMAL); - WacomTablet::I.init(hWnd); + if (!sandboxed) + { + LOG("init WinTab"); + WacomTablet::I.init(hWnd); + } + else + { + LOG("SKIP init WinTab"); + } + + LOG("change icon"); SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON1))); + LOG("set redraw interval"); SetTimer(hWnd, 1, 500, [](HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { App::I.redraw = true; }); - SetWindowPos(hWnd, NULL, 0, 0, - (float)(clientRect.right - clientRect.left) * App::I.zoom, - (float)(clientRect.bottom - clientRect.top) * App::I.zoom, - SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER); - bool running = true; std::mutex render_mutex; std::condition_variable render_cv; std::thread renderer([&] { BT_SetTerminate(); + LOG("start render thread"); const float target_fps = 10; const float target_tick_rate = 60; unsigned long t0 = GetTickCount(); @@ -507,6 +609,8 @@ int main(int argc, char** argv) render_timer += dt; frame_timer += dt; timer_stylus += dt; + timer_ink_touch += dt; + timer_ink_pen += dt; t0 = t1; if (one_sec > 1.f) @@ -548,12 +652,23 @@ int main(int argc, char** argv) App::I.redraw = true; render_timer = 0; } - if (timer_stylus > 0.1 && WacomTablet::I.m_stylus) + if (timer_stylus > 0.1 && (WacomTablet::I.m_stylus || WacomTablet::I.m_eraser)) { WacomTablet::I.m_stylus = false; WacomTablet::I.m_eraser = false; App::I.redraw = true; } + if (timer_ink_pen > 0.1 && WacomTablet::I.m_ink_pen) + { + WacomTablet::I.m_ink_pen = false; + App::I.redraw = true; + } + if (timer_ink_touch > 0.1 && WacomTablet::I.m_ink_touch) + { + WacomTablet::I.m_ink_touch = false; + App::I.redraw = true; + } + if (App::I.redraw) { async_lock(); @@ -575,6 +690,7 @@ int main(int argc, char** argv) }); MSG msg; + LOG("start main loop"); while (running) { // If there any message in the queue process it @@ -664,6 +780,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) // } case WT_PACKET: { + App::I.set_stylus(); timer_stylus = 0; std::lock_guard lock(task_mutex); tasklist.emplace_back([=] { @@ -701,9 +818,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { std::lock_guard lock(task_mutex); tasklist.emplace_back([lp, extra, p = WacomTablet::I.get_pressure()]{ - auto pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; - if ((extra & 0xFFFFFF00) == 0xFF515700) - pointer_source = kEventSource::Touch; + kEventSource pointer_source; + if (WacomTablet::I.m_ink_pen || WacomTablet::I.m_ink_touch) + { + pointer_source = WacomTablet::I.m_ink_pen ? kEventSource::Stylus : kEventSource::Touch; + } + else + { + pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; + if ((extra & 0xFFFFFF00) == 0xFF515700) + pointer_source = kEventSource::Touch; + } App::I.mouse_move((float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), p, pointer_source, WacomTablet::I.m_eraser); }); } @@ -713,9 +838,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) std::lock_guard lock(task_mutex); tasklist.emplace_back([lp, extra, hWnd, p = WacomTablet::I.get_pressure()]{ SetCapture(hWnd); - auto pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; - if ((extra & 0xFFFFFF00) == 0xFF515700) - pointer_source = kEventSource::Touch; + kEventSource pointer_source; + if (WacomTablet::I.m_ink_pen || WacomTablet::I.m_ink_touch) + { + pointer_source = WacomTablet::I.m_ink_pen ? kEventSource::Stylus : kEventSource::Touch; + } + else + { + pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; + if ((extra & 0xFFFFFF00) == 0xFF515700) + pointer_source = kEventSource::Touch; + } App::I.mouse_down(0, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), p, pointer_source, WacomTablet::I.m_eraser); }); } @@ -726,9 +859,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) tasklist.emplace_back([lp, extra]{ WacomTablet::I.reset_pressure(); ReleaseCapture(); - auto pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; - if ((extra & 0xFFFFFF00) == 0xFF515700) - pointer_source = kEventSource::Touch; + kEventSource pointer_source; + if (WacomTablet::I.m_ink_pen || WacomTablet::I.m_ink_touch) + { + pointer_source = WacomTablet::I.m_ink_pen ? kEventSource::Stylus : kEventSource::Touch; + } + else + { + pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; + if ((extra & 0xFFFFFF00) == 0xFF515700) + pointer_source = kEventSource::Touch; + } App::I.mouse_up(0, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), pointer_source, WacomTablet::I.m_eraser); }); } @@ -738,9 +879,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) std::lock_guard lock(task_mutex); tasklist.emplace_back([lp, extra, hWnd]{ SetCapture(hWnd); - auto pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; - if ((extra & 0xFFFFFF00) == 0xFF515700) - pointer_source = kEventSource::Touch; + kEventSource pointer_source; + if (WacomTablet::I.m_ink_pen || WacomTablet::I.m_ink_touch) + { + pointer_source = WacomTablet::I.m_ink_pen ? kEventSource::Stylus : kEventSource::Touch; + } + else + { + pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; + if ((extra & 0xFFFFFF00) == 0xFF515700) + pointer_source = kEventSource::Touch; + } App::I.mouse_down(1, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), 1.f, pointer_source, 0); }); } @@ -750,9 +899,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) std::lock_guard lock(task_mutex); tasklist.emplace_back([lp, extra]{ ReleaseCapture(); - auto pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; - if ((extra & 0xFFFFFF00) == 0xFF515700) - pointer_source = kEventSource::Touch; + kEventSource pointer_source; + if (WacomTablet::I.m_ink_pen || WacomTablet::I.m_ink_touch) + { + pointer_source = WacomTablet::I.m_ink_pen ? kEventSource::Stylus : kEventSource::Touch; + } + else + { + pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; + if ((extra & 0xFFFFFF00) == 0xFF515700) + pointer_source = kEventSource::Touch; + } App::I.mouse_up(1, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), pointer_source, 0); }); } @@ -808,6 +965,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) // success, process touchInfo // mark as handled to skip call to DefWindowProc //fHandled = TRUE; + timer_ink_touch = 0; + WacomTablet::I.m_ink_touch = true; + WacomTablet::I.m_pen_pres = 1; } break; case PT_PEN: @@ -822,6 +982,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) // mark as handled to skip call to DefWindowProc //fHandled = TRUE; //penInfo.pressure + timer_ink_pen = 0; + WacomTablet::I.m_ink_pen = true; + WacomTablet::I.m_pen_pres = (float)penInfo.pressure / 1024.f; + App::I.set_stylus(); } break; default: diff --git a/src/wacom.cpp b/src/wacom.cpp index 02c187d..d45d966 100644 --- a/src/wacom.cpp +++ b/src/wacom.cpp @@ -126,6 +126,7 @@ bool WacomTablet::init(HWND hWnd) if (ret != sizeof(LOGCONTEXTA)) return false; #endif // _DEBUG + LOG("TabletInit"); g_hCtx = TabletInit(hWnd); if (!g_hCtx) { @@ -166,6 +167,9 @@ void WacomTablet::handle_message(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lPar static POINT ptOld, ptNew; static UINT prsOld, prsNew; + if (!gpWTPacket) + return; + if (gpWTPacket((HCTX)lParam, (UINT)wParam, &pkt)) { if (HIWORD(pkt.pkButtons) == TBN_DOWN) diff --git a/src/wacom.h b/src/wacom.h index d085a39..d9079b7 100644 --- a/src/wacom.h +++ b/src/wacom.h @@ -20,6 +20,8 @@ public: bool m_mouse_down = false; bool m_stylus = false; bool m_eraser = false; + bool m_ink_pen = false; + bool m_ink_touch = false; HCTX TabletInit(HWND hWnd);