Added love.touch module and touch screen events. Resolves issue #825.

Note: this implementation is slightly different from the implementation in the love 0.9.x Android and iOS ports!

Added love.touchpressed(id, x, y), love.touchmoved(id, x, y, dx, dy), and love.touchreleased(id, x, y, dx, dy).

id is a unique identifier for the touch press that persists until love.touchreleased. After that it is no longer unique.
x and y are the coordinates of the touch event in pixels within the window.
dx and dy are the amount in pixels that the touch has moved since the last event.

Added love.touch.getTouchCount and love.touch.getTouch(index).

love.touch.getTouch takes an index (not the same as an id. indices are not stable and don't correspond to a unique touch press.)
It returns the id of the touch and its current x and y coordinates in pixels.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2015-02-16 16:29:45 -04:00
parent 24cb934fa6
commit 7f9abc1e77
15 changed files with 536 additions and 2 deletions
+23 -2
View File
@@ -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}
)
@@ -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 = "<group>"; };
FAD661A11A91BA1800B64301 /* Font.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Font.cpp; sourceTree = "<group>"; };
FAD8E84E1A7C949B0084E24D /* Vera.ttf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Vera.ttf.h; sourceTree = "<group>"; };
FADC9E551A926DE40040EA96 /* Touch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Touch.cpp; sourceTree = "<group>"; };
FADC9E561A926DE40040EA96 /* Touch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Touch.h; sourceTree = "<group>"; };
FADC9E571A926DE40040EA96 /* Touch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Touch.h; sourceTree = "<group>"; };
FADC9E581A926DE40040EA96 /* wrap_Touch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Touch.cpp; sourceTree = "<group>"; };
FADC9E591A926DE40040EA96 /* wrap_Touch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Touch.h; sourceTree = "<group>"; };
FADD58DC18C30367005FC3BF /* FormatHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FormatHandler.cpp; sourceTree = "<group>"; };
FADDCDAB1A91817800B32118 /* CoreAudioDecoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CoreAudioDecoder.cpp; sourceTree = "<group>"; };
FADDCDAC1A91817800B32118 /* CoreAudioDecoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoreAudioDecoder.h; sourceTree = "<group>"; };
@@ -1576,6 +1586,7 @@
FA34E7CA174B512200E04D3F /* system */,
02E0744773D13AD65E7C49DC /* thread */,
6D590DDD41E72A60262E4A4F /* timer */,
FADC9E531A926DE40040EA96 /* touch */,
153D76205F7A4ACD12FB4C0E /* window */,
);
name = modules;
@@ -2064,6 +2075,26 @@
path = luautf8;
sourceTree = "<group>";
};
FADC9E531A926DE40040EA96 /* touch */ = {
isa = PBXGroup;
children = (
FADC9E541A926DE40040EA96 /* sdl */,
FADC9E571A926DE40040EA96 /* Touch.h */,
FADC9E581A926DE40040EA96 /* wrap_Touch.cpp */,
FADC9E591A926DE40040EA96 /* wrap_Touch.h */,
);
path = touch;
sourceTree = "<group>";
};
FADC9E541A926DE40040EA96 /* sdl */ = {
isa = PBXGroup;
children = (
FADC9E551A926DE40040EA96 /* Touch.cpp */,
FADC9E561A926DE40040EA96 /* Touch.h */,
);
path = sdl;
sourceTree = "<group>";
};
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 */,
+1
View File
@@ -51,6 +51,7 @@ public:
M_SYSTEM,
M_THREAD,
M_TIMER,
M_TOUCH,
M_WINDOW,
M_MAX_ENUM
};
+66
View File
@@ -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<window::Window>(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<SDL_Keycode, love::keyboard::Keyboard::Key>::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:
+6
View File
@@ -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
+73
View File
@@ -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 <vector>
#include <limits>
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
+77
View File
@@ -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<int64, TouchInfo>::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
+70
View File
@@ -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 <map>
// SDL
#include <SDL_events.h>
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<int64, TouchInfo> touches;
}; // Touch
} // sdl
} // touch
} // love
#endif // LOVE_TOUCH_SDL_TOUCH_H
+84
View File
@@ -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<Touch>(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
+40
View File
@@ -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
+2
View File
@@ -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;
+18
View File
@@ -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;
+2
View File
@@ -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;
+11
View File
@@ -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",
+27
View File
@@ -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,