diff --git a/Applications.cfg b/Applications.cfg
index c79cb418..21464798 100644
--- a/Applications.cfg
+++ b/Applications.cfg
@@ -248,14 +248,14 @@
url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/advancedLua.lua",
type="Library",
preloadFile=true,
- version=1.15,
+ version=1.16,
},
{
path="/lib/web.lua",
url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/web.lua",
type="Library",
preloadFile=true,
- version=1.03,
+ version=1.04,
},
{
path="/lib/event.lua",
@@ -274,14 +274,14 @@
url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/color.lua",
type="Library",
preloadFile=true,
- version=1.08,
+ version=1.09,
},
{
path="/lib/ImageFormatModules/OCIF.lua",
url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/ImageFormatModules/OCIF.lua",
type="Library",
preloadFile=true,
- version=1.01,
+ version=1.02,
},
{
path="/lib/image.lua",
@@ -301,7 +301,7 @@
url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/GUI.lua",
type="Library",
preloadFile=true,
- version=1.68,
+ version=1.69,
},
{
path="/lib/rayEngine.lua",
@@ -537,6 +537,21 @@
url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Spinner/8.pic"
},
}
+ },
+ {
+ path="/MineOS/Applications/Translate",
+ url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Translate/Main.lua",
+ about="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Translate/About/",
+ type="Application",
+ icon="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Translate/Icon.pic",
+ createShortcut="desktop",
+ version=1.00,
+ resources={
+ {
+ path="/Logo.pic",
+ url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Translate/Logo.pic"
+ },
+ }
},
{
path="/MineOS/Applications/GeoScan2",
diff --git a/Applications/Translate/About/English.txt b/Applications/Translate/About/English.txt
new file mode 100644
index 00000000..5269dec0
--- /dev/null
+++ b/Applications/Translate/About/English.txt
@@ -0,0 +1 @@
+Fully functional Yandex translate tool that supports almost all existing languages
\ No newline at end of file
diff --git a/Applications/Translate/About/Russian.txt b/Applications/Translate/About/Russian.txt
new file mode 100755
index 00000000..92adc561
--- /dev/null
+++ b/Applications/Translate/About/Russian.txt
@@ -0,0 +1 @@
+Полноценный онлайн-переводчик, основанный на Yandex API, поддерживающий практически все существующие языки мира
\ No newline at end of file
diff --git a/Applications/Translate/Icon.pic b/Applications/Translate/Icon.pic
new file mode 100644
index 00000000..5f6fae5a
Binary files /dev/null and b/Applications/Translate/Icon.pic differ
diff --git a/Applications/Translate/Logo.pic b/Applications/Translate/Logo.pic
new file mode 100644
index 00000000..e5bed51b
Binary files /dev/null and b/Applications/Translate/Logo.pic differ
diff --git a/Applications/Translate/Main.lua b/Applications/Translate/Main.lua
new file mode 100644
index 00000000..8ad20d3e
--- /dev/null
+++ b/Applications/Translate/Main.lua
@@ -0,0 +1,115 @@
+
+require("advancedLua")
+local fs = require("filesystem")
+local json = require("json")
+local web = require("web")
+local GUI = require("GUI")
+local buffer = require("doubleBuffering")
+local image = require("image")
+local unicode = require("unicode")
+
+------------------------------------------------------------------------------------------------------------------
+
+local mainContainer = GUI.fullScreenContainer()
+mainContainer:addChild(GUI.panel(1, 1, mainContainer.width, mainContainer.height, 0x1E1E1E))
+local layout = mainContainer:addChild(GUI.layout(1, 1, mainContainer.width, mainContainer.height, 1, 1))
+
+local logo = layout:addChild(GUI.image(1, 1, image.load(fs.path(getCurrentScript()) .. "/Resources/Logo.pic")))
+local elementWidth = image.getWidth(logo.image)
+layout:addChild(GUI.object(1, 1, 1, 1))
+
+local fromComboBox = layout:addChild(GUI.comboBox(1, 1, elementWidth, 1, 0x2D2D2D, 0xAAAAAA, 0x444444, 0x888888))
+local fromInputField = layout:addChild(GUI.inputField(1, 1, elementWidth, 5, 0x2D2D2D, 0x666666, 0x444444, 0x3C3C3C, 0xBBBBBB, nil, "Введите текст"))
+local switchButton = layout:addChild(GUI.adaptiveRoundedButton(1, 1, 2, 1, 0x2D2D2D, 0xBBBBBB, 0x666666, 0xBBBBBB, "<>"))
+local toComboBox = layout:addChild(GUI.comboBox(1, 1, elementWidth, 1, 0x2D2D2D, 0xAAAAAA, 0x444444, 0x888888))
+local toInputField = layout:addChild(GUI.inputField(1, 1, elementWidth, 5, 0x2D2D2D, 0x666666, 0x444444, 0x3C3C3C, 0xBBBBBB, nil, "Введите текст"))
+local infoLabel = layout:addChild(GUI.label(1, 1, layout.width, 1, 0xFF6D40, " "):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.top))
+
+------------------------------------------------------------------------------------------------------------------
+
+local languages
+local function updateLanguages()
+ local result, reason = web.request("https://translate.yandex.net/api/v1.5/tr.json/getLangs?key=trnsl.1.1.20170831T153247Z.6ecf9d7198504994.8ce5a3aa9f9a2ecbe7b2377af37ffe5ad379f4ca&ui=ru")
+ if result then
+ fromComboBox:clear()
+ toComboBox:clear()
+ languages = {}
+
+ local yandexArray = json:decode(result)
+ for key, value in pairs(yandexArray.langs) do
+ table.insert(languages, {short = key, full = value})
+ end
+ table.sort(languages, function(a, b) return a.full < b.full end)
+ for i = 1, #languages do
+ fromComboBox:addItem(languages[i].full)
+ toComboBox:addItem(languages[i].full)
+ end
+ else
+ infoLabel.text = "Ошибка получения списка языков: " .. tostring(reason)
+ mainContainer:draw()
+ buffer.draw()
+ end
+end
+
+local function getLanguageIndex(text)
+ for i = 1, #languages do
+ if languages[i].full == text then
+ return i
+ end
+ end
+ error("CYKA BLYAD LANG NOT FOUND")
+end
+
+local function translate(text, direction)
+ if text then
+ infoLabel.text = "Отправка запроса на перевод..."
+ mainContainer:draw()
+ buffer.draw()
+
+ local first, second = fromComboBox:getItem(fromComboBox.selectedItem).text, toComboBox:getItem(toComboBox.selectedItem).text
+ if not direction then
+ first, second = second, first
+ end
+
+ local result, reason = web.request("https://translate.yandex.net/api/v1.5/tr.json/translate?key=trnsl.1.1.20170831T153247Z.6ecf9d7198504994.8ce5a3aa9f9a2ecbe7b2377af37ffe5ad379f4ca&text=" .. string.optimizeForURLRequests(text) .. "&lang=" .. languages[getLanguageIndex(first)].short .. "-" .. languages[getLanguageIndex(second)].short)
+ if result then
+ result = json:decode(result).text[1]
+ if direction then
+ toInputField.text = result
+ else
+ fromInputField.text = result
+ end
+ infoLabel.text = " "
+ else
+ infoLabel.text = "Ошибка запроса на перевод: " .. tostring(reason)
+ end
+
+ mainContainer:draw()
+ buffer.draw()
+ end
+end
+
+fromInputField.onInputFinished = function()
+ translate(fromInputField.text, true)
+end
+
+toInputField.onInputFinished = function()
+ translate(fromInputField.text, false)
+end
+
+switchButton.onTouch = function()
+ fromComboBox.selectedItem, toComboBox.selectedItem = toComboBox.selectedItem, fromComboBox.selectedItem
+ mainContainer:draw()
+ buffer.draw()
+end
+
+------------------------------------------------------------------------------------------------------------------
+
+updateLanguages()
+fromComboBox.selectedItem = getLanguageIndex("Русский")
+toComboBox.selectedItem = getLanguageIndex("Английский")
+mainContainer:draw()
+buffer.draw(true)
+mainContainer:startEventHandling()
+
+
diff --git a/ImageConverter/.idea/workspace.xml b/ImageConverter/.idea/workspace.xml
index ae8b395a..090ff492 100644
--- a/ImageConverter/.idea/workspace.xml
+++ b/ImageConverter/.idea/workspace.xml
@@ -64,11 +64,23 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -131,7 +143,7 @@
-
+
@@ -151,8 +163,6 @@
-
-
@@ -221,6 +231,8 @@
+
+
@@ -507,8 +519,7 @@
-
-
+
@@ -519,7 +530,7 @@
-
+
@@ -564,17 +575,6 @@
-
-
-
-
-
-
-
-
-
-
-
@@ -620,15 +620,15 @@
-
-
-
+
+
+
@@ -685,15 +685,15 @@
-
-
-
+
+
+
@@ -750,15 +750,15 @@
-
-
-
+
+
+
@@ -825,15 +825,15 @@
-
-
-
+
+
+
@@ -916,12 +916,6 @@
-
-
-
-
-
-
@@ -945,16 +939,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -972,20 +956,35 @@
-
-
-
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/GUI.lua b/lib/GUI.lua
index 17ec9f28..3fe4dff2 100755
--- a/lib/GUI.lua
+++ b/lib/GUI.lua
@@ -283,7 +283,11 @@ function GUI.addChildToContainer(container, object, atIndex)
object.parent = container
object.addAnimation = containerObjectAddAnimation
- table.insert(container.children, object)
+ if atIndex then
+ table.insert(container.children, atIndex, object)
+ else
+ table.insert(container.children, object)
+ end
return object
end
@@ -1628,7 +1632,7 @@ local function inputBeginInput(input)
input.text = unicode.sub(input.text, 1, input.cursorPosition - 1) .. e[3] .. unicode.sub(input.text, input.cursorPosition, -1)
input:setCursorPosition(input.cursorPosition + unicode.len(e[3]))
input.cursorBlinkState = true; input:draw(); buffer.draw()
- else
+ elseif not e[1] then
input.cursorBlinkState = not input.cursorBlinkState; input:draw(); buffer.draw()
end
end
@@ -2024,6 +2028,24 @@ local function drawComboBox(object)
return object
end
+local function comboBoxGetItem(object, index)
+ return object.dropDownMenu.itemsContainer.children[index]
+end
+
+local function comboBoxClear(object)
+ object.dropDownMenu.itemsContainer:deleteChildren()
+
+ return object
+end
+
+local function comboBoxIndexOfItem(object, text)
+ for i = 1, #object.dropDownMenu.itemsContainer.children do
+ if object.dropDownMenu.itemsContainer.children[i].text == text then
+ return i
+ end
+ end
+end
+
local function selectComboBoxItem(object)
object.pressed = true
object:draw()
@@ -2080,6 +2102,9 @@ function GUI.comboBox(x, y, width, elementHeight, backgroundColor, textColor, ar
object.addSeparator = comboBoxAddSeparator
object.draw = drawComboBox
object.selectItem = selectComboBoxItem
+ object.clear = comboBoxClear
+ object.indexOfItem = comboBoxIndexOfItem
+ object.getItem = comboBoxGetItem
return object
end
diff --git a/lib/ImageFormatModules/OCIF.lua b/lib/ImageFormatModules/OCIF.lua
index 8c5c9a24..07144ce3 100755
--- a/lib/ImageFormatModules/OCIF.lua
+++ b/lib/ImageFormatModules/OCIF.lua
@@ -38,19 +38,30 @@ end
---------------------------------------- Uncompressed OCIF1 encoding ----------------------------------------
-encodingMethods.save[1] = function(file, picture)
+encodingMethods.save[5] = function(file, picture)
for i = 3, #picture, 4 do
- writeByteArrayToFile(file, {color.HEXToRGB(picture[i])})
- writeByteArrayToFile(file, {color.HEXToRGB(picture[i + 1])})
+ -- writeByteArrayToFile(file, {color.HEXToRGB(picture[i])})
+ -- writeByteArrayToFile(file, {color.HEXToRGB(picture[i + 1])})
+
+ file:write(string.char(color.to8Bit(picture[i])))
+ file:write(string.char(color.to8Bit(picture[i + 1])))
+
file:write(string.char(picture[i + 2]))
writeByteArrayToFile(file, {string.byte(picture[i + 3], 1, 6)})
end
end
-encodingMethods.load[1] = function(file, picture)
+encodingMethods.load[5] = function(file, picture)
+ table.insert(picture, readNumberFromFile(file, 2))
+ table.insert(picture, readNumberFromFile(file, 2))
+
for i = 1, image.getWidth(picture) * image.getHeight(picture) do
- table.insert(picture, color.RGBToHEX(string.byte(file:read(1)), string.byte(file:read(1)), string.byte(file:read(1))))
- table.insert(picture, color.RGBToHEX(string.byte(file:read(1)), string.byte(file:read(1)), string.byte(file:read(1))))
+ -- table.insert(picture, color.RGBToHEX(string.byte(file:read(1)), string.byte(file:read(1)), string.byte(file:read(1))))
+ -- table.insert(picture, color.RGBToHEX(string.byte(file:read(1)), string.byte(file:read(1)), string.byte(file:read(1))))
+
+ table.insert(picture, color.to24Bit(string.byte(file:read(1))))
+ table.insert(picture, color.to24Bit(string.byte(file:read(1))))
+
table.insert(picture, string.byte(file:read(1)))
table.insert(picture, string.readUnicodeChar(file))
end
@@ -105,6 +116,9 @@ encodingMethods.save[6] = function(file, picture)
end
encodingMethods.load[6] = function(file, picture)
+ table.insert(picture, string.byte(file:read(1)))
+ table.insert(picture, string.byte(file:read(1)))
+
local currentAlpha, currentSymbol, currentBackground, currentForeground, currentY, currentX
local alphaSize, symbolSize, backgroundSize, foregroundSize, ySize, xSize
@@ -150,11 +164,10 @@ function module.load(path)
if readedSignature == OCIFSignature then
local encodingMethod = string.byte(file:read(1))
if encodingMethods.load[encodingMethod] then
- -- Reading width and height of a picture
- local picture = {string.byte(file:read(1)), string.byte(file:read(1))}
- -- Continue parsing
+ local picture = {}
encodingMethods.load[encodingMethod](file, picture)
file:close()
+
return picture
else
file:close()
diff --git a/lib/advancedLua.lua b/lib/advancedLua.lua
index d7c6c8ed..736459c5 100755
--- a/lib/advancedLua.lua
+++ b/lib/advancedLua.lua
@@ -1,6 +1,6 @@
--[[
-
+
Advanced Lua Library v1.1 by ECS
This library extends a lot of default Lua methods
@@ -70,7 +70,7 @@ end
-- Split nubmer to it's own bytes with specified count of bytes (0xAABB, 5 -> {0x00, 0x00, 0x00, 0xAA, 0xBB})
function bit32.numberToFixedSizeByteArray(number, size)
local byteArray, counter = {}, 0
-
+
repeat
table.insert(byteArray, 1, bit32.band(number, 0xFF))
number = bit32.rshift(number, 8)
@@ -100,13 +100,12 @@ function bit32.bitArrayToByte(bitArray)
for i = 1, #bitArray do
number = bit32.bor(bitArray[i], bit32.lshift(number, 1))
end
-
return number
end
-------------------------------------------------- Math extensions --------------------------------------------------
-function math.round(num)
+function math.round(num)
if num >= 0 then
return math.floor(num + 0.5)
else
@@ -208,7 +207,7 @@ function filesystem.sortedList(path, sortingMethod, showHiddenFiles)
currentExtensionList, currentExtension = {fileList[i][1]}, fileList[i][2]
end
end
-
+
table.sort(currentExtensionList, function(a, b) return a < b end)
for j = 1, #currentExtensionList do
table.insert(sortedFileList, currentExtensionList[j])
@@ -252,7 +251,7 @@ function filesystem.directorySize(path)
size = size + filesystem.size(path .. file)
end
end
-
+
return size
end
@@ -261,7 +260,7 @@ end
local function doSerialize(array, prettyLook, indentationSymbol, indentationSymbolAdder, equalsSymbol, currentRecusrionStack, recursionStackLimit)
local text, keyType, valueType, stringValue = {"{"}
table.insert(text, (prettyLook and "\n" or nil))
-
+
for key, value in pairs(array) do
keyType, valueType, stringValue = type(key), type(value), tostring(value)
@@ -271,7 +270,7 @@ local function doSerialize(array, prettyLook, indentationSymbol, indentationSymb
table.insert(text, (keyType == "string" and table.concat({"\"", key, "\""}) or key))
table.insert(text, "]")
table.insert(text, equalsSymbol)
-
+
if valueType == "number" or valueType == "boolean" or valueType == "nil" then
table.insert(text, stringValue)
elseif valueType == "string" or valueType == "function" then
@@ -286,7 +285,7 @@ local function doSerialize(array, prettyLook, indentationSymbol, indentationSymb
table.insert(text, "...")
end
end
-
+
table.insert(text, ",")
table.insert(text, (prettyLook and "\n" or nil))
end
@@ -417,7 +416,7 @@ end
function table.indexOf(t, object)
for i = 1, #t do
- if t[i] == object then
+ if t[i] == object then
return i
end
end
@@ -460,7 +459,7 @@ function string.optimizeForURLRequests(code)
end)
code = string.gsub(code, " ", "+")
end
- return code
+ return code
end
function string.unicodeFind(str, pattern, init, plain)
@@ -471,9 +470,9 @@ function string.unicodeFind(str, pattern, init, plain)
init = #unicode.sub(str, 1, init - 1) + 1
end
end
-
+
a, b = string.find(str, pattern, init, plain)
-
+
if a then
local ap, bp = str:sub(1, a - 1), str:sub(a,b)
a = unicode.len(ap) + 1
@@ -528,7 +527,7 @@ function string.wrap(strings, limit)
strings[currentString + 1] = right .. " " .. strings[currentString + 1]
else
strings[currentString + 1] = right
- end
+ end
end
break
else
@@ -579,3 +578,5 @@ end
------------------------------------------------------------------------------------------------------------------
return {loaded = true}
+
+
diff --git a/lib/color.lua b/lib/color.lua
index 7dfd2cc4..b2f17140 100755
--- a/lib/color.lua
+++ b/lib/color.lua
@@ -156,6 +156,18 @@ function color.optimize(color24Bit)
return color.to24Bit(color.to8Bit(color24Bit))
end
+function color.blendRGBA(c1, c2, a1, a2)
+ local oneMinusA1, oneMinusA2 = 1 - a1, 1 - a2
+ return
+ color.blend(c1, c2, a2),
+ 1 - (oneMinusA1 + a1 * oneMinusA2)
+end
+
+-----------------------------------------------------------------------------------------------------------------------
+
+-- local c, a = color.blendRGBA(0x0000FF, 0xFF0000, 0.5, 0.5)
+-- print(string.format("0x%06X", c), a)
+
-----------------------------------------------------------------------------------------------------------------------
return color