Улучшение фотошопа, улучшение либы подсветки синтаксиса, тестовая версия МайнКода на замену Хайлайту

This commit is contained in:
Igor Timofeev 2016-03-26 12:29:33 +03:00
parent c2930947da
commit 857a4c7872
11 changed files with 384 additions and 999 deletions

View File

@ -251,6 +251,12 @@
----------------------------------------------------- Библиотеки --------------------------------------------------------------------------
{
["name"]="lib/filemanager.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/filemanager.lua",
["type"]="Library",
["version"]=1.0,
},
{
["name"]="lib/modemConnection.lua",
["url"]="IgorTimofeev/OpenComputers/master/lib/modemConnection.lua",
@ -752,18 +758,11 @@
},
},
{
["name"]="MineOS/Applications/Highlight",
["url"]="IgorTimofeev/OpenComputers/master/Applications/Highlight/Highlight.lua",
["type"]="Application",
["icon"]="IgorTimofeev/OpenComputers/master/Applications/Highlight/Icon.pic",
["name"]="MineOS/Applications/MineCode",
["url"]="IgorTimofeev/OpenComputers/master/Applications/MineCode/MineCode.lua",
["icon"]="IgorTimofeev/OpenComputers/master/Applications/MineCode/Icon.pic",
["createShortcut"] = "desktop",
["version"]=1.0,
["resources"]={
{
["name"]="TestFile.txt",
["url"]="IgorTimofeev/OpenComputers/master/Applications/Highlight/TestFile.txt",
},
},
},
{
["name"]="MineOS/Applications/HoloEdit",

View File

@ -3,10 +3,11 @@ ecs.prepareToExit()
local data = ecs.universalWindow("auto", "auto", 40, 0xeeeeee, true, {"EmptyLine"}, {"CenterText", 0x262626, "Enter path to file"}, {"EmptyLine"}, {"Input", 0x262626, 0x880000, "MineOS/Applications/Highlight.app/Resources/TestFile.txt"}, {"EmptyLine"}, {"Button", {0x33db80, 0xffffff, "GO!"}})
local path = data[1]
local strings = syntax.convertFileToStrings(path)
local strings, maxStringWidth = syntax.convertFileToStrings(path)
local xSize, ySize = gpu.getResolution()
buffer.square(1, 1, xSize, ySize, ecs.colors.green, 0xFFFFFF, " ")
buffer.draw(true)
syntax.viewCode(2, 2, 70, 20, strings, 1, 1, true, {from = {x = 6, y = 2}, to = {x = 3, y = 8}})
syntax.viewCode(2, 2, 70, 20, strings, maxStringWidth, 1, 1, true, {from = {x = 6, y = 2}, to = {x = 10, y = 4}})
buffer.draw()
ecs.waitForTouchOrClick()

View File

@ -1,8 +0,0 @@
topMenuFile = File
topMenuEdit = Edit
topMenuFind = Find
topMenuView = View
topMenuGoto = Goto
infoPanelNewProject = New project
infoPanelString = String
infoPanelStringOf = of

Binary file not shown.

View File

@ -1,4 +0,0 @@
c3c3c3 ffffff c3c3c3 ffffff ffffff c3c3c3 ffffff 0f0f0f ffffff 0f0f0f ffffff 0f0f0f c3c3c3 ffffff c3c3c3 ffffff
5a5a5a c3c3c3 1 2d2d2d 339240 - 2d2d2d 339240 - 2d2d2d 339240 П 2d2d2d 339240 р 2d2d2d 339240 о 2d2d2d 339240 г 2d2d2d 339240 а
5a5a5a c3c3c3 2 2d2d2d ffffff l 2d2d2d ffffff o 2d2d2d ffffff c 2d2d2d ffffff a 2d2d2d ffffff l 2d2d2d ffffff 2d2d2d ffffff i
5a5a5a c3c3c3 3 2d2d2d ffffff 2d2d2d ffffff 2d2d2d ffffff p 2d2d2d ffffff r 2d2d2d ffffff i 2d2d2d ffffff n 2d2d2d ffffff t

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +0,0 @@
topMenuFile = Файл
topMenuEdit = Правка
topMenuFind = Поиск
topMenuView = Вид
topMenuGoto = Переход
infoPanelNewProject = Новый проект
infoPanelString = Строка
infoPanelStringOf = из

View File

@ -387,12 +387,16 @@ local function inputText(x, y, limit)
elseif e[4] == 28 then
break
elseif e[4] == 200 then
text = ""
inputPos = 1
text = text .. ""
if unicode.len(text) < limit then
inputPos = inputPos + 1
end
drawThisShit()
elseif e[4] == 208 then
text = ""
inputPos = 1
text = text .. ""
if unicode.len(text) < limit then
inputPos = inputPos + 1
end
drawThisShit()
else
local symbol = ecs.convertCodeToSymbol(e[3])

View File

@ -108,7 +108,7 @@ function buffer.square(x, y, width, height, background, foreground, symbol, tran
local index, indexPlus1, indexPlus2
if transparency then transparency = transparency * 2.55 end
if not foreground then foreground = 0x000000 end
if symbol == " " then foreground = 0x000000 elseif not symbol then symbol = " " end
-- if symbol == " " then foreground = 0x000000 elseif not symbol then symbol = " " end
for j = y, (y + height - 1) do
for i = x, (x + width - 1) do
@ -323,7 +323,8 @@ function buffer.image(x, y, picture)
end
--Если символ равен пробелу, то сбрасываем цвет текста на ноль
buffer.screen.new[indexPlus1] = picture[imageIndexPlus3] == " " and 0x000000 or picture[imageIndexPlus1]
-- buffer.screen.new[indexPlus1] = picture[imageIndexPlus3] == " " and 0x000000 or picture[imageIndexPlus1]
buffer.screen.new[indexPlus1] = picture[imageIndexPlus1]
buffer.screen.new[indexPlus2] = picture[imageIndexPlus3]
end
end
@ -353,7 +354,7 @@ end
-- Вертикальный скролл-бар
function buffer.scrollBar(x, y, width, height, countOfAllElements, currentElement, backColor, frontColor)
local sizeOfScrollBar = math.ceil(1 / countOfAllElements * height)
local sizeOfScrollBar = math.ceil(height / countOfAllElements)
local displayBarFrom = math.floor(y + height * ((currentElement - 1) / countOfAllElements))
buffer.square(x, y, width, height, backColor, 0xFFFFFF, " ")
@ -362,6 +363,14 @@ function buffer.scrollBar(x, y, width, height, countOfAllElements, currentElemen
sizeOfScrollBar, displayBarFrom = nil, nil
end
function buffer.horizontalScrollBar(x, y, width, countOfAllElements, currentElement, background, foreground)
local pipeSize = math.ceil(width / countOfAllElements)
local displayBarFrom = math.floor(x + width * ((currentElement - 1) / countOfAllElements))
buffer.text(x, y, background, string.rep("", width))
buffer.text(displayBarFrom, y, foreground, string.rep("", pipeSize))
end
-- Отрисовка любого изображения в виде трехмерного массива. Неоптимизированно, зато просто.
function buffer.customImage(x, y, pixels)
x = x - 1

96
lib/filemanager.lua Normal file
View File

@ -0,0 +1,96 @@
_G.fs = require("filesystem")
_G.buffer = require("doubleBuffering")
local filemanager = {}
local massiv = {
{
name = "Root",
showContent = true,
content = {
{
name = "File1",
},
{
name = "File2",
},
{
name = "Folder1",
showContent = true,
content = {
{
name = "FileInFolder1",
},
{
name = "FileInFolder2",
},
{
name = "FolderInFolder1",
showContent = true,
content = {
{
name = "FileInFolderInFolder1",
},
},
},
},
},
{
name = "File3",
},
{
name = "File4",
},
},
},
}
filemanager.colors = {
background = 0xcccccc,
text = 0x262626,
scrollBar = 0x444444,
scrollBarPipe = 0x24c0ff,
}
local function recursiveDraw(x, y, array)
for i = 1, #array do
if array[i].content then
if array[i].showContent then
buffer.text(x, y, filemanager.colors.text, "" .. array[i].name)
y = y + 1
_, y = recursiveDraw(x + 2, y, array[i].content)
else
buffer.text(x, y, filemanager.colors.text, "> ▄ " .. array[i].name)
y = y + 1
end
else
buffer.text(x, y, filemanager.colors.text, "" .. array[i].name)
y = y + 1
end
end
return x, y
end
function filemanager.draw(x, y, width, height, path, fromElement)
buffer.square(x, y, width, height, filemanager.colors.background, 0xFFFFFF, " ")
buffer.setDrawLimit(x, y, width - 2, height)
recursiveDraw(x + 1, y, massiv)
buffer.resetDrawLimit()
buffer.scrollBar(x + width - 1, y, 1, height, #massiv, 1, filemanager.colors.scrollBar, filemanager.colors.scrollBarPipe)
end
return filemanager

View File

@ -1,6 +1,6 @@
local gpu = require("component").gpu
local buffer = require("doubleBuffering")
local unicode = require("unicode")
_G.buffer = require("doubleBuffering")
_G.unicode = require("unicode")
local syntax = {}
----------------------------------------------------------------------------------------------------------------------------------------
@ -179,36 +179,41 @@ end
function syntax.convertFileToStrings(path)
local array = {}
local maximumStringWidth = 0
local file = io.open(path, "r")
for line in file:lines() do
line = string.gsub(line, " ", string.rep(" ", 4))
maximumStringWidth = math.max(maximumStringWidth, unicode.len(line))
table.insert(array, line)
end
file:close()
return array
return array, maximumStringWidth
end
-- Открыть окно-просмотрщик кода
function syntax.viewCode(x, y, width, height, strings, fromSymbol, fromString, highlightLuaSyntax, selection, highlightedStrings)
function syntax.viewCode(x, y, width, height, strings, maximumStringWidth, fromSymbol, fromString, highlightLuaSyntax, selection, highlightedStrings)
--Рассчитываем максимальное количество строк, которое мы будем отображать
local maximumNumberOfAvailableStrings, yPos
if strings[fromString + height - 1] then
maximumNumberOfAvailableStrings = fromString + height - 1
maximumNumberOfAvailableStrings = fromString + height - 2
else
maximumNumberOfAvailableStrings = #strings
maximumNumberOfAvailableStrings = #strings - 1
end
--Рассчитываем ширину полоски с номерами строк
local widthOfStringCounter = unicode.len(maximumNumberOfAvailableStrings) + 2
--Рассчитываем стратовую позицию текстового поля
local textFieldPosition = x + widthOfStringCounter
local widthOfText = width - widthOfStringCounter - 3
local xEnd, yEnd = x + width - 1, y + height - 1
--Рисуем подложку под текст
buffer.square(textFieldPosition, y, width - widthOfStringCounter - 1, height, currentColorScheme.background, 0xFFFFFF, " ")
--Рисуем скроллбар
buffer.scrollBar(x + width - 1, y, 1, height, #strings, fromString, currentColorScheme.scrollBar, currentColorScheme.scrollBarPipe)
--Рисуем номера строк
buffer.square(x, y, width, height, currentColorScheme.background, 0xFFFFFF, " ")
--Рисуем подложку под номера строк
buffer.square(x, y, widthOfStringCounter, height, currentColorScheme.lineNumbers, 0xFFFFFF, " ")
--Рисуем вертикальный скроллбар
buffer.scrollBar(xEnd, y, 1, height, #strings, fromString, currentColorScheme.scrollBar, currentColorScheme.scrollBarPipe)
--Рисуем горизонтальный скроллбар
buffer.horizontalScrollBar(x + widthOfStringCounter, yEnd, width - widthOfStringCounter - 1, maximumStringWidth, fromSymbol, currentColorScheme.scrollBar, currentColorScheme.scrollBarPipe)
--Подсвечиваем некоторые строки, если указано
if highlightedStrings then
@ -220,6 +225,7 @@ function syntax.viewCode(x, y, width, height, strings, fromSymbol, fromString, h
end
end
--Рисуем номера строк
yPos = y
for i = fromString, maximumNumberOfAvailableStrings do
buffer.text(x + widthOfStringCounter - unicode.len(i) - 1, yPos, currentColorScheme.text, tostring(i))
@ -276,8 +282,6 @@ function syntax.viewCode(x, y, width, height, strings, fromSymbol, fromString, h
yPos = yPos + 1
end
--Рисуем изменения из буфера
buffer.draw()
--Убираем ограничение отрисовки
buffer.resetDrawLimit()
@ -290,7 +294,7 @@ end
syntax.setColorScheme(syntax.colorSchemes.midnight)
-- -- Епты бля!
-- local strings = syntax.convertFileToStrings("MineOS/Applications/Highlight.app/Resources/TestFile.txt")
-- local strings, maximumStringWidth = syntax.convertFileToStrings("MineOS/Applications/Highlight.app/Resources/TestFile.txt")
-- local strings = syntax.convertFileToStrings("OS.lua")
-- local xSize, ySize = gpu.getResolution()
@ -307,7 +311,7 @@ syntax.setColorScheme(syntax.colorSchemes.midnight)
-- {number = 32, color = 0xFF4444},
-- }
-- syntax.viewCode(20, 5, 100, 40, strings, 1, 20, true, selection, highlightedStrings)
-- syntax.viewCode(20, 5, 100, 40, strings, maximumStringWidth, 1, 20, true, selection, highlightedStrings)
----------------------------------------------------------------------------------------------------------------