Added "wallpaper" component

Added common dimensions script
This commit is contained in:
Hersi 2022-03-03 03:55:19 +01:00 committed by RealFD
parent 0d1fa4ceb1
commit 76477b5cf3
2 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,48 @@
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

View File

@ -0,0 +1,23 @@
local Dim = require("common.dimensions")
local backgroundImage = gfx.CreateSkinImage("bg_pattern.png", gfx.IMAGE_REPEATX | gfx.IMAGE_REPEATY)
local bgImageWidth, bgImageHeight = gfx.ImageSize(backgroundImage)
local patternAngle = 0
local patternAlpha = 0.2
function render()
gfx.Save()
gfx.ResetTransform()
gfx.BeginPath()
gfx.Rect(0, 0, Dim.screen.width, Dim.screen.height)
gfx.FillPaint(gfx.ImagePattern(0, 0, bgImageWidth, bgImageHeight, patternAngle, backgroundImage, patternAlpha))
gfx.Fill()
gfx.Restore()
end
return {
render = render
}