Wallpapers rework is finished

This commit is contained in:
IgorTimofeev 2024-01-30 03:00:35 +03:00
parent 51b5ebb6c2
commit 96d2748ace
8 changed files with 519 additions and 521 deletions

View File

@ -17,9 +17,10 @@ local function configure()
end end
-- Add new controls if needed -- Add new controls if needed
if system.wallpaper and system.wallpaper.configure then local wallpaper = system.getWallpaper()
if wallpaper.configure then
configureFrom = #window.contentLayout.children + 1 configureFrom = #window.contentLayout.children + 1
system.wallpaper.configure(window.contentLayout) wallpaper.configure(window.contentLayout)
configureTo = #window.contentLayout.children configureTo = #window.contentLayout.children
end end
end end

View File

@ -35,9 +35,7 @@ local dockContainer
local desktopMenu local desktopMenu
local desktopMenuLayout local desktopMenuLayout
local desktopIconField local desktopIconField
local desktopBackground local wallpaper
local desktopBackgroundWallpaperX
local desktopBackgroundWallpaperY
-- Caching commonly used icons -- Caching commonly used icons
local iconCache = { local iconCache = {
@ -485,7 +483,7 @@ function system.addSetAsWallpaperMenuItem(menu, path)
system.updateWallpaper() system.updateWallpaper()
end end
system.wallpaper.setPicture(path) wallpaper.setPicture(path)
workspace:draw() workspace:draw()
system.saveUserSettings() system.saveUserSettings()
@ -2414,43 +2412,45 @@ function system.execute(path, ...)
return success, errorPath, line, traceback return success, errorPath, line, traceback
end end
local function desktopBackgroundAmbientDraw() local function wallpaperDraw()
screen.drawRectangle(1, desktopBackground.y, desktopBackground.width, desktopBackground.height, 0x1E1E1E, 0, " ") screen.drawRectangle(1, wallpaper.y, wallpaper.width, wallpaper.height, 0x1E1E1E, 0, " ")
end
function system.getWallpaper()
return wallpaper
end end
function system.updateWallpaper() function system.updateWallpaper()
desktopBackground.draw = desktopBackgroundAmbientDraw local function reset()
wallpaper.draw = wallpaperDraw
wallpaper.eventHandler = nil
wallpaper.configure = nil
end
local function alert(...)
GUI.alert(...)
reset()
end
interfaceDrawInterval = 1 interfaceDrawInterval = 1
reset()
if not userSettings.interfaceWallpaperPath then if not userSettings.interfaceWallpaperPath then
return return
end end
local executable, reason = loadfile(userSettings.interfaceWallpaperPath .. "Main.lua") local result, reason = loadfile(userSettings.interfaceWallpaperPath .. "Main.lua")
if not executable then if not result then
GUI.alert(reason) alert(reason)
return return
end end
local success, wallpaperOrError = xpcall(executable, debug.traceback) result, reason = xpcall(result, debug.traceback, workspace, wallpaper)
if not success then if not result then
GUI.alert(wallpaperOrError) alert()
return return
end end
if type(wallpaperOrError) ~= "table" then
GUI.alert("Wallpaper script didn't return table")
return
elseif type(wallpaperOrError.draw) ~= "function" then
GUI.alert("Wallpaper does not contain proper draw function")
return
end
desktopBackground.draw = wallpaperOrError.draw
desktopBackground.eventHandler = wallpaperOrError.eventHandler
system.wallpaper = wallpaperOrError
interfaceDrawInterval = 0.01 interfaceDrawInterval = 0.01
end end
@ -2475,7 +2475,7 @@ function system.updateResolution()
desktopMenu.width = workspace.width desktopMenu.width = workspace.width
desktopMenuLayout.width = workspace.width desktopMenuLayout.width = workspace.width
desktopBackground.localY, desktopBackground.width, desktopBackground.height = 2, workspace.width, workspace.height - 1 wallpaper.localY, wallpaper.width, wallpaper.height = 2, workspace.width, workspace.height - 1
desktopWindowsContainer.width, desktopWindowsContainer.height = workspace.width, workspace.height - 1 desktopWindowsContainer.width, desktopWindowsContainer.height = workspace.width, workspace.height - 1
@ -2963,11 +2963,12 @@ function system.updateWorkspace()
workspace.ignoresCapturedObject = true workspace.ignoresCapturedObject = true
-- Creating desktop background object -- Creating desktop background object
desktopBackground = workspace:addChild(GUI.object(1, 1, workspace.width, workspace.height)) wallpaper = workspace:addChild(GUI.object(1, 1, workspace.width, workspace.height))
desktopBackground.ignoresCapturedObject = true -- wallpaper.ignoresCapturedObject = true
wallpaper.blockScreenEvents = false
local oldDraw = desktopBackground and desktopBackground.draw local oldDraw = wallpaper and wallpaper.draw
desktopBackground.draw = oldDraw or desktopBackgroundAmbientDraw wallpaper.draw = oldDraw or wallpaperDraw
end end
function system.createUser(name, language, password, wallpaper) function system.createUser(name, language, password, wallpaper)
@ -3038,7 +3039,7 @@ function system.authorize()
local container = workspace:addChild(GUI.container(1, 1, workspace.width, workspace.height)) local container = workspace:addChild(GUI.container(1, 1, workspace.width, workspace.height))
-- If we've loaded wallpaper(from user logout or above) then add a panel to make it darker -- If we've loaded wallpaper(from user logout or above) then add a panel to make it darker
if desktopBackground.draw ~= desktopBackgroundAmbientDraw then if wallpaper.draw ~= wallpaperDraw then
container:addChild(GUI.panel(1, 1, container.width, container.height, 0x0, 0.5)) container:addChild(GUI.panel(1, 1, container.width, container.height, 0x0, 0.5))
end end

View File

@ -5,6 +5,8 @@ local GUI = require("GUI")
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local workspace, wallpaper = select(1, ...), select(2, ...)
local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg" local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg"
local config = { local config = {
@ -46,10 +48,7 @@ end
reset(object) reset(object)
-------------------------------------------------------------------------------- wallpaper.draw = function(object)
return {
draw = function(object)
screen.drawRectangle(object.x, object.y, object.width, object.height, config.backgroundColor, 0, " ") screen.drawRectangle(object.x, object.y, object.width, object.height, config.backgroundColor, 0, " ")
local point1, point2 local point1, point2
@ -81,9 +80,9 @@ return {
if point1.x < 0 or point1.x >= object.width then point1.vx = -point1.vx end if point1.x < 0 or point1.x >= object.width then point1.vx = -point1.vx end
if point1.y < 0 or point1.y >= object.height * 2 then point1.vy = -point1.vy end if point1.y < 0 or point1.y >= object.height * 2 then point1.vy = -point1.vy end
end end
end, end
configure = function(layout) wallpaper.configure = function(layout)
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.backgroundColor, "Background color")).onColorSelected = function(_, object) layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.backgroundColor, "Background color")).onColorSelected = function(_, object)
config.backgroundColor = object.color config.backgroundColor = object.color
saveConfig() saveConfig()
@ -116,5 +115,4 @@ return {
saveConfig() saveConfig()
reset() reset()
end end
end end
}

View File

@ -6,6 +6,8 @@ local GUI = require("GUI")
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local workspace, wallpaper = select(1, ...), select(2, ...)
local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg" local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg"
local config = { local config = {
@ -30,8 +32,7 @@ end
local drops = {} local drops = {}
local lastUpdateTime = computer.uptime() local lastUpdateTime = computer.uptime()
return { wallpaper.draw = function(wallpaper)
draw = function(wallpaper)
-- Spawning drops -- Spawning drops
local distance local distance
@ -91,9 +92,9 @@ return {
end end
lastUpdateTime = updateTime lastUpdateTime = updateTime
end, end
configure = function(layout) wallpaper.configure = function(layout)
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.backgroundColor, "Background color")).onColorSelected = function(_, object) layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.backgroundColor, "Background color")).onColorSelected = function(_, object)
config.backgroundColor = object.color config.backgroundColor = object.color
saveConfig() saveConfig()
@ -146,5 +147,4 @@ return {
config.speed = speedSlider.value / 100 config.speed = speedSlider.value / 100
saveConfig() saveConfig()
end end
end end
}

View File

@ -6,6 +6,8 @@ local GUI = require("GUI")
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local workspace, wallpaper = select(1, ...), select(2, ...)
local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg" local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg"
local config = { local config = {
@ -53,8 +55,7 @@ local wind = 0
local lastUpdateTime = computer.uptime() local lastUpdateTime = computer.uptime()
return { wallpaper.draw = function(wallpaper)
draw = function(wallpaper)
-- Spawning snowflakes -- Spawning snowflakes
local distance local distance
@ -160,9 +161,9 @@ return {
end end
lastUpdateTime = currentTime lastUpdateTime = currentTime
end, end
configure = function(layout) wallpaper.configure = function(layout)
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.backgroundColor, "Background color")).onColorSelected = function(_, object) layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.backgroundColor, "Background color")).onColorSelected = function(_, object)
config.backgroundColor = object.color config.backgroundColor = object.color
saveConfig() saveConfig()
@ -214,5 +215,4 @@ return {
config.maxStackHeight = math.floor(maxStackHeightSlider.value) config.maxStackHeight = math.floor(maxStackHeightSlider.value)
saveConfig() saveConfig()
end end
end end
}

View File

@ -5,6 +5,8 @@ local GUI = require("GUI")
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local workspace, wallpaper = select(1, ...), select(2, ...)
local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg" local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg"
local config = { local config = {
@ -23,15 +25,13 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
return { wallpaper.draw = function(object)
draw = function(object)
screen.drawRectangle(object.x, object.y, object.width, object.height, config.color, 0, ' ') screen.drawRectangle(object.x, object.y, object.width, object.height, config.color, 0, ' ')
end, end
configure = function(layout) wallpaper.configure = function(layout)
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.color, "Color")).onColorSelected = function(_, object) layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.color, "Color")).onColorSelected = function(_, object)
config.color = object.color config.color = object.color
saveConfig() saveConfig()
end end
end end
}

View File

@ -6,6 +6,8 @@ local color = require("Color")
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local workspace, wallpaper = select(1, ...), select(2, ...)
local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg" local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg"
local config = { local config = {
@ -72,10 +74,7 @@ end
resetColors() resetColors()
-------------------------------------------------------------------------------- wallpaper.draw = function(wallpaper)
return {
draw = function(wallpaper)
local hitsDeadline = computerUptime() >= deadline local hitsDeadline = computerUptime() >= deadline
-- Drawing background -- Drawing background
@ -160,9 +159,9 @@ return {
if hitsDeadline then if hitsDeadline then
deadline = computerUptime() + 0.05 deadline = computerUptime() + 0.05
end end
end, end
configure = function(layout) wallpaper.configure = function(layout)
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.backgroundColor, "Background color")).onColorSelected = function(_, object) layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.backgroundColor, "Background color")).onColorSelected = function(_, object)
config.backgroundColor = object.color config.backgroundColor = object.color
resetColors() resetColors()
@ -237,5 +236,4 @@ return {
config.starOffset = offsetSlider.value / 100 config.starOffset = offsetSlider.value / 100
saveConfig() saveConfig()
end end
end end
}

View File

@ -6,6 +6,8 @@ local image = require("Image")
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local workspace, wallpaper = select(1, ...), select(2, ...)
local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg" local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg"
local config = { local config = {
@ -40,8 +42,7 @@ loadPicture()
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
return { wallpaper.draw = function(object)
draw = function(object)
if picture then if picture then
screen.drawImage(object.x, object.y, picture) screen.drawImage(object.x, object.y, picture)
else else
@ -50,14 +51,13 @@ return {
local text = reason or "Unknown reason" local text = reason or "Unknown reason"
screen.drawText(math.floor(object.x + object.width / 2 - unicode.len(text) / 2), math.floor(object.y + object.height / 2), 0x646464, text) screen.drawText(math.floor(object.x + object.width / 2 - unicode.len(text) / 2), math.floor(object.y + object.height / 2), 0x646464, text)
end end
end, end
configure = function(layout) wallpaper.configure = function(layout)
local chooser = layout:addChild(GUI.filesystemChooser(1, 1, 36, 3, 0xE1E1E1, 0x696969, 0xD2D2D2, 0xA5A5A5, config.path, "Open", "Cancel", "Wallpaper path", "/")) local chooser = layout:addChild(GUI.filesystemChooser(1, 1, 36, 3, 0xE1E1E1, 0x696969, 0xD2D2D2, 0xA5A5A5, config.path, "Open", "Cancel", "Wallpaper path", "/"))
chooser:setMode(GUI.IO_MODE_OPEN, GUI.IO_MODE_FILE) chooser:setMode(GUI.IO_MODE_OPEN, GUI.IO_MODE_FILE)
chooser:addExtensionFilter(".pic") chooser:addExtensionFilter(".pic")
chooser.onSubmit = setPicture chooser.onSubmit = setPicture
end, end
setPicture = setPicture wallpaper.setPicture = setPicture
}