hate icon indicating copy to clipboard operation
hate copied to clipboard

Multiple Windows?

Open JomerDev opened this issue 10 years ago • 5 comments
trafficstars

I would like to know if you have any plans to suport multiple windows?

JomerDev avatar Jan 21 '15 19:01 JomerDev

it's a definite maybe, leaning on probably. just a matter of defining a good API, and knowing where the side effects would be.

shakesoda avatar Jan 21 '15 21:01 shakesoda

You dont need a new API... use the Thread API which currently doesnt support graphics... you also have the window namespace, and most of the graphics functions there so I guess this wouldnt be so hard

pablomayobre avatar Jan 22 '15 00:01 pablomayobre

the thread API wouldn't be any good (and you do /not/ want to deal with different windows in different threads). you'd really just want a way to mark a window/GL context as active and some window-specific management functions.

@lpghatguy probably has some input on this!

shakesoda avatar Jan 22 '15 04:01 shakesoda

I think it's straightforward enough to have multiple windows with SDL2, especially if the API provides a single method to switch across contexts/windows.

The big thing might be requiring a reference to the window from every asset, which would end up at most an identifying integer or pointer.

LPGhatguy avatar Jan 22 '15 05:01 LPGhatguy

I made some plans on how such an api could look. I'll try to describe how it would work.

-- First there is this function. It creates a new window
function window.newWindow(title, x, y, width, height, flags)
    -- This returns a table, which I'll describe a bit down the line
end

function window.closeWindow(window)
    -- This function will close the window given as argument
end

function window.setActiveWindow(window)
    -- This function will set the active window to the window in the arguments
    -- It ill also set the drawing context to this window
end

These functions would only work when something like multiwindow in the conf.lua is true. Also, when not specified differently, only the active window will raise events. The only event a window which isn't active would raise is of course when it got the focus. The normal window functions from loves window api would always use the active window. When only the window that gets created on programmstart exists, it will be the active window. This should create a complete compatibility with Love2D

Next is the window table, that gets returned when a new window gets created.

It has many functions on its own.


window:setTitle(title) -- Sets the title of the window
window:getTitle() -- Returns the title of the window
window:setPosition(x, y) -- Sets the window position
window:getPosition() -- Returns the window position
window:setSize(width, height) -- Sets the window size
window:getSize() -- Returns the window size
window:setFocus(true/false) -- Sets the windows focus
window:hasFocus() -- Returns the windows focus
window:getID() -- Returns the window ID
window:get/setVisible() -- Gets/sets the windows visibility
window:minimize() -- Minimizes the window
window:maximize() -- Maximizes the window
window:setOnlyActiveWithFocus(true/false) -- This function defines if any events other than the 
-- focus event should get raised when the window is not active
window:getOnlyActiveWithFocus() -- Returns if any other events should get raised

-- Note: Any other functions in the Love2D window api that i forgot 
-- will also be available for this table

window:draw() -- This is a callback for this window. It will be called before hate.draw(). 
-- It could be used to have split up draw functions and that you don't have to change 
-- the active window everytime in hate.draw(). The function will set the active window 
-- to the window of the table, draw onit, and set the active window back to the window before. 

Any other hate callbacks (such as mousefocus, keypressed and such) will have the window the event happened as the last argument after the normal arguments, so it doesn't break the compatibility with love. This can be used when two windows are 'active' and you want to know which of them called for example hate.mousepressed() This extra argument only gets added as argument when there is more than one window.

If you have any other ideas, or if i forgot something, please tell me.

If this proposal gets adopted, I would like to write it in the next few days.

JomerDev avatar Jan 22 '15 21:01 JomerDev