love.window proposal.

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

love.window proposal.

Post by thelinx »

I want LÖVE to progress more, and become more advanced in the back-end, while the front-end should stay as simple as it always has been.
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}.
It spawns a window, and then returns the instance as a window userdata.

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
That's it.
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!
User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

Re: love.window proposal.

Post by bmelts »

love.window, in some incarnation, is planned for 0.8. This was the case prior to this proposal.

Multiple windows can't happen (whether they will is another matter entirely) until SDL 1.3 is released and LÖVE upgrades. SDL 1.2 doesn't support multiple windows.

I'm dubious about moving functionality like FSAA and background color to the window, since they're much more relevant to the graphics context than to the window containing it.

The buttons/chrome settings can't be ignored just because fullscreen is initialized to true - fullscreen can be toggled, after all.

Things like window:batchEdit don't make a lot of sense given the fact that, internally, the window has to be recreated whenever those settings are changed. I feel it's more consistent (and easier) to just create a new window.

The mod* methods are inconsistent with LÖVE's API for other modules, and I see no reason to implement them.

Drawing to hidden windows is a massive waste of CPU/GPU resources.

Any new callbacks would be renamed to better fit the naming scheme of extant callbacks.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: love.window proposal.

Post by bartbes »

That, and IMO it's overly complicated, it isn't near lovely standards.
User avatar
Luiji
Party member
Posts: 396
Joined: Mon May 17, 2010 6:59 pm

Re: love.window proposal.

Post by Luiji »

Who needs multiple windows for a game? All I can see coming from this is destruction of portability to future-ports for systems such as Dingux and FreeDOS.
Good bye.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: love.window proposal.

Post by Robin »

Also, window:batchEdit(table). How about calling it setMode, instead? (Plus, it works nothing like setMode.)

I agree to the others it is unLÖVEly, especially the way it requires that window argument in places you don't want. (Or I don't want, at any rate.)

And window creation doesn't belong in love.run() -- it's done before running main.lua. Retaining that would also mean less crap for custom love.runners.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: No registered users and 61 guests