Add mouse wheel support for zoom control in camera module (the dumb way)
This commit is contained in:
parent
331aefb0f6
commit
c566d1669e
@ -1,5 +1,3 @@
|
||||
local utils = require "lib.utils.utils"
|
||||
|
||||
--- @alias Device "mouse" | "key" | "pad"
|
||||
|
||||
--- @param device Device
|
||||
@ -27,6 +25,12 @@ controls.keymap = {
|
||||
local currentKeys = {}
|
||||
local cachedKeys = {}
|
||||
|
||||
--- @type number
|
||||
controls.mouseWheelY = 0
|
||||
love.wheelmoved = function(x, y)
|
||||
controls.mouseWheelY = y
|
||||
end
|
||||
|
||||
--- polling controls in O(n)
|
||||
--- should be called at the beginning of every frame
|
||||
function controls:poll()
|
||||
@ -50,6 +54,7 @@ function controls:cache()
|
||||
for k, v in pairs(currentKeys) do
|
||||
cachedKeys[k] = v
|
||||
end
|
||||
controls.mouseWheelY = 0
|
||||
end
|
||||
|
||||
--- marks a control consumed for the current frame
|
||||
|
||||
@ -30,12 +30,6 @@ camera.scale = camera:getDefaultScale()
|
||||
|
||||
---------------------------------------------------
|
||||
|
||||
love.wheelmoved = function(x, y)
|
||||
if camera.scale > camera:getDefaultScale() * 5 and y > 0 then return end;
|
||||
if camera.scale < camera:getDefaultScale() / 5 and y < 0 then return end;
|
||||
camera.scale = camera.scale + (camera.scale * 0.1 * y)
|
||||
end
|
||||
|
||||
local controlMap = {
|
||||
cameraMoveUp = Vec3({ 0, -1 }),
|
||||
cameraMoveLeft = Vec3({ -1 }),
|
||||
@ -50,6 +44,13 @@ function camera:update(dt)
|
||||
return
|
||||
end
|
||||
|
||||
-------------------- зум на колесо ---------------------
|
||||
local y = Tree.controls.mouseWheelY
|
||||
if camera.scale > camera:getDefaultScale() * 5 and y > 0 then return end;
|
||||
if camera.scale < camera:getDefaultScale() / 5 and y < 0 then return end;
|
||||
camera.scale = camera.scale + (camera.scale * 0.1 * y)
|
||||
--------------------------------------------------------
|
||||
|
||||
local ps = Tree.panning
|
||||
if ps.delta:length() > 0 then
|
||||
local worldDelta = ps.delta:scale(1 / (self.pixelsPerMeter * self.scale)):scale(dt):scale(self.speed)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user