Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Libretro
libretro-chailove
Commits
3f9b55e0
Verified
Commit
3f9b55e0
authored
Mar 01, 2018
by
RobLoach
Browse files
Switch to libretro API for the mouse
parent
b3f4919b
Changes
7
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
3f9b55e0
...
...
@@ -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.1
4.3
- Unreleased
## 0.1
5.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()`
...
...
src/love/mouse.cpp
View file @
3f9b55e0
...
...
@@ -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
==
"h
orizwheelup
"
)
{
}
else
if
(
button
==
"h
wu
"
)
{
return
RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP
;
}
else
if
(
button
==
"h
orizwheeldown
"
)
{
}
else
if
(
button
==
"h
wd
"
)
{
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
"l
eft
"
;
return
"l"
;
case
RETRO_DEVICE_ID_MOUSE_RIGHT
:
return
"r
ight
"
;
return
"r"
;
case
RETRO_DEVICE_ID_MOUSE_MIDDLE
:
return
"m
iddle
"
;
return
"m"
;
case
RETRO_DEVICE_ID_MOUSE_WHEELUP
:
return
"w
heelup
"
;
return
"w
d
"
;
case
RETRO_DEVICE_ID_MOUSE_WHEELDOWN
:
return
"w
heeldown
"
;
return
"w
u
"
;
case
RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP
:
return
"h
orizwheelup
"
;
return
"h
wu
"
;
case
RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN
:
return
"h
orizwheeldown
"
;
return
"h
wd
"
;
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
);
}
...
...
src/love/mouse.h
View file @
3f9b55e0
...
...
@@ -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
...
...
src/love/script.cpp
View file @
3f9b55e0
...
...
@@ -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
{
...
...
src/love/script.h
View file @
3f9b55e0
...
...
@@ -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
;
...
...
test/unittests/main.chai
View file @
3f9b55e0
...
...
@@ -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")
...
...
test/unittests/mouse.chai
0 → 100644
View file @
3f9b55e0
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')")
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment