Verified Commit 3f9b55e0 authored by RobLoach's avatar RobLoach
Browse files

Switch to libretro API for the mouse

parent b3f4919b
......@@ -4,10 +4,11 @@ All notable changes to [ChaiLove](https://github.com/RobLoach/ChaiLove) will be
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## 0.14.3 - Unreleased
## 0.15.0 - Unreleased
### Changed
- Updated the input description names
- Switch Keyboard/Mouse input from SDL API to libretro API
- `love.mousepressed()` and `love.mousereleased()` now pass the button name rather than its index
### Added
- `love.keyboard.isScancodeDown()`
......
......@@ -41,9 +41,9 @@ int mouse::getButtonKey(const std::string& button) {
return RETRO_DEVICE_ID_MOUSE_WHEELUP;
} else if (button == "wheeldown" || button == "wd") {
return RETRO_DEVICE_ID_MOUSE_WHEELDOWN;
} else if (button == "horizwheelup") {
} else if (button == "hwu") {
return RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP;
} else if (button == "horizwheeldown") {
} else if (button == "hwd") {
return RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN;
} else if (button == "x1") {
return RETRO_DEVICE_ID_MOUSE_BUTTON_4;
......@@ -56,19 +56,19 @@ int mouse::getButtonKey(const std::string& button) {
std::string mouse::getButtonName(int button) {
switch (button) {
case RETRO_DEVICE_ID_MOUSE_LEFT:
return "left";
return "l";
case RETRO_DEVICE_ID_MOUSE_RIGHT:
return "right";
return "r";
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
return "middle";
return "m";
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
return "wheelup";
return "wd";
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
return "wheeldown";
return "wu";
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP:
return "horizwheelup";
return "hwu";
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN:
return "horizwheeldown";
return "hwd";
case RETRO_DEVICE_ID_MOUSE_BUTTON_4:
return "x1";
case RETRO_DEVICE_ID_MOUSE_BUTTON_5:
......@@ -96,9 +96,9 @@ void mouse::update() {
if (state != buttonState[i]) {
buttonState[i] = state;
if (buttonState[i] == 0) {
mousereleased(m_x, m_y, i);
mousereleased(m_x, m_y, getButtonName(i));
} else {
mousepressed(m_x, m_y, i);
mousepressed(m_x, m_y, getButtonName(i));
}
}
}
......@@ -108,11 +108,11 @@ void mouse::mousemoved(int x, int y, int dx, int dy) {
ChaiLove::getInstance()->script->mousemoved(x, y, dx, dy);
}
void mouse::mousepressed(int x, int y, int button) {
void mouse::mousepressed(int x, int y, const std::string& button) {
ChaiLove::getInstance()->script->mousepressed(x, y, button);
}
void mouse::mousereleased(int x, int y, int button) {
void mouse::mousereleased(int x, int y, const std::string& button) {
ChaiLove::getInstance()->script->mousereleased(x, y, button);
}
......
......@@ -64,8 +64,8 @@ class mouse {
int16_t buttonState[RETRO_DEVICE_ID_MOUSE_BUTTON_5];
void mousemoved(int x, int y, int dx, int dy);
void mousepressed(int x, int y, int button);
void mousereleased(int x, int y, int button);
void mousepressed(int x, int y, const std::string& button);
void mousereleased(int x, int y, const std::string& button);
};
} // namespace love
......
......@@ -359,14 +359,14 @@ script::script(const std::string& file) {
hasjoystickreleased = false;
}
try {
chaimousepressed = chai.eval<std::function<void(int, int, int)> >("mousepressed");
chaimousepressed = chai.eval<std::function<void(int, int, const std::string&)> >("mousepressed");
}
catch (const std::exception& e) {
std::cout << "[ChaiLove] [script] mousepressed() " << e.what() << std::endl;
hasmousepressed = false;
}
try {
chaimousereleased = chai.eval<std::function<void(int, int, int)> >("mousereleased");
chaimousereleased = chai.eval<std::function<void(int, int, const std::string&)> >("mousereleased");
}
catch (const std::exception& e) {
std::cout << "[ChaiLove] [script] mousereleased() " << e.what() << std::endl;
......@@ -510,7 +510,7 @@ void script::joystickreleased(int joystick, const std::string& button) {
#endif
}
void script::mousepressed(int x, int y, int button) {
void script::mousepressed(int x, int y, const std::string& button) {
#ifdef __HAVE_CHAISCRIPT__
if (hasmousepressed) {
try {
......@@ -524,7 +524,7 @@ void script::mousepressed(int x, int y, int button) {
#endif
}
void script::mousereleased(int x, int y, int button) {
void script::mousereleased(int x, int y, const std::string& button) {
#ifdef __HAVE_CHAISCRIPT__
if (hasmousereleased) {
try {
......
......@@ -177,18 +177,18 @@ class script {
*
* @param x The mouse position on the x-axis.
* @param y The mouse position on the y-axis.
* @param button The mouse button index of which was pressed.
* @param button The mouse button name of which was pressed.
*/
void mousepressed(int x, int y, int button);
void mousepressed(int x, int y, const std::string& button);
/**
* @brief Called when a mouse button is released.
*
* @param x The mouse position on the x-axis.
* @param y The mouse position on the y-axis.
* @param button The mouse button index of which was released.
* @param button The mouse button name of which was released.
*/
void mousereleased(int x, int y, int button);
void mousereleased(int x, int y, const std::string& button);
/**
* @brief Called when the mouse is moved.
......@@ -243,8 +243,8 @@ class script {
std::function<std::string()> chaisavestate;
std::function<void(int, const std::string&)> chaijoystickpressed;
std::function<void(int, const std::string&)> chaijoystickreleased;
std::function<void(int, int, int)> chaimousepressed;
std::function<void(int, int, int)> chaimousereleased;
std::function<void(int, int, const std::string&)> chaimousepressed;
std::function<void(int, int, const std::string&)> chaimousereleased;
std::function<void(int, int, int, int)> chaimousemoved;
std::function<void(const std::string&, int)> chaikeypressed;
std::function<void(const std::string&, int)> chaikeyreleased;
......
......@@ -10,6 +10,7 @@ def load() {
love.filesystem.load("font.chai")
love.filesystem.load("graphics.chai")
love.filesystem.load("math.chai")
love.filesystem.load("mouse.chai")
love.filesystem.load("joystick.chai")
love.filesystem.load("keyboard.chai")
love.filesystem.load("timer.chai")
......
var mouseX = love.mouse.getX()
assert_not_equal(-1, mouseX, "love.mouse.getX()")
var mouseY = love.mouse.getY()
assert_not_equal(-1, mouseY, "love.mouse.getY()")
var mousePoint = love.mouse.getPosition()
assert_equal(mousePoint.x, mouseX, "love.mouse.getPosition().x")
assert_equal(mousePoint.y, mouseY, "love.mouse.getPosition().y")
assert_not(love.mouse.isDown("x1"), "love.mouse.isDown('x1')")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment