diff --git a/CMakeLists.txt b/CMakeLists.txt index 446f7d6e8..b442b521e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -742,8 +742,28 @@ set(LOVE_SRC_MODULE_TIMER ${LOVE_SRC_MODULE_TIMER_SDL} ) -source_group("modules\\timer" FILES ${LOVE_SRC_MODULE_TIMER_ROOT}) -source_group("modules\\timer\\sdl" FILES ${LOVE_SRC_MODULE_TIMER_SDL}) +# +# love.touch +# + +set(LOVE_SRC_MODULE_TOUCH_ROOT + src/modules/touch/Touch.h + src/modules/touch/wrap_Touch.cpp + src/modules/touch/wrap_Touch.h +) + +set(LOVE_SRC_MODULE_TOUCH_SDL + src/modules/touch/sdl/Touch.cpp + src/modules/touch/sdl/Touch.h +) + +set(LOVE_SRC_MODULE_TOUCH + ${LOVE_SRC_MODULE_TOUCH_ROOT} + ${LOVE_SRC_MODULE_TOUCH_SDL} +) + +source_group("modules\\touch" FILES ${LOVE_SRC_MODULE_TOUCH_ROOT}) +source_group("modules\\touch\\sdl" FILES ${LOVE_SRC_MODULE_TOUCH_SDL}) # # love.window @@ -1152,6 +1172,7 @@ set(LOVE_LIB_SRC ${LOVE_SRC_MODULE_SYSTEM} ${LOVE_SRC_MODULE_THREAD} ${LOVE_SRC_MODULE_TIMER} + ${LOVE_SRC_MODULE_TOUCH} ${LOVE_SRC_MODULE_WINDOW} ) diff --git a/platform/macosx/love-framework.xcodeproj/project.pbxproj b/platform/macosx/love-framework.xcodeproj/project.pbxproj index 288e82612..4c0e0364a 100644 --- a/platform/macosx/love-framework.xcodeproj/project.pbxproj +++ b/platform/macosx/love-framework.xcodeproj/project.pbxproj @@ -323,6 +323,11 @@ FAD5970C196E174000E8EA36 /* wrap_Text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FAD5970B196E174000E8EA36 /* wrap_Text.cpp */; }; FAD661A21A91BA1800B64301 /* Font.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FAD661A11A91BA1800B64301 /* Font.cpp */; }; FAD8E84F1A7C949B0084E24D /* Vera.ttf.h in Headers */ = {isa = PBXBuildFile; fileRef = FAD8E84E1A7C949B0084E24D /* Vera.ttf.h */; }; + FADC9E5A1A926DE40040EA96 /* Touch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADC9E551A926DE40040EA96 /* Touch.cpp */; }; + FADC9E5B1A926DE40040EA96 /* Touch.h in Headers */ = {isa = PBXBuildFile; fileRef = FADC9E561A926DE40040EA96 /* Touch.h */; }; + FADC9E5C1A926DE40040EA96 /* Touch.h in Headers */ = {isa = PBXBuildFile; fileRef = FADC9E571A926DE40040EA96 /* Touch.h */; }; + FADC9E5D1A926DE40040EA96 /* wrap_Touch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADC9E581A926DE40040EA96 /* wrap_Touch.cpp */; }; + FADC9E5E1A926DE40040EA96 /* wrap_Touch.h in Headers */ = {isa = PBXBuildFile; fileRef = FADC9E591A926DE40040EA96 /* wrap_Touch.h */; }; FADD58DD18C30367005FC3BF /* FormatHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADD58DC18C30367005FC3BF /* FormatHandler.cpp */; }; FADDCDAD1A91817800B32118 /* CoreAudioDecoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADDCDAB1A91817800B32118 /* CoreAudioDecoder.cpp */; }; FADDCDAE1A91817800B32118 /* CoreAudioDecoder.h in Headers */ = {isa = PBXBuildFile; fileRef = FADDCDAC1A91817800B32118 /* CoreAudioDecoder.h */; }; @@ -920,6 +925,11 @@ FAD5970D196E17C100E8EA36 /* wrap_Text.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = wrap_Text.h; sourceTree = ""; }; FAD661A11A91BA1800B64301 /* Font.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Font.cpp; sourceTree = ""; }; FAD8E84E1A7C949B0084E24D /* Vera.ttf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Vera.ttf.h; sourceTree = ""; }; + FADC9E551A926DE40040EA96 /* Touch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Touch.cpp; sourceTree = ""; }; + FADC9E561A926DE40040EA96 /* Touch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Touch.h; sourceTree = ""; }; + FADC9E571A926DE40040EA96 /* Touch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Touch.h; sourceTree = ""; }; + FADC9E581A926DE40040EA96 /* wrap_Touch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Touch.cpp; sourceTree = ""; }; + FADC9E591A926DE40040EA96 /* wrap_Touch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Touch.h; sourceTree = ""; }; FADD58DC18C30367005FC3BF /* FormatHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FormatHandler.cpp; sourceTree = ""; }; FADDCDAB1A91817800B32118 /* CoreAudioDecoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CoreAudioDecoder.cpp; sourceTree = ""; }; FADDCDAC1A91817800B32118 /* CoreAudioDecoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoreAudioDecoder.h; sourceTree = ""; }; @@ -1576,6 +1586,7 @@ FA34E7CA174B512200E04D3F /* system */, 02E0744773D13AD65E7C49DC /* thread */, 6D590DDD41E72A60262E4A4F /* timer */, + FADC9E531A926DE40040EA96 /* touch */, 153D76205F7A4ACD12FB4C0E /* window */, ); name = modules; @@ -2064,6 +2075,26 @@ path = luautf8; sourceTree = ""; }; + FADC9E531A926DE40040EA96 /* touch */ = { + isa = PBXGroup; + children = ( + FADC9E541A926DE40040EA96 /* sdl */, + FADC9E571A926DE40040EA96 /* Touch.h */, + FADC9E581A926DE40040EA96 /* wrap_Touch.cpp */, + FADC9E591A926DE40040EA96 /* wrap_Touch.h */, + ); + path = touch; + sourceTree = ""; + }; + FADC9E541A926DE40040EA96 /* sdl */ = { + isa = PBXGroup; + children = ( + FADC9E551A926DE40040EA96 /* Touch.cpp */, + FADC9E561A926DE40040EA96 /* Touch.h */, + ); + path = sdl; + sourceTree = ""; + }; FAE010D7170DDE99006F29D0 /* ddsparse */ = { isa = PBXGroup; children = ( @@ -2123,6 +2154,8 @@ FADDCDAE1A91817800B32118 /* CoreAudioDecoder.h in Headers */, FAF272AF16E3D44400CC193A /* wrap_ThreadModule.h in Headers */, FAF272B616E3D46400CC193A /* Thread.h in Headers */, + FADC9E5E1A926DE40040EA96 /* wrap_Touch.h in Headers */, + FADC9E5B1A926DE40040EA96 /* Touch.h in Headers */, FAF272B816E3D46400CC193A /* threads.h in Headers */, FA5454C316F1310000D30303 /* MathModule.h in Headers */, FAA0A45E1A704016009487CB /* lprefix.h in Headers */, @@ -2160,6 +2193,7 @@ FA9B492A1875EFB900201DA9 /* Texture.h in Headers */, FAC5710117402D1100D147E4 /* BezierCurve.h in Headers */, FAC5710317402D1100D147E4 /* wrap_BezierCurve.h in Headers */, + FADC9E5C1A926DE40040EA96 /* Touch.h in Headers */, FA5FDC7E1788D548002F0ED2 /* callbacks.h in Headers */, FA5FDC7F1788D548002F0ED2 /* enet.h in Headers */, FA5FDC801788D548002F0ED2 /* list.h in Headers */, @@ -2426,12 +2460,14 @@ FA08F65516C7547300F007B5 /* wrap_Body.cpp in Sources */, FA08F65616C7547300F007B5 /* wrap_ChainShape.cpp in Sources */, FA08F65716C7547300F007B5 /* wrap_CircleShape.cpp in Sources */, + FADC9E5D1A926DE40040EA96 /* wrap_Touch.cpp in Sources */, FA08F65816C7547300F007B5 /* wrap_Contact.cpp in Sources */, FA08F65916C7547300F007B5 /* wrap_DistanceJoint.cpp in Sources */, FA08F65A16C7547300F007B5 /* wrap_EdgeShape.cpp in Sources */, FA48E43618F10D00007CF0BD /* JPEGHandler.cpp in Sources */, FA08F65B16C7547300F007B5 /* wrap_Fixture.cpp in Sources */, FA08F65C16C7547300F007B5 /* wrap_FrictionJoint.cpp in Sources */, + FADC9E5A1A926DE40040EA96 /* Touch.cpp in Sources */, FA08F65D16C7548200F007B5 /* wrap_GearJoint.cpp in Sources */, FA08F65E16C7548200F007B5 /* wrap_Joint.cpp in Sources */, FA08F65F16C7548200F007B5 /* wrap_MouseJoint.cpp in Sources */, diff --git a/src/common/Module.h b/src/common/Module.h index 3665cf482..cac50a3c9 100644 --- a/src/common/Module.h +++ b/src/common/Module.h @@ -51,6 +51,7 @@ public: M_SYSTEM, M_THREAD, M_TIMER, + M_TOUCH, M_WINDOW, M_MAX_ENUM }; diff --git a/src/modules/event/sdl/Event.cpp b/src/modules/event/sdl/Event.cpp index f5a2f9079..5367135dc 100644 --- a/src/modules/event/sdl/Event.cpp +++ b/src/modules/event/sdl/Event.cpp @@ -26,6 +26,7 @@ #include "mouse/Mouse.h" #include "joystick/JoystickModule.h" #include "joystick/sdl/Joystick.h" +#include "touch/sdl/Touch.h" #include "graphics/Graphics.h" #include "window/Window.h" #include "common/Exception.h" @@ -52,6 +53,19 @@ static void windowToPixelCoords(double *x, double *y) *y = window->toPixels(*y); } +static void normalizedToPixelCoords(double *x, double *y) +{ + window::Window *window = Module::getInstance(Module::M_WINDOW); + int w = 1, h = 1; + + if (window) + window->getPixelDimensions(w, h); + + if (x) + *x = ((*x) * (double) w); + if (y) + *y = ((*y) * (double) h); +} const char *Event::getName() const { @@ -114,10 +128,12 @@ Message *Event::convert(const SDL_Event &e) const vargs.reserve(4); love::keyboard::Keyboard *kb = nullptr; + love::touch::sdl::Touch *touchmodule = nullptr; love::filesystem::Filesystem *filesystem = nullptr; love::keyboard::Keyboard::Key key; love::mouse::Mouse::Button button; + love::touch::Touch::TouchInfo touchinfo; const char *txt; std::map::const_iterator keyit; @@ -202,6 +218,56 @@ Message *Event::convert(const SDL_Event &e) const vargs.push_back(new Variant((double) e.wheel.y)); msg = new Message("wheelmoved", vargs); break; + case SDL_FINGERDOWN: + case SDL_FINGERUP: + case SDL_FINGERMOTION: + // Touch events are disabled in OS X because we only actually want touch + // screen events, but most touch devices in OS X aren't touch screens + // (and SDL doesn't differentiate.) Non-screen touch devices like Mac + // trackpads won't give touch coords in the window's coordinate-space. +#ifndef LOVE_MACOSX + touchinfo.id = (int64) e.tfinger.fingerId; + touchinfo.x = e.tfinger.x; + touchinfo.y = e.tfinger.y; + touchinfo.dx = e.tfinger.dx; + touchinfo.dy = e.tfinger.dy; + +#ifdef LOVE_LINUX + // FIXME: hacky workaround for SDL not normalizing touch coordinates in + // its X11 backend: https://bugzilla.libsdl.org/show_bug.cgi?id=2307 + if (fabs(touchinfo.x) >= 1.5 || fabs(touchinfo.y) >= 1.5 || fabs(touchinfo.dx) >= 1.5 || fabs(touchinfo.dy) >= 1.5) + { + windowToPixelCoords(&touchinfo.x, &touchinfo.y); + windowToPixelCoords(&touchinfo.dx, &touchinfo.dy); + } + else +#endif + { + // SDL's coords are normalized to [0, 1], but we want them in pixels. + normalizedToPixelCoords(&touchinfo.x, &touchinfo.y); + normalizedToPixelCoords(&touchinfo.dx, &touchinfo.dy); + } + + // We need to update the love.touch.sdl internal state from here. + touchmodule = (touch::sdl::Touch *) Module::getInstance("love.touch.sdl"); + if (touchmodule) + touchmodule->onEvent(e.type, touchinfo); + + vargs.push_back(new Variant((double) touchinfo.id)); + vargs.push_back(new Variant(touchinfo.x)); + vargs.push_back(new Variant(touchinfo.y)); + vargs.push_back(new Variant(touchinfo.dx)); + vargs.push_back(new Variant(touchinfo.dy)); + + if (e.type == SDL_FINGERDOWN) + txt = "touchpressed"; + else if (e.type == SDL_FINGERUP) + txt = "touchreleased"; + else + txt = "touchmoved"; + msg = new Message(txt, vargs); +#endif + break; case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: case SDL_JOYAXISMOTION: diff --git a/src/modules/love/love.cpp b/src/modules/love/love.cpp index 2e205f2a1..81878e75f 100644 --- a/src/modules/love/love.cpp +++ b/src/modules/love/love.cpp @@ -100,6 +100,9 @@ extern "C" #if defined(LOVE_ENABLE_THREAD) extern int luaopen_love_thread(lua_State*); #endif +#if defined(LOVE_ENABLE_THREAD) + extern int luaopen_love_touch(lua_State*); +#endif #if defined(LOVE_ENABLE_WINDOW) extern int luaopen_love_window(lua_State*); #endif @@ -152,6 +155,9 @@ static const luaL_Reg modules[] = { #if defined(LOVE_ENABLE_THREAD) { "love.thread", luaopen_love_thread }, #endif +#if defined(LOVE_ENABLE_THREAD) + { "love.touch", luaopen_love_touch }, +#endif #if defined(LOVE_ENABLE_WINDOW) { "love.window", luaopen_love_window }, #endif diff --git a/src/modules/touch/Touch.h b/src/modules/touch/Touch.h new file mode 100644 index 000000000..b45581c53 --- /dev/null +++ b/src/modules/touch/Touch.h @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2006-2015 LOVE Development Team + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + **/ + +#ifndef LOVE_TOUCH_TOUCH_H +#define LOVE_TOUCH_TOUCH_H + +// LOVE +#include "common/int.h" +#include "common/Object.h" +#include "common/Module.h" + +// C++ +#include +#include + +namespace love +{ +namespace touch +{ + +class Touch : public Module +{ +public: + + struct TouchInfo + { + int64 id; // Identifier. Only unique for the duration of the touch-press. + double x; // Position in pixels along the x-axis. + double y; // Position in pixels along the y-axis. + double dx; // Amount in pixels moved along the x-axis. + double dy; // Amount in pixels moved along the y-axis. + }; + + virtual ~Touch() {} + + // Implements Module. + virtual ModuleType getModuleType() const { return M_TOUCH; } + + /** + * Gets the number of current touch presses. + **/ + virtual int getTouchCount() const = 0; + + /** + * Gets information about a touch press. The index should only be used for + * iterating over the current touch presses - it may change throughout a + * touch press' lifetime. + **/ + virtual TouchInfo getTouch(int index) const = 0; + +}; // Touch + +} // touch +} // love + +#endif // LOVE_TOUCH_TOUCH_H diff --git a/src/modules/touch/sdl/Touch.cpp b/src/modules/touch/sdl/Touch.cpp new file mode 100644 index 000000000..3a32c9b40 --- /dev/null +++ b/src/modules/touch/sdl/Touch.cpp @@ -0,0 +1,77 @@ +/** + * Copyright (c) 2006-2015 LOVE Development Team + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + **/ + +// LOVE +#include "common/config.h" +#include "common/Exception.h" +#include "Touch.h" + +namespace love +{ +namespace touch +{ +namespace sdl +{ + +int Touch::getTouchCount() const +{ + return (int) touches.size(); +} + +Touch::TouchInfo Touch::getTouch(int index) const +{ + if (index < 0) + throw love::Exception("Invalid touch index: %d", index); + + std::map::const_iterator it = touches.begin(); + + for (int i = 0; i < index; i++) + { + if (++it == touches.end()) + throw love::Exception("Invalid touch index: %d", index); + } + + return it->second; +} + +const char *Touch::getName() const +{ + return "love.touch.sdl"; +} + +void Touch::onEvent(Uint32 eventtype, const TouchInfo &info) +{ + switch (eventtype) + { + case SDL_FINGERDOWN: + case SDL_FINGERMOTION: + touches[info.id] = info; + break; + case SDL_FINGERUP: + touches.erase(info.id); + break; + default: + break; + } +} + +} // sdl +} // touch +} // love diff --git a/src/modules/touch/sdl/Touch.h b/src/modules/touch/sdl/Touch.h new file mode 100644 index 000000000..c123e599f --- /dev/null +++ b/src/modules/touch/sdl/Touch.h @@ -0,0 +1,70 @@ +/** + * Copyright (c) 2006-2015 LOVE Development Team + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + **/ + +#ifndef LOVE_TOUCH_SDL_TOUCH_H +#define LOVE_TOUCH_SDL_TOUCH_H + +// LOVE +#include "touch/Touch.h" + +// C++ +#include + +// SDL +#include + +namespace love +{ +namespace touch +{ +namespace sdl +{ + +class Touch : public love::touch::Touch +{ +public: + + virtual ~Touch() {} + + virtual int getTouchCount() const; + virtual TouchInfo getTouch(int index) const; + + // Implements Module. + virtual const char *getName() const; + + // SDL has functions to query the state of touch presses, but unfortunately + // they are updated on a different thread in some backends, which causes + // issues especially if the user is iterating through the current touches + // when they're updated. So we only update our touch press state in + // love::event::sdl::Event::convert. + void onEvent(Uint32 eventtype, const TouchInfo &info); + +private: + + // All current touches, indexed by their IDs. + std::map touches; + +}; // Touch + +} // sdl +} // touch +} // love + +#endif // LOVE_TOUCH_SDL_TOUCH_H diff --git a/src/modules/touch/wrap_Touch.cpp b/src/modules/touch/wrap_Touch.cpp new file mode 100644 index 000000000..45e586ed2 --- /dev/null +++ b/src/modules/touch/wrap_Touch.cpp @@ -0,0 +1,84 @@ +/** + * Copyright (c) 2006-2015 LOVE Development Team + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + **/ + +#include "common/config.h" + +// LOVE +#include "wrap_Touch.h" + +#include "sdl/Touch.h" + +namespace love +{ +namespace touch +{ + +#define instance() (Module::getInstance(Module::M_TOUCH)) + +int w_getTouchCount(lua_State *L) +{ + lua_pushinteger(L, instance()->getTouchCount()); + return 1; +} + +int w_getTouch(lua_State *L) +{ + int index = luaL_checkint(L, 1) - 1; + + Touch::TouchInfo info; + luax_catchexcept(L, [&](){ info = instance()->getTouch(index); }); + + // Lets hope the ID can be accurately represented in a Lua number... + lua_pushnumber(L, (lua_Number) info.id); + lua_pushnumber(L, info.x); + lua_pushnumber(L, info.y); + + return 3; +} + +static const luaL_Reg functions[] = +{ + { "getTouchCount", w_getTouchCount }, + { "getTouch", w_getTouch }, + { 0, 0 } +}; + +extern "C" int luaopen_love_touch(lua_State *L) +{ + Touch *instance = instance(); + if (instance == nullptr) + { + luax_catchexcept(L, [&](){ instance = new love::touch::sdl::Touch(); }); + } + else + instance->retain(); + + WrappedModule w; + w.module = instance; + w.name = "touch"; + w.flags = MODULE_T; + w.functions = functions; + w.types = nullptr; + + return luax_register_module(L, w); +} + +} // touch +} // love diff --git a/src/modules/touch/wrap_Touch.h b/src/modules/touch/wrap_Touch.h new file mode 100644 index 000000000..89d376c54 --- /dev/null +++ b/src/modules/touch/wrap_Touch.h @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2006-2015 LOVE Development Team + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + **/ + +#ifndef LOVE_TOUCH_WRAP_TOUCH_H +#define LOVE_TOUCH_WRAP_TOUCH_H + +// LOVE +#include "Touch.h" +#include "common/runtime.h" + +namespace love +{ +namespace touch +{ + +int w_getTouchCount(lua_State *L); +int w_getTouch(lua_State *L); +extern "C" LOVE_EXPORT int luaopen_love_touch(lua_State *L); + +} // touch +} // love + +#endif // LOVE_TOUCH_WRAP_TOUCH_H diff --git a/src/modules/window/Window.h b/src/modules/window/Window.h index c1d9b9d71..02bb6773b 100644 --- a/src/modules/window/Window.h +++ b/src/modules/window/Window.h @@ -153,6 +153,8 @@ public: virtual void setMouseGrab(bool grab) = 0; virtual bool isMouseGrabbed() const = 0; + virtual void getPixelDimensions(int &w, int &h) const = 0; + virtual double getPixelScale() const = 0; virtual double toPixels(double x) const = 0; diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index 7617ea8bc..ee6a95cad 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -856,6 +856,24 @@ bool Window::isMouseGrabbed() const return mouseGrabbed; } +void Window::getPixelDimensions(int &w, int &h) const +{ + if (window) + { + // FIXME: disabled in Linux for runtime SDL 2.0.0 compatibility. +#if SDL_VERSION_ATLEAST(2,0,1) && !defined(LOVE_LINUX) + SDL_GL_GetDrawableSize(window, &w, &h); +#else + SDL_GetWindowSize(window, &w, &h); +#endif + } + else + { + w = curMode.width; + h = curMode.height; + } +} + double Window::getPixelScale() const { double scale = 1.0; diff --git a/src/modules/window/sdl/Window.h b/src/modules/window/sdl/Window.h index 9b10e7d80..bf623a005 100644 --- a/src/modules/window/sdl/Window.h +++ b/src/modules/window/sdl/Window.h @@ -84,6 +84,8 @@ public: void setMouseGrab(bool grab); bool isMouseGrabbed() const; + void getPixelDimensions(int &w, int &h) const; + double getPixelScale() const; double toPixels(double x) const; diff --git a/src/scripts/boot.lua b/src/scripts/boot.lua index 13012b6ee..b4af7c829 100644 --- a/src/scripts/boot.lua +++ b/src/scripts/boot.lua @@ -178,6 +178,15 @@ function love.createhandlers() wheelmoved = function (x,y) if love.wheelmoved then return love.wheelmoved(x,y) end end, + touchpressed = function (id,x,y,dx,dy) + if love.touchpressed then return love.touchpressed(id,x,y,dx,dy) end + end, + touchreleased = function (id,x,y,dx,dy) + if love.touchreleased then return love.touchreleased(id,x,y,dx,dy) end + end, + touchmoved = function (id,x,y,dx,dy) + if love.touchmoved then return love.touchmoved(id,x,y,dx,dy) end + end, joystickpressed = function (j,b) if love.joystickpressed then return love.joystickpressed(j,b) end end, @@ -333,6 +342,7 @@ function love.init() mouse = true, timer = true, joystick = true, + touch = true, image = true, graphics = true, audio = true, @@ -383,6 +393,7 @@ function love.init() "keyboard", "joystick", "mouse", + "touch", "sound", "system", "audio", diff --git a/src/scripts/boot.lua.h b/src/scripts/boot.lua.h index 06ef8f649..5b1e27488 100644 --- a/src/scripts/boot.lua.h +++ b/src/scripts/boot.lua.h @@ -314,6 +314,31 @@ const unsigned char boot_lua[] = 0x76, 0x65, 0x2e, 0x77, 0x68, 0x65, 0x65, 0x6c, 0x6d, 0x6f, 0x76, 0x65, 0x64, 0x28, 0x78, 0x2c, 0x79, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x2c, 0x0a, + 0x09, 0x09, 0x74, 0x6f, 0x75, 0x63, 0x68, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x20, 0x3d, 0x20, 0x66, + 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x69, 0x64, 0x2c, 0x78, 0x2c, 0x79, 0x2c, 0x64, 0x78, + 0x2c, 0x64, 0x79, 0x29, 0x0a, + 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x74, 0x6f, 0x75, 0x63, 0x68, 0x70, 0x72, + 0x65, 0x73, 0x73, 0x65, 0x64, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x74, 0x6f, 0x75, 0x63, 0x68, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x28, + 0x69, 0x64, 0x2c, 0x78, 0x2c, 0x79, 0x2c, 0x64, 0x78, 0x2c, 0x64, 0x79, 0x29, 0x20, 0x65, 0x6e, 0x64, 0x0a, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x2c, 0x0a, + 0x09, 0x09, 0x74, 0x6f, 0x75, 0x63, 0x68, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x64, 0x20, 0x3d, 0x20, + 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x69, 0x64, 0x2c, 0x78, 0x2c, 0x79, 0x2c, 0x64, + 0x78, 0x2c, 0x64, 0x79, 0x29, 0x0a, + 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x74, 0x6f, 0x75, 0x63, 0x68, 0x72, 0x65, + 0x6c, 0x65, 0x61, 0x73, 0x65, 0x64, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, + 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x74, 0x6f, 0x75, 0x63, 0x68, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, + 0x64, 0x28, 0x69, 0x64, 0x2c, 0x78, 0x2c, 0x79, 0x2c, 0x64, 0x78, 0x2c, 0x64, 0x79, 0x29, 0x20, 0x65, 0x6e, + 0x64, 0x0a, + 0x09, 0x09, 0x65, 0x6e, 0x64, 0x2c, 0x0a, + 0x09, 0x09, 0x74, 0x6f, 0x75, 0x63, 0x68, 0x6d, 0x6f, 0x76, 0x65, 0x64, 0x20, 0x3d, 0x20, 0x66, 0x75, 0x6e, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x69, 0x64, 0x2c, 0x78, 0x2c, 0x79, 0x2c, 0x64, 0x78, 0x2c, 0x64, + 0x79, 0x29, 0x0a, + 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x74, 0x6f, 0x75, 0x63, 0x68, 0x6d, 0x6f, + 0x76, 0x65, 0x64, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6c, 0x6f, + 0x76, 0x65, 0x2e, 0x74, 0x6f, 0x75, 0x63, 0x68, 0x6d, 0x6f, 0x76, 0x65, 0x64, 0x28, 0x69, 0x64, 0x2c, 0x78, + 0x2c, 0x79, 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, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x20, 0x3d, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x6a, 0x2c, 0x62, 0x29, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, @@ -604,6 +629,7 @@ const unsigned char boot_lua[] = 0x09, 0x09, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x72, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x74, 0x6f, 0x75, 0x63, 0x68, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x0a, @@ -690,6 +716,7 @@ const unsigned char boot_lua[] = 0x09, 0x09, 0x22, 0x6b, 0x65, 0x79, 0x62, 0x6f, 0x61, 0x72, 0x64, 0x22, 0x2c, 0x0a, 0x09, 0x09, 0x22, 0x6a, 0x6f, 0x79, 0x73, 0x74, 0x69, 0x63, 0x6b, 0x22, 0x2c, 0x0a, 0x09, 0x09, 0x22, 0x6d, 0x6f, 0x75, 0x73, 0x65, 0x22, 0x2c, 0x0a, + 0x09, 0x09, 0x22, 0x74, 0x6f, 0x75, 0x63, 0x68, 0x22, 0x2c, 0x0a, 0x09, 0x09, 0x22, 0x73, 0x6f, 0x75, 0x6e, 0x64, 0x22, 0x2c, 0x0a, 0x09, 0x09, 0x22, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x22, 0x2c, 0x0a, 0x09, 0x09, 0x22, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x22, 0x2c, 0x0a,