-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.lua
82 lines (73 loc) · 2.07 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
gui = require('Gspot/Gspot')
require('lovefs/lovefs')
require('lovefs/gspotDialog')
love.load = function()
fs = lovefs()
local button = gui:button('Load Image', {0, 0, 200, 40})
button.click = function(this)
save = false
fs:loadDialog(gui, 'Load Image', {'All | *.*', 'Jpeg | *.jpg *.jpeg', 'Png | *.png', 'Bmp | *.bmp', 'Gif | *.gif'})
end
local button = gui:button('Load Sound', {200, 0, 200, 40})
button.click = function(this)
save = false
fs:loadDialog(gui, 'Load Sound', {'Sound | *.mp3 *.wav', 'All | *.*'})
end
local button = gui:button('Load TrueType', {400, 0, 200, 40})
button.click = function(this)
save = false
fs:loadDialog(gui, 'Load TrueType', {'TrueType | *.ttf', 'All | *.*'})
end
saveButton = gui:button('Save Image (as png)', {600, 0, 200, 40})
saveButton.click = function(this)
save = true
fs:saveDialog(gui, 'Save Image')
end
saveButton:hide()
end
love.update = function(dt)
gui:update(dt)
if fs.selectedFile then
ext = fs.selectedFile:match('[^'..fs.sep..']+$'):match('[^.]+$')
if save then
if newImage then fs:saveImage(newImage) end
save = false
elseif ext == 'jpg' or ext == 'png' or ext == 'bmp' then
newImage = fs:loadImage()
saveButton:show()
elseif ext == 'mp3' or ext == 'wav' then
sound = fs:loadSource()
sound:play()
elseif ext == 'ttf' then
font = fs:loadFont(32)
if font then love.graphics.setFont(font) end
end
end
end
love.draw = function()
love.graphics.setColor(255, 255, 255)
if newImage then
love.graphics.draw(newImage, 0, 0, 0, math.min(800 / newImage:getWidth(), 600 / newImage:getHeight()), math.min(800 / newImage:getWidth(), 600 / newImage:getHeight()))
end
love.graphics.print('LoveFS Demo', 5, 550)
gui:draw()
end
love.mousepressed = function(x, y, button)
gui:mousepress(x, y, button)
end
love.mousereleased = function(x, y, button)
gui:mouserelease(x, y, button)
end
love.wheelmoved = function(x, y)
gui:mousewheel(x, y)
end
love.keypressed = function(key)
if gui.focus then
gui:keypress(key)
end
end
love.textinput = function(key)
if gui.focus then
gui:textinput(key)
end
end