Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
local fullscreenCycle =
{
_VERSION = 1000,
_URL = "https://gist.github.com/Vovkiv/f234b4c9263d4642f87d48ce8db37be8",
_INTERPRETER = {
love = 11.3,
},
_DESCRIPTION = "Can switch in-beetwen window mode easly, return window state in Love2d",
_LICENSE = "None",
_NAME = "Fullscreen Cycle",
}
--[[
local fsCycle = require("fullScreenCycle")
love.window.setMode(800, 600, {resizable = true})
love.keypressed = function(key)
if key == "c" then
fsCycle.cycle()
elseif key == "m" then
fsCycle.maximize()
elseif key == "w" then
fsCycle.windowed()
elseif key == "f" then
fsCycle.fullscreen()
elseif key == "n" then
fsCycle.minimize()
end
end
love.draw = function()
love.graphics.print("Press F for fullscreen; W for windowed; N for minimized; C to cycle in-beetwen mode")
love.graphics.print("Window state: " .. fsCycle.getState("string"), 0, 30)
end
--]]
fullscreenCycle.cycle = function()
if not love.window.isMaximized() and not love.window.getFullscreen() then -- maximize window
love.window.setFullscreen (false)
love.window.maximize()
elseif love.window.isMaximized() and not love.window.getFullscreen() then -- fullscreen
love.window.setFullscreen (true)
elseif love.window.getFullscreen() then -- windowed
love.window.setFullscreen (false)
love.window.restore()
end
end
fullscreenCycle.windowed = function()
love.window.setFullscreen(false) -- disable fullscreen mode, so window can be restored to windowed
love.window.restore()
end
fullscreenCycle.fullscreen = function()
love.window.setFullscreen(true)
end
fullscreenCycle.maximize = function()
love.window.setFullscreen(false) -- disable fullscreen mode, so window can be maximized
love.window.maximize()
end
fullscreenCycle.minimize = function()
love.window.minimize() -- when window will be restored, it will be restored in state, as it was before minimized
end
fullscreenCycle.getState = function(resultType)
-- if you pass to function "string", then result will be returned as string representation
local states = {}
if resultType == "string" then
states = {[0] = "undefined", [1] = "maximized", [2] = "windowed", [3] = "fullscreen", [4] = "minimized"} -- meaning
end
if love.window.isMinimized() then
return states[4] or 4 -- minimized
else
if not love.window.getFullscreen() then
if not love.window.isMaximized() then
return states[2] or 2 -- windowed
else -- if not maximized
return states[1] or 1 -- maximized
end -- end maximized
else -- if not fullscreen
return states[3] or 3 -- fullscreen
end -- end fullscreen
end -- end if minimized
return states[0] or 0 -- if something went wrong then undefined
end -- end getState
return fullscreenCycle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment