Add events when mouse enters/leaves canvas on emscripten. Handle that in fps-camera.
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@5457 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
parent
d4a0f30d82
commit
92f42e41bf
@ -78,7 +78,7 @@ namespace irr
|
|||||||
|
|
||||||
//! Pass on raw events from the OS
|
//! Pass on raw events from the OS
|
||||||
EET_SYSTEM_EVENT,
|
EET_SYSTEM_EVENT,
|
||||||
|
|
||||||
//! Application state events like a resume, pause etc.
|
//! Application state events like a resume, pause etc.
|
||||||
EET_APPLICATION_EVENT,
|
EET_APPLICATION_EVENT,
|
||||||
|
|
||||||
@ -140,6 +140,14 @@ namespace irr
|
|||||||
//! This event is generated after the third EMIE_MMOUSE_PRESSED_DOWN event.
|
//! This event is generated after the third EMIE_MMOUSE_PRESSED_DOWN event.
|
||||||
EMIE_MMOUSE_TRIPLE_CLICK,
|
EMIE_MMOUSE_TRIPLE_CLICK,
|
||||||
|
|
||||||
|
//! Mouse enters canvas used for rendering.
|
||||||
|
//! Only generated on emscripten
|
||||||
|
EMIE_MOUSE_ENTER_CANVAS,
|
||||||
|
|
||||||
|
//! Mouse leaves canvas used for rendering.
|
||||||
|
//! Only generated on emscripten
|
||||||
|
EMIE_MOUSE_LEAVE_CANVAS,
|
||||||
|
|
||||||
//! No real event. Just for convenience to get number of events
|
//! No real event. Just for convenience to get number of events
|
||||||
EMIE_COUNT
|
EMIE_COUNT
|
||||||
};
|
};
|
||||||
@ -186,25 +194,25 @@ namespace irr
|
|||||||
//! No real event, but to get number of event types
|
//! No real event, but to get number of event types
|
||||||
ESET_COUNT
|
ESET_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Enumeration for a commonly used application state events (it's useful mainly for mobile devices)
|
//! Enumeration for a commonly used application state events (it's useful mainly for mobile devices)
|
||||||
enum EAPPLICATION_EVENT_TYPE
|
enum EAPPLICATION_EVENT_TYPE
|
||||||
{
|
{
|
||||||
//! The application will be resumed.
|
//! The application will be resumed.
|
||||||
EAET_WILL_RESUME = 0,
|
EAET_WILL_RESUME = 0,
|
||||||
|
|
||||||
//! The application has been resumed.
|
//! The application has been resumed.
|
||||||
EAET_DID_RESUME,
|
EAET_DID_RESUME,
|
||||||
|
|
||||||
//! The application will be paused.
|
//! The application will be paused.
|
||||||
EAET_WILL_PAUSE,
|
EAET_WILL_PAUSE,
|
||||||
|
|
||||||
//! The application has been paused.
|
//! The application has been paused.
|
||||||
EAET_DID_PAUSE,
|
EAET_DID_PAUSE,
|
||||||
|
|
||||||
//! The application will be terminated.
|
//! The application will be terminated.
|
||||||
EAET_WILL_TERMINATE,
|
EAET_WILL_TERMINATE,
|
||||||
|
|
||||||
//! The application received a memory warning.
|
//! The application received a memory warning.
|
||||||
EAET_MEMORY_WARNING,
|
EAET_MEMORY_WARNING,
|
||||||
|
|
||||||
@ -560,7 +568,7 @@ struct SEvent
|
|||||||
struct SAndroidCmd AndroidCmd;
|
struct SAndroidCmd AndroidCmd;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Application state event
|
// Application state event
|
||||||
struct SApplicationEvent
|
struct SApplicationEvent
|
||||||
{
|
{
|
||||||
|
@ -60,13 +60,55 @@ namespace irr
|
|||||||
namespace irr
|
namespace irr
|
||||||
{
|
{
|
||||||
#ifdef _IRR_EMSCRIPTEN_PLATFORM_
|
#ifdef _IRR_EMSCRIPTEN_PLATFORM_
|
||||||
EM_BOOL MouseUpDownCallback(int eventType, const EmscriptenMouseEvent * event, void* userData)
|
EM_BOOL CIrrDeviceSDL::MouseUpDownCallback(int eventType, const EmscriptenMouseEvent * event, void* userData)
|
||||||
{
|
{
|
||||||
// We need this callback so far only because otherwise "emscripten_request_pointerlock" calls will
|
// We need this callback so far only because otherwise "emscripten_request_pointerlock" calls will
|
||||||
// fail as their request are infinitely deferred.
|
// fail as their request are infinitely deferred.
|
||||||
// Not exactly certain why, maybe SDL does catch those mouse-events otherwise and not pass them on.
|
// Not exactly certain why, maybe SDL does catch those mouse-events otherwise and not pass them on.
|
||||||
return EM_FALSE;
|
return EM_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EM_BOOL CIrrDeviceSDL::MouseEnterCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
|
||||||
|
{
|
||||||
|
CIrrDeviceSDL * This = static_cast<CIrrDeviceSDL*>(userData);
|
||||||
|
|
||||||
|
SEvent irrevent;
|
||||||
|
|
||||||
|
irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;
|
||||||
|
irrevent.MouseInput.Event = irr::EMIE_MOUSE_ENTER_CANVAS;
|
||||||
|
This->MouseX = irrevent.MouseInput.X = mouseEvent->canvasX;
|
||||||
|
This->MouseY = irrevent.MouseInput.Y = mouseEvent->canvasY;
|
||||||
|
This->MouseXRel = mouseEvent->movementX; // should be 0 I guess? Or can it enter while pointer is locked()?
|
||||||
|
This->MouseYRel = mouseEvent->movementY;
|
||||||
|
irrevent.MouseInput.ButtonStates = This->MouseButtonStates; // TODO: not correct, but couldn't figure out the bitset of mouseEvent->buttons yet.
|
||||||
|
irrevent.MouseInput.Shift = mouseEvent->shiftKey;
|
||||||
|
irrevent.MouseInput.Control = mouseEvent->ctrlKey;
|
||||||
|
|
||||||
|
This->postEventFromUser(irrevent);
|
||||||
|
|
||||||
|
return EM_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
EM_BOOL CIrrDeviceSDL::MouseLeaveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
|
||||||
|
{
|
||||||
|
CIrrDeviceSDL * This = static_cast<CIrrDeviceSDL*>(userData);
|
||||||
|
|
||||||
|
SEvent irrevent;
|
||||||
|
|
||||||
|
irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;
|
||||||
|
irrevent.MouseInput.Event = irr::EMIE_MOUSE_LEAVE_CANVAS;
|
||||||
|
This->MouseX = irrevent.MouseInput.X = mouseEvent->canvasX;
|
||||||
|
This->MouseY = irrevent.MouseInput.Y = mouseEvent->canvasY;
|
||||||
|
This->MouseXRel = mouseEvent->movementX; // should be 0 I guess? Or can it enter while pointer is locked()?
|
||||||
|
This->MouseYRel = mouseEvent->movementY;
|
||||||
|
irrevent.MouseInput.ButtonStates = This->MouseButtonStates; // TODO: not correct, but couldn't figure out the bitset of mouseEvent->buttons yet.
|
||||||
|
irrevent.MouseInput.Shift = mouseEvent->shiftKey;
|
||||||
|
irrevent.MouseInput.Control = mouseEvent->ctrlKey;
|
||||||
|
|
||||||
|
This->postEventFromUser(irrevent);
|
||||||
|
|
||||||
|
return EM_FALSE;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//! constructor
|
//! constructor
|
||||||
@ -171,8 +213,12 @@ bool CIrrDeviceSDL::createWindow()
|
|||||||
emscripten_set_canvas_size( Width, Height);
|
emscripten_set_canvas_size( Width, Height);
|
||||||
Screen = SDL_SetVideoMode( 0, 0, 32, SDL_OPENGL ); // 0,0 will use the canvas size
|
Screen = SDL_SetVideoMode( 0, 0, 32, SDL_OPENGL ); // 0,0 will use the canvas size
|
||||||
|
|
||||||
emscripten_set_mousedown_callback(0, 0, true, MouseUpDownCallback);
|
// "#canvas" is for the opengl context
|
||||||
emscripten_set_mouseup_callback(0, 0, true, MouseUpDownCallback);
|
emscripten_set_mousedown_callback("#canvas", (void*)this, true, MouseUpDownCallback);
|
||||||
|
emscripten_set_mouseup_callback("#canvas", (void*)this, true, MouseUpDownCallback);
|
||||||
|
emscripten_set_mouseenter_callback("#canvas", (void*)this, false, MouseEnterCallback);
|
||||||
|
emscripten_set_mouseleave_callback("#canvas", (void*)this, false, MouseLeaveCallback);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#else // !_IRR_EMSCRIPTEN_PLATFORM_
|
#else // !_IRR_EMSCRIPTEN_PLATFORM_
|
||||||
if ( Close )
|
if ( Close )
|
||||||
@ -386,10 +432,12 @@ bool CIrrDeviceSDL::run()
|
|||||||
if ( CursorControl->isVisible() && pointerlockStatus.isActive )
|
if ( CursorControl->isVisible() && pointerlockStatus.isActive )
|
||||||
{
|
{
|
||||||
emscripten_exit_pointerlock();
|
emscripten_exit_pointerlock();
|
||||||
|
return !Close;
|
||||||
}
|
}
|
||||||
else if ( !CursorControl->isVisible() && !pointerlockStatus.isActive )
|
else if ( !CursorControl->isVisible() && !pointerlockStatus.isActive )
|
||||||
{
|
{
|
||||||
emscripten_request_pointerlock(0, true);
|
emscripten_request_pointerlock(0, true);
|
||||||
|
return !Close;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,6 +217,12 @@ namespace irr
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
#ifdef _IRR_EMSCRIPTEN_PLATFORM_
|
||||||
|
static EM_BOOL MouseUpDownCallback(int eventType, const EmscriptenMouseEvent * event, void* userData);
|
||||||
|
static EM_BOOL MouseEnterCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData);
|
||||||
|
static EM_BOOL MouseLeaveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData);
|
||||||
|
#endif
|
||||||
|
|
||||||
//! create the driver
|
//! create the driver
|
||||||
void createDriver();
|
void createDriver();
|
||||||
|
|
||||||
|
@ -91,6 +91,11 @@ bool CSceneNodeAnimatorCameraFPS::OnEvent(const SEvent& evt)
|
|||||||
CursorPos = CursorControl->getRelativePosition();
|
CursorPos = CursorControl->getRelativePosition();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if ( evt.MouseInput.Event == EMIE_MOUSE_ENTER_CANVAS)
|
||||||
|
{
|
||||||
|
resetCursorPos();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -277,6 +282,13 @@ void CSceneNodeAnimatorCameraFPS::animateNode(ISceneNode* node, u32 timeMs)
|
|||||||
camera->setTarget(target);
|
camera->setTarget(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSceneNodeAnimatorCameraFPS::resetCursorPos()
|
||||||
|
{
|
||||||
|
CursorControl->setPosition(0.5f, 0.5f);
|
||||||
|
CenterCursor = CursorControl->getRelativePosition();
|
||||||
|
CursorPos = CenterCursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void CSceneNodeAnimatorCameraFPS::allKeysUp()
|
void CSceneNodeAnimatorCameraFPS::allKeysUp()
|
||||||
{
|
{
|
||||||
|
@ -109,8 +109,9 @@ namespace scene
|
|||||||
//! Reads attributes of the scene node animator.
|
//! Reads attributes of the scene node animator.
|
||||||
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) _IRR_OVERRIDE_;
|
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) _IRR_OVERRIDE_;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void resetCursorPos();
|
||||||
|
|
||||||
void allKeysUp();
|
void allKeysUp();
|
||||||
|
|
||||||
gui::ICursorControl *CursorControl;
|
gui::ICursorControl *CursorControl;
|
||||||
|
@ -85,14 +85,7 @@ bool CSceneNodeAnimatorCameraMaya::OnEvent(const SEvent& event)
|
|||||||
MousePos = CursorControl->getRelativePosition();
|
MousePos = CursorControl->getRelativePosition();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EMIE_MOUSE_WHEEL:
|
default:
|
||||||
case EMIE_LMOUSE_DOUBLE_CLICK:
|
|
||||||
case EMIE_RMOUSE_DOUBLE_CLICK:
|
|
||||||
case EMIE_MMOUSE_DOUBLE_CLICK:
|
|
||||||
case EMIE_LMOUSE_TRIPLE_CLICK:
|
|
||||||
case EMIE_RMOUSE_TRIPLE_CLICK:
|
|
||||||
case EMIE_MMOUSE_TRIPLE_CLICK:
|
|
||||||
case EMIE_COUNT:
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user