8
-- private property: _thisFrame
9
-- what buttons are pressed this frame
10
-- if you are interested in this, use allPressed() instead
13
-- private property: lastFrame
14
-- what mouse buttons were pressed last frame
17
new = function (self, obj)
18
obj = self:extend(obj)
20
love.mousepressed = function (x, y, button) obj:mousePressed(button) end
21
love.mousereleased = function (x, y, button) obj:mouseReleased(button) end
22
if obj.onNew then obj:onNew() end
27
-- Are *any* of the buttons passed held down this frame?
30
-- string button descriptions passed as individual arguments;
31
-- if none are passed, the left mouse button is assumed
36
pressed = function (self, ...)
39
if #buttons == 0 then buttons[1] = 'l' end
41
for _, value in pairs(buttons) do
43
assert(type(value) == 'string', 'all mouse buttons are strings; asked to check a ' .. type(value))
46
if self._thisFrame[value] then
54
-- Method: justPressed
55
-- Are *any* of the buttons passed pressed for the first time this frame?
58
-- string button descriptions passed as individual arguments;
59
-- if none are passed, the left mouse button is assumed
64
justPressed = function (self, ...)
67
if #buttons == 0 then buttons[1] = 'l' end
69
for _, value in pairs(buttons) do
71
assert(type(value) == 'string', 'all mouse buttons are strings; asked to check a ' .. type(value))
74
if self._thisFrame[value] and not self._lastFrame[value] then
83
-- Are *all* of the buttons passed not held down this frame?
86
-- string button descriptions passed as individual arguments;
87
-- if none are passed, the left mouse button is assumed
92
released = function (self, ...)
94
if #buttons == 0 then buttons[1] = 'l' end
96
for _, value in pairs(buttons) do
98
assert(type(value) == 'string', 'all mouse buttons are strings; asked to check a ' .. type(value))
101
if self._thisFrame[value] then
109
-- Method: justReleased
110
-- Are *any* of the buttons passed released after being held last frame?
113
-- string button descriptions passed as individual arguments;
114
-- if none are passed, the left mouse button is assumed
119
justReleased = function (self, ...)
120
local buttons = {...}
121
if #buttons == 0 then buttons[1] = 'l' end
123
for _, value in pairs(buttons) do
125
assert(type(value) == 'string', 'all mouse buttons are strings; asked to check a ' .. type(value))
128
if self._lastFrame[value] and not self._thisFrame[value] then
136
-- Method: allPressed
137
-- Returns all buttons currently pressed this frame.
143
-- string button descriptions; if nothing is pressed, nil
145
allPressed = function (self)
148
for key, value in pairs(self._thisFrame) do
149
if value then table.insert(result, key) end
152
return unpack(result)
155
-- Method: allJustPressed
156
-- Returns all buttons just pressed this frame.
162
-- string button descriptions; if nothing is just pressed, nil
164
allJustPressed = function (self)
167
for key, value in pairs(self._thisFrame) do
168
if value and not self._lastFrame[key] then table.insert(result, key) end
171
return unpack(result)
174
-- Method: allJustReleased
175
-- Returns all buttons just released this frame.
181
-- string buttons descriptions; if nothing is just pressed, nil
183
allJustPressed = function (self)
186
for key, value in pairs(self._thisFrame) do
187
if not value and self._lastFrame[key] then table.insert(result, key) end
190
return unpack(result)
193
mousePressed = function (self, button)
194
self._thisFrame[button] = true
197
mouseReleased = function (self, button)
198
self._thisFrame[button] = false
201
endFrame = function (self, elapsed)
202
for key, value in pairs(self._thisFrame) do
203
self._lastFrame[key] = value
206
self.x = love.mouse.getX() - the.app.inset.x
207
self.y = love.mouse.getY() - the.app.inset.y
209
Sprite.endFrame(self)
212
update = function() end