Commits

Alex Szpakowski committed 2e0c668

Added love.joystickaxismoved, love.joystickballmoved, and love.joystickhatmoved callbacks

Comments (0)

Files changed (5)

src/modules/event/Event.h

 #include "common/Variant.h"
 #include "keyboard/Keyboard.h"
 #include "mouse/Mouse.h"
+#include "joystick/Joystick.h"
 #include "thread/threads.h"
 
 // STL

src/modules/event/sdl/Event.cpp

 #include "keyboard/Keyboard.h"
 #include "mouse/Mouse.h"
 
+#include <cmath>
+
 namespace love
 {
 namespace event
 	Message *msg = NULL;
 	love::keyboard::Keyboard::Key key;
 	love::mouse::Mouse::Button button;
-	Variant *arg1, *arg2, *arg3;
+	love::joystick::Joystick::Hat hat;
+	Variant *arg1, *arg2, *arg3, *arg4;
 	const char *txt;
 	switch (e.type)
 	{
 		arg1->release();
 		arg2->release();
 		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("joystickaxismoved", 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("joystickballmoved", 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("joystickhatmoved", arg1, arg2, arg3);
+			arg1->release();
+			arg2->release();
+			arg3->release();
+		}
+		break;
 	case SDL_ACTIVEEVENT:
 		arg1 = new Variant(e.active.gain != 0);
 		if (e.active.state & SDL_APPINPUTFOCUS)
 
 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
 } // event
 } // love

src/modules/event/sdl/Event.h

 	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> 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
 

src/scripts/boot.lua

 		joystickreleased = function (j,b)
 			if love.joystickreleased then love.joystickreleased(j,b) end
 		end,
+		joystickaxismoved = function (j,a,v)
+			if love.joystickaxismoved then love.joystickaxismoved(j,a,v) end
+		end,
+		joystickballmoved = function (j,b,dx,dy)
+			if love.joystickballmoved then love.joystickballmoved(j,b,dx,dy) end
+		end,
+		joystickhatmoved = function(j,h,v)
+			if love.joystickhatmoved then love.joystickhatmoved(j,h,v) end
+		end,
 		focus = function (f)
 			if love.focus then love.focus(f) end
 		end,

src/scripts/boot.lua.h

 	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,
 	0x09, 0x09, 0x65, 0x6e, 0x64, 0x2c, 0x0a,
+	0x09, 0x09, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x61, 0x78, 0x69, 0x73, 0x6d, 0x6f, 0x76, 0x65, 
+	0x64, 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, 0x6d, 0x6f, 0x76, 0x65, 0x64, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6c, 0x6f, 
+	0x76, 0x65, 0x2e, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x61, 0x78, 0x69, 0x73, 0x6d, 0x6f, 0x76, 
+	0x65, 0x64, 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, 0x6d, 0x6f, 0x76, 0x65, 
+	0x64, 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, 0x6d, 0x6f, 0x76, 0x65, 0x64, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6c, 0x6f, 
+	0x76, 0x65, 0x2e, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x62, 0x61, 0x6c, 0x6c, 0x6d, 0x6f, 0x76, 
+	0x65, 0x64, 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, 0x6d, 0x6f, 0x76, 0x65, 0x64, 
+	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, 0x6d, 0x6f, 0x76, 0x65, 0x64, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 
+	0x65, 0x2e, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x68, 0x61, 0x74, 0x6d, 0x6f, 0x76, 0x65, 0x64, 
+	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, 
 	0x20, 0x28, 0x66, 0x29, 0x0a,
 	0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x66, 0x6f, 0x63, 0x75, 0x73, 0x20, 0x74,