Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2o committed Mar 2, 2023
1 parent 907c79d commit eef94df
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
24 changes: 24 additions & 0 deletions Modules/Gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,20 @@ gui = {
dy = 0,
button = 0,
touch = false,
},
cursors = {
arrow = nil,
hand = nil,
wait = nil
}
}

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()
for _, button in pairs(self.buttons) do
if button.is_toggle and button.toggled then
Expand Down Expand Up @@ -80,6 +91,18 @@ function gui:check_buttons()
end
end

function gui:hover()
local mx = self.mouse.x
local my = self.mouse.y
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)
end
end
end

function gui:add_button_action(id, action)
self.buttons[id].action = action
end
Expand Down Expand Up @@ -119,6 +142,7 @@ end
function love.mousemoved(x, y, dx, dy, istouch)
gui.mouse.x = x
gui.mouse.y = y
gui:hover()
end

function love.mousepressed(x, y, button, istouch)
Expand Down
27 changes: 15 additions & 12 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,12 @@ function love.load()
colors = NamedColorPalette:new()
colors:create(require("Assets.colors"))

gui:add_button(
"quit",
"Quit",
font:getHeight(),
love.graphics.getHeight() - 3 * font:getHeight(),
false
)
gui:add_button_action("quit", function () love.event.quit() end)
gui:add_hotkey("quit", "escape")

gui:init()

gui:add_button(
"play_pause",
"Play/Pause",
gui.buttons["quit"].rect.x + gui.buttons["quit"].rect.w + font:getHeight(),
font:getHeight(),
love.graphics.getHeight() - 3 * font:getHeight(),
true
)
Expand All @@ -279,7 +271,18 @@ function love.load()
false
)
gui:add_button_action("export", function () write_aiff() end)


gui:add_button(
"quit",
"Quit",
gui.buttons["export"].rect.x + gui.buttons["export"].rect.w + 2 * font:getHeight(),
love.graphics.getHeight() - 3 * font:getHeight(),
false
)
gui:add_button_action("quit", function () love.event.quit() end)
gui:add_hotkey("quit", "escape")


---

MIN_dt = 1/60
Expand Down
Binary file modified music-preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit eef94df

Please sign in to comment.