From 035d94ba3f708f4c0d55c110a9afed50a3eb4ca2 Mon Sep 17 00:00:00 2001 From: Igor Timofeev Date: Wed, 11 Oct 2017 21:42:40 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D0=BE=D0=B5=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=82=D1=80=D0=B8=D1=81=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=B3=D1=80=D0=B0=D1=84=D0=B8=D0=BA=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=B8=20=D0=BF=D0=B0=D1=80=D0=B0=20=D0=B1=D0=B0=D0=B3=D1=84?= =?UTF-8?q?=D0=B8=D0=BA=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Applications.cfg | 18 +-- Applications/Braille/Main.lua | 19 ++- Applications/Graph2/Icon.pic | Bin 0 -> 161 bytes Applications/Graph2/Main.lua | 144 +++++++++++++++++ Documentation/GUI.md | 40 +++-- OS.lua | 10 +- lib/GUI.lua | 287 ++++++++++++++++++---------------- lib/MineOSInterface.lua | 29 ++-- lib/doubleBuffering.lua | 12 +- lib/syntax.lua | 4 +- 10 files changed, 366 insertions(+), 197 deletions(-) create mode 100644 Applications/Graph2/Icon.pic create mode 100644 Applications/Graph2/Main.lua diff --git a/Applications.cfg b/Applications.cfg index 1aa16e3b..b13c68f2 100644 --- a/Applications.cfg +++ b/Applications.cfg @@ -5,7 +5,7 @@ about="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Localization/About/", type="Script", forceDownload=true, - version=3.91, + version=3.92, }, { path="/MineOS/Pictures/MoonTouch.pic", @@ -236,7 +236,7 @@ path="/lib/MineOSInterface.lua", url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/MineOSInterface.lua", type="Library", - version=1.04, + version=1.05, }, { path="/lib/MineOSPaths.lua", @@ -303,7 +303,7 @@ url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/GUI.lua", type="Library", preloadFile=true, - version=1.82, + version=1.83, }, { path="/lib/rayEngine.lua", @@ -333,7 +333,7 @@ path="/lib/syntax.lua", url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/syntax.lua", type="Library", - version=1.16, + version=1.17, }, { path="/lib/palette.lua", @@ -346,7 +346,7 @@ url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/doubleBuffering.lua", type="Library", preloadFile=true, - version=1.31, + version=1.32, }, { path="/lib/compressor.lua", @@ -838,12 +838,12 @@ version=1.01, }, { - path="/MineOS/Applications/Graph", - url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Graph/Graph.lua", + path="/MineOS/Applications/Graph2", + url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Graph2/Main.lua", type="Application", - icon="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Graph/Icon.pic", + icon="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Graph2/Icon.pic", createShortcut=true, - version=1.03, + version=1.00, }, { path="/MineOS/Applications/Battleship", diff --git a/Applications/Braille/Main.lua b/Applications/Braille/Main.lua index e3367514..07542ec6 100644 --- a/Applications/Braille/Main.lua +++ b/Applications/Braille/Main.lua @@ -54,8 +54,8 @@ local function newCell(x, y, shaded) object.background = colorSelector1.color object.foreground = colorSelector2.color - -- CTRL or CMD - if keyboard.isKeyDown(29) or keyboard.isKeyDown(219) then + -- CTRL or CMD or ALT + if keyboard.isKeyDown(29) or keyboard.isKeyDown(219) or keyboard.isKeyDown(56) then object.pixels[y][x] = nil else object.pixels[y][x] = eventData[5] == 0 and 1 or 0 @@ -72,22 +72,19 @@ end local drawingArea = window:addChild(GUI.container(1, 4, 1, 1)) --- local lines = { --- "LMB/RMB - draw with foreground/background", --- "Ctrl+LMB - erase" --- } --- window:addChild(GUI.textBox(1, 1, window.width, #lines, nil, 0x555555, lines, 1, 0, 0)):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.top) - - local function getBrailleChar(a, b, c, d, e, f, g, h) return unicode.char(10240 + 128*h + 64*g + 32*f + 16*d + 8*b + 4*e + 2*c + a) end local function newNoGUI(width, height) drawingArea.width, drawingArea.height = width * 4, height * 4 - window.width, window.height = drawingArea.width, drawingArea.height + 3 + + window.width = drawingArea.width + window.height = drawingArea.height + 3 + panel.width = window.width layout.width = panel.width + drawingArea:deleteChildren() @@ -201,6 +198,8 @@ end actionButtons.close.onTouch = function() window:close() end +actionButtons.minimize:delete() +actionButtons.maximize:delete() --------------------------------------------------------------------------------------------------------- diff --git a/Applications/Graph2/Icon.pic b/Applications/Graph2/Icon.pic new file mode 100644 index 0000000000000000000000000000000000000000..4e74cc44f455197724f65e3ed48314abca7771fc GIT binary patch literal 161 zcmXYpF%H5o3`O(p#EHbQkdQiYB^ZH~1Gr`F(6PM;2k=R-Lnc4{|DUht=^`y7rIYCs zUnDS!>3d){y*a)ZLY#{ scaleSlider.maximumValue then + scaleSlider.value = scaleSlider.maximumValue + end + + update() + + mainContainer:draw() + buffer.draw() + end +end + +--------------------------------------------------------------------------------------------------------- + +update() +mainContainer:draw() +buffer.draw() + + + diff --git a/Documentation/GUI.md b/Documentation/GUI.md index 424bc868..89897751 100644 --- a/Documentation/GUI.md +++ b/Documentation/GUI.md @@ -1106,18 +1106,23 @@ local buffer = require("doubleBuffering") local GUI = require("GUI") local unicode = require("unicode") +------------------------------------------------------------------------------------------ + local mainContainer = GUI.fullScreenContainer() mainContainer:addChild(GUI.panel(1, 1, mainContainer.width, mainContainer.height, 0x0)) -local codeView = mainContainer:addCodeView(2, 2, 130, 40, {}, 1, 1, 1, {}, {}, true, 2) -local file = io.open("/lib/OpenComputersGL/Main.lua", "r") +local codeView = mainContainer:addChild(GUI.codeView(2, 2, 130, 30, {}, 1, 1, 1, {}, {}, true, 2)) + +local file = io.open("/lib/color.lua", "r") for line in file:lines() do - line = line:gsub("\t", " ") + line = line:gsub("\t", " "):gsub("\r\n", "\n") table.insert(codeView.lines, line) codeView.maximumLineLength = math.max(codeView.maximumLineLength, unicode.len(line)) end file:close() +------------------------------------------------------------------------------------------ + mainContainer:draw() buffer.draw(true) mainContainer:startEventHandling() @@ -1125,7 +1130,7 @@ mainContainer:startEventHandling() Результат: -![enter image description here](http://i89.fastpic.ru/big/2017/0402/a9/a00b12a34bf367940dccde93d28b03a9.png) +![](https://i.imgur.com/o1yLMJr.png) GUI.**chart**( x, y, width, height, axisColor, axisValueColor, axisHelpersColor, chartColor, xAxisValueInterval, yAxisValueInterval, xAxisPostfix, yAxisPostfix, fillChartArea, values ): *table* chart ------------------------------------------------------------------------ @@ -1229,7 +1234,7 @@ mainContainer:startEventHandling() ![Imgur](http://i.imgur.com/3Oq1nzY.png) -GUI.**scrollBar**( x, y, width, height, backgroundColor, foregroundColor, minimumValue, maximumValue, value, shownValueCount, onScrollValueIncrement, thinHorizontalMode ): *table* scrollBar +GUI.**scrollBar**( x, y, width, height, backgroundColor, foregroundColor, minimumValue, maximumValue, value, shownValueCount, onScrollValueIncrement, thinMode ): *table* scrollBar ------------------------------------------------------------------------ | Тип | Аргумент | Описание | | ------ | ------ | ------ | @@ -1244,7 +1249,7 @@ GUI.**scrollBar**( x, y, width, height, backgroundColor, foregroundColor, minimu | *int* | value | Текущее значение scrollBar | | *int* | shownValueCount | Число "отображаемых" значений scrollBar | | *int* | onScrollValueIncrement | Количество строк, пролистываемых при прокрутке | -| *boolean* | thinHorizontalMode | Режим отображения scrollBar в полупиксельном виде при горизонтальной ориентации | +| *boolean* | thinMode | Режим отображения scrollBar в тонком пиксельном виде | Создать объект типа "ScrollBar", предназначенный для визуальной демонстрации числа показанных объектов на экране. Сам по себе практически не используется, полезен в совокупности с другими виджетами. @@ -1259,14 +1264,25 @@ GUI.**scrollBar**( x, y, width, height, backgroundColor, foregroundColor, minimu local buffer = require("doubleBuffering") local GUI = require("GUI") -local mainContainer = GUI.fullScreenContainer() -mainContainer:addChild(GUI.panel(1, 1, mainContainer.width, mainContainer.height, 0x0)) +------------------------------------------------------------------------------------------ -local scrollBar = mainContainer:addChild(GUI.scrollBar(2, 2, 1, 30, 0xEEEEEE, 0x3366CC, 1, 100, 1, 10, 1, false)) -scrollBar.onTouch = function() - -- Do something on scrollBar touch +local mainContainer = GUI.fullScreenContainer() +mainContainer:addChild(GUI.panel(1, 1, mainContainer.width, mainContainer.height, 0x2D2D2D)) + +-- Добавляем вертикальный скроллбар в главный контейнер +local verticalScrollBar = mainContainer:addChild(GUI.scrollBar(2, 3, 1, 15, 0x444444, 0x888888, 1, 100, 1, 10, 1, true)) +verticalScrollBar.onTouch = function() + GUI.error("Vertical scrollbar was touched") end +-- И горизонтальный заодно тоже +local horizontalScrollBar = mainContainer:addChild(GUI.scrollBar(3, 2, 60, 1, 0x444444, 0x888888, 1, 100, 1, 10, 1, true)) +horizontalScrollBar.onTouch = function() + GUI.error("Horizontal scrollbar was touched") +end + +------------------------------------------------------------------------------------------ + mainContainer:draw() buffer.draw(true) mainContainer:startEventHandling() @@ -1274,7 +1290,7 @@ mainContainer:startEventHandling() Результат: -![enter image description here](http://i89.fastpic.ru/big/2017/0402/90/b78e291e777f9bcb84802ef6451bc790.png) +![enter image description here](https://i.imgur.com/XrqDvBk.png) GUI.**textBox**(x, y, width, height, backgroundColor, textColor, lines, currentLine, horizontalOffset, verticalOffset): *table* textBox ------------------------------------------------------------------------ diff --git a/OS.lua b/OS.lua index b0ba1463..ac287e49 100755 --- a/OS.lua +++ b/OS.lua @@ -23,6 +23,7 @@ local copyright = { ---------------------------------------------- Либсы-хуибсы ------------------------------------------------------------------------ +-- package.loaded.MineOSInterface = nil -- package.loaded.MineOSCore = nil local computer = require("computer") @@ -41,7 +42,7 @@ local MineOSInterface = require("MineOSInterface") ---------------------------------------------- Всякая константная залупа ------------------------------------------------------------------------ local menuTransparency = 0.2 -local dockTransparency = 0.5 +local dockTransparency = 0.4 local computerUptimeOnBoot = computer.uptime() local computerDateUptime = computerUptimeOnBoot @@ -529,7 +530,7 @@ local function createOSWindow() MineOSCore.properties.network.name = textBox.text MineOSCore.saveProperties() MineOSNetwork.broadcastComputerState(MineOSCore.properties.network.enabled) - + container:delete() MineOSInterface.OSDraw() end @@ -551,7 +552,7 @@ local function createOSWindow() if MineOSCore.properties.network.enabled then menu:addSeparator() - + if MineOSNetwork.getProxyCount() > 0 then for proxy, path in fs.mounts() do if proxy.network then @@ -576,7 +577,7 @@ local function createOSWindow() textBox.onInputFinished = function() if textBox.text then MineOSNetwork.sendMessage(proxy.address, "MineOSNetwork", "message", textBox.text) - + container:delete() MineOSInterface.OSDraw() end @@ -876,6 +877,7 @@ while true do createOSWindow() changeResolution() changeWallpaper() + MineOSCore.OSUpdateDate() MineOSInterface.mainContainer.updateFileListAndDraw() MineOSInterface.showErrorWindow(path, line, traceback) diff --git a/lib/GUI.lua b/lib/GUI.lua index f0726db9..3314d73c 100755 --- a/lib/GUI.lua +++ b/lib/GUI.lua @@ -4,12 +4,13 @@ require("advancedLua") local computer = require("computer") local keyboard = require("keyboard") +local fs = require("filesystem") local unicode = require("unicode") local event = require("event") -local fs = require("filesystem") local color = require("color") local image = require("image") local buffer = require("doubleBuffering") +local syntax = require("syntax") ----------------------------------------- Constants ----------------------------------------- @@ -920,114 +921,6 @@ function GUI.error(...) mainContainer:startEventHandling() end ------------------------------------------ Scrollbar object ----------------------------------------- - -local function scrollBarDraw(scrollBar) - local isVertical = scrollBar.height > scrollBar.width - local valuesDelta = scrollBar.maximumValue - scrollBar.minimumValue + 1 - local part = scrollBar.value / valuesDelta - - if not isVertical and scrollBar.thinHorizontalMode then - buffer.text(scrollBar.x, scrollBar.y, scrollBar.colors.background, string.rep("▄", scrollBar.width)) - else - buffer.square(scrollBar.x, scrollBar.y, scrollBar.width, scrollBar.height, scrollBar.colors.background, 0x0, " ") - end - - if isVertical then - local barSize = math.ceil(scrollBar.shownValueCount / valuesDelta * scrollBar.height) - local halfBarSize = math.floor(barSize / 2) - - scrollBar.ghostPosition.x = scrollBar.x - scrollBar.ghostPosition.y = scrollBar.y + halfBarSize - scrollBar.ghostPosition.width = scrollBar.width - scrollBar.ghostPosition.height = scrollBar.height - barSize - - buffer.square( - scrollBar.ghostPosition.x, - math.floor(scrollBar.ghostPosition.y + part * scrollBar.ghostPosition.height - halfBarSize), - scrollBar.ghostPosition.width, - barSize, - scrollBar.colors.foreground, 0x0, " " - ) - else - local barSize = math.ceil(scrollBar.shownValueCount / valuesDelta * scrollBar.width) - local halfBarSize = math.floor(barSize / 2) - - scrollBar.ghostPosition.x = scrollBar.x + halfBarSize - scrollBar.ghostPosition.y = scrollBar.y - scrollBar.ghostPosition.width = scrollBar.width - barSize - scrollBar.ghostPosition.height = scrollBar.height - - if not isVertical and scrollBar.thinHorizontalMode then - buffer.text(math.floor(scrollBar.ghostPosition.x + part * scrollBar.ghostPosition.width - halfBarSize), scrollBar.ghostPosition.y, scrollBar.colors.foreground, string.rep("▄", barSize)) - else - buffer.square( - math.floor(scrollBar.ghostPosition.x + part * scrollBar.ghostPosition.width - halfBarSize), - scrollBar.ghostPosition.y, - barSize, - scrollBar.ghostPosition.height, - scrollBar.colors.foreground, 0x0, " " - ) - end - end - - return scrollBar -end - -local function scrollBarEventHandler(mainContainer, object, eventData) - local newValue = object.value - - if eventData[1] == "touch" or eventData[1] == "drag" then - local delta = object.maximumValue - object.minimumValue + 1 - if object.height > object.width then - newValue = math.floor((eventData[4] - object.y + 1) / object.height * delta) - else - newValue = math.floor((eventData[3] - object.x + 1) / object.width * delta) - end - elseif eventData[1] == "scroll" then - if eventData[5] == 1 then - if object.value >= object.minimumValue + object.onScrollValueIncrement then - newValue = object.value - object.onScrollValueIncrement - else - newValue = object.minimumValue - end - else - if object.value <= object.maximumValue - object.onScrollValueIncrement then - newValue = object.value + object.onScrollValueIncrement - else - newValue = object.maximumValue - end - end - end - - if eventData[1] == "touch" or eventData[1] == "drag" or eventData[1] == "scroll" then - object.value = newValue - GUI.callMethod(object.onTouch, eventData) - mainContainer:draw() - buffer.draw() - end -end - -function GUI.scrollBar(x, y, width, height, backgroundColor, foregroundColor, minimumValue, maximumValue, value, shownValueCount, onScrollValueIncrement, thinHorizontalMode) - local scrollBar = GUI.object(x, y, width, height) - - scrollBar.eventHandler = scrollBarEventHandler - scrollBar.maximumValue = maximumValue - scrollBar.minimumValue = minimumValue - scrollBar.value = value - scrollBar.onScrollValueIncrement = onScrollValueIncrement - scrollBar.shownValueCount = shownValueCount - scrollBar.thinHorizontalMode = thinHorizontalMode - scrollBar.colors = { - background = backgroundColor, - foreground = foregroundColor, - } - scrollBar.ghostPosition = {} - scrollBar.draw = scrollBarDraw - - return scrollBar -end - ----------------------------------------- CodeView object ----------------------------------------- local function codeViewDraw(codeView) @@ -1038,8 +931,8 @@ local function codeViewDraw(codeView) codeView.lineNumbersWidth = unicode.len(tostring(toLine)) + 2 codeView.codeAreaPosition = codeView.x + codeView.lineNumbersWidth codeView.codeAreaWidth = codeView.width - codeView.lineNumbersWidth - buffer.square(codeView.x, codeView.y, codeView.lineNumbersWidth, codeView.height, require("syntax").colorScheme.lineNumbersBackground, require("syntax").colorScheme.lineNumbersText, " ") - buffer.square(codeView.codeAreaPosition, codeView.y, codeView.codeAreaWidth, codeView.height, require("syntax").colorScheme.background, require("syntax").colorScheme.text, " ") + buffer.square(codeView.x, codeView.y, codeView.lineNumbersWidth, codeView.height, syntax.colorScheme.lineNumbersBackground, syntax.colorScheme.lineNumbersText, " ") + buffer.square(codeView.codeAreaPosition, codeView.y, codeView.codeAreaWidth, codeView.height, syntax.colorScheme.background, syntax.colorScheme.text, " ") -- Line numbers texts local y = codeView.y @@ -1047,10 +940,10 @@ local function codeViewDraw(codeView) if codeView.lines[line] then local text = tostring(line) if codeView.highlights[line] then - buffer.square(codeView.x, y, codeView.lineNumbersWidth, 1, codeView.highlights[line], require("syntax").colorScheme.text, " ", 0.3) - buffer.square(codeView.codeAreaPosition, y, codeView.codeAreaWidth, 1, codeView.highlights[line], require("syntax").colorScheme.text, " ") + buffer.square(codeView.x, y, codeView.lineNumbersWidth, 1, codeView.highlights[line], syntax.colorScheme.text, " ", 0.3) + buffer.square(codeView.codeAreaPosition, y, codeView.codeAreaWidth, 1, codeView.highlights[line], syntax.colorScheme.text, " ") end - buffer.text(codeView.codeAreaPosition - unicode.len(text) - 1, y, require("syntax").colorScheme.lineNumbersText, text) + buffer.text(codeView.codeAreaPosition - unicode.len(text) - 1, y, syntax.colorScheme.lineNumbersText, text) y = y + 1 else break @@ -1066,7 +959,7 @@ local function codeViewDraw(codeView) y + codeView.selections[selectionIndex].from.line - codeView.fromLine, codeView.codeAreaWidth - codeView.selections[selectionIndex].from.symbol + codeView.fromSymbol - 1, 1, - codeView.selections[selectionIndex].color or require("syntax").colorScheme.selection, require("syntax").colorScheme.text, " " + codeView.selections[selectionIndex].color or syntax.colorScheme.selection, syntax.colorScheme.text, " " ) end @@ -1076,7 +969,7 @@ local function codeViewDraw(codeView) y + codeView.selections[selectionIndex].from.line - codeView.fromLine, codeView.selections[selectionIndex].to.symbol - codeView.fromSymbol + 2, 1, - codeView.selections[selectionIndex].color or require("syntax").colorScheme.selection, require("syntax").colorScheme.text, " " + codeView.selections[selectionIndex].color or syntax.colorScheme.selection, syntax.colorScheme.text, " " ) end @@ -1090,7 +983,7 @@ local function codeViewDraw(codeView) y + codeView.selections[selectionIndex].from.line - codeView.fromLine, codeView.selections[selectionIndex].to.symbol - codeView.selections[selectionIndex].from.symbol + 1, 1, - codeView.selections[selectionIndex].color or require("syntax").colorScheme.selection, require("syntax").colorScheme.text, " " + codeView.selections[selectionIndex].color or syntax.colorScheme.selection, syntax.colorScheme.text, " " ) elseif dy == 1 then drawUpperSelection(y, selectionIndex); y = y + 1 @@ -1098,7 +991,7 @@ local function codeViewDraw(codeView) else drawUpperSelection(y, selectionIndex); y = y + 1 for i = 1, dy - 1 do - buffer.square(codeView.codeAreaPosition, y + codeView.selections[selectionIndex].from.line - codeView.fromLine, codeView.codeAreaWidth, 1, codeView.selections[selectionIndex].color or require("syntax").colorScheme.selection, require("syntax").colorScheme.text, " "); y = y + 1 + buffer.square(codeView.codeAreaPosition, y + codeView.selections[selectionIndex].from.line - codeView.fromLine, codeView.codeAreaWidth, 1, codeView.selections[selectionIndex].color or syntax.colorScheme.selection, syntax.colorScheme.text, " "); y = y + 1 end drawLowerSelection(y, selectionIndex) @@ -1112,9 +1005,9 @@ local function codeViewDraw(codeView) for i = codeView.fromLine, toLine do if codeView.lines[i] then if codeView.highlightLuaSyntax then - require("syntax").highlightString(codeView.codeAreaPosition - codeView.fromSymbol + 2, y, codeView.lines[i], codeView.indentationWidth) + syntax.highlightString(codeView.codeAreaPosition - codeView.fromSymbol + 2, y, codeView.lines[i], codeView.indentationWidth) else - buffer.text(codeView.codeAreaPosition - codeView.fromSymbol + 2, y, require("syntax").colorScheme.text, codeView.lines[i]) + buffer.text(codeView.codeAreaPosition - codeView.fromSymbol + 2, y, syntax.colorScheme.text, codeView.lines[i]) end y = y + 1 else @@ -1125,21 +1018,22 @@ local function codeViewDraw(codeView) if #codeView.lines > codeView.height then codeView.scrollBars.vertical.hidden = false - codeView.scrollBars.vertical.colors.background, codeView.scrollBars.vertical.colors.foreground = require("syntax").colorScheme.scrollBarBackground, require("syntax").colorScheme.scrollBarForeground + codeView.scrollBars.vertical.colors.background, codeView.scrollBars.vertical.colors.foreground = syntax.colorScheme.scrollBarBackground, syntax.colorScheme.scrollBarForeground codeView.scrollBars.vertical.minimumValue, codeView.scrollBars.vertical.maximumValue, codeView.scrollBars.vertical.value, codeView.scrollBars.vertical.shownValueCount = 1, #codeView.lines, codeView.fromLine, codeView.height codeView.scrollBars.vertical.localPosition.x = codeView.width codeView.scrollBars.vertical.localPosition.y = 1 - codeView.scrollBars.vertical.height = codeView.height + codeView.scrollBars.vertical.height = codeView.height - 1 else codeView.scrollBars.vertical.hidden = true end if codeView.maximumLineLength > codeView.codeAreaWidth - 2 then codeView.scrollBars.horizontal.hidden = false - codeView.scrollBars.horizontal.colors.background, codeView.scrollBars.horizontal.colors.foreground = require("syntax").colorScheme.scrollBarBackground, require("syntax").colorScheme.scrollBarForeground + codeView.scrollBars.horizontal.colors.background, codeView.scrollBars.horizontal.colors.foreground = syntax.colorScheme.scrollBarBackground, syntax.colorScheme.scrollBarForeground codeView.scrollBars.horizontal.minimumValue, codeView.scrollBars.horizontal.maximumValue, codeView.scrollBars.horizontal.value, codeView.scrollBars.horizontal.shownValueCount = 1, codeView.maximumLineLength, codeView.fromSymbol, codeView.codeAreaWidth - 2 - codeView.scrollBars.horizontal.localPosition.x, codeView.scrollBars.horizontal.width = codeView.lineNumbersWidth + 1, codeView.codeAreaWidth - 1 + codeView.scrollBars.horizontal.localPosition.x = codeView.lineNumbersWidth + 1 codeView.scrollBars.horizontal.localPosition.y = codeView.height + codeView.scrollBars.horizontal.width = codeView.codeAreaWidth - 1 else codeView.scrollBars.horizontal.hidden = true end @@ -1160,7 +1054,7 @@ function GUI.codeView(x, y, width, height, lines, fromSymbol, fromLine, maximumL codeView.indentationWidth = indentationWidth codeView.scrollBars = { - vertical = codeView:addChild(GUI.scrollBar(1, 1, 1, 1, 0x0, 0x0, 1, 1, 1, 1, 1, false)), + vertical = codeView:addChild(GUI.scrollBar(1, 1, 1, 1, 0x0, 0x0, 1, 1, 1, 1, 1, true)), horizontal = codeView:addChild(GUI.scrollBar(1, 1, 1, 1, 0x0, 0x0, 1, 1, 1, 1, 1, true)) } @@ -3184,29 +3078,146 @@ function GUI.resizer(x, y, width, height, helperColor, arrowColor) return object end +----------------------------------------- Scrollbar object ----------------------------------------- + +local function scrollBarDraw(scrollBar) + local isVertical = scrollBar.height > scrollBar.width + local valuesDelta = scrollBar.maximumValue - scrollBar.minimumValue + 1 + local part = scrollBar.value / valuesDelta + + if isVertical then + local barSize = math.ceil(scrollBar.shownValueCount / valuesDelta * scrollBar.height) + local halfBarSize = math.floor(barSize / 2) + + scrollBar.ghostPosition.y = scrollBar.y + halfBarSize + scrollBar.ghostPosition.height = scrollBar.height - barSize + + if scrollBar.thin then + local y1 = math.floor(scrollBar.ghostPosition.y + part * scrollBar.ghostPosition.height - halfBarSize) + local y2 = y1 + barSize - 1 + local background + + for y = scrollBar.y, scrollBar.y + scrollBar.height - 1 do + background = buffer.get(scrollBar.x, y) + buffer.set(scrollBar.x, y, background, y >= y1 and y <= y2 and scrollBar.colors.foreground or scrollBar.colors.background, "┃") + end + else + buffer.square(scrollBar.x, scrollBar.y, scrollBar.width, scrollBar.height, scrollBar.colors.background, scrollBar.colors.foreground, " ") + buffer.square( + scrollBar.x, + math.floor(scrollBar.ghostPosition.y + part * scrollBar.ghostPosition.height - halfBarSize), + scrollBar.width, + barSize, + scrollBar.colors.foreground, 0x0, " " + ) + end + else + local barSize = math.ceil(scrollBar.shownValueCount / valuesDelta * scrollBar.width) + local halfBarSize = math.floor(barSize / 2) + + scrollBar.ghostPosition.x = scrollBar.x + halfBarSize + scrollBar.ghostPosition.width = scrollBar.width - barSize + + if scrollBar.thin then + local x1 = math.floor(scrollBar.ghostPosition.x + part * scrollBar.ghostPosition.width - halfBarSize) + local x2 = x1 + barSize - 1 + local background + + for x = scrollBar.x, scrollBar.x + scrollBar.width - 1 do + background = buffer.get(x, scrollBar.y) + buffer.set(x, scrollBar.y, background, x >= x1 and x <= x2 and scrollBar.colors.foreground or scrollBar.colors.background, "⠤") + end + else + buffer.square(scrollBar.x, scrollBar.y, scrollBar.width, scrollBar.height, scrollBar.colors.background, scrollBar.colors.foreground, " ") + buffer.square( + math.floor(scrollBar.ghostPosition.x + part * scrollBar.ghostPosition.width - halfBarSize), + scrollBar.y, + barSize, + scrollBar.height, + scrollBar.colors.foreground, 0x0, " " + ) + end + end + + return scrollBar +end + +local function scrollBarEventHandler(mainContainer, object, eventData) + local newValue = object.value + + if eventData[1] == "touch" or eventData[1] == "drag" then + local delta = object.maximumValue - object.minimumValue + 1 + if object.height > object.width then + newValue = math.floor((eventData[4] - object.y + 1) / object.height * delta) + else + newValue = math.floor((eventData[3] - object.x + 1) / object.width * delta) + end + elseif eventData[1] == "scroll" then + if eventData[5] == 1 then + if object.value >= object.minimumValue + object.onScrollValueIncrement then + newValue = object.value - object.onScrollValueIncrement + else + newValue = object.minimumValue + end + else + if object.value <= object.maximumValue - object.onScrollValueIncrement then + newValue = object.value + object.onScrollValueIncrement + else + newValue = object.maximumValue + end + end + end + + if eventData[1] == "touch" or eventData[1] == "drag" or eventData[1] == "scroll" then + object.value = newValue + GUI.callMethod(object.onTouch, eventData) + mainContainer:draw() + buffer.draw() + end +end + +function GUI.scrollBar(x, y, width, height, backgroundColor, foregroundColor, minimumValue, maximumValue, value, shownValueCount, onScrollValueIncrement, thin) + local scrollBar = GUI.object(x, y, width, height) + + scrollBar.eventHandler = scrollBarEventHandler + scrollBar.maximumValue = maximumValue + scrollBar.minimumValue = minimumValue + scrollBar.value = value + scrollBar.onScrollValueIncrement = onScrollValueIncrement + scrollBar.shownValueCount = shownValueCount + scrollBar.thin = thin + scrollBar.colors = { + background = backgroundColor, + foreground = foregroundColor, + } + scrollBar.ghostPosition = {} + scrollBar.draw = scrollBarDraw + + return scrollBar +end + -------------------------------------------------------------------------------------------------------------------------------- -- buffer.flush() -- buffer.draw(true) + +-- ------------------------------------------------------------------------------------------ + -- local mainContainer = GUI.fullScreenContainer() --- mainContainer:addChild(GUI.panel(1, 1, mainContainer.width, mainContainer.height, 0x262626)) +-- mainContainer:addChild(GUI.panel(1, 1, mainContainer.width, mainContainer.height, 0x0)) --- local dialog = GUI.addFilesystemDialogToContainer(mainContainer, "Save", "Cancel", "File name", "/") +-- local codeView = mainContainer:addChild(GUI.codeView(2, 2, 130, 30, {}, 1, 1, 1, {}, {}, true, 2)) --- dialog:setMode(GUI.filesystemModes.save, GUI.filesystemModes.file) --- dialog:addExtensionFilter(".pic") --- dialog:addExtensionFilter(".app") --- dialog.onSubmit = function(path) --- GUI.error(path) +-- local file = io.open("/lib/color.lua", "r") +-- for line in file:lines() do +-- line = line:gsub("\t", " "):gsub("\r\n", "\n") +-- table.insert(codeView.lines, line) +-- codeView.maximumLineLength = math.max(codeView.maximumLineLength, unicode.len(line)) -- end --- dialog:show() +-- file:close() --- local filesystemChooser = mainContainer:addChild(GUI.filesystemChooser(2, 2, 30, 3, 0xE1E1E1, 0x888888, 0x3C3C3C, 0x888888, nil, "Open", "Cancel", "Choose file", "/")) --- filesystemChooser:addExtensionFilter(".cfg") --- filesystemChooser.onSubmit = function(path) --- GUI.error("File \"" .. path .. "\" was selected") --- end +-- ------------------------------------------------------------------------------------------ -- mainContainer:draw() -- buffer.draw(true) diff --git a/lib/MineOSInterface.lua b/lib/MineOSInterface.lua index 2b352e09..516d0ec8 100755 --- a/lib/MineOSInterface.lua +++ b/lib/MineOSInterface.lua @@ -76,25 +76,24 @@ local function iconDraw(icon) buffer.text(textX, textY, icon.colors.text, text) - if icon.cut then - if not icon.semiTransparentImage then - icon.semiTransparentImage = image.copy(icon.image) - for i = 3, #icon.semiTransparentImage, 4 do - icon.semiTransparentImage[i + 2] = icon.semiTransparentImage[i + 2] + 0.6 - if icon.semiTransparentImage[i + 2] > 1 then - icon.semiTransparentImage[i + 2] = 1 + if icon.image then + if icon.cut then + if not icon.semiTransparentImage then + icon.semiTransparentImage = image.copy(icon.image) + for i = 3, #icon.semiTransparentImage, 4 do + icon.semiTransparentImage[i + 2] = icon.semiTransparentImage[i + 2] + 0.6 + if icon.semiTransparentImage[i + 2] > 1 then + icon.semiTransparentImage[i + 2] = 1 + end end end - end - - buffer.image(icon.x + 2, icon.y, icon.semiTransparentImage, true) - else - - if icon.image then + + buffer.image(icon.x + 2, icon.y, icon.semiTransparentImage, true) + else buffer.image(icon.x + 2, icon.y, icon.image) - elseif icon.liveImage then - icon.liveImage(icon.x + 2, icon.y) end + elseif icon.liveImage then + icon.liveImage(icon.x + 2, icon.y) end if icon.isShortcut then diff --git a/lib/doubleBuffering.lua b/lib/doubleBuffering.lua index 81a4f77a..c065b2b9 100755 --- a/lib/doubleBuffering.lua +++ b/lib/doubleBuffering.lua @@ -223,26 +223,24 @@ end function buffer.image(x, y, picture, blendForeground) local xPos, xEnd, bufferIndexStepOnReachOfImageWidth = x, x + picture[1] - 1, (buffer.width - picture[1]) * 3 - local bufferIndex, bufferIndexPlus1 = buffer.getIndexByCoordinates(x, y) - local imageIndexPlus1, imageIndexPlus2, imageIndexPlus3 + local bufferIndex, bufferIndexPlus1, imageIndexPlus1, imageIndexPlus2, imageIndexPlus3 = buffer.getIndexByCoordinates(x, y) for imageIndex = 3, #picture, 4 do if xPos >= buffer.drawLimit.x1 and y >= buffer.drawLimit.y1 and xPos <= buffer.drawLimit.x2 and y <= buffer.drawLimit.y2 then bufferIndexPlus1, imageIndexPlus1, imageIndexPlus2, imageIndexPlus3 = bufferIndex + 1, imageIndex + 1, imageIndex + 2, imageIndex + 3 if picture[imageIndexPlus2] == 0 then - buffer.newFrame[bufferIndex] = picture[imageIndex] - buffer.newFrame[bufferIndex + 1] = picture[imageIndex + 1] + buffer.newFrame[bufferIndex], buffer.newFrame[bufferIndexPlus1] = picture[imageIndex], picture[imageIndexPlus1] elseif picture[imageIndexPlus2] > 0 and picture[imageIndexPlus2] < 1 then buffer.newFrame[bufferIndex] = color.blend(buffer.newFrame[bufferIndex], picture[imageIndex], picture[imageIndexPlus2]) if blendForeground then - buffer.newFrame[bufferIndex + 1] = color.blend(buffer.newFrame[bufferIndexPlus1], picture[imageIndexPlus1], picture[imageIndexPlus2]) + buffer.newFrame[bufferIndexPlus1] = color.blend(buffer.newFrame[bufferIndexPlus1], picture[imageIndexPlus1], picture[imageIndexPlus2]) else - buffer.newFrame[bufferIndex + 1] = picture[imageIndex + 1] + buffer.newFrame[bufferIndexPlus1] = picture[imageIndexPlus1] end elseif picture[imageIndexPlus2] == 1 and picture[imageIndexPlus3] ~= " " then - buffer.newFrame[bufferIndex + 1] = picture[imageIndex + 1] + buffer.newFrame[bufferIndexPlus1] = picture[imageIndexPlus1] end buffer.newFrame[bufferIndex + 2] = picture[imageIndexPlus3] diff --git a/lib/syntax.lua b/lib/syntax.lua index 9887a85c..0fe06287 100755 --- a/lib/syntax.lua +++ b/lib/syntax.lua @@ -22,8 +22,8 @@ syntax.colorScheme = { compares = 0xffff98, lineNumbersBackground = 0x2D2D2D, lineNumbersText = 0xCCCCCC, - scrollBarBackground = 0x444444, - scrollBarForeground = 0x33B6FF, + scrollBarBackground = 0x2D2D2D, + scrollBarForeground = 0x5A5A5A, selection = 0x555555, indentation = 0x3C3C3C, }