Улучшенное приложение отрисовки графиков и пара багфиксов

This commit is contained in:
Igor Timofeev 2017-10-11 21:42:40 +03:00
parent a2628d11b8
commit 035d94ba3f
10 changed files with 366 additions and 197 deletions

View File

@ -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",

View File

@ -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,23 +72,20 @@ 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()
local x, y, step = 1, 1, false
@ -201,6 +198,8 @@ end
actionButtons.close.onTouch = function()
window:close()
end
actionButtons.minimize:delete()
actionButtons.maximize:delete()
---------------------------------------------------------------------------------------------------------

Binary file not shown.

View File

@ -0,0 +1,144 @@
require("advancedLua")
local fs = require("filesystem")
local buffer = require("doubleBuffering")
local GUI = require("GUI")
local unicode = require("unicode")
local MineOSInterface = require("MineOSInterface")
---------------------------------------------------------------------------------------------------------
local mainContainer, window = MineOSInterface.addWindow(GUI.filledWindow(nil, nil, 110, 25, 0xE1E1E1))
local yDependencyString = "math.sin(x)"
local xOffset, yOffset, xDrag, yDrag, points = 0, 0, 1, 1
---------------------------------------------------------------------------------------------------------
window.backgroundPanel.localPosition.y, window.backgroundPanel.height = 4, window.backgroundPanel.height - 3
local titlePanel = window:addChild(GUI.panel(1, 1, window.width, 3, 0x2D2D2D, 0.1))
local layout = window:addChild(GUI.layout(1, 1, window.width, 3, 1, 1))
layout:setCellDirection(1, 1, GUI.directions.horizontal)
layout:setCellSpacing(1, 1, 3)
local switchAndLabel = layout:addChild(GUI.switchAndLabel(1, 1, 16, 6, 0x66DB80, 0x1D1D1D, 0xEEEEEE, 0x999999, "Quants:", false))
local scaleSlider = layout:addChild(GUI.slider(1, 1, 12, 0x66DB80, 0x0, 0xFFFFFF, 0x999999, 1, 1000, 400, false, "Scale: ", "%"))
local rangeSlider = layout:addChild(GUI.slider(1, 1, 12, 0x66DB80, 0x0, 0xFFFFFF, 0x999999, 5, 60, 25, false, "Range: ", ""))
local precisionSlider = layout:addChild(GUI.slider(1, 1, 12, 0x66DB80, 0x0, 0xFFFFFF, 0x999999, 10, 100, 72, false, "Precision: ", ""))
local functionButton = window:addChild(GUI.button(1, 1, 1, 3, 0xE1E1E1, 0x3C3C3C, 0xCCCCCC, 0x3C3C3C, ""))
window.actionButtons:moveToFront()
local graph = window:addChild(GUI.object(1, 4, window.width, window.height - 3))
graph.draw = function(graph)
local x1, x2, y1, y2 = buffer.getDrawLimit()
buffer.setDrawLimit(graph.x, graph.y, graph.x + graph.width - 1, graph.y + graph.height - 1)
local xCenter, yCenter = graph.x + xOffset + graph.width / 2 - 1, graph.y + yOffset + graph.height / 2 - 1
buffer.semiPixelLine(math.floor(graph.x), math.floor(yCenter * 2), math.floor(graph.x + graph.width - 1), math.floor(yCenter * 2), 0xD2D2D2)
buffer.semiPixelLine(math.floor(xCenter), math.floor(graph.y * 2 - 1), math.floor(xCenter), math.floor(graph.y + graph.height - 1) * 2, 0xD2D2D2)
for i = 1, #points - 1 do
local x1, x2, y1, y2 = math.floor(xCenter + points[i].x), math.floor(yCenter - points[i].y + 1) * 2, math.floor(xCenter + points[i + 1].x), math.floor(yCenter - points[i + 1].y + 1) * 2
buffer.semiPixelLine(x1, x2, y1, y2, 0x0)
if switchAndLabel.switch.state then
buffer.semiPixelSet(x1, x2, 0x66DB80)
end
end
buffer.setDrawLimit(x1, x2, y1, y2)
end
local function update()
functionButton.text = "f(x)=" .. yDependencyString:gsub("%s+", "")
functionButton.width = unicode.len(functionButton.text) + 4
functionButton.localPosition.x = window.width - functionButton.width + 1
titlePanel.width = window.width - functionButton.width
layout.width = titlePanel.width
points = {}
local scale = scaleSlider.value / 100
local xRange = rangeSlider.value
local step = precisionSlider.value / 100
for x = -xRange, xRange, step do
local success, y = pcall(load("local x = " .. x .. "; local y = " .. yDependencyString .. "; return y"))
if success and tonumber(y) then
if not (y ~= y) then
table.insert(points, {
x = x * scale,
y = y * scale
})
end
else
GUI.error("Invalid input function")
return
end
end
end
functionButton.onTouch = function()
local container = MineOSInterface.addUniversalContainer(window, "Set function f(x)")
local inputField = container.layout:addChild(GUI.inputField(1, 1, 36, 3, 0xEEEEEE, 0x666666, 0x666666, 0xEEEEEE, 0x262626, yDependencyString, "f(x)", false))
inputField.onInputFinished = function()
if inputField.text then
yDependencyString = inputField.text
update()
container:delete()
mainContainer:draw()
buffer.draw()
end
end
mainContainer:draw()
buffer.draw()
end
scaleSlider.onValueChanged = function()
update()
mainContainer:draw()
buffer.draw()
end
rangeSlider.onValueChanged = scaleSlider.onValueChanged
precisionSlider.onValueChanged = scaleSlider.onValueChanged
window.onResize = function(width, height)
window.backgroundPanel.width, window.backgroundPanel.height = width, height - 3
graph.width, graph.height = width, height - 3
update()
end
graph.eventHandler = function(mainContainer, graph, eventData)
if eventData[1] == "touch" then
xDrag, yDrag = eventData[3], eventData[4]
elseif eventData[1] == "drag" then
xOffset, yOffset = xOffset + (eventData[3] - xDrag), yOffset + (eventData[4] - yDrag)
mainContainer:draw()
buffer.draw()
xDrag, yDrag = eventData[3], eventData[4]
elseif eventData[1] == "scroll" then
scaleSlider.value = scaleSlider.value + eventData[5] * 10
if scaleSlider.value < scaleSlider.minimumValue then
scaleSlider.value = scaleSlider.minimumValue
elseif scaleSlider.value > scaleSlider.maximumValue then
scaleSlider.value = scaleSlider.maximumValue
end
update()
mainContainer:draw()
buffer.draw()
end
end
---------------------------------------------------------------------------------------------------------
update()
mainContainer:draw()
buffer.draw()

View File

@ -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
------------------------------------------------------------------------

4
OS.lua
View File

@ -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
@ -876,6 +877,7 @@ while true do
createOSWindow()
changeResolution()
changeWallpaper()
MineOSCore.OSUpdateDate()
MineOSInterface.mainContainer.updateFileListAndDraw()
MineOSInterface.showErrorWindow(path, line, traceback)

View File

@ -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)

View File

@ -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

View File

@ -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]

View File

@ -22,8 +22,8 @@ syntax.colorScheme = {
compares = 0xffff98,
lineNumbersBackground = 0x2D2D2D,
lineNumbersText = 0xCCCCCC,
scrollBarBackground = 0x444444,
scrollBarForeground = 0x33B6FF,
scrollBarBackground = 0x2D2D2D,
scrollBarForeground = 0x5A5A5A,
selection = 0x555555,
indentation = 0x3C3C3C,
}