Share the simulateMouse with android and iOS
This commit is contained in:
parent
f9c2e40f13
commit
1f826b5ba7
@ -70,7 +70,6 @@ CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param)
|
|||||||
AccelerometerActive(false),
|
AccelerometerActive(false),
|
||||||
GyroscopeActive(false),
|
GyroscopeActive(false),
|
||||||
HasTouchDevice(false),
|
HasTouchDevice(false),
|
||||||
IsMousePressed(false),
|
|
||||||
GamepadAxisX(0),
|
GamepadAxisX(0),
|
||||||
GamepadAxisY(0),
|
GamepadAxisY(0),
|
||||||
DefaultOrientation(ORIENTATION_UNKNOWN)
|
DefaultOrientation(ORIENTATION_UNKNOWN)
|
||||||
@ -637,44 +636,8 @@ s32 CIrrDeviceAndroid::handleTouch(AInputEvent* androidEvent)
|
|||||||
// Simulate mouse event for first finger on multitouch device.
|
// Simulate mouse event for first finger on multitouch device.
|
||||||
// This allows to click on GUI elements.
|
// This allows to click on GUI elements.
|
||||||
if (simulate_mouse)
|
if (simulate_mouse)
|
||||||
{
|
simulateMouse(event, mouse_pos);
|
||||||
CursorControl->setPosition(mouse_pos);
|
|
||||||
|
|
||||||
SEvent irrevent;
|
|
||||||
bool send_event = true;
|
|
||||||
|
|
||||||
switch (event.TouchInput.Event)
|
|
||||||
{
|
|
||||||
case ETIE_PRESSED_DOWN:
|
|
||||||
irrevent.MouseInput.Event = EMIE_LMOUSE_PRESSED_DOWN;
|
|
||||||
IsMousePressed = true;
|
|
||||||
break;
|
|
||||||
case ETIE_LEFT_UP:
|
|
||||||
irrevent.MouseInput.Event = EMIE_LMOUSE_LEFT_UP;
|
|
||||||
IsMousePressed = false;
|
|
||||||
break;
|
|
||||||
case ETIE_MOVED:
|
|
||||||
irrevent.MouseInput.Event = EMIE_MOUSE_MOVED;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
send_event = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (send_event)
|
|
||||||
{
|
|
||||||
irrevent.MouseInput.Control = false;
|
|
||||||
irrevent.MouseInput.Shift = false;
|
|
||||||
irrevent.MouseInput.ButtonStates = IsMousePressed ?
|
|
||||||
irr::EMBSM_LEFT : 0;
|
|
||||||
irrevent.EventType = EET_MOUSE_INPUT_EVENT;
|
|
||||||
irrevent.MouseInput.X = mouse_pos.X;
|
|
||||||
irrevent.MouseInput.Y = mouse_pos.Y + adjusted_height;
|
|
||||||
|
|
||||||
postEventFromUser(irrevent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +118,6 @@ namespace irr
|
|||||||
|
|
||||||
TouchEventData TouchEventsData[32];
|
TouchEventData TouchEventsData[32];
|
||||||
bool HasTouchDevice;
|
bool HasTouchDevice;
|
||||||
bool IsMousePressed;
|
|
||||||
float GamepadAxisX;
|
float GamepadAxisX;
|
||||||
float GamepadAxisY;
|
float GamepadAxisY;
|
||||||
DeviceOrientation DefaultOrientation;
|
DeviceOrientation DefaultOrientation;
|
||||||
|
@ -21,7 +21,7 @@ CIrrDeviceStub::CIrrDeviceStub(const SIrrlichtCreationParameters& params)
|
|||||||
: IrrlichtDevice(), VideoDriver(0), GUIEnvironment(0), SceneManager(0),
|
: IrrlichtDevice(), VideoDriver(0), GUIEnvironment(0), SceneManager(0),
|
||||||
Timer(0), CursorControl(0), UserReceiver(params.EventReceiver), Logger(0), Operator(0),
|
Timer(0), CursorControl(0), UserReceiver(params.EventReceiver), Logger(0), Operator(0),
|
||||||
Randomizer(0), FileSystem(0), InputReceivingSceneManager(0), CreationParams(params),
|
Randomizer(0), FileSystem(0), InputReceivingSceneManager(0), CreationParams(params),
|
||||||
Close(false)
|
Close(false), IsMousePressed(false)
|
||||||
{
|
{
|
||||||
Timer = new CTimer(params.UsePerformanceTimer);
|
Timer = new CTimer(params.UsePerformanceTimer);
|
||||||
if (os::Printer::Logger)
|
if (os::Printer::Logger)
|
||||||
@ -426,7 +426,43 @@ void CIrrDeviceStub::clearSystemMessages()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CIrrDeviceStub::simulateMouse(const SEvent& event, core::position2d<s32>& mouse_pos)
|
||||||
|
{
|
||||||
|
if (!CursorControl) return;
|
||||||
|
CursorControl->setPosition(mouse_pos);
|
||||||
|
|
||||||
|
SEvent irrevent;
|
||||||
|
bool send_event = true;
|
||||||
|
|
||||||
|
switch (event.TouchInput.Event)
|
||||||
|
{
|
||||||
|
case ETIE_PRESSED_DOWN:
|
||||||
|
irrevent.MouseInput.Event = EMIE_LMOUSE_PRESSED_DOWN;
|
||||||
|
IsMousePressed = true;
|
||||||
|
break;
|
||||||
|
case ETIE_LEFT_UP:
|
||||||
|
irrevent.MouseInput.Event = EMIE_LMOUSE_LEFT_UP;
|
||||||
|
IsMousePressed = false;
|
||||||
|
break;
|
||||||
|
case ETIE_MOVED:
|
||||||
|
irrevent.MouseInput.Event = EMIE_MOUSE_MOVED;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
send_event = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (send_event)
|
||||||
|
{
|
||||||
|
irrevent.MouseInput.Control = false;
|
||||||
|
irrevent.MouseInput.Shift = false;
|
||||||
|
irrevent.MouseInput.ButtonStates = IsMousePressed ? irr::EMBSM_LEFT : 0;
|
||||||
|
irrevent.EventType = EET_MOUSE_INPUT_EVENT;
|
||||||
|
irrevent.MouseInput.X = mouse_pos.X;
|
||||||
|
irrevent.MouseInput.Y = mouse_pos.Y + getMovedHeight();
|
||||||
|
postEventFromUser(irrevent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // end namespace irr
|
} // end namespace irr
|
||||||
|
|
||||||
|
@ -151,9 +151,8 @@ namespace irr
|
|||||||
//! Remove all messages pending in the system message loop
|
//! Remove all messages pending in the system message loop
|
||||||
virtual void clearSystemMessages();
|
virtual void clearSystemMessages();
|
||||||
|
|
||||||
|
void simulateMouse(const SEvent& event, core::position2d<s32>& mouse_pos);
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void createGUIAndScene();
|
void createGUIAndScene();
|
||||||
|
|
||||||
//! checks version of SDK and prints warning if there might be a problem
|
//! checks version of SDK and prints warning if there might be a problem
|
||||||
@ -193,7 +192,7 @@ namespace irr
|
|||||||
SMouseMultiClicks MouseMultiClicks;
|
SMouseMultiClicks MouseMultiClicks;
|
||||||
video::CVideoModeList VideoModeList;
|
video::CVideoModeList VideoModeList;
|
||||||
SIrrlichtCreationParameters CreationParams;
|
SIrrlichtCreationParameters CreationParams;
|
||||||
bool Close;
|
bool Close, IsMousePressed;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace irr
|
} // end namespace irr
|
||||||
|
@ -206,9 +206,13 @@ namespace irr
|
|||||||
ev.EventType = irr::EET_TOUCH_INPUT_EVENT;
|
ev.EventType = irr::EET_TOUCH_INPUT_EVENT;
|
||||||
ev.TouchInput.Event = irr::ETIE_PRESSED_DOWN;
|
ev.TouchInput.Event = irr::ETIE_PRESSED_DOWN;
|
||||||
|
|
||||||
|
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)
|
for (UITouch* touch in touches)
|
||||||
{
|
{
|
||||||
ev.TouchInput.ID = (size_t)touch;
|
ev.TouchInput.ID = id++;
|
||||||
|
|
||||||
CGPoint touchPoint = [touch locationInView:self];
|
CGPoint touchPoint = [touch locationInView:self];
|
||||||
|
|
||||||
@ -216,7 +220,15 @@ namespace irr
|
|||||||
ev.TouchInput.Y = touchPoint.y*Scale;
|
ev.TouchInput.Y = touchPoint.y*Scale;
|
||||||
|
|
||||||
Device->postEventFromUser(ev);
|
Device->postEventFromUser(ev);
|
||||||
|
if (ev.TouchInput.ID == 0)
|
||||||
|
{
|
||||||
|
simulate_mouse = true;
|
||||||
|
mouse_pos.X = ev.TouchInput.X;
|
||||||
|
mouse_pos.Y = ev.TouchInput.Y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (simulate_mouse)
|
||||||
|
Device->simulateMouse(ev, mouse_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
|
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
|
||||||
@ -225,9 +237,13 @@ namespace irr
|
|||||||
ev.EventType = irr::EET_TOUCH_INPUT_EVENT;
|
ev.EventType = irr::EET_TOUCH_INPUT_EVENT;
|
||||||
ev.TouchInput.Event = irr::ETIE_MOVED;
|
ev.TouchInput.Event = irr::ETIE_MOVED;
|
||||||
|
|
||||||
|
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)
|
for (UITouch* touch in touches)
|
||||||
{
|
{
|
||||||
ev.TouchInput.ID = (size_t)touch;
|
ev.TouchInput.ID = id++;
|
||||||
|
|
||||||
CGPoint touchPoint = [touch locationInView:self];
|
CGPoint touchPoint = [touch locationInView:self];
|
||||||
|
|
||||||
@ -235,7 +251,15 @@ namespace irr
|
|||||||
ev.TouchInput.Y = touchPoint.y*Scale;
|
ev.TouchInput.Y = touchPoint.y*Scale;
|
||||||
|
|
||||||
Device->postEventFromUser(ev);
|
Device->postEventFromUser(ev);
|
||||||
|
if (ev.TouchInput.ID == 0)
|
||||||
|
{
|
||||||
|
simulate_mouse = true;
|
||||||
|
mouse_pos.X = ev.TouchInput.X;
|
||||||
|
mouse_pos.Y = ev.TouchInput.Y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (simulate_mouse)
|
||||||
|
Device->simulateMouse(ev, mouse_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
|
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
|
||||||
@ -244,9 +268,13 @@ namespace irr
|
|||||||
ev.EventType = irr::EET_TOUCH_INPUT_EVENT;
|
ev.EventType = irr::EET_TOUCH_INPUT_EVENT;
|
||||||
ev.TouchInput.Event = irr::ETIE_LEFT_UP;
|
ev.TouchInput.Event = irr::ETIE_LEFT_UP;
|
||||||
|
|
||||||
|
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)
|
for (UITouch* touch in touches)
|
||||||
{
|
{
|
||||||
ev.TouchInput.ID = (size_t)touch;
|
ev.TouchInput.ID = id++;
|
||||||
|
|
||||||
CGPoint touchPoint = [touch locationInView:self];
|
CGPoint touchPoint = [touch locationInView:self];
|
||||||
|
|
||||||
@ -254,7 +282,15 @@ namespace irr
|
|||||||
ev.TouchInput.Y = touchPoint.y*Scale;
|
ev.TouchInput.Y = touchPoint.y*Scale;
|
||||||
|
|
||||||
Device->postEventFromUser(ev);
|
Device->postEventFromUser(ev);
|
||||||
|
if (ev.TouchInput.ID == 0)
|
||||||
|
{
|
||||||
|
simulate_mouse = true;
|
||||||
|
mouse_pos.X = ev.TouchInput.X;
|
||||||
|
mouse_pos.Y = ev.TouchInput.Y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (simulate_mouse)
|
||||||
|
Device->simulateMouse(ev, mouse_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event
|
- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event
|
||||||
@ -263,9 +299,13 @@ namespace irr
|
|||||||
ev.EventType = irr::EET_TOUCH_INPUT_EVENT;
|
ev.EventType = irr::EET_TOUCH_INPUT_EVENT;
|
||||||
ev.TouchInput.Event = irr::ETIE_LEFT_UP;
|
ev.TouchInput.Event = irr::ETIE_LEFT_UP;
|
||||||
|
|
||||||
|
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)
|
for (UITouch* touch in touches)
|
||||||
{
|
{
|
||||||
ev.TouchInput.ID = (size_t)touch;
|
ev.TouchInput.ID = id++;
|
||||||
|
|
||||||
CGPoint touchPoint = [touch locationInView:self];
|
CGPoint touchPoint = [touch locationInView:self];
|
||||||
|
|
||||||
@ -273,7 +313,15 @@ namespace irr
|
|||||||
ev.TouchInput.Y = touchPoint.y*Scale;
|
ev.TouchInput.Y = touchPoint.y*Scale;
|
||||||
|
|
||||||
Device->postEventFromUser(ev);
|
Device->postEventFromUser(ev);
|
||||||
|
if (ev.TouchInput.ID == 0)
|
||||||
|
{
|
||||||
|
simulate_mouse = true;
|
||||||
|
mouse_pos.X = ev.TouchInput.X;
|
||||||
|
mouse_pos.Y = ev.TouchInput.Y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (simulate_mouse)
|
||||||
|
Device->simulateMouse(ev, mouse_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user