Skip to content

Instantly share code, notes, and snippets.

@sfan5
Created November 5, 2016 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfan5/31e4f3fb1a689c943ed2907126dc7c11 to your computer and use it in GitHub Desktop.
Save sfan5/31e4f3fb1a689c943ed2907126dc7c11 to your computer and use it in GitHub Desktop.
touch input for irrlicht on windows (incomplete)
From d61676afdfd10fcba779ceab8fa00779a9eb2ccd Mon Sep 17 00:00:00 2001
From: sfan5 <sfan5@live.de>
Date: Sat, 15 Oct 2016 15:13:07 +0200
Subject: [PATCH 1/3] Add STouchInput to header file
---
include/IEventReceiver.h | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/include/IEventReceiver.h b/include/IEventReceiver.h
index feb629b..224e378 100644
--- a/include/IEventReceiver.h
+++ b/include/IEventReceiver.h
@@ -34,6 +34,9 @@ namespace irr
IrrlichtDevice::postEventFromUser. They take the same path as mouse events. */
EET_KEY_INPUT_EVENT,
+ //! A touch input event.
+ EET_TOUCH_INPUT_EVENT,
+
//! A joystick (joypad, gamepad) input event.
/** Joystick events are created by polling all connected joysticks once per
device run() and then passing the events to IrrlichtDevice::postEventFromUser.
@@ -142,6 +145,22 @@ namespace irr
EMBSM_FORCE_32_BIT = 0x7fffffff
};
+ //! Enumeration for all touch input events
+ enum ETOUCH_INPUT_EVENT
+ {
+ //! Touch was pressed down.
+ ETIE_PRESSED_DOWN = 0,
+
+ //! Touch was left up.
+ ETIE_LEFT_UP,
+
+ //! The touch changed its position.
+ ETIE_MOVED,
+
+ //! No real event. Just for convenience to get number of events
+ ETIE_COUNT
+ };
+
namespace gui
{
@@ -331,6 +350,22 @@ struct SEvent
bool Control:1;
};
+ //! Any kind of touch event.
+ struct STouchInput
+ {
+ // Touch ID.
+ size_t ID;
+
+ // X position of simple touch.
+ s32 X;
+
+ // Y position of simple touch.
+ s32 Y;
+
+ //! Type of touch event.
+ ETOUCH_INPUT_EVENT Event;
+ };
+
//! A joystick event.
/** Unlike other events, joystick events represent the result of polling
* each connected joystick once per run() of the device. Joystick events will
@@ -417,6 +452,7 @@ struct SEvent
struct SGUIEvent GUIEvent;
struct SMouseInput MouseInput;
struct SKeyInput KeyInput;
+ struct STouchInput TouchInput;
struct SJoystickEvent JoystickEvent;
struct SLogEvent LogEvent;
struct SUserEvent UserEvent;
--
2.10.0
From 2e7699d1f232179c6fd8796d493488a9f6f01474 Mon Sep 17 00:00:00 2001
From: sfan5 <sfan5@live.de>
Date: Sat, 15 Oct 2016 15:32:49 +0200
Subject: [PATCH 2/3] Support touch input on Win32
---
source/Irrlicht/CIrrDeviceWin32.cpp | 37 +++++++++++++++++++++++++++++++++++++
source/Irrlicht/CIrrDeviceWin32.h | 5 +++++
2 files changed, 42 insertions(+)
diff --git a/source/Irrlicht/CIrrDeviceWin32.cpp b/source/Irrlicht/CIrrDeviceWin32.cpp
index 9734b99..8d334ae 100644
--- a/source/Irrlicht/CIrrDeviceWin32.cpp
+++ b/source/Irrlicht/CIrrDeviceWin32.cpp
@@ -719,6 +719,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
#ifndef WHEEL_DELTA
#define WHEEL_DELTA 120
#endif
+ #ifndef WM_TOUCH
+ #define WM_TOUCH 576 // https://sourceforge.net/p/mingw-w64/bugs/460/
+ #endif
irr::CIrrDeviceWin32* dev = 0;
irr::SEvent event;
@@ -979,6 +982,36 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
KEYBOARD_INPUT_HKL = GetKeyboardLayout(0);
KEYBOARD_INPUT_CODEPAGE = LocaleIdToCodepage( LOWORD(KEYBOARD_INPUT_HKL) );
return 0;
+
+ case WM_TOUCH:
+ {
+ UINT numTouches = LOWORD(wParam);
+ TOUCHINPUT touches[numTouches];
+ event.EventType = irr::EET_TOUCH_INPUT_EVENT;
+ dev = getDeviceFromHWnd(hWnd);
+
+ if (dev && GetTouchInputInfo((HTOUCHINPUT)lParam, numTouches, touches, sizeof(TOUCHINPUT)))
+ {
+ for (UINT i = 0; i < numTouches; i++)
+ {
+ PTOUCHINPUT t = &touches[i];
+ event.TouchInput.ID = t->dwID;
+ event.TouchInput.X = t->x;
+ event.TouchInput.Y = t->y;
+ if (t->dwFlags & TOUCHEVENTF_DOWN)
+ event.TouchInput.Event = irr::ETIE_PRESSED_DOWN;
+ else if (t->dwFlags & TOUCHEVENTF_UP)
+ event.TouchInput.Event = irr::ETIE_LEFT_UP;
+ else if (t->dwFlags & TOUCHEVENTF_MOVE) // order is important, MOVE can be combined with UP
+ event.TouchInput.Event = irr::ETIE_MOVED;
+ else
+ continue;
+ dev->postEventFromUser(event);
+ }
+ CloseTouchInputHandle((HTOUCHINPUT)lParam);
+ }
+ }
+ return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
@@ -1102,6 +1135,10 @@ CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params)
ExternalWindow = true;
}
+ // enable touch input
+ if (!RegisterTouchWindow(HWnd, 0))
+ os::Printer::log("Could not register window for touch input", ELL_ERROR);
+
// create cursor control
Win32CursorControl = new CCursorControl(this, CreationParams.WindowSize, HWnd, CreationParams.Fullscreen);
diff --git a/source/Irrlicht/CIrrDeviceWin32.h b/source/Irrlicht/CIrrDeviceWin32.h
index 171c8f0..4a2def1 100644
--- a/source/Irrlicht/CIrrDeviceWin32.h
+++ b/source/Irrlicht/CIrrDeviceWin32.h
@@ -12,6 +12,11 @@
#include "IrrlichtDevice.h"
#include "IImagePresenter.h"
+#ifdef _WIN32_WINNT
+ #undef _WIN32_WINNT
+#endif
+#define _WIN32_WINNT 0x0601
+
#define WIN32_LEAN_AND_MEAN
#if !defined(_IRR_XBOX_PLATFORM_)
#include <windows.h>
--
2.10.0
From d6f4b57898c51148b82dc0031c522750f40b1159 Mon Sep 17 00:00:00 2001
From: sfan5 <sfan5@live.de>
Date: Sat, 15 Oct 2016 15:34:45 +0200
Subject: [PATCH 3/3] Add touchedCount to STouchInput struct
cf. https://github.com/minetest/minetest/blob/master/build/android/patches/irrlicht-touchcount.patch
---
include/IEventReceiver.h | 3 +++
source/Irrlicht/CIrrDeviceWin32.cpp | 1 +
2 files changed, 4 insertions(+)
diff --git a/include/IEventReceiver.h b/include/IEventReceiver.h
index 224e378..64c0027 100644
--- a/include/IEventReceiver.h
+++ b/include/IEventReceiver.h
@@ -362,6 +362,9 @@ struct SEvent
// Y position of simple touch.
s32 Y;
+ // number of current touches
+ s32 touchedCount;
+
//! Type of touch event.
ETOUCH_INPUT_EVENT Event;
};
diff --git a/source/Irrlicht/CIrrDeviceWin32.cpp b/source/Irrlicht/CIrrDeviceWin32.cpp
index 8d334ae..09ca34b 100644
--- a/source/Irrlicht/CIrrDeviceWin32.cpp
+++ b/source/Irrlicht/CIrrDeviceWin32.cpp
@@ -988,6 +988,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
UINT numTouches = LOWORD(wParam);
TOUCHINPUT touches[numTouches];
event.EventType = irr::EET_TOUCH_INPUT_EVENT;
+ event.TouchInput.touchedCount = numTouches;
dev = getDeviceFromHWnd(hWnd);
if (dev && GetTouchInputInfo((HTOUCHINPUT)lParam, numTouches, touches, sizeof(TOUCHINPUT)))
--
2.10.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment