Stage Events; cleaning up sx/sy clarity, adding deltaX and deltaY values for use with things that have delta (specifically in this case mouse locking support)
Mouse; relative mouse mode (for locking the cursor inside the window, like FPS games do) delta passed into the event if it's enabled
This commit is contained in:
@@ -263,7 +263,13 @@ class InputHandler {
|
|||||||
last_mouse_x = _event.x;
|
last_mouse_x = _event.x;
|
||||||
last_mouse_y = _event.y;
|
last_mouse_y = _event.y;
|
||||||
|
|
||||||
// trace("mouse moved, delta : " + deltaX + ' ' + deltaY);
|
//locked cursor gives us the delta directly from sdl
|
||||||
|
#if lime_native
|
||||||
|
if(lib.window.cursor_locked) {
|
||||||
|
deltaX = _event.deltaX;
|
||||||
|
deltaY = _event.deltaY;
|
||||||
|
}
|
||||||
|
#end //lime_native
|
||||||
|
|
||||||
if(lib.host.onmousemove != null) {
|
if(lib.host.onmousemove != null) {
|
||||||
|
|
||||||
|
|||||||
@@ -92,8 +92,8 @@ enum EventResult
|
|||||||
|
|
||||||
struct Event
|
struct Event
|
||||||
{
|
{
|
||||||
Event(EventType inType=etUnknown,int inX=0,int inY=0,int inValue=0,int inID=0,int inFlags=0,float inSx=1,float inSy=1):
|
Event(EventType inType=etUnknown,int inX=0,int inY=0,int inValue=0,int inID=0,int inFlags=0,float inScaleX=1,float inScaleY=1,int inDeltaX=0,int inDeltaY=0):
|
||||||
type(inType), x(inX), y(inY), value(inValue), id(inID), flags(inFlags), result(erOk), sx(inSx), sy(inSy)
|
type(inType), x(inX), y(inY), value(inValue), id(inID), flags(inFlags), result(erOk), scaleX(inScaleX), scaleY(inScaleY), deltaX(inDeltaX), deltaY(inDeltaY)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +104,8 @@ struct Event
|
|||||||
int id;
|
int id;
|
||||||
int flags;
|
int flags;
|
||||||
EventResult result;
|
EventResult result;
|
||||||
float sx,sy;
|
float scaleX, scaleY;
|
||||||
|
int deltaX, deltaY;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*EventHandler)(Event &ioEvent, void *inUserData);
|
typedef void (*EventHandler)(Event &ioEvent, void *inUserData);
|
||||||
|
|||||||
@@ -1089,8 +1089,19 @@ void ProcessEvent(SDL_Event &inEvent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
{
|
{
|
||||||
Event mouse(etMouseMove, inEvent.motion.x, inEvent.motion.y);
|
//default to 0
|
||||||
|
int deltaX = 0;
|
||||||
|
int deltaY = 0;
|
||||||
|
|
||||||
|
//but if we are locking the cursor,
|
||||||
|
//pass the delta in as well through as deltaX
|
||||||
|
if(SDL_GetRelativeMouseMode()) {
|
||||||
|
SDL_GetRelativeMouseState( &deltaX, &deltaY );
|
||||||
|
}
|
||||||
|
|
||||||
|
//int inValue=0, int inID=0, int inFlags=0, float inScaleX=1,float inScaleY=1, int inDeltaX=0,int inDeltaY=0
|
||||||
|
Event mouse(etMouseMove, inEvent.motion.x, inEvent.motion.y, 0, 0, 0, 1.0f, 1.0f, deltaX, deltaY);
|
||||||
#if defined(WEBOS) || defined(BLACKBERRY)
|
#if defined(WEBOS) || defined(BLACKBERRY)
|
||||||
mouse.value = inEvent.motion.which;
|
mouse.value = inEvent.motion.which;
|
||||||
mouse.flags |= efLeftDown;
|
mouse.flags |= efLeftDown;
|
||||||
|
|||||||
@@ -46,8 +46,10 @@ static int _id_type;
|
|||||||
static int _id_x;
|
static int _id_x;
|
||||||
static int _id_y;
|
static int _id_y;
|
||||||
static int _id_z;
|
static int _id_z;
|
||||||
static int _id_sx;
|
static int _id_scaleX;
|
||||||
static int _id_sy;
|
static int _id_scaleY;
|
||||||
|
static int _id_deltaX;
|
||||||
|
static int _id_deltaY;
|
||||||
static int _id_width;
|
static int _id_width;
|
||||||
static int _id_height;
|
static int _id_height;
|
||||||
static int _id_length;
|
static int _id_length;
|
||||||
@@ -137,8 +139,10 @@ extern "C" void InitIDs()
|
|||||||
_id_x = val_id("x");
|
_id_x = val_id("x");
|
||||||
_id_y = val_id("y");
|
_id_y = val_id("y");
|
||||||
_id_z = val_id("z");
|
_id_z = val_id("z");
|
||||||
_id_sx = val_id("sx");
|
_id_scaleX = val_id("scaleX");
|
||||||
_id_sy = val_id("sy");
|
_id_scaleY = val_id("scaleY");
|
||||||
|
_id_deltaX = val_id("deltaX");
|
||||||
|
_id_deltaY = val_id("deltaY");
|
||||||
_id_width = val_id("width");
|
_id_width = val_id("width");
|
||||||
_id_height = val_id("height");
|
_id_height = val_id("height");
|
||||||
_id_length = val_id("length");
|
_id_length = val_id("length");
|
||||||
@@ -1211,8 +1215,10 @@ void external_handler( lime::Event &ioEvent, void *inUserData )
|
|||||||
alloc_field(o,_id_flags,alloc_int(ioEvent.flags));
|
alloc_field(o,_id_flags,alloc_int(ioEvent.flags));
|
||||||
alloc_field(o,_id_code,alloc_int(ioEvent.code));
|
alloc_field(o,_id_code,alloc_int(ioEvent.code));
|
||||||
alloc_field(o,_id_result,alloc_int(ioEvent.result));
|
alloc_field(o,_id_result,alloc_int(ioEvent.result));
|
||||||
alloc_field(o,_id_sx,alloc_float(ioEvent.sx));
|
alloc_field(o,_id_scaleX,alloc_float(ioEvent.scaleX));
|
||||||
alloc_field(o,_id_sy,alloc_float(ioEvent.sy));
|
alloc_field(o,_id_scaleY,alloc_float(ioEvent.scaleY));
|
||||||
|
alloc_field(o,_id_deltaX,alloc_float(ioEvent.deltaX));
|
||||||
|
alloc_field(o,_id_deltaY,alloc_float(ioEvent.deltaY));
|
||||||
val_call1(handler->get(), o);
|
val_call1(handler->get(), o);
|
||||||
ioEvent.result = (EventResult)val_int( val_field(o,_id_result) );
|
ioEvent.result = (EventResult)val_int( val_field(o,_id_result) );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,8 +193,8 @@ public:
|
|||||||
}
|
}
|
||||||
mouse.value = inID;
|
mouse.value = inID;
|
||||||
|
|
||||||
mouse.sx = sizeX;
|
mouse.scaleX = sizeX;
|
||||||
mouse.sy = sizeY;
|
mouse.scaleY = sizeY;
|
||||||
|
|
||||||
//if (inType==etTouchBegin)
|
//if (inType==etTouchBegin)
|
||||||
//ELOG("DOWN %d %f,%f (%s) %f,%f", inID, inX, inY, (mouse.flags & efPrimaryTouch) ? "P":"S", sizeX, sizeY );
|
//ELOG("DOWN %d %f,%f (%s) %f,%f", inID, inX, inY, (mouse.flags & efPrimaryTouch) ? "P":"S", sizeX, sizeY );
|
||||||
|
|||||||
Reference in New Issue
Block a user