mirror of
https://github.com/love2d/love.git
synced 2026-08-19 04:06:17 +02:00
Merged bartbes/love-experiments/joystickevents into default
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
#include "common/Variant.h"
|
#include "common/Variant.h"
|
||||||
#include "keyboard/Keyboard.h"
|
#include "keyboard/Keyboard.h"
|
||||||
#include "mouse/Mouse.h"
|
#include "mouse/Mouse.h"
|
||||||
|
#include "joystick/Joystick.h"
|
||||||
#include "thread/threads.h"
|
#include "thread/threads.h"
|
||||||
|
|
||||||
// STL
|
// STL
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
#include "keyboard/Keyboard.h"
|
#include "keyboard/Keyboard.h"
|
||||||
#include "mouse/Mouse.h"
|
#include "mouse/Mouse.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
namespace event
|
namespace event
|
||||||
@@ -86,7 +88,8 @@ Message *Event::convert(SDL_Event &e)
|
|||||||
Message *msg = NULL;
|
Message *msg = NULL;
|
||||||
love::keyboard::Keyboard::Key key;
|
love::keyboard::Keyboard::Key key;
|
||||||
love::mouse::Mouse::Button button;
|
love::mouse::Mouse::Button button;
|
||||||
Variant *arg1, *arg2, *arg3;
|
love::joystick::Joystick::Hat hat;
|
||||||
|
Variant *arg1, *arg2, *arg3, *arg4;
|
||||||
const char *txt;
|
const char *txt;
|
||||||
switch (e.type)
|
switch (e.type)
|
||||||
{
|
{
|
||||||
@@ -135,6 +138,44 @@ Message *Event::convert(SDL_Event &e)
|
|||||||
arg1->release();
|
arg1->release();
|
||||||
arg2->release();
|
arg2->release();
|
||||||
break;
|
break;
|
||||||
|
case SDL_JOYAXISMOTION:
|
||||||
|
{
|
||||||
|
arg1 = new Variant((double)(e.jaxis.which+1));
|
||||||
|
arg2 = new Variant((double)(e.jaxis.axis+1));
|
||||||
|
float value = e.jaxis.value / 32768.0f;
|
||||||
|
if (fabsf(value) < 0.001f) value = 0.0f;
|
||||||
|
if (value < -0.99f) value = -1.0f;
|
||||||
|
if (value > 0.99f) value = 1.0f;
|
||||||
|
arg3 = new Variant((double) value);
|
||||||
|
msg = new Message("joystickaxis", arg1, arg2, arg3);
|
||||||
|
arg1->release();
|
||||||
|
arg2->release();
|
||||||
|
arg3->release();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDL_JOYBALLMOTION:
|
||||||
|
arg1 = new Variant((double)(e.jball.which+1));
|
||||||
|
arg2 = new Variant((double)(e.jball.ball+1));
|
||||||
|
arg3 = new Variant((double)e.jball.xrel);
|
||||||
|
arg4 = new Variant((double)e.jball.yrel);
|
||||||
|
msg = new Message("joystickball", arg1, arg2, arg3, arg4);
|
||||||
|
arg1->release();
|
||||||
|
arg2->release();
|
||||||
|
arg3->release();
|
||||||
|
arg4->release();
|
||||||
|
break;
|
||||||
|
case SDL_JOYHATMOTION:
|
||||||
|
if (hats.find(e.jhat.value, hat) && love::joystick::Joystick::getConstant(hat, txt))
|
||||||
|
{
|
||||||
|
arg1 = new Variant((double)(e.jhat.which+1));
|
||||||
|
arg2 = new Variant((double)(e.jhat.hat+1));
|
||||||
|
arg3 = new Variant(txt, strlen(txt));
|
||||||
|
msg = new Message("joystickhat", arg1, arg2, arg3);
|
||||||
|
arg1->release();
|
||||||
|
arg2->release();
|
||||||
|
arg3->release();
|
||||||
|
}
|
||||||
|
break;
|
||||||
case SDL_ACTIVEEVENT:
|
case SDL_ACTIVEEVENT:
|
||||||
arg1 = new Variant(e.active.gain != 0);
|
arg1 = new Variant(e.active.gain != 0);
|
||||||
if (e.active.state & SDL_APPINPUTFOCUS)
|
if (e.active.state & SDL_APPINPUTFOCUS)
|
||||||
@@ -318,6 +359,21 @@ EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM>:
|
|||||||
|
|
||||||
EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM> Event::buttons(Event::buttonEntries, sizeof(Event::buttonEntries));
|
EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM> Event::buttons(Event::buttonEntries, sizeof(Event::buttonEntries));
|
||||||
|
|
||||||
|
EnumMap<love::joystick::Joystick::Hat, Uint8, love::joystick::Joystick::HAT_MAX_ENUM>::Entry Event::hatEntries[] =
|
||||||
|
{
|
||||||
|
{love::joystick::Joystick::HAT_CENTERED, SDL_HAT_CENTERED},
|
||||||
|
{love::joystick::Joystick::HAT_UP, SDL_HAT_UP},
|
||||||
|
{love::joystick::Joystick::HAT_RIGHT, SDL_HAT_RIGHT},
|
||||||
|
{love::joystick::Joystick::HAT_DOWN, SDL_HAT_DOWN},
|
||||||
|
{love::joystick::Joystick::HAT_LEFT, SDL_HAT_LEFT},
|
||||||
|
{love::joystick::Joystick::HAT_RIGHTUP, SDL_HAT_RIGHTUP},
|
||||||
|
{love::joystick::Joystick::HAT_RIGHTDOWN, SDL_HAT_RIGHTDOWN},
|
||||||
|
{love::joystick::Joystick::HAT_LEFTUP, SDL_HAT_LEFTUP},
|
||||||
|
{love::joystick::Joystick::HAT_LEFTDOWN, SDL_HAT_LEFTDOWN},
|
||||||
|
};
|
||||||
|
|
||||||
|
EnumMap<love::joystick::Joystick::Hat, Uint8, love::joystick::Joystick::HAT_MAX_ENUM> Event::hats(Event::hatEntries, sizeof(Event::hatEntries));
|
||||||
|
|
||||||
} // sdl
|
} // sdl
|
||||||
} // event
|
} // event
|
||||||
} // love
|
} // love
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ private:
|
|||||||
static EnumMap<love::keyboard::Keyboard::Key, SDLKey, love::keyboard::Keyboard::KEY_MAX_ENUM> keys;
|
static EnumMap<love::keyboard::Keyboard::Key, SDLKey, love::keyboard::Keyboard::KEY_MAX_ENUM> keys;
|
||||||
static EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM>::Entry buttonEntries[];
|
static EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM>::Entry buttonEntries[];
|
||||||
static EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM> buttons;
|
static EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM> buttons;
|
||||||
|
static EnumMap<love::joystick::Joystick::Hat, Uint8, love::joystick::Joystick::HAT_MAX_ENUM>::Entry hatEntries[];
|
||||||
|
static EnumMap<love::joystick::Joystick::Hat, Uint8, love::joystick::Joystick::Joystick::HAT_MAX_ENUM> hats;
|
||||||
|
|
||||||
}; // System
|
}; // System
|
||||||
|
|
||||||
|
|||||||
@@ -173,6 +173,15 @@ function love.createhandlers()
|
|||||||
joystickreleased = function (j,b)
|
joystickreleased = function (j,b)
|
||||||
if love.joystickreleased then love.joystickreleased(j,b) end
|
if love.joystickreleased then love.joystickreleased(j,b) end
|
||||||
end,
|
end,
|
||||||
|
joystickaxis = function (j,a,v)
|
||||||
|
if love.joystickaxis then love.joystickaxis(j,a,v) end
|
||||||
|
end,
|
||||||
|
joystickball = function (j,b,dx,dy)
|
||||||
|
if love.joystickball then love.joystickball(j,b,dx,dy) end
|
||||||
|
end,
|
||||||
|
joystickhat = function(j,h,v)
|
||||||
|
if love.joystickhat then love.joystickhat(j,h,v) end
|
||||||
|
end,
|
||||||
focus = function (f)
|
focus = function (f)
|
||||||
if love.focus then love.focus(f) end
|
if love.focus then love.focus(f) end
|
||||||
end,
|
end,
|
||||||
|
|||||||
@@ -299,6 +299,28 @@ const unsigned char boot_lua[] =
|
|||||||
0x65, 0x2e, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x64,
|
0x65, 0x2e, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x64,
|
||||||
0x28, 0x6a, 0x2c, 0x62, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a,
|
0x28, 0x6a, 0x2c, 0x62, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a,
|
||||||
0x09, 0x09, 0x65, 0x6e, 0x64, 0x2c, 0x0a,
|
0x09, 0x09, 0x65, 0x6e, 0x64, 0x2c, 0x0a,
|
||||||
|
0x09, 0x09, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x61, 0x78, 0x69, 0x73, 0x20, 0x3d, 0x20, 0x66,
|
||||||
|
0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x6a, 0x2c, 0x61, 0x2c, 0x76, 0x29, 0x0a,
|
||||||
|
0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63,
|
||||||
|
0x6b, 0x61, 0x78, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6a, 0x6f,
|
||||||
|
0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x61, 0x78, 0x69, 0x73, 0x28, 0x6a, 0x2c, 0x61, 0x2c, 0x76, 0x29, 0x20,
|
||||||
|
0x65, 0x6e, 0x64, 0x0a,
|
||||||
|
0x09, 0x09, 0x65, 0x6e, 0x64, 0x2c, 0x0a,
|
||||||
|
0x09, 0x09, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x62, 0x61, 0x6c, 0x6c, 0x20, 0x3d, 0x20, 0x66,
|
||||||
|
0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x6a, 0x2c, 0x62, 0x2c, 0x64, 0x78, 0x2c, 0x64, 0x79,
|
||||||
|
0x29, 0x0a,
|
||||||
|
0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63,
|
||||||
|
0x6b, 0x62, 0x61, 0x6c, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6a, 0x6f,
|
||||||
|
0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x62, 0x61, 0x6c, 0x6c, 0x28, 0x6a, 0x2c, 0x62, 0x2c, 0x64, 0x78, 0x2c,
|
||||||
|
0x64, 0x79, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a,
|
||||||
|
0x09, 0x09, 0x65, 0x6e, 0x64, 0x2c, 0x0a,
|
||||||
|
0x09, 0x09, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x68, 0x61, 0x74, 0x20, 0x3d, 0x20, 0x66, 0x75,
|
||||||
|
0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x6a, 0x2c, 0x68, 0x2c, 0x76, 0x29, 0x0a,
|
||||||
|
0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63,
|
||||||
|
0x6b, 0x68, 0x61, 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6a, 0x6f, 0x79,
|
||||||
|
0x73, 0x74, 0x69, 0x63, 0x6b, 0x68, 0x61, 0x74, 0x28, 0x6a, 0x2c, 0x68, 0x2c, 0x76, 0x29, 0x20, 0x65, 0x6e,
|
||||||
|
0x64, 0x0a,
|
||||||
|
0x09, 0x09, 0x65, 0x6e, 0x64, 0x2c, 0x0a,
|
||||||
0x09, 0x09, 0x66, 0x6f, 0x63, 0x75, 0x73, 0x20, 0x3d, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e,
|
0x09, 0x09, 0x66, 0x6f, 0x63, 0x75, 0x73, 0x20, 0x3d, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e,
|
||||||
0x20, 0x28, 0x66, 0x29, 0x0a,
|
0x20, 0x28, 0x66, 0x29, 0x0a,
|
||||||
0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x6f, 0x63, 0x75, 0x73, 0x20, 0x74,
|
0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x6f, 0x63, 0x75, 0x73, 0x20, 0x74,
|
||||||
|
|||||||
Reference in New Issue
Block a user