Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2o committed Jun 26, 2023
1 parent eef94df commit aa8c25c
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 198 deletions.
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Lua.runtime.version": "LuaJIT",
"Lua.runtime.special": {
"love.filesystem.load": "loadfile"
},
"Lua.workspace.library": [
"${3rd}/love2d/library"
],
"Lua.diagnostics.globals": [
"write_aiff"
]
}
Empty file modified Assets/FiraCode-Medium.ttf
100755 → 100644
Empty file.
18 changes: 0 additions & 18 deletions Examples/chipped.txt

This file was deleted.

4 changes: 2 additions & 2 deletions Examples/euphory.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;---------------------------------------------------------------
#TITLE EUPHORY / 町
#TITLE EUPHORY
#COMPOSER Manabu Saito
;---------------------------------------------------------------

Expand Down Expand Up @@ -31,7 +31,7 @@ C rrccrrccrrccrrc+c+rrddrrddrr<aarraa
C rra+a+rra+a+rr>ggrrggrreerreef4r4
C q8a2.&a8.&a32r32a1d2e2f2g2a2.&a8.&a32r32a1d2e2f2g4r4

E o3 @env1 v120
E o4 @env1 v127
E l8[rc4c4ccc4c4c4ccc4c4c4ccc4c4cc4rr]2
E l16
E crcccrcccrcccrcc crcccrcccrcccrcc
Expand Down
34 changes: 0 additions & 34 deletions Examples/test.txt

This file was deleted.

74 changes: 39 additions & 35 deletions Modules/Gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
]]

gui = {
Gui = {
buttons = {},
mouse = {
x = 0,
Expand All @@ -23,35 +23,35 @@ gui = {
arrow = nil,
hand = nil,
wait = nil
}
},
}

function gui:init()
function Gui:init()
self.cursors.arrow = love.mouse.getSystemCursor("arrow")
self.cursors.hand = love.mouse.getSystemCursor("hand")
self.cursors.wait = love.mouse.getSystemCursor("wait")
end

function gui:draw_buttons()
function Gui:draw_buttons()
for _, button in pairs(self.buttons) do
if button.is_toggle and button.toggled then
love.graphics.setColor(colors:get_color("text_info"))
love.graphics.setColor(Colors:get_color("text_info"))
love.graphics.rectangle("fill", button.rect.x, button.rect.y, button.rect.w, button.rect.h);
elseif button.clicked then
love.graphics.setColor(colors:get_color("text_empty"))
love.graphics.setColor(Colors:get_color("text_empty"))
love.graphics.rectangle("fill", button.rect.x, button.rect.y, button.rect.w, button.rect.h);
end
if button.is_active then
love.graphics.setColor(colors:get_color("text_value"))
love.graphics.setColor(Colors:get_color("text_value"))
else
love.graphics.setColor(colors:get_color("text_empty"))
love.graphics.setColor(Colors:get_color("text_empty"))
end
love.graphics.rectangle("line", button.rect.x, button.rect.y, button.rect.w, button.rect.h);
love.graphics.print(button.label.text, button.label.x, button.label.y)
end
end

function gui:execute_action(button)
function Gui:execute_action(button)
if button.is_toggle then
if not button.toggled then
button.toggled = true
Expand All @@ -65,7 +65,7 @@ function gui:execute_action(button)
end
end

function gui:check_hotkeys(key)
function Gui:check_hotkeys(key)
for _, button in pairs(self.buttons) do
if button.hotkey ~= "" then
if button.is_active and button.hotkey == key then
Expand All @@ -75,7 +75,7 @@ function gui:check_hotkeys(key)
end
end

function gui:check_buttons()
function Gui:check_buttons()
for _, button in pairs(self.buttons) do
local mx = self.mouse.x
local my = self.mouse.y
Expand All @@ -91,44 +91,48 @@ function gui:check_buttons()
end
end

function gui:hover()
function Gui:hover()
local mx = self.mouse.x
local my = self.mouse.y
local bcount = 0
for _, button in pairs(self.buttons) do
if button.is_active and mx > button.rect.x and mx < button.rect.x + button.rect.w and my > button.rect.y and my < button.rect.y + button.rect.h then
love.mouse.setCursor(self.cursors.hand)
else
love.mouse.setCursor(self.cursors.arrow)
bcount = bcount + 1
end
end
if bcount > 0 then
love.mouse.setCursor(self.cursors.hand)
else
love.mouse.setCursor(self.cursors.arrow)
end
end

function gui:add_button_action(id, action)
function Gui:add_button_action(id, action)
self.buttons[id].action = action
end

function gui:add_button_toggle_actions(id, action_on, action_off)
function Gui:add_button_toggle_actions(id, action_on, action_off)
self.buttons[id].action_on = action_on
self.buttons[id].action_off = action_off
end

function gui:add_hotkey(id, hotkey)
function Gui:add_hotkey(id, hotkey)
self.buttons[id].hotkey = hotkey
end

function gui:add_button(id, label, x, y, is_toggle)
function Gui:add_button(id, label, x, y, is_toggle)
local button = {}
local width = font:getWidth(label)
local height = font:getHeight()
local width = Font:getWidth(label)
local height = Font:getHeight()
width = width + 2 * height
height = 2 * height

button.is_toggle = is_toggle or false
button.is_active = true
button.label = {}
button.label.text = label
button.label.x = x + font:getHeight()
button.label.y = y + font:getHeight() / 2
button.label.x = x + Font:getHeight()
button.label.y = y + Font:getHeight() / 2
button.rect = {}
button.rect.x = x
button.rect.y = y
Expand All @@ -140,30 +144,30 @@ function gui:add_button(id, label, x, y, is_toggle)
end

function love.mousemoved(x, y, dx, dy, istouch)
gui.mouse.x = x
gui.mouse.y = y
gui:hover()
Gui.mouse.x = x
Gui.mouse.y = y
Gui:hover()
end

function love.mousepressed(x, y, button, istouch)
if button == 1 then
gui.mouse.x = x
gui.mouse.y = y
gui.mouse.button = button
gui:check_buttons()
Gui.mouse.x = x
Gui.mouse.y = y
Gui.mouse.button = button
Gui:check_buttons()
end
end

function love.mousereleased(x, y, button, istouch)
if button == 1 then
gui.mouse.x = x
gui.mouse.y = y
gui.mouse.button = 0
gui:check_buttons()
Gui.mouse.x = x
Gui.mouse.y = y
Gui.mouse.button = 0
Gui:check_buttons()
end
end

function love.keypressed(key, scancode, isrepeat)
gui:check_hotkeys(key)
Gui:check_hotkeys(key)
end

Loading

0 comments on commit aa8c25c

Please sign in to comment.