From e629d0ffa47fa1fc6bc2204556c6ee30679a1c8a Mon Sep 17 00:00:00 2001 From: Ivan Kuzmenko <6745157+rndtrash@users.noreply.github.com> Date: Fri, 12 Sep 2025 03:56:44 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=81=D1=82=D1=83=D1=8E=20=D0=BE=D0=B1=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D1=83=20=D0=BC=D1=8B=D1=88=D0=B8?= =?UTF-8?q?=20=D1=81=20=D1=83=D1=87=D1=91=D1=82=D0=BE=D0=BC=20=D0=BC=D0=B0?= =?UTF-8?q?=D1=81=D1=88=D1=82=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/main.lua | 48 ++++++++++++++++++++++++++++++++++++++++ game/platform/native.lua | 10 +++++++++ 2 files changed, 58 insertions(+) diff --git a/game/main.lua b/game/main.lua index fc4d77d..1e38d95 100644 --- a/game/main.lua +++ b/game/main.lua @@ -47,6 +47,48 @@ function love.load() 16 * 5 ) tilemap:random(10, 10) + +end + +-- 0: nothing +-- 1: holding LMB +-- 2: dragging with LMB held +local mouseState = 0 +local mouseStartX = 0 +local mouseStartY = 0 +local mouseEndX = 0 +local mouseEndY = 0 + +function love.mousepressed(x, y, button) + if button == 1 then + if mouseState == 0 then + mouseState = 1 + mouseStartX = x + mouseStartY = y + end + end +end + +function love.mousemoved(x, y, dx, dy) + if mouseState == 1 then + mouseState = 2 + end + -- fallthrough + if mouseState == 2 then + mouseEndX = x + mouseEndY = y + end +end + +function love.mousereleased(x, y, button) + if button == 1 then + if mouseState == 1 then + -- TODO: callback + elseif mouseState == 2 then + -- TODO: callback + end + mouseState = 0 + end end function love.update(dt) @@ -84,6 +126,12 @@ function love.draw() drawText('Hellorld!', 160, 100) + if mouseState == 2 then + love.graphics.setColor(0, 255, 255) + love.graphics.rectangle("line", mouseStartX, mouseStartY, mouseEndX - mouseStartX, mouseEndY - mouseStartY) + love.graphics.setColor(255, 255, 255) + end + love.graphics.draw(hamsterMouse, love.mouse.getX(), love.mouse.getY()) platform.drawEnd() diff --git a/game/platform/native.lua b/game/platform/native.lua index be35531..df99698 100644 --- a/game/platform/native.lua +++ b/game/platform/native.lua @@ -11,6 +11,16 @@ function platform.init() love.graphics.setCanvas() -- Reset the canvas to avoid any bugs love.window.setMode(screenWidth * screenScale, screenHeight * screenScale, { resizable = false, vsync = true }) canvas = love.graphics.newCanvas(screenWidth, screenHeight) + + love.handlers.mousemoved = function(x, y, dx, dy, t) + if love.mousemoved then return love.mousemoved(x / screenScale, y / screenScale, dx / screenScale, dy / screenScale, t) end + end + love.handlers.mousepressed = function(x, y, b, t, c) + if love.mousepressed then return love.mousepressed(x / screenScale, y / screenScale, b, t, c) end + end + love.handlers.mousereleased = function(x, y, b, t, c) + if love.mousereleased then return love.mousereleased(x / screenScale, y / screenScale, b, t, c) end + end end function platform.drawStart()