imported Löve GLES branch (changeset 1ba9037e558b)

This commit is contained in:
Martin Felis
2013-12-05 18:05:13 +01:00
parent 41b2db04a7
commit 2644d1ee18
615 changed files with 150300 additions and 0 deletions
+79
View File
@@ -0,0 +1,79 @@
/**
* Copyright (c) 2006-2013 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 "Cursor.h"
namespace love
{
namespace mouse
{
Cursor::~Cursor()
{
}
bool Cursor::getConstant(const char *in, SystemCursor &out)
{
return systemCursors.find(in, out);
}
bool Cursor::getConstant(SystemCursor in, const char *&out)
{
return systemCursors.find(in, out);
}
bool Cursor::getConstant(const char *in, CursorType &out)
{
return types.find(in, out);
}
bool Cursor::getConstant(CursorType in, const char *&out)
{
return types.find(in, out);
}
StringMap<Cursor::SystemCursor, Cursor::CURSOR_MAX_ENUM>::Entry Cursor::systemCursorEntries[] =
{
{"arrow", Cursor::CURSOR_ARROW},
{"ibeam", Cursor::CURSOR_IBEAM},
{"wait", Cursor::CURSOR_WAIT},
{"crosshair", Cursor::CURSOR_CROSSHAIR},
{"waitarrow", Cursor::CURSOR_WAITARROW},
{"sizenwse", Cursor::CURSOR_SIZENWSE},
{"sizenesw", Cursor::CURSOR_SIZENESW},
{"sizewe", Cursor::CURSOR_SIZEWE},
{"sizens", Cursor::CURSOR_SIZENS},
{"sizeall", Cursor::CURSOR_SIZEALL},
{"no", Cursor::CURSOR_NO},
{"hand", Cursor::CURSOR_HAND},
};
StringMap<Cursor::SystemCursor, Cursor::CURSOR_MAX_ENUM> Cursor::systemCursors(Cursor::systemCursorEntries, sizeof(Cursor::systemCursorEntries));
StringMap<Cursor::CursorType, Cursor::CURSORTYPE_MAX_ENUM>::Entry Cursor::typeEntries[] =
{
{"system", Cursor::CURSORTYPE_SYSTEM},
{"image", Cursor::CURSORTYPE_IMAGE},
};
StringMap<Cursor::CursorType, Cursor::CURSORTYPE_MAX_ENUM> Cursor::types(Cursor::typeEntries, sizeof(Cursor::typeEntries));
} // mouse
} // love
+100
View File
@@ -0,0 +1,100 @@
/**
* Copyright (c) 2006-2013 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_MOUSE_CURSOR_H
#define LOVE_MOUSE_CURSOR_H
// LOVE
#include "image/ImageData.h"
#include "common/Object.h"
#include "common/StringMap.h"
namespace love
{
namespace mouse
{
class Cursor : public Object
{
public:
// Types of system cursors.
enum SystemCursor
{
CURSOR_ARROW,
CURSOR_IBEAM,
CURSOR_WAIT,
CURSOR_CROSSHAIR,
CURSOR_WAITARROW,
CURSOR_SIZENWSE,
CURSOR_SIZENESW,
CURSOR_SIZEWE,
CURSOR_SIZENS,
CURSOR_SIZEALL,
CURSOR_NO,
CURSOR_HAND,
CURSOR_MAX_ENUM
};
enum CursorType
{
CURSORTYPE_SYSTEM,
CURSORTYPE_IMAGE,
CURSORTYPE_MAX_ENUM
};
virtual ~Cursor();
/**
* Returns a pointer to the implementation-dependent handle of this Cursor.
**/
virtual void *getHandle() const = 0;
/**
* Returns whether this Cursor is system-defined or a custom image.
**/
virtual CursorType getType() const = 0;
/**
* Returns the type type of system cursor used, if this Cursor is using a
* system-defined image.
**/
virtual SystemCursor getSystemType() const = 0;
static bool getConstant(const char *in, SystemCursor &out);
static bool getConstant(SystemCursor in, const char *&out);
static bool getConstant(const char *in, CursorType &out);
static bool getConstant(CursorType in, const char *&out);
private:
static StringMap<SystemCursor, CURSOR_MAX_ENUM>::Entry systemCursorEntries[];
static StringMap<SystemCursor, CURSOR_MAX_ENUM> systemCursors;
static StringMap<CursorType, CURSORTYPE_MAX_ENUM>::Entry typeEntries[];
static StringMap<CursorType, CURSORTYPE_MAX_ENUM> types;
};
} // mouse
} // love
#endif // LOVE_MOUSE_CURSOR_H
+52
View File
@@ -0,0 +1,52 @@
/**
* Copyright (c) 2006-2013 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 "Mouse.h"
namespace love
{
namespace mouse
{
bool Mouse::getConstant(const char *in, Button &out)
{
return buttons.find(in, out);
}
bool Mouse::getConstant(Button in, const char *&out)
{
return buttons.find(in, out);
}
StringMap<Mouse::Button, Mouse::BUTTON_MAX_ENUM>::Entry Mouse::buttonEntries[] =
{
{"l", Mouse::BUTTON_LEFT},
{"m", Mouse::BUTTON_MIDDLE},
{"r", Mouse::BUTTON_RIGHT},
{"wu", Mouse::BUTTON_WHEELUP},
{"wd", Mouse::BUTTON_WHEELDOWN},
{"x1", Mouse::BUTTON_X1},
{"x2", Mouse::BUTTON_X2},
};
StringMap<Mouse::Button, Mouse::BUTTON_MAX_ENUM> Mouse::buttons(Mouse::buttonEntries, sizeof(Mouse::buttonEntries));
} // mouse
} // love
+87
View File
@@ -0,0 +1,87 @@
/**
* Copyright (c) 2006-2013 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_MOUSE_MOUSE_H
#define LOVE_MOUSE_MOUSE_H
// LOVE
#include "Cursor.h"
#include "common/Module.h"
#include "common/StringMap.h"
#include "image/ImageData.h"
namespace love
{
namespace mouse
{
class Mouse : public Module
{
public:
enum Button
{
BUTTON_INVALID,
BUTTON_LEFT,
BUTTON_MIDDLE,
BUTTON_RIGHT,
BUTTON_X1,
BUTTON_X2,
BUTTON_WHEELUP,
BUTTON_WHEELDOWN,
BUTTON_MAX_ENUM
};
virtual ~Mouse() {};
virtual Cursor *newCursor(love::image::ImageData *data, int hotx, int hoty) = 0;
virtual Cursor *getSystemCursor(Cursor::SystemCursor cursortype) = 0;
virtual void setCursor(Cursor *cursor) = 0;
virtual void setCursor() = 0;
virtual Cursor *getCursor() const = 0;
virtual int getX() const = 0;
virtual int getY() const = 0;
virtual void getPosition(int &x, int &y) const = 0;
virtual void setX(int x) = 0;
virtual void setY(int y) = 0;
virtual void setPosition(int x, int y) = 0;
virtual void setVisible(bool visible) = 0;
virtual bool isDown(Button *buttonlist) const = 0;
virtual bool isVisible() const = 0;
virtual void setGrabbed(bool grab) = 0;
virtual bool isGrabbed() const = 0;
static bool getConstant(const char *in, Button &out);
static bool getConstant(Button in, const char *&out);
private:
static StringMap<Button, BUTTON_MAX_ENUM>::Entry buttonEntries[];
static StringMap<Button, BUTTON_MAX_ENUM> buttons;
}; // Mouse
} // mouse
} // love
#endif // LOVE_MOUSE_MOUSE_H
+122
View File
@@ -0,0 +1,122 @@
/**
* Copyright (c) 2006-2013 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 "Cursor.h"
#include "common/config.h"
namespace love
{
namespace mouse
{
namespace sdl
{
Cursor::Cursor(image::ImageData *data, int hotx, int hoty)
: cursor(0)
, type(CURSORTYPE_IMAGE)
, systemType(CURSOR_MAX_ENUM)
{
Uint32 rmask, gmask, bmask, amask;
#ifdef LOVE_BIG_ENDIAN
rmask = 0xFF000000;
gmask = 0x00FF0000;
bmask = 0x0000FF00;
amask = 0x000000FF;
#else
rmask = 0x000000FF;
gmask = 0x0000FF00;
bmask = 0x00FF0000;
amask = 0xFF000000;
#endif
int w = data->getWidth();
int h = data->getHeight();
int pitch = w * 4;
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(data->getData(), w, h, 32, pitch, rmask, gmask, bmask, amask);
if (!surface)
throw love::Exception("Cannot create cursor: out of memory!");
cursor = SDL_CreateColorCursor(surface, hotx, hoty);
SDL_FreeSurface(surface);
if (!cursor)
throw love::Exception("Cannot create cursor: %s", SDL_GetError());
}
Cursor::Cursor(mouse::Cursor::SystemCursor cursortype)
: cursor(0)
, type(CURSORTYPE_SYSTEM)
, systemType(cursortype)
{
SDL_SystemCursor sdlcursortype;
if (systemCursors.find(cursortype, sdlcursortype))
cursor = SDL_CreateSystemCursor(sdlcursortype);
else
throw love::Exception("Cannot create system cursor: invalid type.");
if (!cursor)
throw love::Exception("Cannot create system cursor: %s", SDL_GetError());
}
Cursor::~Cursor()
{
if (cursor)
SDL_FreeCursor(cursor);
}
void *Cursor::getHandle() const
{
return cursor;
}
Cursor::CursorType Cursor::getType() const
{
return type;
}
Cursor::SystemCursor Cursor::getSystemType() const
{
return systemType;
}
EnumMap<Cursor::SystemCursor, SDL_SystemCursor, Cursor::CURSOR_MAX_ENUM>::Entry Cursor::systemCursorEntries[] =
{
{Cursor::CURSOR_ARROW, SDL_SYSTEM_CURSOR_ARROW},
{Cursor::CURSOR_IBEAM, SDL_SYSTEM_CURSOR_IBEAM},
{Cursor::CURSOR_WAIT, SDL_SYSTEM_CURSOR_WAIT},
{Cursor::CURSOR_CROSSHAIR, SDL_SYSTEM_CURSOR_CROSSHAIR},
{Cursor::CURSOR_WAITARROW, SDL_SYSTEM_CURSOR_WAITARROW},
{Cursor::CURSOR_SIZENWSE, SDL_SYSTEM_CURSOR_SIZENWSE},
{Cursor::CURSOR_SIZENESW, SDL_SYSTEM_CURSOR_SIZENESW},
{Cursor::CURSOR_SIZEWE, SDL_SYSTEM_CURSOR_SIZEWE},
{Cursor::CURSOR_SIZENS, SDL_SYSTEM_CURSOR_SIZENS},
{Cursor::CURSOR_SIZEALL, SDL_SYSTEM_CURSOR_SIZEALL},
{Cursor::CURSOR_NO, SDL_SYSTEM_CURSOR_NO},
{Cursor::CURSOR_HAND, SDL_SYSTEM_CURSOR_HAND},
};
EnumMap<Cursor::SystemCursor, SDL_SystemCursor, Cursor::CURSOR_MAX_ENUM> Cursor::systemCursors(Cursor::systemCursorEntries, sizeof(Cursor::systemCursorEntries));
} // sdl
} // mouse
} // love
+64
View File
@@ -0,0 +1,64 @@
/**
* Copyright (c) 2006-2013 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_MOUSE_SDL_CURSOR_H
#define LOVE_MOUSE_SDL_CURSOR_H
// LOVE
#include "mouse/Cursor.h"
#include "common/EnumMap.h"
// SDL
#include <SDL_mouse.h>
namespace love
{
namespace mouse
{
namespace sdl
{
class Cursor : public love::mouse::Cursor
{
public:
Cursor(image::ImageData *imageData, int hotx, int hoty);
Cursor(SystemCursor cursortype);
~Cursor();
void *getHandle() const;
CursorType getType() const;
SystemCursor getSystemType() const;
private:
SDL_Cursor *cursor;
CursorType type;
SystemCursor systemType;
static EnumMap<SystemCursor, SDL_SystemCursor, CURSOR_MAX_ENUM>::Entry systemCursorEntries[];
static EnumMap<SystemCursor, SDL_SystemCursor, CURSOR_MAX_ENUM> systemCursors;
};
} // sdl
} // mouse
} // love
#endif // LOVE_MOUSE_SDL_CURSOR_H
+181
View File
@@ -0,0 +1,181 @@
/**
* Copyright (c) 2006-2013 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 "Mouse.h"
#include "window/sdl/Window.h"
// SDL
#include <SDL_mouse.h>
namespace love
{
namespace mouse
{
namespace sdl
{
const char *Mouse::getName() const
{
return "love.mouse.sdl";
}
Mouse::Mouse()
: curCursor(0)
{
}
Mouse::~Mouse()
{
if (curCursor)
setCursor();
for (auto it = systemCursors.begin(); it != systemCursors.end(); ++it)
it->second->release();
}
love::mouse::Cursor *Mouse::newCursor(love::image::ImageData *data, int hotx, int hoty)
{
return new Cursor(data, hotx, hoty);
}
love::mouse::Cursor *Mouse::getSystemCursor(Cursor::SystemCursor cursortype)
{
Cursor *cursor = NULL;
auto it = systemCursors.find(cursortype);
if (it != systemCursors.end())
cursor = it->second;
else
{
cursor = new Cursor(cursortype);
systemCursors[cursortype] = cursor;
}
return cursor;
}
void Mouse::setCursor(love::mouse::Cursor *cursor)
{
Object::AutoRelease cursorrelease(curCursor);
curCursor = cursor;
curCursor->retain();
SDL_SetCursor((SDL_Cursor *) cursor->getHandle());
}
void Mouse::setCursor()
{
Object::AutoRelease cursorrelease(curCursor);
curCursor = NULL;
SDL_SetCursor(SDL_GetDefaultCursor());
}
love::mouse::Cursor *Mouse::getCursor() const
{
return curCursor;
}
int Mouse::getX() const
{
int x;
SDL_GetMouseState(&x, 0);
return x;
}
int Mouse::getY() const
{
int y;
SDL_GetMouseState(0, &y);
return y;
}
void Mouse::getPosition(int &x, int &y) const
{
SDL_GetMouseState(&x, &y);
}
void Mouse::setPosition(int x, int y)
{
love::window::Window *window = love::window::sdl::Window::getSingleton();
SDL_Window *handle = NULL;
if (window)
handle = (SDL_Window *) window->getHandle();
SDL_WarpMouseInWindow(handle, x, y);
}
void Mouse::setX(int x)
{
int y = getY();
setPosition(x, y);
}
void Mouse::setY(int y)
{
int x = getX();
setPosition(x, y);
}
void Mouse::setVisible(bool visible)
{
SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
}
bool Mouse::isDown(Button *buttonlist) const
{
Uint32 buttonstate = SDL_GetMouseState(0, 0);
for (Button button = *buttonlist; button != BUTTON_MAX_ENUM; button = *(++buttonlist))
{
if (buttonstate & SDL_BUTTON(button))
return true;
}
return false;
}
bool Mouse::isVisible() const
{
return SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE;
}
void Mouse::setGrabbed(bool grab)
{
love::window::Window *window = love::window::sdl::Window::getSingleton();
if (window)
window->setMouseGrab(grab);
}
bool Mouse::isGrabbed() const
{
love::window::Window *window = love::window::sdl::Window::getSingleton();
if (window)
return window->isMouseGrabbed();
else
return false;
}
} // sdl
} // mouse
} // love
+80
View File
@@ -0,0 +1,80 @@
/**
* Copyright (c) 2006-2013 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_MOUSE_SDL_MOUSE_H
#define LOVE_MOUSE_SDL_MOUSE_H
// LOVE
#include "mouse/Mouse.h"
#include "Cursor.h"
// C++
#include <map>
namespace love
{
namespace mouse
{
namespace sdl
{
class Mouse : public love::mouse::Mouse
{
public:
// Implements Module.
const char *getName() const;
Mouse();
~Mouse();
love::mouse::Cursor *newCursor(love::image::ImageData *data, int hotx, int hoty);
love::mouse::Cursor *getSystemCursor(Cursor::SystemCursor cursortype);
void setCursor(love::mouse::Cursor *cursor);
void setCursor();
love::mouse::Cursor *getCursor() const;
int getX() const;
int getY() const;
void getPosition(int &x, int &y) const;
void setX(int x);
void setY(int y);
void setPosition(int x, int y);
void setVisible(bool visible);
bool isDown(Button *buttonlist) const;
bool isVisible() const;
void setGrabbed(bool grab);
bool isGrabbed() const;
private:
love::mouse::Cursor *curCursor;
std::map<Cursor::SystemCursor, Cursor *> systemCursors;
}; // Mouse
} // sdl
} // mouse
} // love
#endif // LOVE_MOUSE_SDL_MOUSE_H
@@ -0,0 +1,68 @@
/**
* Copyright (c) 2006-2013 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 "wrap_Cursor.h"
namespace love
{
namespace mouse
{
Cursor *luax_checkcursor(lua_State *L, int idx)
{
return luax_checktype<Cursor>(L, idx, "Cursor", MOUSE_CURSOR_T);
}
int w_Cursor_getType(lua_State *L)
{
Cursor *cursor = luax_checkcursor(L, 1);
Cursor::CursorType ctype = cursor->getType();
const char *typestr = 0;
if (ctype == Cursor::CURSORTYPE_IMAGE)
mouse::Cursor::getConstant(ctype, typestr);
else if (ctype == Cursor::CURSORTYPE_SYSTEM)
{
Cursor::SystemCursor systype = cursor->getSystemType();
mouse::Cursor::getConstant(systype, typestr);
}
if (!typestr)
return luaL_error(L, "Unknown cursor type.");
lua_pushstring(L, typestr);
return 1;
};
static const luaL_Reg functions[] =
{
{ "getType", w_Cursor_getType },
{ 0, 0 },
};
extern "C" int luaopen_cursor(lua_State *L)
{
return luax_register_type(L, "Cursor", functions);
}
} // mouse
} // love
+41
View File
@@ -0,0 +1,41 @@
/**
* Copyright (c) 2006-2013 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_MOUSE_WRAP_CURSOR_H
#define LOVE_MOUSE_WRAP_CURSOR_H
// LOVE
#include "common/runtime.h"
#include "Cursor.h"
namespace love
{
namespace mouse
{
Cursor *luax_checkcursor(lua_State *L, int idx);
int w_Cursor_getType(lua_State *L);
extern "C" int luaopen_cursor(lua_State *L);
} // mouse
} // love
#endif // LOVE_MOUSE_WRAP_CURSOR_H
+233
View File
@@ -0,0 +1,233 @@
/**
* Copyright (c) 2006-2013 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 "wrap_Mouse.h"
#include "wrap_Cursor.h"
#include "common/config.h"
#include "sdl/Mouse.h"
namespace love
{
namespace mouse
{
static Mouse *instance = 0;
int w_newCursor(lua_State *L)
{
Cursor *cursor = 0;
if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || luax_istype(L, 1, FILESYSTEM_FILE_DATA_T))
luax_convobj(L, 1, "image", "newImageData");
love::image::ImageData *data = luax_checktype<love::image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
int hotx = luaL_optint(L, 2, 0);
int hoty = luaL_optint(L, 3, 0);
EXCEPT_GUARD(cursor = instance->newCursor(data, hotx, hoty);)
luax_pushtype(L, "Cursor", MOUSE_CURSOR_T, cursor);
return 1;
}
int w_getSystemCursor(lua_State *L)
{
const char *str = luaL_checkstring(L, 1);
Cursor::SystemCursor systemCursor;
if (!Cursor::getConstant(str, systemCursor))
return luaL_error(L, "Invalid system cursor type: %s", str);
Cursor *cursor = 0;
EXCEPT_GUARD(cursor = instance->getSystemCursor(systemCursor);)
cursor->retain();
luax_pushtype(L, "Cursor", MOUSE_CURSOR_T, cursor);
return 1;
}
int w_setCursor(lua_State *L)
{
// Revert to the default system cursor if no argument is given.
if (lua_isnoneornil(L, 1))
{
instance->setCursor();
return 0;
}
Cursor *cursor = luax_checkcursor(L, 1);
instance->setCursor(cursor);
return 0;
}
int w_getCursor(lua_State *L)
{
Cursor *cursor = instance->getCursor();
if (cursor)
{
cursor->retain();
luax_pushtype(L, "Cursor", MOUSE_CURSOR_T, cursor);
}
else
lua_pushnil(L);
return 1;
}
int w_getX(lua_State *L)
{
lua_pushnumber(L, instance->getX());
return 1;
}
int w_getY(lua_State *L)
{
lua_pushnumber(L, instance->getY());
return 1;
}
int w_getPosition(lua_State *L)
{
int x, y;
instance->getPosition(x, y);
lua_pushinteger(L, x);
lua_pushinteger(L, y);
return 2;
}
int w_setX(lua_State *L)
{
int x = luaL_checkint(L, 1);
instance->setX(x);
return 0;
}
int w_setY(lua_State *L)
{
int y = luaL_checkint(L, 1);
instance->setY(y);
return 0;
}
int w_setPosition(lua_State *L)
{
int x = luaL_checkint(L, 1);
int y = luaL_checkint(L, 2);
instance->setPosition(x, y);
return 0;
}
int w_isDown(lua_State *L)
{
Mouse::Button b;
unsigned int num = lua_gettop(L);
Mouse::Button *buttonlist = new Mouse::Button[num+1];
unsigned int counter = 0;
for (unsigned int i = 0; i < num; i++)
{
if (Mouse::getConstant(luaL_checkstring(L, i+1), b))
buttonlist[counter++] = b;
}
buttonlist[counter] = Mouse::BUTTON_MAX_ENUM;
luax_pushboolean(L, instance->isDown(buttonlist));
delete[] buttonlist;
return 1;
}
int w_setVisible(lua_State *L)
{
bool b = luax_toboolean(L, 1);
instance->setVisible(b);
return 0;
}
int w_isVisible(lua_State *L)
{
luax_pushboolean(L, instance->isVisible());
return 1;
}
int w_setGrabbed(lua_State *L)
{
bool b = luax_toboolean(L, 1);
instance->setGrabbed(b);
return 0;
}
int w_isGrabbed(lua_State *L)
{
luax_pushboolean(L, instance->isGrabbed());
return 1;
}
// List of functions to wrap.
static const luaL_Reg functions[] =
{
{ "newCursor", w_newCursor },
{ "getSystemCursor", w_getSystemCursor },
{ "setCursor", w_setCursor },
{ "getCursor", w_getCursor },
{ "getX", w_getX },
{ "getY", w_getY },
{ "setX", w_setX },
{ "setY", w_setY },
{ "setPosition", w_setPosition },
{ "isDown", w_isDown },
{ "setVisible", w_setVisible },
{ "isVisible", w_isVisible },
{ "getPosition", w_getPosition },
{ "setGrabbed", w_setGrabbed },
{ "isGrabbed", w_isGrabbed },
{ 0, 0 }
};
// Types for this module.
static const lua_CFunction types[] =
{
luaopen_cursor,
0,
};
extern "C" int luaopen_love_mouse(lua_State *L)
{
if (instance == 0)
{
EXCEPT_GUARD(instance = new love::mouse::sdl::Mouse();)
}
else
instance->retain();
WrappedModule w;
w.module = instance;
w.name = "mouse";
w.flags = MODULE_T;
w.functions = functions;
w.types = types;
return luax_register_module(L, w);
}
} // mouse
} // love
+54
View File
@@ -0,0 +1,54 @@
/**
* Copyright (c) 2006-2013 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_MOUSE_WRAP_MOUSE_H
#define LOVE_MOUSE_WRAP_MOUSE_H
// LOVE
#include "common/runtime.h"
#include "common/config.h"
namespace love
{
namespace mouse
{
int w_newCursor(lua_State *L);
int w_getSystemCursor(lua_State *L);
int w_setCursor(lua_State *L);
int w_getCursor(lua_State *L);
int w_getX(lua_State *L);
int w_getY(lua_State *L);
int w_getPosition(lua_State *L);
int w_setX(lua_State *L);
int w_setY(lua_State *L);
int w_setPosition(lua_State *L);
int w_isDown(lua_State *L);
int w_setVisible(lua_State *L);
int w_isVisible(lua_State *L);
int w_setGrabbed(lua_State *L);
int w_isGrabbed(lua_State *L);
extern "C" LOVE_EXPORT int luaopen_love_mouse(lua_State *L);
} // mouse
} // love
#endif // LOVE_MOUSE_WRAP_MOUSE_H