implement eraser detection on windows
This commit is contained in:
61
src/main.cpp
61
src/main.cpp
@@ -29,6 +29,7 @@ std::thread::id gl_thread;
|
||||
int gl_count = 0;
|
||||
std::deque<std::packaged_task<void()>> tasklist;
|
||||
std::mutex task_mutex;
|
||||
float timer_stylus = 0;
|
||||
|
||||
//Returns the last Win32 error, in string format. Returns an empty string if there is no error.
|
||||
std::string GetLastErrorAsString()
|
||||
@@ -466,10 +467,6 @@ int main(int argc, char** argv)
|
||||
auto y = unsigned{};
|
||||
GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &x, &y);
|
||||
App::I.zoom = (float)x / 96.f;
|
||||
// SetWindowPos(hWnd, NULL, 0, 0,
|
||||
// (clientRect.right - clientRect.left) * App::I.zoom,
|
||||
// (clientRect.bottom - clientRect.top) * App::I.zoom,
|
||||
// SWP_NOREPOSITION | SWP_NOOWNERZORDER);
|
||||
|
||||
App::I.init();
|
||||
|
||||
@@ -483,6 +480,11 @@ int main(int argc, char** argv)
|
||||
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;
|
||||
@@ -504,6 +506,7 @@ int main(int argc, char** argv)
|
||||
one_sec += dt;
|
||||
render_timer += dt;
|
||||
frame_timer += dt;
|
||||
timer_stylus += dt;
|
||||
t0 = t1;
|
||||
|
||||
if (one_sec > 1.f)
|
||||
@@ -531,6 +534,9 @@ int main(int argc, char** argv)
|
||||
working_list.pop_front();
|
||||
}
|
||||
async_unlock();
|
||||
//LOG("clear");
|
||||
//WacomTablet::I.m_stylus = false;
|
||||
//WacomTablet::I.m_eraser = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -542,6 +548,12 @@ int main(int argc, char** argv)
|
||||
App::I.redraw = true;
|
||||
render_timer = 0;
|
||||
}
|
||||
if (timer_stylus > 0.1 && WacomTablet::I.m_stylus)
|
||||
{
|
||||
WacomTablet::I.m_stylus = false;
|
||||
WacomTablet::I.m_eraser = false;
|
||||
App::I.redraw = true;
|
||||
}
|
||||
if (App::I.redraw)
|
||||
{
|
||||
async_lock();
|
||||
@@ -597,9 +609,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
static POINT lastPoint;
|
||||
|
||||
auto extra = GetMessageExtraInfo();
|
||||
auto pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse;
|
||||
if ((extra & 0xFFFFFF00) == 0xFF515700)
|
||||
pointer_source = kEventSource::Touch;
|
||||
// if ((extra & 0xFFFFFF00) == 0xFF515700)
|
||||
// LOG("source %s", extra & 0x80 ? "touch" : "pen");
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
@@ -653,6 +664,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
// }
|
||||
case WT_PACKET:
|
||||
{
|
||||
timer_stylus = 0;
|
||||
std::lock_guard<std::mutex> lock(task_mutex);
|
||||
tasklist.emplace_back([=] {
|
||||
WacomTablet::I.handle_message(hWnd, msg, wp, lp);
|
||||
@@ -688,45 +700,60 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
case WM_MOUSEMOVE:
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(task_mutex);
|
||||
tasklist.emplace_back([lp, pointer_source, p = WacomTablet::I.get_pressure()]{
|
||||
App::I.mouse_move((float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), p, pointer_source);
|
||||
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;
|
||||
App::I.mouse_move((float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), p, pointer_source, WacomTablet::I.m_eraser);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case WM_LBUTTONDOWN:
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(task_mutex);
|
||||
tasklist.emplace_back([lp, pointer_source, hWnd, p = WacomTablet::I.get_pressure()]{
|
||||
tasklist.emplace_back([lp, extra, hWnd, p = WacomTablet::I.get_pressure()]{
|
||||
SetCapture(hWnd);
|
||||
App::I.mouse_down(0, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), p, pointer_source);
|
||||
auto 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);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(task_mutex);
|
||||
tasklist.emplace_back([lp, pointer_source]{
|
||||
tasklist.emplace_back([lp, extra]{
|
||||
WacomTablet::I.reset_pressure();
|
||||
ReleaseCapture();
|
||||
App::I.mouse_up(0, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), pointer_source);
|
||||
auto 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);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case WM_RBUTTONDOWN:
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(task_mutex);
|
||||
tasklist.emplace_back([lp, pointer_source, hWnd]{
|
||||
tasklist.emplace_back([lp, extra, hWnd]{
|
||||
SetCapture(hWnd);
|
||||
App::I.mouse_down(1, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), 1.f, pointer_source);
|
||||
auto 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);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case WM_RBUTTONUP:
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(task_mutex);
|
||||
tasklist.emplace_back([lp, pointer_source]{
|
||||
tasklist.emplace_back([lp, extra]{
|
||||
ReleaseCapture();
|
||||
App::I.mouse_up(1, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), pointer_source);
|
||||
auto 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);
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user