The addition of love.window would not complicate the front-end at all, the standard callback approach would work the same way it always has.
So, here is the proposal:
love.window
window = love.window.new(table) - Spawns a new window.
Conf is an optional table that can contain the following variables:
- width - width in pixels. Defaults to 800.
- height - height in pixels. Defaults to 600.
- x - x position to spawn window at. Defaults to whatever free space is available.
- y - y position to spawn window at. Defaults to whatever free space is available.
- title - title. Defaults to "Untitled".
- closebutton - a boolean that defines whether it should have a close button. Defaults to true.
- maxbutton - a boolean that defines whether it should have a maximize button. Defaults to true.
- minbutton - a boolean that defines whether it should have a minimize button. Defaults to true.
- chrome - a boolean that defines whether the window should have a chrome/border. Defaults to true. Overrides *button values.
- fullscreen - a boolean that defines whether the window should be fullscreen. Defaults to false. Overrides *button and chrome values.
- vsync - a boolean that defines whether the window should use VSync. Defaults to true.
- fsaa - the number of FSAA-buffers. Defaults to 0.
- backgroundColor - background colour. Defaults to {0, 0, 0}.
window userdata
Setting functions
window:batchEdit(table) - Takes a table and sets all new variables accordingly.
The key names should be the same as in love.window.new.
window:setWidth(number) - Changes the width of a window.
window:setHeight(number) - Changes the height of a window.
window:setSize(number, number) - Sets the size of a window.
window:modSize(number, number) - Changes the size of a window.
If you want to increase the window size by 10 pixels on both ends, use window:modSize(10, 10)
window:setX(number) - Changes the x position of a window.
window:setY(number) - Changes the y position of a window.
window:setPos(number, number) - Sets the position of a window.
window:modPos(number, number) - Changes the position of a window.
window:setTitle(string) - Sets the window title.
window:setVsync(boolean) - Sets VSync enablation.
window:setFsaa(number) - Sets the number of FSAA-buffers.
window:setBackgroundColor(table) - Sets the background colour.
Accessory functions
number = window:getWidth() - returns the window width.
number = window:getHeight() - returns the window height.
number, number = window:getSize() - returns the window size.
number = window:getX() - returns the window's x position.
number = window:getY() - returns the window's y position.
number, number = window:getPos() - returns the window's position.
string = window:getTitle() - returns the window's title.
boolean = window:isVisible() - returns true if the window is currently shown.
table = window:getBackgroundColor() - returns the window's background colour.
Action functions
window:show() - shows the window.
Note that windows are automatically opened when they are created.
window:hide() - temporarily hides a window.
The instance is left intact, and all drawing operations to it are still executed.
window:destroy() - destroys the window instance.
love.graphics changes
Modified functions:
love.graphics.present(window) - presents drawing operations to a window.
Note that it now takes a required window argument.
love.graphics.clear(window)
Moved functions:
love.graphics.checkMode -> love.window.checkMode
love.graphics.getModes -> love.window.getModes
Removed functions:
love.graphics.getCaption()
love.graphics.getWidth()
love.graphics.getHeight()
love.graphics.isCreated()
love.graphics.setMode()
Global callback changes
Modified callbacks:
love.draw(window) - The draw callback is now fed the window instance in the (new) default love.run function.
New callbacks:
love.windowclose(window) - Called when a window's close button is pressed.
love.windowmaximize(window) - Called when a window's maximize button is pressed.
love.windowminimize(window) - Called when a window's minimize button is pressed.
Return false to cancel any of these events.
love.windowfocus(window) - Called when a window gets focus. (When it's selected)
love.windowblur(window) - Called when a window loses focus. (When another window is selected)
love.run
The new love.run function would look something like this:
Code: Select all
function love.run()
if love.load then love.load(arg) end
local dt = 0
-- using variables from love.conf in some magic way
mainWindow = love.window.new {
width = t.screen.width,
height = t.screen.height,
title = t.title,
fullscreen = t.screen.fullscreen,
vsync = t.screen.vsync,
fsaa = t.screen.fsaa,
}
-- Main loop time.
while true do
if love.timer then
love.timer.step()
dt = love.timer.getDelta()
end
if love.update then love.update(dt) end -- will pass 0 if love.timer is disabled
if love.graphics then
love.graphics.clear(mainWindow)
if love.draw then love.draw(mainWindow) end
end
-- Process events.
if love.event then
for e,a,b,c in love.event.poll() do
if e == "q" then
if love.audio then
love.audio.stop()
end
return
end
love.handlers[e](a,b,c)
end
end
if love.timer then love.timer.sleep(1) end
if love.graphics then love.graphics.present(mainWindow) end
end
end
You'd probably also need some love.system thing or something to get the desktop resolution, but that's another story.
Feedback is welcome, and I hope that all this functionality will be present in a future LÖVE version!