-- The MIT License (MIT) -- -- Copyright © 2021 Jens Hofschröer -- -- Permission is hereby granted, free of charge, to any person obtaining a copy -- of this software and associated documentation files (the “Software”), to deal -- in the Software without restriction, including without limitation the rights -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -- copies of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be included in -- all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. -- require "button" function love.load() dx,dy,width,height=love.window.getSafeArea() Button.useChars = love.filesystem.getInfo("DejaVuSans.ttf", "file") ~= nil if Button.useChars == true then Button.basefont = love.graphics.newFont("DejaVuSans.ttf", 16) end local btnBorder = 8 local quit = Button:new("Quit", function(btn) love.event.quit( "quit" ) end, width-btnBorder, height-btnBorder, "BR") quit.enabled = false quit.visible = false local restart = Button:new("Restart", function(btn) love.event.quit( "restart" ) end, btnBorder, btnBorder) local toggle = Selectable:new("Toggle", function(btn) if btn.selected == true then btn.bgcol = {1,1,0,1} else btn.bgcol = {0,.8,0,1} end end, restart.posx+restart.width+btnBorder, restart.posy) toggle.bgcol = {0,.8,0,1} local checker = Checkbox:new("Checkböx", function(btn) quit.enabled = btn.selected quit.visible = btn.selected end, restart.posx, restart.posy+restart.height+btnBorder) local radio1 = Radiobutton:new("Option 1", function(btn) end, btnBorder, height/2, "BL") local radio2 = Radiobutton:new("Option 2", function(btn) end, radio1.posx+radio1.width+btnBorder, radio1.posy) local radios ={radio1,radio2} radio1:setGroup(radios) radio2:setGroup(radios) buttons={ quit, restart,toggle,checker,radio1,radio2 } end function love.mousepressed(x, y, button, istouch, presses) if button==1 then mouseStartAction = Button.findAction(x-dx,y-dy,buttons) end end function love.mousereleased( x, y, button, istouch, presses ) if button==1 then mouseEndAction = Button.findAction(x-dx,y-dy,buttons) if mouseEndAction.name == mouseStartAction.name then print("perform action "..mouseEndAction.name) mouseEndAction.action() end mouseEndAction = nil end mouseStartAction = nil end function love.draw() love.graphics.translate(dx,dy) for i,btn in ipairs(buttons) do if btn.visible ~= false then btn:draw() end end end