diff --git a/scripts/common/dimensions.lua b/scripts/common/dimensions.lua new file mode 100644 index 0000000..bdcfbdd --- /dev/null +++ b/scripts/common/dimensions.lua @@ -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 \ No newline at end of file diff --git a/scripts/components/wallpaper.lua b/scripts/components/wallpaper.lua new file mode 100644 index 0000000..a719ebf --- /dev/null +++ b/scripts/components/wallpaper.lua @@ -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 +} \ No newline at end of file