-
Notifications
You must be signed in to change notification settings - Fork 187
Creating your own wallpapers
Desktop wallpaper in MineOS is simple GUI object that is managed by the system. Wallpapers are small applications which providing drawing method for this object and (if needed) a configuration method for the settings app.
If you want to make custom wallpaper for your beautiful system, start by creating a new directory with extension .wlp
under the /Wallpapers/
. For example, i will create /Wallpapers/Random.wlp
.
The only required file here is Main.lua
. System will automatically run it and pass 2 objects - workspace and wallpaper itself, so you can define your own draw
function and use Screen API to create masterpieces.
Let's see an example:
local screen = require("Screen")
-------------------------------------------------------
-- Obtain system workspace & wallpaper objects
local workspace, wallpaper = select(1, ...), select(2, ...)
local points = {}
local limit = 20
local backgroundColor = 0x0F0F0F
local pointColor = 0xFFFFFF
-- Define custom draw function
wallpaper.draw = function()
-- Spawn new point
table.insert(points, {
x = math.random(0, wallpaper.width - 1),
y = math.random(0, wallpaper.height - 1)
})
-- Remove first point if limit was reached
if #points > limit then
table.remove(points, 1, #points - limit)
end
-- Clear area
screen.drawRectangle(wallpaper.x, wallpaper.y, wallpaper.width, wallpaper.height, backgroundColor, 0, " ")
-- Draw points
for i = 1, #points do
screen.set(wallpaper.x + points[i].x, wallpaper.y + points[i].y, pointColor, 0, " ")
end
end
You'll probably want to control the behavior and appearance of wallpaper via GUI. For these purposes, we've developed an interface that allows you to add custom controls to the Wallpaper tab of default Settings app.
Just define configure
function, which takes GUI.layout instance as first argument. You can fill it with buttons, sliders, comboxes - anything that needs to be shown when user goes to settings.
Let's improve our script:
local screen = require("Screen")
local system = require("System")
local filesystem = require("Filesystem")
local GUI = require("GUI")
-------------------------------------------------------
-- Obtain system workspace & wallpaper objects
local workspace, wallpaper = select(1, ...), select(2, ...)
-- Define a path to store the wallpaper config file
-- For convenience, we can do it directly with Main.lua script
local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg"
-- Read config if it exists or create default one otherwise
local config =
filesystem.exists(configPath) and
filesystem.readTable(configPath) or
{
backgroundColor = 0x0F0F0F,
pointColor = 0xFFFFFF
}
-- Define function to save config table
local function saveConfig()
filesystem.writeTable(configPath, config)
end
local limit = 20
local points = {}
-- Define custom draw function
wallpaper.draw = function()
-- Spawn new point
table.insert(points, {
x = math.random(0, wallpaper.width - 1),
y = math.random(0, wallpaper.height - 1)
})
-- Remove first point if limit was reached
if #points > limit then
table.remove(points, 1, #points - limit)
end
-- Clear area
screen.drawRectangle(wallpaper.x, wallpaper.y, wallpaper.width, wallpaper.height, config.backgroundColor, 0, " ")
-- Draw points
for i = 1, #points do
screen.set(wallpaper.x + points[i].x, wallpaper.y + points[i].y, config.pointColor, 0, " ")
end
end
-- Define a function that will populate settings layout with some controls
wallpaper.configure = function(layout)
-- Add selector for the background color
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.backgroundColor, "Background color")).onColorSelected = function(_, selector)
config.backgroundColor = selector.color
-- Save config to file when parameter has changed
saveConfig()
end
-- Add selector for the point color
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.pointColor, "Point color")).onColorSelected = function(_, selector)
config.pointColor = selector.color
saveConfig()
end
end