-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.lua
executable file
·120 lines (97 loc) · 2.56 KB
/
main.lua
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
MIN_POINT_DISTANCE = 14
POINT_HIT_DISTANCE = MIN_POINT_DISTANCE/2
POINT_RADIUS = 4
LINE_WIDTH = 4
WHITE = {255,255,255}
SCALING_FACTOR = 0.95
function love.load()
require "class"
require "mesh/mesh"
require "background"
love.window.setMode(0,0,{highdpi = true, fullscreen = true})
WINDOW_WIDTH, WINDOW_HEIGHT = love.graphics.getDimensions()
mesh = mesh()
background = background("background.png")
screen = {}
screen.translate = {x=0,y=0}
local imagewider = WINDOW_HEIGHT / background.height > WINDOW_WIDTH / background.width
if imagewider then
screen.scale = WINDOW_WIDTH / background.width
screen.translate.y = (WINDOW_HEIGHT - background.height * screen.scale) / 2
else
screen.scale = WINDOW_HEIGHT / background.height
screen.translate.x = (WINDOW_WIDTH - background.width * screen.scale) / 2
end
love.graphics.setLineWidth( LINE_WIDTH )
POINT_RADIUS = POINT_RADIUS * WINDOW_HEIGHT / 1080
end
function love.update()
x, y = love.mouse.getPosition()
x = x - screen.translate.x
y = y - screen.translate.y
x = x / screen.scale
y = y / screen.scale
mesh:update({x=x,y=y})
end
function love.draw()
love.graphics.translate(screen.translate.x, screen.translate.y)
love.graphics.scale(screen.scale)
background:draw()
mesh:draw(screen.scale)
end
function love.mousepressed(x,y,button)
if moving or moving2 then return end
if button == 3 then
moving = true
end
x = x - screen.translate.x
y = y - screen.translate.y
x = x / screen.scale
y = y / screen.scale
mesh:mousepressed(x,y,button)
end
function love.wheelmoved(wx,wy)
zoom(wy)
end
function love.mousemoved(x,y,dx,dy)
if moving or moving2 then
screen.translate.x = screen.translate.x + dx
screen.translate.y = screen.translate.y + dy
end
end
function love.mousereleased(x,y,button)
if button == 3 then
moving = false
end
end
function love.keypressed(key)
if moving or moving2 then return end
if key == "escape" then
mesh:save()
love.event.quit()
elseif key == "space" then
moving2 = true
elseif key == "+" then
zoom(1)
elseif key == "-" then
zoom(-1)
else
mesh:keypressed(key)
end
end
function love.keyreleased(key)
if key == "space" then
moving2 = false
end
end
function zoom(direction)
local x, y = love.mouse.getPosition();
x = x - screen.translate.x
y = y - screen.translate.y
x = x / screen.scale
y = y / screen.scale
local oldscale = screen.scale
screen.scale = screen.scale * math.pow(SCALING_FACTOR, -direction)
screen.translate.x = screen.translate.x + x * (oldscale - screen.scale)
screen.translate.y = screen.translate.y + y * (oldscale - screen.scale)
end