Fix multitouch in iOS
This commit is contained in:
parent
cf966308f6
commit
9a62b97a67
@ -14,6 +14,8 @@
|
||||
#include "CIrrDeviceStub.h"
|
||||
#include "IrrlichtDevice.h"
|
||||
#include "IImagePresenter.h"
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
namespace irr
|
||||
{
|
||||
@ -75,6 +77,40 @@ namespace irr
|
||||
|
||||
//! Returns true if system has native on screen keyboard
|
||||
virtual bool hasOnScreenKeyboard() const { return false; }
|
||||
|
||||
//! Get a unique touch id per touch, create one if it's a new touch
|
||||
size_t getTouchId(void* touch)
|
||||
{
|
||||
auto it = m_touch_id_map.find(touch);
|
||||
if (it == m_touch_id_map.end())
|
||||
{
|
||||
std::set<size_t> ids;
|
||||
for (auto& p : m_touch_id_map)
|
||||
ids.insert(p.second);
|
||||
size_t cur_id = 0;
|
||||
while (true)
|
||||
{
|
||||
if (ids.find(cur_id) == ids.end())
|
||||
break;
|
||||
cur_id++;
|
||||
}
|
||||
m_touch_id_map[touch] = cur_id;
|
||||
return cur_id;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
//! Remove a unique touch id, free it for future usage
|
||||
void removeTouchId(void* touch)
|
||||
{
|
||||
m_touch_id_map.erase(touch);
|
||||
}
|
||||
|
||||
//! Clear all unique touch ids, used when the app out focused
|
||||
void clearAllTouchIds()
|
||||
{
|
||||
m_touch_id_map.clear();
|
||||
}
|
||||
private:
|
||||
void createWindow();
|
||||
void createViewAndDriver();
|
||||
@ -82,6 +118,8 @@ namespace irr
|
||||
void* DataStorage;
|
||||
|
||||
bool Close;
|
||||
|
||||
std::map<void*, size_t> m_touch_id_map;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ namespace irr
|
||||
{
|
||||
if (Device != nil)
|
||||
{
|
||||
Device->clearAllTouchIds();
|
||||
irr::SEvent ev;
|
||||
ev.EventType = irr::EET_APPLICATION_EVENT;
|
||||
ev.ApplicationEvent.EventType = irr::EAET_WILL_PAUSE;
|
||||
@ -104,6 +105,7 @@ namespace irr
|
||||
{
|
||||
if (Device != nil)
|
||||
{
|
||||
Device->clearAllTouchIds();
|
||||
irr::SEvent ev;
|
||||
ev.EventType = irr::EET_APPLICATION_EVENT;
|
||||
ev.ApplicationEvent.EventType = irr::EAET_DID_PAUSE;
|
||||
@ -118,6 +120,7 @@ namespace irr
|
||||
{
|
||||
if (Device != nil)
|
||||
{
|
||||
Device->clearAllTouchIds();
|
||||
irr::SEvent ev;
|
||||
ev.EventType = irr::EET_APPLICATION_EVENT;
|
||||
ev.ApplicationEvent.EventType = irr::EAET_WILL_RESUME;
|
||||
@ -132,6 +135,7 @@ namespace irr
|
||||
{
|
||||
if (Device != nil)
|
||||
{
|
||||
Device->clearAllTouchIds();
|
||||
irr::SEvent ev;
|
||||
ev.EventType = irr::EET_APPLICATION_EVENT;
|
||||
ev.ApplicationEvent.EventType = irr::EAET_DID_RESUME;
|
||||
@ -178,6 +182,7 @@ namespace irr
|
||||
@implementation CIrrViewiOS
|
||||
{
|
||||
irr::CIrrDeviceiOS* Device;
|
||||
std::map<void*, size_t> m_touch_id_map;
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame forDevice:(irr::CIrrDeviceiOS*)device forContext:(EAGLContext*)eagl_context
|
||||
@ -187,16 +192,13 @@ namespace irr
|
||||
{
|
||||
self.drawableDepthFormat = GLKViewDrawableDepthFormat24;
|
||||
self.drawableStencilFormat = GLKViewDrawableStencilFormat8;
|
||||
self.multipleTouchEnabled = YES;
|
||||
Device = device;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)isMultipleTouchEnabled
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
|
||||
{
|
||||
@ -206,11 +208,10 @@ namespace irr
|
||||
|
||||
irr::core::position2d<irr::s32> mouse_pos = irr::core::position2d<irr::s32>(0, 0);
|
||||
bool simulate_mouse = false;
|
||||
size_t id = 0;
|
||||
|
||||
for (UITouch* touch in touches)
|
||||
{
|
||||
ev.TouchInput.ID = id++;
|
||||
ev.TouchInput.ID = Device->getTouchId(touch);
|
||||
|
||||
CGPoint touchPoint = [touch locationInView:self];
|
||||
|
||||
@ -237,11 +238,10 @@ namespace irr
|
||||
|
||||
irr::core::position2d<irr::s32> mouse_pos = irr::core::position2d<irr::s32>(0, 0);
|
||||
bool simulate_mouse = false;
|
||||
size_t id = 0;
|
||||
|
||||
for (UITouch* touch in touches)
|
||||
{
|
||||
ev.TouchInput.ID = id++;
|
||||
ev.TouchInput.ID = Device->getTouchId(touch);
|
||||
|
||||
CGPoint touchPoint = [touch locationInView:self];
|
||||
|
||||
@ -268,11 +268,11 @@ namespace irr
|
||||
|
||||
irr::core::position2d<irr::s32> mouse_pos = irr::core::position2d<irr::s32>(0, 0);
|
||||
bool simulate_mouse = false;
|
||||
size_t id = 0;
|
||||
|
||||
for (UITouch* touch in touches)
|
||||
{
|
||||
ev.TouchInput.ID = id++;
|
||||
ev.TouchInput.ID = Device->getTouchId(touch);
|
||||
Device->removeTouchId(touch);
|
||||
|
||||
CGPoint touchPoint = [touch locationInView:self];
|
||||
|
||||
@ -299,11 +299,11 @@ namespace irr
|
||||
|
||||
irr::core::position2d<irr::s32> mouse_pos = irr::core::position2d<irr::s32>(0, 0);
|
||||
bool simulate_mouse = false;
|
||||
size_t id = 0;
|
||||
|
||||
for (UITouch* touch in touches)
|
||||
{
|
||||
ev.TouchInput.ID = id++;
|
||||
ev.TouchInput.ID = Device->getTouchId(touch);
|
||||
Device->removeTouchId(touch);
|
||||
|
||||
CGPoint touchPoint = [touch locationInView:self];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user