From 49e19af2c599e7316b5a01983adc040421429f86 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 19 Dec 2014 14:05:07 +0200 Subject: [PATCH] Add an availability check to Touchscreen --- source/input/android/touchscreen.cpp | 5 +++++ source/input/generic/touchscreen.cpp | 5 +++++ source/input/touchscreen.cpp | 3 +++ source/input/touchscreen.h | 2 ++ source/input/windows/touchscreen.cpp | 22 ++++++++++++++++++++++ 5 files changed, 37 insertions(+) diff --git a/source/input/android/touchscreen.cpp b/source/input/android/touchscreen.cpp index f4703c3..6472f44 100644 --- a/source/input/android/touchscreen.cpp +++ b/source/input/android/touchscreen.cpp @@ -4,6 +4,11 @@ namespace Msp { namespace Input { +bool Touchscreen::is_available() +{ + return true; +} + void Touchscreen::input_event(const Graphics::Window::Event &event) { int action = AMotionEvent_getAction(event.aevent); diff --git a/source/input/generic/touchscreen.cpp b/source/input/generic/touchscreen.cpp index bfbf7aa..aff6b82 100644 --- a/source/input/generic/touchscreen.cpp +++ b/source/input/generic/touchscreen.cpp @@ -3,6 +3,11 @@ namespace Msp { namespace Input { +bool Touchscreen::is_available() +{ + return false; +} + void Touchscreen::input_event(const Graphics::Window::Event &) { } diff --git a/source/input/touchscreen.cpp b/source/input/touchscreen.cpp index 18e795f..4facb8c 100644 --- a/source/input/touchscreen.cpp +++ b/source/input/touchscreen.cpp @@ -8,6 +8,9 @@ namespace Input { Touchscreen::Touchscreen(Graphics::Window &w): window(w) { + if(!is_available()) + throw runtime_error("touchscreen not available"); + name = "Touchscreen"; window.set_touch_input(true); diff --git a/source/input/touchscreen.h b/source/input/touchscreen.h index 99432d2..0c96406 100644 --- a/source/input/touchscreen.h +++ b/source/input/touchscreen.h @@ -23,6 +23,8 @@ public: Touchscreen(Graphics::Window &); ~Touchscreen(); + static bool is_available(); + Graphics::Window &get_window() const { return window; } virtual std::string get_button_name(unsigned) const; diff --git a/source/input/windows/touchscreen.cpp b/source/input/windows/touchscreen.cpp index 180f1c0..7e314ca 100644 --- a/source/input/windows/touchscreen.cpp +++ b/source/input/windows/touchscreen.cpp @@ -8,6 +8,28 @@ using namespace std; namespace Msp { namespace Input { +bool Touchscreen::is_available() +{ + // Must have at least Windows 7 (WinNT 6.1) for WM_TOUCHMOVE + OSVERSIONINFOEX version; + version.dwOSVersionInfoSize = sizeof(version); + version.dwMajorVersion = 6; + version.dwMinorVersion = 1; + version.dwServicePackMajor = 0; + version.dwServicePackMinor = 0; + DWORD mask = VER_MAJORVERSION|VER_MINORVERSION|VER_SERVICEPACKMAJOR|VER_SERVICEPACKMINOR; + DWORDLONG cond = VerSetConditionMask(0, mask, VER_GREATER_EQUAL); + if(!VerifyVersionInfo(&version, type, cond)) + return false; + + if(!GetSystemMetrics(SM_TABLETPC)) + return false; + if(!(GetSystemMetrics(SM_DIGITIZER)&NID_READY)) + return false; + + return true; +} + void Touchscreen::input_event(const Graphics::Window::Event &event) { if(event.msg==WM_TOUCHMOVE) -- 2.43.0