more window stuff, still unfinished

This commit is contained in:
airstruck
2015-12-17 16:52:51 -05:00
parent f9924fb028
commit e2602348df
21 changed files with 634 additions and 151 deletions

View File

@@ -15,9 +15,10 @@ local IntOut = ffi.typeof 'int[1]'
local stack = {}
-- create window and renderer
sdl.setHint(sdl.HINT_VIDEO_ALLOW_SCREENSAVER, '1')
sdl.enableScreenSaver()
local window = sdl.createWindow('', 0, 0, 800, 600,
local window = sdl.createWindow('',
sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED, 800, 600,
sdl.WINDOW_SHOWN + sdl.WINDOW_RESIZABLE)
if window == nil then
@@ -337,22 +338,54 @@ function Backend.show (layout)
end)
end
function Backend.getWindowMaximized ()
local flags = sdl.getWindowFlags(window)
return bit.band(flags, sdl.WINDOW_MAXIMIZED) ~= 0
end
function Backend.setWindowMaximized (maximized)
return maximized and sdl.maximizeWindow(window) or sdl.restoreWindow(window)
if maximized then
sdl.maximizeWindow(window)
else
sdl.restoreWindow(window)
end
end
function Backend.getWindowMinimized ()
local flags = sdl.getWindowFlags(window)
return bit.band(flags, sdl.WINDOW_MINIMIZED) ~= 0
end
function Backend.setWindowMinimized (minimized)
return minimized and sdl.minimizeWindow(window) or sdl.restoreWindow(window)
if minimized then
sdl.minimizeWindow(window)
else
sdl.restoreWindow(window)
end
end
function Backend.getWindowBorderless ()
local flags = sdl.getWindowFlags(window)
return bit.band(flags, sdl.WINDOW_BORDERLESS) ~= 0
end
function Backend.setWindowBorderless (borderless)
return sdl.setWindowBordered(window, not borderless)
end
function Backend.getWindowFullscreen ()
local flags = sdl.getWindowFlags(window)
return bit.band(flags, sdl.WINDOW_FULLSCREEN) ~= 0
end
function Backend.setWindowFullscreen (fullscreen)
return sdl.setWindowFullscreen(window, not not fullscreen)
end
function Backend.getWindowGrab ()
return sdl.getWindowGrab(window)
end
function Backend.setWindowGrab (grab)
return sdl.setWindowGrab(window, not not grab)
end
@@ -366,56 +399,108 @@ function Backend.setWindowIcon (icon)
if surface == nil then
error(ffi.string(sdl.getError()))
end
sdl.setWindowIcon(window, surface)
end
function Backend.getWindowMaxwidth ()
local w, h = IntOut(), IntOut()
sdl.getWindowMaximumSize(window, w, h)
return w[0]
end
function Backend.setWindowMaxwidth (maxwidth)
local w, h = IntOut(), IntOut()
sdl.getWindowMaximumSize(window, w, h)
sdl.setWindowMaximumSize(window, maxwidth, h[0] ~= nil and h[0] or math.huge)
sdl.setWindowMaximumSize(window, maxwidth, h[0] or 16384)
end
function Backend.getWindowMaxheight ()
local w, h = IntOut(), IntOut()
sdl.getWindowMaximumSize(window, w, h)
return h[0]
end
function Backend.setWindowMaxheight (maxheight)
local w, h = IntOut(), IntOut()
sdl.getWindowMaximumSize(window, w, h)
sdl.setWindowMaximumSize(window, w[0] ~= nil and w[0] or math.huge, maxheight)
sdl.setWindowMaximumSize(window, w[0] or 16384, maxheight)
end
function Backend.getWindowMinwidth ()
local w, h = IntOut(), IntOut()
sdl.getWindowMinimumSize(window, w, h)
return w[0]
end
function Backend.setWindowMinwidth (minwidth)
local w, h = IntOut(), IntOut()
sdl.getWindowMinimumSize(window, w, h)
sdl.setWindowMinimumSize(window, minwidth, h[0] ~= nil and h[0] or 0)
sdl.setWindowMinimumSize(window, minwidth, h[0] or 0)
end
function Backend.getWindowMinheight ()
local w, h = IntOut(), IntOut()
sdl.getWindowMinimumSize(window, w, h)
return h[0]
end
function Backend.setWindowMinheight (minheight)
local w, h = IntOut(), IntOut()
sdl.getWindowMinimumSize(window, w, h)
sdl.setWindowMinimumSize(window, w[0] ~= nil and w[0] or 0, minheight)
sdl.setWindowMinimumSize(window, w[0] or 0, minheight)
end
function Backend.getWindowTop ()
local x, y = IntOut(), IntOut()
sdl.getWindowPosition(window, x, y)
return y[0]
end
function Backend.setWindowTop (top)
local x, y = IntOut(), IntOut()
sdl.getWindowPosition(window, x, y)
sdl.setWindowPosition(window, x[0] ~= nil and x[0] or 0, top)
sdl.setWindowPosition(window, x[0] or 0, top)
end
function Backend.getWindowLeft ()
local x, y = IntOut(), IntOut()
sdl.getWindowPosition(window, x, y)
return x[0]
end
function Backend.setWindowLeft (left)
local x, y = IntOut(), IntOut()
sdl.getWindowPosition(window, x, y)
sdl.setWindowPosition(window, left, y[0] ~= nil and y[0] or 0)
sdl.setWindowPosition(window, left, y[0] or 0)
end
function Backend.getWindowWidth ()
local w, h = IntOut(), IntOut()
sdl.getWindowSize(window, w, h)
return w[0]
end
function Backend.setWindowWidth (width)
local w, h = IntOut(), IntOut()
sdl.getWindowSize(window, w, h)
sdl.setWindowSize(window, width, h[0] ~= nil and h[0] or 600)
sdl.setWindowSize(window, width, h[0] or 600)
end
function Backend.getWindowHeight ()
local w, h = IntOut(), IntOut()
sdl.getWindowSize(window, w, h)
return h[0]
end
function Backend.setWindowHeight (height)
local w, h = IntOut(), IntOut()
sdl.getWindowSize(window, w, h)
sdl.setWindowSize(window, w[0] ~= nil and w[0] or 800, height)
sdl.setWindowSize(window, w[0] or 800, height)
end
function Backend.getWindowTitle (title)
return sdl.getWindowTitle(window)
end
function Backend.setWindowTitle (title)

View File

@@ -214,8 +214,15 @@ function Input:handleReshape (layout, width, height)
local root = layout.root
root:reshape()
root.dimensions.width = width
root.dimensions.height = height
if root.type ~= 'window' then
if not root.width then
root.dimensions.width = width
end
if not root.height then
root.dimensions.height = height
end
end
Event.Reshape:emit(layout, { target = layout })
end

View File

@@ -7,7 +7,7 @@ This widget should only be used as the root widget of a layout.
@usage
-- create a new window
local window = Layout {
type = 'window',
type = 'window',
icon = 'logo.png',
text = 'Window Example',
width = 800,
@@ -42,244 +42,210 @@ Special Attributes
--]]--
--[[--
Maximized.
Maximized. Set to `true` to make the window as large as possible.
Set to `false` to restore the size and position.
@attrib maximized
--]]--
local maximized
self:defineAttribute('maximized', {
set = function (_, value)
if not value then return end
maximized = value
Backend.setWindowMaximized(maximized)
end,
get = function () return maximized end
if value == nil then return end
Backend.setWindowMaximized(value)
end,
get = Backend.getWindowMaximized
})
--[[--
Minimized.
Minimized. Set to `true` to minimize the window to an iconic representation.
Set to `false` to restore the size and position.
@attrib minimized
--]]--
local minimized
self:defineAttribute('minimized', {
set = function (_, value)
if not value then return end
minimized = value
Backend.setWindowMinimized(minimized)
end,
get = function () return minimized end
if value == nil then return end
Backend.setWindowMinimized(value)
end,
get = Backend.getWindowMinimized
})
--[[--
Borderless.
Borderless. Set to `true` or `false` to change the border state of the window.
You can't change the border state of a fullscreen window.
@attrib borderless
--]]--
local borderless
self:defineAttribute('borderless', {
set = function (_, value)
if not value then return end
borderless = value
Backend.setWindowBorderless(borderless)
end,
get = function () return borderless end
if value == nil then return end
Backend.setWindowBorderless(value)
end,
get = Backend.getWindowBorderless
})
--[[--
Fullscreen.
Fullscreen. Set to `true` or `false` to change the fullscreen state
of the window.
@attrib fullscreen
--]]--
local fullscreen
self:defineAttribute('fullscreen', {
set = function (_, value)
if not value then return end
fullscreen = value
Backend.setWindowFullscreen(fullscreen)
end,
get = function () return fullscreen end
if value == nil then return end
Backend.setWindowFullscreen(value)
end,
get = Backend.getWindowFullscreen
})
--[[--
Grab mouse.
Mouse grab. Set to `true` or `false` to change the window's input grab mode.
When input is grabbed the mouse is confined to the window.
If the caller enables a grab while another window is currently grabbed,
the other window loses its grab in favor of the caller's window.
@attrib grab
--]]--
local grab
self:defineAttribute('grab', {
set = function (_, value)
if not value then return end
grab = value
Backend.setWindowGrab(grab)
end,
get = function () return grab end
if value == nil then return end
Backend.setWindowGrab(value)
end,
get = Backend.getWindowGrab
})
--[[--
Icon.
Window icon. Should be a string containing a path to an image.
@attrib icon
--]]--
local icon
self:defineAttribute('icon', {
set = function (_, value)
if not value then return end
if value == nil then return end
icon = value
Backend.setWindowIcon(icon)
end,
Backend.setWindowIcon(value)
end,
get = function () return icon end
})
self.attributes.icon = nil
--[[--
Maximum width.
Maximum width of the window's client area.
@attrib maxwidth
--]]--
local maxwidth
self:defineAttribute('maxwidth', {
set = function (_, value)
if not value then return end
maxwidth = value
Backend.setWindowMaxwidth(maxwidth)
end,
get = function () return maxwidth end
if value == nil then return end
Backend.setWindowMaxwidth(value)
end,
get = Backend.getWindowMaxwidth
})
--[[--
Maximum height.
Maximum height of the window's client area.
@attrib maxheight
--]]--
local maxheight
self:defineAttribute('maxheight', {
set = function (_, value)
if not value then return end
maxheight = value
Backend.setWindowMaxheight(maxheight)
end,
get = function () return maxheight end
if value == nil then return end
Backend.setWindowMaxheight(value)
end,
get = Backend.getWindowMaxheight
})
--[[--
Minimum width.
Minimum width of the window's client area.
@attrib minwidth
--]]--
local minwidth
self:defineAttribute('minwidth', {
set = function (_, value)
if not value then return end
minwidth = value
Backend.setWindowMinwidth(minwidth)
end,
get = function () return minwidth end
if value == nil then return end
Backend.setWindowMinwidth(value)
end,
get = Backend.getWindowMinwidth
})
--[[--
Minimum height.
Minimum height of the window's client area.
@attrib minheight
--]]--
local minheight
self:defineAttribute('minheight', {
set = function (_, value)
if not value then return end
minheight = value
Backend.setWindowMinheight(minheight)
end,
get = function () return minheight end
if value == nil then return end
Backend.setWindowMinheight(value)
end,
get = Backend.getWindowMinheight
})
--[[--
Top position.
Position of the window's top edge.
@attrib top
--]]--
local top
self:defineAttribute('top', {
set = function (_, value)
if not value then return end
top = value
Backend.setWindowTop(top)
end,
get = function () return top end
if value == nil then return end
Backend.setWindowTop(value)
end,
get = Backend.getWindowTop
})
--[[--
Left position.
Position of the window's left edge.
@attrib left
--]]--
local left
self:defineAttribute('left', {
set = function (_, value)
if not value then return end
left = value
Backend.setWindowLeft(left)
end,
get = function () return left end
if value == nil then return end
Backend.setWindowLeft(value)
end,
get = Backend.getWindowLeft
})
--[[--
Width.
Width of the window's content area.
@attrib width
--]]--
local width
self:defineAttribute('width', {
set = function (_, value)
if not value then return end
width = value
Backend.setWindowWidth(width)
end,
get = function () return width end
if value == nil then return end
Backend.setWindowWidth(value)
end,
get = Backend.getWindowWidth
})
--[[--
Height.
Height of the window's content area.
@attrib height
--]]--
local height
self:defineAttribute('height', {
set = function (_, value)
if not value then return end
height = value
Backend.setWindowHeight(height)
end,
get = function () return height end
if value == nil then return end
Backend.setWindowHeight(value)
end,
get = Backend.getWindowHeight
})
--[[--
Title.
Title of the window.
@attrib title
--]]--
local title
self:defineAttribute('title', {
set = function (_, value)
if not value then return end
title = value
Backend.setWindowTitle(title)
end,
get = function () return title end
if value == nil then return end
Backend.setWindowTitle(value)
end,
get = Backend.getWindowTitle
})
--[[--