Новое приложение: радио

This commit is contained in:
Igor 2016-03-04 14:55:56 +03:00
parent fa4300cb64
commit 916e18dcaf
8 changed files with 856 additions and 223 deletions

View File

@ -381,6 +381,15 @@
["version"]=1.0,
},
----------------------------------------------------- Приложения без ресурсов --------------------------------------------------------------------------
{
["name"]="MineOS/Applications/Radio",
["url"]="IgorTimofeev/OpenComputers/master/Applications/Radio/Radio.lua",
["about"]="IgorTimofeev/OpenComputers/master/Applications/Radio/About.txt",
["type"]="Application",
["icon"]="IgorTimofeev/OpenComputers/master/Applications/Radio/Icon.pic",
["createShortcut"] = "desktop",
["version"]=1.0,
},
{
["name"]="MineOS/Applications/FuckTheRain",
["url"]="IgorTimofeev/OpenComputers/master/Applications/FuckTheRain/FuckTheRain.lua",

View File

@ -0,0 +1 @@
Программа для управления радио из мода OpenFM, стилизованная под известный плеер iRiver SPINN.

BIN
Applications/Radio/Icon.pic Normal file

Binary file not shown.

View File

@ -0,0 +1,308 @@
package.loaded.bigLetters = nil
local buffer = require("doubleBuffering")
local bigLetters = require("bigLetters")
local unicode = require("unicode")
local component = require("component")
local fs = require("filesystem")
local context = require("context")
local serialization = require("serialization")
local radio
if not component.isAvailable("openfm_radio") then
ecs.error("Этой программе требется радио из мода OpenFM для работы.")
return
else
radio = component.openfm_radio
end
local pathToSaveStations = "MineOS/System/Radio/Stations.cfg"
local stationNameLimit = 8
local spaceBetweenStations = 8
local countOfStationsLimit = 9
local lineHeight
local config = {
colors = {
background = 0x1b1b1b,
line = 0xFFFFFF,
lineShadow = 0x000000,
activeStation = 0xFFA800,
otherStation = 0xBBBBBB,
bottomToolBarDefaultColor = 0xaaaaaa,
bottomToolBarCurrentColor = 0xFFA800,
},
}
local radioStations = {
currentStation = 3,
{
name = "Galnet Soft",
url = "http://galnet.ru:8000/soft"
},
{
name = "Европа Плюс",
url = "http://ep256.streamr.ru"
},
{
name = "L-Radio",
url = "http://server2.lradio.ru:8000/lradio64.aac.m3u"
},
{
name = "Radio Record",
url = "http://online.radiorecord.ru:8101/rr_128.m3u"
},
{
name = "Moscow FM",
url = "http://livestream.rfn.ru:8080/moscowfmen128.m3u"
},
}
--Объекты для тача
local obj = {}
local function drawStation(x, y, name, color)
bigLetters.drawText(x, y, color, name)
end
local function drawLine()
local x = math.floor(buffer.screen.width / 2)
for i = 1, lineHeight do
buffer.text(x + 1, i, config.colors.lineShadow, "")
buffer.text(x, i, config.colors.line, "")
end
end
local function drawLeftArrow(x, y, color)
local bg, fg = config.colors.background, color
local arrow = {
{ {bg, fg, " "}, {bg, fg, " "}, {bg, fg, "*"} },
{ {bg, fg, " "}, {bg, fg, "*"}, {bg, fg, " "} },
{ {bg, fg, "*"}, {bg, fg, " "}, {bg, fg, " "} },
{ {bg, fg, " "}, {bg, fg, "*"}, {bg, fg, " "} },
{ {bg, fg, " "}, {bg, fg, " "}, {bg, fg, "*"} },
}
buffer.drawCustomImage(x, y, arrow)
end
local function drawRightArrow(x, y, color)
local bg, fg = config.colors.background, color
local arrow = {
{ {bg, fg, "*"}, {bg, fg, " "}, {bg, fg, " "} },
{ {bg, fg, " "}, {bg, fg, "*"}, {bg, fg, " "} },
{ {bg, fg, " "}, {bg, fg, " "}, {bg, fg, "*"} },
{ {bg, fg, " "}, {bg, fg, "*"}, {bg, fg, " "} },
{ {bg, fg, "*"}, {bg, fg, " "}, {bg, fg, " "} },
}
buffer.drawCustomImage(x, y, arrow)
end
local function drawMenu()
local width = 36 + (3 * 2 + 2) * #radioStations
local x, y = math.floor(buffer.screen.width / 2 - width / 2), lineHeight + math.floor((buffer.screen.height - lineHeight) / 2 - 1)
obj.gromkostPlus = {x, y, x + 3, y + 3}
x = bigLetters.drawText(x, y, config.colors.bottomToolBarDefaultColor, "+", "*") + 1
x = x + 1
obj.strelkaVlevo = {x, y, x + 3, y + 3}
drawLeftArrow(x, y, config.colors.bottomToolBarDefaultColor); x = x + 5
x = x + 3
local color
for i = 1, #radioStations do
if i == radioStations.currentStation then color = config.colors.bottomToolBarCurrentColor else color = config.colors.bottomToolBarDefaultColor end
x = bigLetters.drawText(x, y, color, tostring(i), "*") + 1
end
x = x + 2
obj.strelkaVpravo = {x, y, x + 3, y + 3}
drawRightArrow(x, y, config.colors.bottomToolBarDefaultColor)
x = x + 8
obj.gromkostMinus = {x, y, x + 3, y + 3}
x = bigLetters.drawText(x, y, config.colors.bottomToolBarDefaultColor, "-", "*") + 1
end
local function drawStations()
local prevWidth, currentWidth, nextWidth, name
-- Текущая станция
name = ecs.stringLimit("end", unicode.lower(radioStations[radioStations.currentStation].name), stationNameLimit)
currentWidth = bigLetters.getTextSize(name)
local x, y = math.floor(buffer.screen.width / 2 - currentWidth / 2), math.floor(buffer.screen.height / 2 - 3)
drawStation(x, y, name, config.colors.activeStation)
-- Предедущая
if radioStations[radioStations.currentStation - 1] then
name = ecs.stringLimit("start", unicode.lower(radioStations[radioStations.currentStation - 1].name), stationNameLimit)
prevWidth = bigLetters.getTextSize(name)
drawStation(x - prevWidth - spaceBetweenStations, y, name, config.colors.otherStation)
end
-- Следующая
if radioStations[radioStations.currentStation + 1] then
name = ecs.stringLimit("end", unicode.lower(radioStations[radioStations.currentStation + 1].name), stationNameLimit)
nextWidth = bigLetters.getTextSize(name)
drawStation(x + currentWidth + spaceBetweenStations + 1, y, name, config.colors.otherStation)
end
-- ecs.error(x, x - prevWidth - spaceBetweenStations, prevWidth, currentWidth, nextWidth)
end
local function drawAll()
-- Коррекция от кривых ручонок юзверей
if radioStations.currentStation < 1 then
radioStations.currentStation = 1
elseif radioStations.currentStation > #radioStations then
radioStations.currentStation = #radioStations
end
buffer.square(1, 1, buffer.screen.width, buffer.screen.height, config.colors.background, 0xFFFFFF, " ")
drawStations()
drawLine()
drawMenu()
buffer.draw()
end
local function saveStations()
fs.makeDirectory(fs.path(pathToSaveStations))
local file = io.open(pathToSaveStations, "w")
file:write(serialization.serialize(radioStations))
file:close()
end
local function loadStations()
if fs.exists(pathToSaveStations) then
local file = io.open(pathToSaveStations, "r")
radioStations = serialization.unserialize(file:read("*a"))
file:close()
else
saveStations()
end
end
local function switchStation(i)
if i == 1 then
if radioStations.currentStation < #radioStations then
radioStations.currentStation = radioStations.currentStation + 1
saveStations()
radio.setURL(radioStations[radioStations.currentStation].url)
radio.start()
end
else
if radioStations.currentStation > 1 then
radioStations.currentStation = radioStations.currentStation - 1
saveStations()
radio.setURL(radioStations[radioStations.currentStation].url)
radio.start()
end
end
end
local function volume(i)
if i == 1 then
radio.volUp()
else
radio.volDown()
end
end
buffer.start()
lineHeight = math.floor(buffer.screen.height * 0.7)
loadStations()
drawAll()
while true do
local e = {event.pull()}
if e[1] == "touch" then
if e[5] == 0 then
if ecs.clickedAtArea(e[3], e[4], obj.strelkaVlevo[1], obj.strelkaVlevo[2], obj.strelkaVlevo[3], obj.strelkaVlevo[4]) then
drawLeftArrow(obj.strelkaVlevo[1], obj.strelkaVlevo[2], config.colors.bottomToolBarCurrentColor)
buffer.draw()
os.sleep(0.2)
switchStation(-1)
drawAll()
elseif ecs.clickedAtArea(e[3], e[4], obj.strelkaVpravo[1], obj.strelkaVpravo[2], obj.strelkaVpravo[3], obj.strelkaVpravo[4]) then
drawRightArrow(obj.strelkaVpravo[1], obj.strelkaVpravo[2], config.colors.bottomToolBarCurrentColor)
buffer.draw()
os.sleep(0.2)
switchStation(1)
drawAll()
elseif ecs.clickedAtArea(e[3], e[4], obj.gromkostPlus[1], obj.gromkostPlus[2], obj.gromkostPlus[3], obj.gromkostPlus[4]) then
bigLetters.drawText(obj.gromkostPlus[1], obj.gromkostPlus[2], config.colors.bottomToolBarCurrentColor, "+", "*" )
buffer.draw()
volume(1)
os.sleep(0.2)
drawAll()
elseif ecs.clickedAtArea(e[3], e[4], obj.gromkostMinus[1], obj.gromkostMinus[2], obj.gromkostMinus[3], obj.gromkostMinus[4]) then
bigLetters.drawText(obj.gromkostMinus[1], obj.gromkostMinus[2], config.colors.bottomToolBarCurrentColor, "-", "*" )
buffer.draw()
volume(-1)
os.sleep(0.2)
drawAll()
end
else
local action = context.menu(e[3], e[4], {"Добавить станцию", #radioStations >= countOfStationsLimit}, {"Удалить станцию", #radioStations < 2}, "-", {"О программе"}, "-", {"Выход"})
if action == "Добавить станцию" then
local data = ecs.universalWindow("auto", "auto", 36, 0x262626, true,
{"EmptyLine"},
{"CenterText", ecs.colors.orange, "Добавить станцию"},
{"EmptyLine"},
{"Input", 0xFFFFFF, ecs.colors.orange, "Название станции"},
{"EmptyLine"},
{"Input", 0xFFFFFF, ecs.colors.orange, "URL-ссылка на стрим"},
{"EmptyLine"},
{"Button", {ecs.colors.orange, 0x262626, "OK"}, {0x999999, 0xffffff, "Отмена"}}
)
if data[3] == "OK" then
table.insert(radioStations, {name = data[1], url = data[2]})
saveStations()
drawAll()
end
elseif action == "Удалить станцию" then
table.remove(radioStations, radioStations.currentStation)
saveStations()
drawAll()
elseif action == "О программе" then
ecs.universalWindow("auto", "auto", 36, 0x262626, true,
{"EmptyLine"},
{"CenterText", ecs.colors.orange, "Radio v1.0"},
{"EmptyLine"},
{"CenterText", 0xFFFFFF, "Автор:"},
{"CenterText", 0xBBBBBB, "Тимофеев Игорь"},
{"CenterText", 0xBBBBBB, "vk.com/id7799889"},
{"EmptyLine"},
{"CenterText", 0xFFFFFF, "Тестер:"},
{"CenterText", 0xBBBBBB, "Олег Гречкин"},
{"CenterText", 0xBBBBBB, "http://vk.com/id250552893"},
{"EmptyLine"},
{"CenterText", 0xFFFFFF, "Автор идеи:"},
{"CenterText", 0xBBBBBB, "MrHerobrine с Dreamfinity"},
{"EmptyLine"},
{"Button", {ecs.colors.orange, 0xffffff, "OK"}}
)
elseif action == "Выход" then
buffer.square(1, 1, buffer.screen.width, buffer.screen.height, config.colors.background, 0xFFFFFF, " ")
buffer.draw()
ecs.prepareToExit()
radio.stop()
return
end
end
elseif e[1] == "scroll" then
switchStation(e[5])
drawAll()
end
end

View File

@ -5,6 +5,8 @@ local bigLetters = {}
local pixelHeight = 5
local lettersInterval = 2
local unknownSymbol = "*"
local spaceWidth = 2
local letters = {
["0"] = {
@ -15,11 +17,11 @@ local letters = {
{ 1, 1, 1 },
},
["1"] = {
{ 0, 0, 1 },
{ 0, 0, 1 },
{ 0, 0, 1 },
{ 0, 0, 1 },
{ 0, 0, 1 },
{ 0, 1, 0 },
{ 1, 1, 0 },
{ 0, 1, 0 },
{ 0, 1, 0 },
{ 1, 1, 1 },
},
["2"] = {
{ 1, 1, 1 },
@ -77,40 +79,482 @@ local letters = {
{ 0, 0, 1 },
{ 1, 1, 1 },
},
-- ["A"] = {
-- { 0, 1, 1, 1, 0 },
-- { 1, 0, 0, 0, 1 },
-- { 1, 0, 0, 0, 1 },
-- { 1, 1, 1, 1, 1 },
-- { 1, 0, 0, 0, 1 },
-- { 1, 0, 0, 0, 1 },
-- { 1, 0, 0, 0, 1 },
-- },
-- ["a"] = {
-- { 0, 1, 1, 1, 0 },
-- { 0, 0, 0, 0, 1 },
-- { 0, 1, 1, 1, 1 },
-- { 1, 0, 0, 0, 1 },
-- { 0, 1, 1, 1, 1 },
-- },
-- ["SAMPLELITTLE"] = {
-- { 0, 0, 0, 0, 0 },
-- { 0, 0, 0, 0, 0 },
-- { 0, 0, 0, 0, 0 },
-- { 0, 0, 0, 0, 0 },
-- { 0, 0, 0, 0, 0 },
-- },
["a"] = {
{ 0, 1, 1, 0 },
{ 1, 0, 0, 1 },
{ 1, 1, 1, 1 },
{ 1, 0, 0, 1 },
{ 1, 0, 0, 1 },
},
["b"] = {
{ 1, 1, 1, 0},
{ 1, 0, 0, 1},
{ 1, 1, 1, 0},
{ 1, 0, 0, 1},
{ 1, 1, 1, 1},
},
["c"] = {
{ 0, 1, 1, 1 },
{ 1, 0, 0, 0 },
{ 1, 0, 0, 0 },
{ 1, 0, 0, 0 },
{ 0, 1, 1, 1 },
},
["d"] = {
{ 1, 1, 1, 1, 0 },
{ 0, 1, 0, 0, 1 },
{ 0, 1, 0, 0, 1 },
{ 0, 1, 0, 0, 1 },
{ 1, 1, 1, 1, 0 },
},
["e"] = {
{ 1, 1,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 1, 0, 0, 1, 1, 0 },
},
["я"] = {
{ 0, 1, 1, 1 },
{ 1, 0, 0, 1 },
{ 0, 1, 1, 1 },
{ 1, 0, 0, 1 },
{ 1, 0, 0, 1 },
},
["-"] = {
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 1, 1, 1 },
{ 0, 0, 0 },
{ 0, 0, 0 },
},
["_"] = {
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 1, 1, 1 },
},
["+"] = {
{ 0, 0, 0 },
{ 0, 1, 0 },
{ 1, 1, 1 },
{ 0, 1, 0 },
{ 0, 0, 0 },
},
["*"] = {
{ 0, 0, 0 },
{ 1, 0, 1 },
{ 0, 1, 0 },
{ 1, 0, 1 },
{ 0, 0, 0 },
},
[""] = {
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 1, 0, 1, 0, 1 },
},
}
function bigLetters.draw(x, y, color, symbol)
if not letters[symbol] then
error("Symbol \"" .. symbol .. "\" is not supported yet.")
function bigLetters.draw(x, y, color, symbol, drawWithSymbol)
if symbol == " " then
return spaceWidth
elseif not letters[symbol] then
symbol = unknownSymbol
end
for j = 1, #letters[symbol] do
for i = 1, #letters[symbol][j] do
if letters[symbol][j][i] == 1 then
buffer.square(x + i * 2 - 2, y + (pixelHeight - #letters[symbol]) + j - 1, 2, 1, color, 0xFFFFFF, " ")
if not drawWithSymbol then
buffer.square(x + i * 2 - 2, y + (pixelHeight - #letters[symbol]) + j - 1, 2, 1, color, 0xFFFFFF, " ")
else
buffer.text(x + i * 2 - 2, y + (pixelHeight - #letters[symbol]) + j - 1, color, "*")
end
end
end
end
@ -118,16 +562,36 @@ function bigLetters.draw(x, y, color, symbol)
return #letters[symbol][1]
end
function bigLetters.drawText(x, y, color, stroka)
function bigLetters.drawText(x, y, color, stroka, drawWithSymbol)
checkArg(4, stroka, "string")
for i = 1, unicode.len(stroka) do
x = x + bigLetters.draw(x, y, color, unicode.sub(stroka, i, i)) * 2 + lettersInterval
x = x + bigLetters.draw(x, y, color, unicode.sub(stroka, i, i), drawWithSymbol) * 2 + lettersInterval
end
return x
end
function bigLetters.getTextSize(text)
local width, height = 0, 0
local symbol, symbolWidth, symbolHeight
for i = 1, unicode.len(text) do
symbol = unicode.sub(text, i, i)
if symbol == " " then
symbolWidth = spaceWidth
symbolHeight = 5
elseif not letters[symbol] then
symbolHeight = #letters[unknownSymbol]
symbolWidth = #letters[unknownSymbol][1]
else
symbolHeight = #letters[symbol]
symbolWidth = #letters[symbol][1]
end
-- ecs.prepareToExit()
-- bigLetters.drawString(1, 1, 0x00FF00, "0123456789Aa")
width = width + symbolWidth * 2 + lettersInterval
height = math.max(height, symbolHeight)
end
return (width - lettersInterval), height
end
return bigLetters

View File

@ -337,6 +337,43 @@ function buffer.scrollBar(x, y, width, height, countOfAllElements, currentElemen
sizeOfScrollBar, displayBarFrom = nil, nil
end
function buffer.drawCustomImage(x, y, pixels)
x = x - 1
y = y - 1
for i=1, #pixels do
for j=1, #pixels[1] do
if pixels[i][j][3] ~= "#" then
buffer.set(x + j, y + i, pixels[i][j][1], pixels[i][j][2], pixels[i][j][3])
end
end
end
return (x + 1), (y + 1), (x + #pixels[1]), (y + #pixels)
end
--Нарисовать топ-меню, горизонтальная полоска такая с текстами
function buffer.drawTopMenu(x, y, width, color, selectedObject, ...)
local objects = { ... }
local objectsToReturn = {}
local xPos = x + 2
local spaceBetween = 2
buffer.square(x, y, width, 1, color, 0xFFFFFF, " ")
for i = 1, #objects do
if i == selectedObject then
buffer.square(xPos - 1, y, unicode.len(objects[i][1]) + spaceBetween, 1, 0x3366CC, 0xFFFFFF, " ")
buffer.text(xPos, y, 0xFFFFFF, objects[i][1])
else
buffer.text(xPos, y, objects[i][2], objects[i][1])
end
objectsToReturn[objects[i][1]] = { xPos, y, xPos + unicode.len(objects[i][1]) - 1, y, i }
xPos = xPos + unicode.len(objects[i][1]) + spaceBetween
end
return objectsToReturn
end
------------------------------------------------------------------------------------------------------------------------
function buffer.calculateDifference(x, y)
local index = convertCoordsToIndex(x, y)
local backgroundIsChanged, foregroundIsChanged, symbolIsChanged = false, false, false

View File

@ -19,7 +19,7 @@ modemConnection.receiveMessagesFromTablets = true
modemConnection.receiveMessagesFromComputers = true
local infoMessages = {
userTriesToConnectNoGUI = "Пользователь %s желает установить с вами соединение. Разрешить?",
userTriesToConnectNoGUI = "Пользователь %s желает установить с вами соединение. Разрешить? Y/N",
noModem = "Этой библиотеке требуется сетевая карта для работы",
}

View File

@ -1,186 +0,0 @@
local ecs = require("ECSAPI")
local xml = require("xmlParser")
local image = require("image")
local event = require("event")
local unicode = require("unicode")
local fs = require("filesystem")
local gpu = require("component").gpu
------------------------------------------------------------------------------------------------------------------
local config = {
scale = 0.63,
leftBarWidth = 20,
scrollSpeed = 6,
pathToInfoPanelFolder = "MineOS/System/InfoPanel/",
colors = {
leftBar = 0x262626,
leftBarText = 0xFFFFFF,
leftBarSelection = 0x7b1fa2,
leftBarSelectionText = 0xFFFFFF,
scrollbarBack = 0x7b1fa2,
scrollbarPipe = 0x7b1fa2,
background = 0x222222,
text = 0xdddddd,
},
}
local xOld, yOld = gpu.getResolution()
ecs.setScale(config.scale)
local xSize, ySize = gpu.getResolution()
fs.makeDirectory(config.pathToInfoPanelFolder)
local currentFile = 1
local fileList
local stroki = {}
local currentString = 1
local stringsHeightLimit = ySize - 2
local stringsWidthLimit = xSize - config.leftBarWidth - 4
------------------------------------------------------------------------------------------------------------------
local obj = {}
local function newObj(class, name, ...)
obj[class] = obj[class] or {}
obj[class][name] = {...}
end
local function drawLeftBar()
--ecs.square(1, 1, config.leftBarWidth, ySize, config.colors.leftBar)
fileList = ecs.getFileList(config.pathToInfoPanelFolder)
obj["Files"] = {}
local yPos = 1, 1
for i = 1, #fileList do
if i == currentFile then
newObj("Files", i, ecs.drawButton(1, yPos, config.leftBarWidth, 3, ecs.hideFileFormat(fileList[i]), config.colors.leftBarSelection, config.colors.leftBarSelectionText))
else
if i % 2 == 0 then
newObj("Files", i, ecs.drawButton(1, yPos, config.leftBarWidth, 3, ecs.stringLimit("end", fileList[i], config.leftBarWidth - 2), config.colors.leftBar, config.colors.leftBarText))
else
newObj("Files", i, ecs.drawButton(1, yPos, config.leftBarWidth, 3, ecs.stringLimit("end", fileList[i], config.leftBarWidth - 2), config.colors.leftBar - 0x111111, config.colors.leftBarText))
end
end
yPos = yPos + 3
end
ecs.square(1, yPos, config.leftBarWidth, ySize - yPos + 1, config.colors.leftBar)
end
local function loadFile()
currentString = 1
stroki = {}
local file = io.open(config.pathToInfoPanelFolder .. fileList[currentFile], "r")
for line in file:lines() do table.insert(stroki, xml.collect(line)) end
file:close()
end
local function drawMain()
local x, y = config.leftBarWidth + 1, 1
local xPos, yPos = x, y
ecs.square(xPos, yPos, xSize - config.leftBarWidth - 3, ySize, config.colors.background)
gpu.setForeground(config.colors.text)
xPos = xPos + 2
for line = currentString, (stringsHeightLimit + currentString - 1) do
if stroki[line] then
for i = 1, #stroki[line] do
if type(stroki[line][i]) == "table" then
if stroki[line][i].label == "color" then
gpu.setForeground(tonumber(stroki[line][i][1]))
elseif stroki[line][i].label == "image" then
local bg, fg = gpu.getBackground(), gpu.getForeground()
local picture = image.load(stroki[line][i][1])
image.draw(xPos, yPos, picture)
yPos = yPos + picture.height - 1
gpu.setForeground(fg)
gpu.setBackground(bg)
end
else
gpu.set(xPos, yPos, stroki[line][i])
xPos = xPos + unicode.len(stroki[line][i])
end
end
yPos = yPos + 1
xPos = x + 2
else
break
end
end
end
local function drawScrollBar()
local name
name = ""; newObj("Scroll", name, ecs.drawButton(xSize - 2, 1, 3, 3, name, config.colors.leftBarSelection, config.colors.leftBarSelectionText))
name = ""; newObj("Scroll", name, ecs.drawButton(xSize - 2, ySize - 2, 3, 3, name, config.colors.leftBarSelection, config.colors.leftBarSelectionText))
ecs.srollBar(xSize - 2, 4, 3, ySize - 6, #stroki, currentString, config.colors.scrollbarBack, config.colors.scrollbarPipe)
end
local function dro4er()
if currentString < (#stroki) then
currentString = currentString + 1
else
currentString = 1
end
drawMain()
drawScrollBar()
end
------------------------------------------------------------------------------------------------------------------
ecs.prepareToExit()
drawLeftBar()
loadFile()
drawMain()
drawScrollBar()
local timerID = event.timer(0.5, dro4er)
while true do
local e = {event.pull()}
if e[1] == "touch" then
for key in pairs(obj["Files"]) do
if ecs.clickedAtArea(e[3], e[4], obj["Files"][key][1], obj["Files"][key][2], obj["Files"][key][3], obj["Files"][key][4]) then
currentFile = key
loadFile()
drawLeftBar()
drawMain()
drawScrollBar()
break
end
end
for key in pairs(obj["Scroll"]) do
if ecs.clickedAtArea(e[3], e[4], obj["Scroll"][key][1], obj["Scroll"][key][2], obj["Scroll"][key][3], obj["Scroll"][key][4]) then
ecs.drawButton(obj["Scroll"][key][1], obj["Scroll"][key][2], 3, 3, key, config.colors.leftBarSelectionText, config.colors.leftBarSelection)
os.sleep(0.2)
ecs.drawButton(obj["Scroll"][key][1], obj["Scroll"][key][2], 3, 3, key, config.colors.leftBarSelection, config.colors.leftBarSelectionText)
if key == "" then
if currentString > config.scrollSpeed then
currentString = currentString - config.scrollSpeed
drawMain()
drawScrollBar()
end
else
if currentString < (#stroki - config.scrollSpeed + 1) then
currentString = currentString + config.scrollSpeed
drawMain()
drawScrollBar()
end
end
break
end
end
elseif e[1] == "key_down" then
if e[4] == 28 then
gpu.setResolution(xOld, yOld)
ecs.prepareToExit()
event.cancel(timerID)
return
end
end
end