Блядь, да как затрахал этот опенсурс

This commit is contained in:
IgorTimofeev 2021-08-25 03:56:12 +07:00
parent d08ed5c0fd
commit 25289c43d2
6 changed files with 190 additions and 179 deletions

View File

@ -3,8 +3,6 @@
slideShow = "Slideshow", slideShow = "Slideshow",
delay = "Delay: ", delay = "Delay: ",
seconds = " seconds", seconds = " seconds",
hidePanel = "Hide panel",
shpwPanel = "Show panel",
fullScreen = "Full screen", fullScreen = "Full screen",
setWallpaper = "Do you want to set this picture as wallpaper?", setWallpaper = "Do you want to set this picture as wallpaper?",
yes = "Yes", yes = "Yes",

View File

@ -3,8 +3,6 @@
slideShow = "Слайдшоу", slideShow = "Слайдшоу",
delay = "Задержка: ", delay = "Задержка: ",
seconds = " секунд(ы)", seconds = " секунд(ы)",
hidePanel = "Скрыть панель",
showPanel = "Показать панель",
fullScreen = "На полный экран", fullScreen = "На полный экран",
setWallpaper = "Вы хотите установить это изображение в качестве обоев?", setWallpaper = "Вы хотите установить это изображение в качестве обоев?",
yes = "Да", yes = "Да",

View File

@ -4,216 +4,228 @@ local fs = require("Filesystem")
local image = require("Image") local image = require("Image")
local text = require("Text") local text = require("Text")
local screen = require("Screen") local screen = require("Screen")
local paths = require("Paths")
local args, options = system.parseArguments(...)
local currentDir, dirFiles = '/Pictures/'
local currentNum = 1
local workspace, window, menu = system.addWindow(GUI.titledWindow(1, 1, 70, 30, 'Viewer', true))
local localization = system.getCurrentScriptLocalization() local localization = system.getCurrentScriptLocalization()
local iconsPath = fs.path(system.getCurrentScript())..'Icons/' local args, options = system.parseArguments(...)
local iconsPath = fs.path(system.getCurrentScript()) .. "Icons/"
local currentDir, files = ((options.o or options.open) and args[1] and fs.exists(args[1])) and fs.path(args[1]) or paths.system.pictures
local fileIndex = 1
local loadedImage
local arrowLeftPic = image.load(iconsPath .. "ArrowLeft.pic") --------------------------------------------------------------------------------
local arrowRightPic = image.load(iconsPath .. "ArrowRight.pic")
local playPic = image.load(iconsPath .. "Play.pic")
local setWallpaperPic = image.load(iconsPath.."SetWallpaper.pic")
local layout = window:addChild(GUI.layout(1, 2, window.width, window.height, 1, 1)) local workspace, window, menu = system.addWindow(GUI.filledWindow(1, 1, 80, 25, 0x1E1E1E))
local panel = window:addChild(GUI.panel(1, window.height-5, window.width, 6, 0x000000, 0.5)) local imageObject = window:addChild(GUI.object(1, 1, 1, 1))
local panelLay = window:addChild(GUI.layout(1, window.height-5, window.width, 6, 4, 1))
local imageObj
local function scanDir() imageObject.draw = function()
dirFiles = {} if loadedImage then
for lab, file in pairs(fs.list(currentDir)) do screen.drawImage(
if lab ~= 'n' and string.lower(fs.extension(file) or '') == ".pic" then math.floor(window.x + window.width / 2 - loadedImage[1] / 2),
table.insert(dirFiles, currentDir .. file) math.floor(window.y + window.height / 2 - loadedImage[2] / 2),
end loadedImage
end )
end
end end
local function loadImg() window.actionButtons:moveToFront()
if imageObj then
imageObj:remove() local title = window:addChild(GUI.text(1, 2, 0xFFFFFF, " ", 0.5))
end local panel = window:addChild(GUI.panel(1, 1, 1, 6, 0x000000, 0.5))
local panelContainer = window:addChild(GUI.container(1, 1, 1, panel.height))
local slideShowDelay, slideShowDeadline
local function setUIHidden(state)
panel.hidden = state
panelContainer.hidden = state
window.actionButtons.hidden = state
title.hidden = state
end
local function updateSlideshowDeadline()
slideShowDeadline = computer.uptime() + slideShowDelay
end
local function updateTitlePosition()
title.localX = math.floor(window.width / 2 - unicode.len(title.text) / 2)
end
local function loadImage()
local result, reason = image.load(files[fileIndex])
local newImg, ifErr = image.load(dirFiles[currentNum]) if result then
title.text = fs.name(files[fileIndex])
if not newImg then updateTitlePosition()
GUI.alert(ifErr)
loadedImage = result
else
GUI.alert(reason)
window:remove() window:remove()
return
end end
imageObj = layout:addChild(GUI.image(1, 1, newImg))
window.titleLabel.text = 'Viewer - ' .. text.limit(dirFiles[currentNum], 30, "center")
workspace:draw() workspace:draw()
end end
local arrowLeft = panelLay:addChild(GUI.image(1, 1, arrowLeftPic)) local function loadIncremented(value)
arrowLeft.eventHandler = function(_, _, typ) fileIndex = fileIndex + value
if typ == 'touch' then
currentNum = currentNum == 1 and #dirFiles or currentNum-1 if fileIndex > #files then
loadImg() fileIndex = 1
elseif fileIndex < 1 then
fileIndex = #files
end end
loadImage()
end end
local play = panelLay:addChild(GUI.image(2, 1, playPic)) local function addButton(imageName, onTouch)
play.eventHandler = function(_, _, typ) -- Spacing
if typ == 'touch' then if #panelContainer.children > 0 then
local container = GUI.addBackgroundContainer(workspace, true, true, localization.slideShow) panelContainer.width = panelContainer.width + 5
container.panel.eventHandler = nil end
container.layout:setSpacing(1, 1, 2)
local i = GUI.image(panelContainer.width, 2, image.load(iconsPath .. imageName .. ".pic"))
local delay = container.layout:addChild(GUI.slider(1, 1, 50, 0x66DB80, 0x0, 0xFFFFFF, 0xFFFFFF, 3, 30, 0, true, localization.delay, localization.seconds))
delay.roundValues = true panelContainer:addChild(i).eventHandler = function(_, _, e)
if e == "touch" then
local onFull = container.layout:addChild(GUI.switchAndLabel(1, 1, 27, 8, 0x66DB80, 0x1D1D1D, 0xEEEEEE, 0xFFFFFF, localization.fullScreen..":", false)) onTouch()
end
local buttonsLay = container.layout:addChild(GUI.layout(1, 1, 30, 7, 1, 1)) end
buttonsLay:addChild(GUI.button(1, 1, 30, 3, 0xFFFFFF, 0x555555, 0x880000, 0xFFFFFF, localization.start)).onTouch = function() panelContainer.width = panelContainer.width + i.width
local slDelay = delay.value end
if onFull.switch.state then
local w, h = screen.getResolution() addButton("ArrowLeft", function()
local flScr = workspace:addChild(GUI.window(1, 1, w, h)) loadIncremented(-1)
flScr:addChild(GUI.panel(1, 1, w, h, 0xFFFFFF)) end)
local flLay = flScr:addChild(GUI.layout(1, 1, w, h, 1, 1))
local img = flLay:addChild(GUI.image(1, 1, imageObj.image)) addButton("Play", function()
local container = GUI.addBackgroundContainer(workspace, true, true, localization.slideShow)
container.panel.eventHandler = nil
container.layout:setSpacing(1, 1, 2)
flScr.eventHandler = function(_, _, typ) local delay = container.layout:addChild(GUI.slider(1, 1, 50, 0x66DB80, 0x0, 0xFFFFFF, 0xFFFFFF, 3, 30, 0, true, localization.delay, localization.seconds))
if typ == 'touch' or typ == 'key_down' then flScr:remove() loadImg() delay.roundValues = true
elseif strTim + slDelay <= system.getTime() then
img:remove() local buttonsLay = container.layout:addChild(GUI.layout(1, 1, 30, 7, 1, 1))
currentNum = currentNum == #dirFiles and 1 or currentNum+1
local newImg, ifErr = image.load(dirFiles[currentNum]) buttonsLay:addChild(GUI.button(1, 1, 30, 3, 0xFFFFFF, 0x555555, 0x880000, 0xFFFFFF, localization.start)).onTouch = function()
if not newImg then GUI.alert(ifErr) flScr:remove() window:remove() return end setUIHidden(true)
img = flLay:addChild(GUI.image(1, 1, newImg))
strTim = system.getTime()
end
end
else
panel.hidden = true
panelLay.hidden = true
local strTim = system.getTime()
layout.eventHandler = function(_, _, typ) if not window.maximized then
if typ == 'touch' or typ == 'key_down' then window:maximize()
layout.eventHandler = nil
panel.hidden = false
panelLay.hidden = false
elseif strTim + slDelay <= system.getTime() then
currentNum = currentNum == #dirFiles and 1 or currentNum+1
loadImg()
strTim = system.getTime()
end
end
end
container:remove()
end
buttonsLay:addChild(GUI.button(1, 1, 30, 3, 0xFFFFFF, 0x555555, 0x880000, 0xFFFFFF, localization.cancel)).onTouch = function()
container:remove()
end end
slideShowDelay = delay.value
updateSlideshowDeadline()
container:remove()
end
buttonsLay:addChild(GUI.button(1, 1, 30, 3, 0xFFFFFF, 0x555555, 0x880000, 0xFFFFFF, localization.cancel)).onTouch = function()
container:remove()
end end
end
panelLay:setPosition(2, 1, play) workspace:draw()
end)
-- Arrow right -- Arrow right
local arrowRight = panelLay:addChild(GUI.image(1, 1, arrowRightPic)) addButton("ArrowRight", function()
loadIncremented(1)
arrowRight.eventHandler = function(_, _, typ) end)
if typ == 'touch' then
currentNum = currentNum == #dirFiles and 1 or currentNum+1
loadImg()
end
end
panelLay:setPosition(3, 1, arrowRight)
-- Set wallpaper -- Set wallpaper
local setWallpaper = panelLay:addChild(GUI.image(1, 1, setWallpaperPic)) addButton("SetWallpaper", function()
local container = GUI.addBackgroundContainer(workspace, true, true, localization.setWallpaper)
setWallpaper.eventHandler = function(_, _, typ) container.panel.eventHandler = nil
if typ == 'touch' then
local container = GUI.addBackgroundContainer(workspace, true, true, localization.setWallpaper)
container.panel.eventHandler = nil
local buttLay = container.layout:addChild(GUI.layout(1, 1, 24, 6, 2, 1))
buttLay:addChild(GUI.button(1, 1, 10, 3, 0xFFFFFF, 0x555555, 0x880000, 0xFFFFFF, localization.yes)).onTouch = function()
local sets = system.getUserSettings()
sets.interfaceWallpaperPath = dirFiles[currentNum]
system.saveUserSettings()
system.updateWallpaper()
container:remove()
end
local cancel = buttLay:addChild(GUI.button(1, 1, 10, 3, 0xFFFFFF, 0x555555, 0x880000, 0xFFFFFF, localization.no)) local buttLay = container.layout:addChild(GUI.layout(1, 1, 24, 6, 2, 1))
cancel.onTouch = function()
container:remove()
end
buttLay:setPosition(2, 1, cancel)
end
end
panelLay:setPosition(4, 1, setWallpaper)
local hsPanel = menu:addItem(localization.hidePanel)
hsPanel.onTouch = function()
hsPanel.text = panel.hidden and localization.hidePanel or localization.showPanel
panel.hidden = not panel.hidden
panelLay.hidden = not panelLay.hidden
end
menu:addItem(localization.fullScreen).onTouch = function()
local w, h = screen.getResolution()
local flScr = workspace:addChild(GUI.window(1, 1, w, h))
flScr:addChild(GUI.panel(1, 1, w, h, 0xFFFFFF))
local flLay = flScr:addChild(GUI.layout(1, 1, w, h, 1, 1))
flLay:addChild(GUI.image(1, 1, imageObj.image))
flScr.eventHandler = function(_, _, typ) buttLay:addChild(GUI.button(1, 1, 10, 3, 0xFFFFFF, 0x555555, 0x880000, 0xFFFFFF, localization.yes)).onTouch = function()
if typ == 'touch' or typ == 'key_down' then flScr:remove() end local sets = system.getUserSettings()
sets.interfaceWallpaperPath = files[fileIndex]
system.saveUserSettings()
system.updateWallpaper()
container:remove()
end end
end
local cancel = buttLay:addChild(GUI.button(1, 1, 10, 3, 0xFFFFFF, 0x555555, 0x880000, 0xFFFFFF, localization.no))
cancel.onTouch = function()
container:remove()
end
buttLay:setPosition(2, 1, cancel)
end)
window.onResize = function(newWidth, newHeight) window.onResize = function(newWidth, newHeight)
window.backgroundPanel.width, window.backgroundPanel.height = newWidth, newHeight window.backgroundPanel.width, window.backgroundPanel.height = newWidth, newHeight
layout.width, layout.height = newWidth, newHeight imageObject.width, imageObject.height = newWidth, newHeight
window.titlePanel.width = newWidth panel.width, panel.localY = newWidth, newHeight - 5
window.titleLabel.width = newWidth panelContainer.localX, panelContainer.localY = math.floor(newWidth / 2 - panelContainer.width / 2), panel.localY
panel.width, panel.localY = newWidth, newHeight-5
panelLay.width, panelLay.localY = newWidth, newHeight-5 updateTitlePosition()
end end
if (options.o or options.open) and args[1] then local overrideWindowEventHandler = window.eventHandler
currentDir = fs.path(args[1]) window.eventHandler = function(workspace, window, e1, ...)
if e1 == "double_touch" then
scanDir() setUIHidden(not panel.hidden)
workspace:draw()
elseif e1 == "touch" or e1 == "key_down" then
if slideShowDeadline then
setUIHidden(false)
slideShowDelay, slideShowDeadline = nil, nil
for i=1, #dirFiles do workspace:draw()
if dirFiles[i] == args[1] then currentNum = i loadImg() break end end
end
else
scanDir()
if #dirFiles == 0 then
layout:addChild(GUI.text(1, 1, 0x4B4B4B, localization.noPictures))
panel.hidden = true
panelLay.hidden = true
hsPanel.disabled = true
flScreen.disabled = true
else else
loadImg() if slideShowDelay and computer.uptime() > slideShowDeadline then
loadIncremented(1)
workspace:draw()
updateSlideshowDeadline()
end
end end
overrideWindowEventHandler(workspace, window, e1, ...)
end end
--------------------------------------------------------------------------------
window.onResize(window.width, window.height)
files = fs.list(currentDir)
if #files == 0 then
layout:addChild(GUI.text(1, 1, 0x4B4B4B, localization.noPictures))
panel.hidden = true
panelContainer.hidden = true
hsPanel.disabled = true
flScreen.disabled = true
else
local i, extension = 1
while i <= #files do
extension = fs.extension(files[i])
if extension and extension:lower() == ".pic" then
files[i] = currentDir .. files[i]
if args and args[1] == files[i] then
fileIndex = i
end
i = i + 1
else
table.remove(files, i)
end
end
loadImage()
end
workspace:draw() workspace:draw()

View File

@ -3524,20 +3524,23 @@ end
local function textUpdate(object) local function textUpdate(object)
object.width = unicode.len(object.text) object.width = unicode.len(object.text)
return object return object
end end
local function textDraw(object) local function textDraw(object)
object:update() object:update()
screen.drawText(object.x, object.y, object.color, object.text) screen.drawText(object.x, object.y, object.color, object.text, object.transparency)
return object return object
end end
function GUI.text(x, y, color, text) function GUI.text(x, y, color, text, transparency)
local object = GUI.object(x, y, 1, 1) local object = GUI.object(x, y, 1, 1)
object.text = text object.text = text
object.color = color object.color = color
object.transparency = transparency
object.update = textUpdate object.update = textUpdate
object.draw = textDraw object.draw = textDraw
object:update() object:update()

View File

@ -23,7 +23,7 @@ paths.system.applicationPictureEdit = paths.system.applications .. "Picture Edit
paths.system.applicationSettings = paths.system.applications .. "Settings.app/Main.lua" paths.system.applicationSettings = paths.system.applications .. "Settings.app/Main.lua"
paths.system.applicationPrint3D = paths.system.applications .. "3D Print.app/Main.lua" paths.system.applicationPrint3D = paths.system.applications .. "3D Print.app/Main.lua"
paths.system.applicationConsole = paths.system.applications .. "Console.app/Main.lua" paths.system.applicationConsole = paths.system.applications .. "Console.app/Main.lua"
paths.system.applicationViewer = paths.system.applications .. "Viewer.app/Main.lua" paths.system.applicationPictureView = paths.system.applications .. "Picture View.app/Main.lua"
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@ -131,7 +131,7 @@ function system.getDefaultUserSettings()
[".cfg"] = filesystem.path(paths.system.applicationMineCodeIDE), [".cfg"] = filesystem.path(paths.system.applicationMineCodeIDE),
[".txt"] = filesystem.path(paths.system.applicationMineCodeIDE), [".txt"] = filesystem.path(paths.system.applicationMineCodeIDE),
[".lang"] = filesystem.path(paths.system.applicationMineCodeIDE), [".lang"] = filesystem.path(paths.system.applicationMineCodeIDE),
[".pic"] = filesystem.path(paths.system.applicationViewer), [".pic"] = filesystem.path(paths.system.applicationPictureView),
[".3dm"] = paths.system.applications .. "3D Print.app/" [".3dm"] = paths.system.applications .. "3D Print.app/"
}, },
} }