48 lines
1.3 KiB
Lua
48 lines
1.3 KiB
Lua
local dimtable = {
|
|
design = {
|
|
width = 1080,
|
|
height = 1920
|
|
},
|
|
screen = {
|
|
width = nil,
|
|
height = nil
|
|
},
|
|
view = {
|
|
width = nil,
|
|
height = nil
|
|
},
|
|
ratio = {
|
|
landscapeUW = 21 / 9,
|
|
landscapeWide = 16 / 9,
|
|
landscapeStd = 4 / 3,
|
|
portrait = 9 / 16
|
|
}
|
|
}
|
|
|
|
dimtable.screen.width, dimtable.screen.height = game.GetResolution()
|
|
|
|
local function transformToDesignSpace()
|
|
gfx.Translate((dimtable.screen.width - dimtable.view.width) / 2, 0);
|
|
gfx.Scale(dimtable.view.width / dimtable.design.width, dimtable.view.height / dimtable.design.height);
|
|
gfx.Scissor(0, 0, dimtable.design.width, dimtable.design.height);
|
|
end
|
|
|
|
local function updateResolution(ratio)
|
|
if not ratio then
|
|
ratio = dimtable.ratio.portrait
|
|
end
|
|
|
|
local screenWidth, screenHeight = game.GetResolution()
|
|
if screenWidth ~= dimtable.screen.width or screenHeight ~= dimtable.screen.height then
|
|
dimtable.screen.width, dimtable.screen.height = screenWidth, screenHeight
|
|
dimtable.view.width, dimtable.view.height = ratio * dimtable.screen.height, dimtable.screen.height
|
|
end
|
|
end
|
|
|
|
|
|
-- return by reference trickery:
|
|
|
|
local t = dimtable
|
|
t.transformToDesignSpace = transformToDesignSpace
|
|
t.updateResolution = updateResolution
|
|
return t |