-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.lua
More file actions
39 lines (32 loc) · 1.01 KB
/
Copy pathbackground.lua
File metadata and controls
39 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Background = {}
Background.__index = Background
local DRAG_CURSOR = love.mouse.getSystemCursor("sizewe")
local DRAG_BEGIN_DISTANCE = 5
--- The background, with a hint of blue.
function Background:create()
local this = {
blueness = 0,
bluenessOnDragStart = nil,
}
setmetatable(this, self)
return this
end
--- LOVE update handler
function Background:update()
local mouseInfo = love.mouse.registerSolid(self, { isWholeScreen = true })
self.isHovered = mouseInfo.isHovered
if mouseInfo.drag then
if mouseInfo.dragStarted then
self.bluenessOnDragStart = self.blueness
end
if mouseInfo.drag.maxDx >= DRAG_BEGIN_DISTANCE then
love.mouse.importantCursor = DRAG_CURSOR
self.blueness = math.min(1, math.max(0,
self.bluenessOnDragStart + (mouseInfo.drag.toX - mouseInfo.drag.fromX) / love.graphics.getWidth()))
end
end
end
--- LOVE draw handler
function Background:draw()
love.graphics.clear(1 - self.blueness, 1 - self.blueness, 1)
end