local blendMode = love.graphics.getBlendMode()
local r,g,b,a = love.graphics.getColor()
local colorMode = love.graphics.getColorMode()
local font = love.graphics.getFont()
local lineStyle = love.graphics.getLineStyle()
local lineWidth = love.graphics.getLineWidth()
local lineStipple = love.graphics.getLineStipple()
--DO STUFF
love.graphics.setBlendMode(blendMode)
love.graphics.setColor(r,g,b,a)
love.graphics.setColorMode(colorMode)
love.graphics.setFont(font)
love.graphics.setLine(lineWidth, lineStyle)
love.graphics.setLineStipple(lineStipple)
local stack = {}
function love.graphics.pushState()
-- get state
local state = {}
state.blendMode = love.graphics.getBlendMode()
state.color = {love.graphics.getColor()}
state.colorMode = love.graphics.getColorMode()
state.font = love.graphics.getFont() or 12
state.lineStyle = love.graphics.getLineStyle()
state.lineWidth = love.graphics.getLineWidth()
state.lineStipple = love.graphics.getLineStipple() and {love.graphics.getLineStipple()} or {1,255}
-- push state
stack[#stack+1] = state
end
function love.graphics.popState()
-- restore state
local state = stack[#stack]
love.graphics.setBlendMode( state.blendMode )
love.graphics.setColor( unpack(state.color) )
love.graphics.setColorMode( state.colorMode )
love.graphics.setFont( state.font )
love.graphics.setLine( state.lineWidth, state.lineStyle )
love.graphics.setLineStipple( unpack(state.lineStipple) )
-- pop state
stack[#stack] = nil
end
Put that either on top of main.lua or (better) into a separate file which you then require in main.lua
Edit: Account for possible nil-ness of love.graphics.getFont() and love.graphics.getLineStipple(). See TechnoCat's post
Last edited by vrld on Tue Nov 09, 2010 2:41 pm, edited 1 time in total.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.
if love.graphics.getFont()==nil then
love.graphics.setFont(love.graphics.newFont(12))
end
if love.graphics.getLineStipple()==nil then
love.graphics.setLineStipple(1111111111111111, 1)
end
I wasn't aware of that love.graphics.getFont() and love.graphics.getLineStipple() could be nil (possible bug there?).
The pushState function now accounts for that by setting default values. This will be done only once, so don''t worry this will take up too much runtime.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.