Переход на унифицированный оконный метод и отказ от библиотеки windows в угоду современным йоба-технологиям

This commit is contained in:
Igor Timofeev 2017-04-01 18:44:43 +03:00
parent 0cd211b136
commit 9d5e545f63
12 changed files with 372 additions and 440 deletions

View File

@ -253,7 +253,7 @@
name="lib/MineOSCore.lua",
url="IgorTimofeev/OpenComputers/master/lib/MineOSCore.lua",
type="Library",
version=1.51,
version=1.52,
},
{
name="lib/advancedLua.lua",
@ -300,13 +300,7 @@
name="lib/GUI.lua",
url="IgorTimofeev/OpenComputers/master/lib/GUI.lua",
type="Library",
version=1.48,
},
{
name="lib/windows.lua",
url="IgorTimofeev/OpenComputers/master/lib/windows.lua",
type="Library",
version=1.20,
version=1.49,
},
{
name="lib/rayEngine.lua",
@ -366,7 +360,7 @@
name="lib/palette.lua",
url="IgorTimofeev/OpenComputers/master/lib/palette.lua",
type="Library",
version=1.10,
version=1.11,
},
{
name="lib/doubleBuffering.lua",
@ -511,7 +505,7 @@
icon="IgorTimofeev/OpenComputers/master/Applications/MineCodeIDE/Icon.pic",
createShortcut="dock",
forceDownload=true,
version=1.69,
version=1.70,
resources={
{
name="Localization/Russian.lang",
@ -530,7 +524,7 @@
type="Application",
icon="IgorTimofeev/OpenComputers/master/Applications/3DTest/Icon.pic",
createShortcut="desktop",
version=1.15,
version=1.16,
},
{
name="MineOS/Applications/GeoScan2",
@ -538,7 +532,7 @@
type="Application",
icon="IgorTimofeev/OpenComputers/master/Applications/GeoScan2/Icon.pic",
createShortcut="desktop",
version=1.03,
version=1.04,
resources={
{
name="Earth.pic",
@ -552,7 +546,7 @@
type="Application",
icon="IgorTimofeev/OpenComputers/master/Applications/SmartHouse/Icon.pic",
createShortcut="desktop",
version=1.29,
version=1.30,
resources={
{
name="Modules/command_block/Icon.pic",
@ -644,7 +638,7 @@
type="Application",
icon="IgorTimofeev/OpenComputers/master/Applications/Control2/Icon.pic",
createShortcut="desktop",
version=1.05,
version=1.06,
resources={
{
name="LuaLogo.pic",
@ -726,7 +720,7 @@
type="Application",
icon="IgorTimofeev/OpenComputers/master/Applications/RayWalk/Icon.pic",
createShortcut="desktop",
version=1.62,
version=1.63,
resources={
{
name="Localization/Russian.lang",
@ -849,7 +843,7 @@
type="Application",
icon="IgorTimofeev/OpenComputers/master/Applications/PrintImage/Icon.pic",
createShortcut="desktop",
version=1.07,
version=1.08,
},
{
name="MineOS/Applications/Palette",

View File

@ -14,7 +14,6 @@ local computer = require("computer")
local buffer = require("doubleBuffering")
local event = require("event")
local GUI = require("GUI")
local windows = require("windows")
local vector = require("vector")
local materials = require("OpenComputersGL/Materials")
local renderer = require("OpenComputersGL/Renderer")
@ -28,7 +27,7 @@ local polyCatEngine = require("PolyCatEngine/Main")
buffer.start()
polyCatEngine.intro(vector.newVector3(0, 0, 0), 20)
local mainWindow = windows.fullScreen()
local mainWindow = GUI.fullScreenWindow()
local scene = polyCatEngine.newScene(0x1D1D1D)
scene.renderMode = OCGL.renderModes.flatShading

View File

@ -3,7 +3,6 @@ local fs = require("filesystem")
local advancedLua = require("advancedLua")
local buffer = require("doubleBuffering")
local GUI = require("GUI")
local windows = require("windows")
local MineOSCore = require("MineOSCore")
local event = require("event")
local unicode = require("unicode")
@ -15,7 +14,7 @@ local window = {}
-----------------------------------------------------------------------------------------------------------------------------
local function createWindow()
window = windows.empty("auto", "auto", math.floor(buffer.screen.width * 0.8), math.floor(buffer.screen.height * 0.7), 78, 24)
window = GUI.window("auto", "auto", math.floor(buffer.screen.width * 0.8), math.floor(buffer.screen.height * 0.7), 78, 24)
window:addPanel(1, 1, window.width, window.height, 0xEEEEEE).disabled = true
window.resourcesPath = MineOSCore.getCurrentApplicationResourcesDirectory()

View File

@ -4,7 +4,6 @@ local colorlib = require("colorlib")
local image = require("image")
local buffer = require("doubleBuffering")
local GUI = require("GUI")
local windows = require("windows")
local MineOSCore = require("MineOSCore")
--------------------------------------------------------------------------------------------------------------------
@ -20,7 +19,7 @@ local earthImage = image.load(resourcesDirectory .. "Earth.pic")
local onScreenDataXOffset, onScreenDataYOffset = math.floor(buffer.screen.width / 2), buffer.screen.height
local onProjectorDataYOffset = 0
local scanResult = {horizontalRange = 0, verticalRange = 0}
local window = windows.fullScreen()
local window = GUI.fullScreenWindow()
--------------------------------------------------------------------------------------------------------------------

View File

@ -6,7 +6,6 @@
-- package.loaded.syntax = nil
-- package.loaded.ECSAPI = nil
-- package.loaded.GUI = nil
-- package.loaded.windows = nil
-- package.loaded.MineOSCore = nil
require("advancedLua")
@ -15,7 +14,6 @@ local component = require("component")
local fs = require("filesystem")
local buffer = require("doubleBuffering")
local GUI = require("GUI")
local windows = require("windows")
local MineOSCore = require("MineOSCore")
local event = require("event")
local syntax = require("syntax")
@ -1328,7 +1326,7 @@ local function createEditOrRightClickMenu(x, y)
end
local function createWindow()
mainWindow = windows.fullScreen()
mainWindow = GUI.fullScreenWindow()
mainWindow.codeView = mainWindow:addCodeView(1, 1, 1, 1, {""}, 1, 1, 1, {}, {}, config.highlightLuaSyntax, 2)
mainWindow.codeView.scrollBars.vertical.onTouch = function()

View File

@ -1,8 +1,6 @@
----------------------------------------- Libraries -----------------------------------------
-- package.loaded.windows = nil
local component = require("component")
local computer = require("computer")
local unicode = require("unicode")
@ -12,7 +10,6 @@ local colorlib = require("colorlib")
local image = require("image")
local buffer = require("doubleBuffering")
local GUI = require("GUI")
local windows = require("windows")
----------------------------------------- cyka -----------------------------------------
@ -186,7 +183,7 @@ local function drawMainImageObject(object)
end
local function createWindow()
window = windows.fullScreen()
window = GUI.fullScreenWindow()
window:addPanel(1, 1, window.width, window.height, 0xEEEEEE)
window:addObject(1, 1, window.width, window.height).draw = drawMainImageObject
local textBoxesWidth = math.floor(panelWidth * 0.55)

View File

@ -1,11 +1,10 @@
package.loaded.rayEngine, package.loaded.GUI, package.loaded.windows, _G.rayEngine, _G.GUI, _G.windows = nil, nil, nil, nil, nil, nil, nil, nil
package.loaded.rayEngine, package.loaded.GUI, _G.rayEngine, _G.GUI = nil, nil, nil, nil, nil, nil
local fs = require("filesystem")
local component = require("component")
local buffer = require("doubleBuffering")
local GUI = require("GUI")
local windows = require("windows")
local rayEngine = require("rayEngine")
local MineOSCore = require("MineOSCore")
local unicode = require("unicode")
@ -26,7 +25,7 @@ local function menuBackground()
end
local function settings()
local window = windows.empty(1, 1, buffer.screen.width, buffer.screen.height, buffer.screen.width, buffer.screen.height)
local window = GUI.window(1, 1, buffer.screen.width, buffer.screen.height, buffer.screen.width, buffer.screen.height)
window.onDrawStarted = menuBackground
local sliderWidth, textBoxWidth = 43, 19
@ -106,7 +105,7 @@ local function settings()
end
local function menu()
local window = windows.empty(1, 1, buffer.screen.width, buffer.screen.height, buffer.screen.width, buffer.screen.height)
local window = GUI.window(1, 1, buffer.screen.width, buffer.screen.height, buffer.screen.width, buffer.screen.height)
window.onDrawStarted = menuBackground
local buttonWidth, buttonHeight = 50, 3
@ -164,7 +163,7 @@ rayEngine.loadEngineProperties(applicationResourcesDirectory .. "RayEngine.cfg")
rayEngine.loadWeapons(applicationResourcesDirectory .. "Weapons/")
rayEngine.loadWorld(worldsPath .. "ExampleWorld")
rayEngine.changeResolution(rayEngine.properties.screenResolution.width, rayEngine.properties.screenResolution.height)
rayEngine.intro()
-- rayEngine.intro()
menu()
rayEngine.update()

View File

@ -7,7 +7,6 @@ local buffer = require("doubleBuffering")
local keyboard = require("keyboard")
local GUI = require("GUI")
local ecs = require("ECSAPI")
local windows = require("windows")
local MineOSCore = require("MineOSCore")
local computer = require("computer")
local fs = require("filesystem")
@ -332,7 +331,7 @@ local function drawSignals()
end
local function createWindow()
window = windows.fullScreen()
window = GUI.fullScreenWindow()
-- Создаем главное и неебически важное устройство домашнего писюка
local homePC = createDevice(math.floor(window.width / 2 - 8), math.floor(window.height / 2 - 4), "homePC", component.proxy(computer.address()), "Сервак")

View File

@ -2,6 +2,7 @@
----------------------------------------- Libraries -----------------------------------------
require("advancedLua")
local computer = require("computer")
local keyboard = require("keyboard")
local buffer = require("doubleBuffering")
local unicode = require("unicode")
@ -375,11 +376,7 @@ local function drawContainerContent(container)
-- We use :draw() method against of recursive call. The reason is possible user-defined :draw() reimplementations
container.children[objectIndex]:draw()
else
-- if container.children[objectIndex].draw then
container.children[objectIndex]:draw()
-- else
-- error("Container object with index " .. objectIndex .. " doesn't have :draw() method")
-- end
container.children[objectIndex]:draw()
end
end
end
@ -1874,43 +1871,283 @@ function GUI.chart(x, y, width, height, axisColor, axisValueColor, axisHelpersCo
return object
end
----------------------------------------- Window object -----------------------------------------
local function windowExecuteMethod(method, ...)
if method then method(...) end
end
local function windowButtonHandler(window, object, objectIndex, eventData)
if object.switchMode then
object.pressed = not object.pressed
window:draw(); buffer.draw()
windowExecuteMethod(object.onTouch, eventData)
else
object.pressed = true
window:draw(); buffer.draw()
os.sleep(0.2)
object.pressed = false
window:draw(); buffer.draw()
windowExecuteMethod(object.onTouch, eventData)
end
end
local function windowTabBarTabHandler(window, object, objectIndex, eventData)
object.parent.parent.selectedTab = objectIndex
window:draw(); buffer.draw()
windowExecuteMethod(object.parent.parent.onTabSwitched, object.parent.parent.selectedTab, eventData)
end
local function windowInputTextBoxHandler(window, object, objectIndex, eventData)
object:input()
window:draw(); buffer.draw()
windowExecuteMethod(object.onInputFinished, object.text, eventData)
end
local function windowTextBoxScrollHandler(window, object, objectIndex, eventData)
if eventData[5] == 1 then
object:scrollUp()
window:draw(); buffer.draw()
else
object:scrollDown()
window:draw(); buffer.draw()
end
end
local function windowHorizontalSliderHandler(window, object, objectIndex, eventData)
local clickPosition = eventData[3] - object.x + 1
object.value = object.minimumValue + (clickPosition * (object.maximumValue - object.minimumValue) / object.width)
window:draw(); buffer.draw()
windowExecuteMethod(object.onValueChanged, object.value, eventData)
end
local function windowSwitchHandler(window, object, objectIndex, eventData)
object.state = not object.state
window:draw(); buffer.draw()
windowExecuteMethod(object.onStateChanged, object.state, eventData)
end
local function windowComboBoxHandler(window, object, objectIndex, eventData)
object:selectItem()
windowExecuteMethod(object.onItemSelected, object.items[object.currentItem], eventData)
end
local function windowMenuItemHandler(window, object, objectIndex, eventData)
object.pressed = true
window:draw(); buffer.draw()
windowExecuteMethod(object.onTouch, eventData)
object.pressed = false
window:draw(); buffer.draw()
end
local function windowScrollBarHandler(window, object, objectIndex, 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
object.value = newValue
windowExecuteMethod(object.onTouch, eventData)
window:draw(); buffer.draw()
end
local function windowTreeViewHandler(window, object, objectIndex, eventData)
if eventData[1] == "touch" then
local fileIndex = eventData[4] - object.y + object.fromFile - 1
if object.fileList[fileIndex] then
if object.fileList[fileIndex].isDirectory then
if object.directoriesToShowContent[object.fileList[fileIndex].path] then
object.directoriesToShowContent[object.fileList[fileIndex].path] = nil
else
object.directoriesToShowContent[object.fileList[fileIndex].path] = true
end
object:updateFileList()
object:draw(); buffer.draw()
else
object.currentFile = object.fileList[fileIndex].path
object:draw(); buffer.draw()
windowExecuteMethod(object.onFileSelected, object.currentFile, eventData)
end
end
elseif eventData[1] == "scroll" then
if eventData[5] == 1 then
if object.fromFile > 1 then
object.fromFile = object.fromFile - 1
object:draw(); buffer.draw()
end
else
if object.fromFile < #object.fileList then
object.fromFile = object.fromFile + 1
object:draw(); buffer.draw()
end
end
end
end
local function windowColorSelectorHandler(window, object, objectIndex, eventData)
object.pressed = true
object:draw(); buffer.draw()
object.color = require("palette").show("auto", "auto", object.color) or object.color
object.pressed = false
object:draw(); buffer.draw()
windowExecuteMethod(object.onTouch, eventData)
end
local function windowHandleEventData(window, eventData)
if eventData[1] == "touch" then
local object, objectIndex = window:getClickedObject(eventData[3], eventData[4])
if object then
if object.type == GUI.objectTypes.button then
windowButtonHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.tabBarTab then
windowTabBarTabHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.inputTextBox then
windowInputTextBoxHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.horizontalSlider then
windowHorizontalSliderHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.switch then
windowSwitchHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.comboBox then
windowComboBoxHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.menuItem then
windowMenuItemHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.scrollBar then
windowScrollBarHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.treeView then
windowTreeViewHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.colorSelector then
windowColorSelectorHandler(window, object, objectIndex, eventData)
elseif object.onTouch then
windowExecuteMethod(object.onTouch, eventData)
end
else
windowExecuteMethod(window.onTouch, eventData)
end
elseif eventData[1] == "scroll" then
local object, objectIndex = window:getClickedObject(eventData[3], eventData[4])
if object then
if object.type == GUI.objectTypes.textBox then
windowTextBoxScrollHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.scrollBar then
windowScrollBarHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.treeView then
windowTreeViewHandler(window, object, objectIndex, eventData)
elseif object.onScroll then
windowExecuteMethod(object.onScroll, eventData)
end
else
windowExecuteMethod(window.onScroll, eventData)
end
elseif eventData[1] == "drag" then
local object, objectIndex = window:getClickedObject(eventData[3], eventData[4])
if object then
if object.type == GUI.objectTypes.horizontalSlider then
windowHorizontalSliderHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.scrollBar then
windowScrollBarHandler(window, object, objectIndex, eventData)
elseif object.onDrag then
windowExecuteMethod(object.onDrag, eventData)
end
else
windowExecuteMethod(window.onDrag, eventData)
end
elseif eventData[1] == "drop" then
local object, objectIndex = window:getClickedObject(eventData[3], eventData[4])
if object then
if object.onDrag then
windowExecuteMethod(object.onDrop, eventData)
end
else
windowExecuteMethod(window.onDrop, eventData)
end
elseif eventData[1] == "key_down" then
windowExecuteMethod(window.onKeyDown, eventData)
elseif eventData[1] == "key_up" then
windowExecuteMethod(window.onKeyUp, eventData)
end
windowExecuteMethod(window.onAnyEvent, eventData)
end
local function windowHandleEvents(window, pullTime)
while true do
windowHandleEventData(window, {event.pull(pullTime)})
if window.dataToReturn then
local data = window.dataToReturn
window = nil
return table.unpack(data)
end
end
end
local function windowReturnData(window, ...)
window.dataToReturn = {...}
computer.pushSignal("windowAction")
end
local function windowClose(window)
windowReturnData(window, nil)
end
local function windowCorrectCoordinates(x, y, width, height, minimumWidth, minimumHeight)
width = minimumWidth and math.max(width, minimumWidth) or width
height = minimumHeight and math.max(height, minimumHeight) or height
x = (x == "auto" and math.floor(buffer.screen.width / 2 - width / 2)) or x
y = (y == "auto" and math.floor(buffer.screen.height / 2 - height / 2)) or y
return x, y, width, height
end
local function windowDraw(window)
if window.onDrawStarted then window.onDrawStarted() end
drawContainerContent(window)
if window.drawShadow then GUI.windowShadow(window.x, window.y, window.width, window.height, 50) end
if window.onDrawFinished then window.onDrawFinished() end
end
function GUI.window(x, y, width, height, minimumWidth, minimumHeight)
x, y, width, height = windowCorrectCoordinates(x, y, width, height, minimumWidth, minimumHeight)
local window = GUI.container(x, y, width, height)
window.minimumWidth = minimumWidth
window.minimumHeight = minimumHeight
window.drawShadow = false
window.draw = windowDraw
window.handleEvents = windowHandleEvents
window.close = windowClose
window.returnData = windowReturnData
return window
end
function GUI.fullScreenWindow()
return GUI.window(1, 1, buffer.screen.width, buffer.screen.height)
end
--------------------------------------------------------------------------------------------------------------------------------
-- buffer.start()
-- buffer.clear(0x262626)
-- local treeView = GUI.treeView(2, 2, 50, 40, 0xFFFFFF, 0x0, 0x262626, 0x555555, 0x888888, 0xFF4444, 0x44FF44, "/MineOS/System/OS/")
-- treeView.directoriesToShowContent["/MineOS/System/OS/Languages/"] = true
-- treeView:updateFileList()
-- treeView:draw()
-- buffer.draw(true)
-- buffer.start()
-- local x, y, width, height = 10, 10, 32, 16
-- local chart = GUI.chart(x, y, width, height, 0xFFFFFF, 0xBBBBBB, 0x777777, 0xFF4444, 0.1, 0.15, "%", " RF/t", true, {})
-- chart.showXAxisValues = false
-- chart.showYAxisValues = false
-- -- buffer.clear(0x262626)
-- -- buffer.square(x, y, width, height, 0x1D1D1D)
-- -- for i = 1, 50 do
-- -- table.insert(chart.values, {i, math.random(1, 100)})
-- -- end
-- -- chart:draw()
-- -- buffer.draw()
-- local counter = 1
-- while true do
-- buffer.clear(0x262626)
-- buffer.square(x, y, width, height, 0x1D1D1D)
-- table.insert(chart.values, {counter, math.random(0, 100)})
-- chart:draw()
-- buffer.draw()
-- counter = counter + 1
-- if #chart.values > 20 then table.remove(chart.values, 1) end
-- os.sleep(0.5)
-- end
--------------------------------------------------------------------------------------------------------------------------------

View File

@ -8,10 +8,10 @@ local advancedLua = require("advancedLua")
local image = require("image")
local buffer = require("doubleBuffering")
local GUI = require("GUI")
local windows = require("windows")
local ecs = require("ECSAPI")
local fs = require("filesystem")
local unicode = require("unicode")
local keyboard = require("keyboard")
---------------------------------------------- Core constants ------------------------------------------------------------------------
@ -43,6 +43,74 @@ MineOSCore.sortingMethods = enum(
MineOSCore.localization = {}
---------------------------------------------- Tasks ------------------------------------------------------------------------
--[[
MineOSCore.tasks = {}
function MineOSCore.showTaskManager()
MineOSCore.tasks.current = 1
buffer.clear(0x2D2D2D)
for i = 1, #MineOSCore.tasks do
buffer.text(1, i, 0xFFFFFF, i .. ": " .. table.toString(MineOSCore.tasks[i]))
end
buffer.draw()
MineOSCore.rawPullSignal()
end
local function replacePullSignal()
MineOSCore.rawPullSignal = computer.pullSignal
computer.pullSignal = function(timeout)
local signalData = {MineOSCore.rawPullSignal(timeout)}
local i = 1
while i <= #MineOSCore.tasks do
if coroutine.status(MineOSCore.tasks[i].coroutine) == "dead" then
if i > 1 then
MineOSCore.tasks.current = 1
MineOSCore.tasks[i].coroutine = nil
table.remove(MineOSCore.tasks, i)
else
error("MineOSCore fatal error cyka bitch")
end
else
i = i + 1
end
end
if MineOSCore.taskManagerOpen then
MineOSCore.showTaskManager()
else
if keyboard.isKeyDown(0) and keyboard.isKeyDown(28) then
MineOSCore.taskManagerOpen = true
MineOSCore.tasks[MineOSCore.tasks.current].isPaused = true
computer.pushSignal("")
coroutine.yield()
else
return table.unpack(signalData)
end
end
end
end
function MineOSCore.newTask(func, name)
local task = {
coroutine = coroutine.create(func),
name = name,
isPaused = false
}
table.insert(MineOSCore.tasks, task)
return task
end
function MineOSCore.newTaskFromFile(path)
local loadSuccess, loadReason = loadfile(path)
MineOSCore.newTask(loadSuccess)
end
]]
---------------------------------------------- Current sсript processing methods ------------------------------------------------------------------------
function MineOSCore.getCurrentScriptDirectory()
@ -468,7 +536,7 @@ local function drawErrorWindow(path, programVersion, errorLine, reason)
local y = math.floor(buffer.screen.height / 2 - height / 2)
-- Окошечко и всякая шняжка на нем
local window = windows.empty(1, y, width, height, width, height)
local window = GUI.window(1, y, width, height, width, height)
window:addPanel(1, 1, width, 3, 0x383838)
window:addLabel(1, 2, width, 1, 0xFFFFFF, MineOSCore.localization.errorWhileRunningProgram .. "\"" .. MineOSCore.getFileName(path) .. "\""):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.top)
local windowActionButtons = window:addWindowActionButtons(2, 2, false)
@ -813,7 +881,7 @@ local function addKeyAndValue(window, x, y, key, value)
end
function MineOSCore.showPropertiesWindow(x, y, width, iconObject)
local window = windows.empty(x, y, width, 1)
local window = GUI.window(x, y, width, 1)
local backgroundPanel = window:addPanel(1, 2, window.width, 1, 0xDDDDDD)
window:addPanel(1, 1, window.width, 1, 0xEEEEEE)
window:addLabel(1, 1, window.width, 1, 0x333333, MineOSCore.localization.contextMenuProperties):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.top)

View File

@ -1,5 +1,5 @@
-- _G.windows, _G.GUI, package.loaded.windows, package.loaded.GUI = nil, nil, nil, nil
-- _G.GUI, package.loaded.GUI = nil, nil
local advancedLua = require("advancedLua")
local component = require("component")
@ -8,7 +8,6 @@ local colorlib = require("colorlib")
local image = require("image")
local buffer = require("doubleBuffering")
local GUI = require("GUI")
local windows = require("windows")
--------------------------------------------------------------------------------------------------------------
@ -46,7 +45,7 @@ local function randomizeFavourites()
favourites = {}; for i = 1, 6 do favourites[i] = math.random(0x000000, 0xFFFFFF) end
end
local function savefavourites()
local function saveFavoutites()
table.toFile(pathToFavouritesConfig, favourites)
end
@ -55,7 +54,7 @@ local function loadFavourites()
favourites = table.fromFile(pathToFavouritesConfig)
else
randomizeFavourites()
savefavourites()
saveFavoutites()
end
end
@ -193,7 +192,7 @@ local function createFavourites()
end
local function createWindow(x, y)
window = windows.empty(x, y, 71, 25, 71, 25)
window = GUI.window(x, y, 71, 25, 71, 25)
x, y = 1, 1
window:addPanel(x, y, window.width, window.height, 0xEEEEEE)
@ -244,7 +243,7 @@ local function createWindow(x, y)
if not favouriteExists then
table.insert(favourites, 1, currentColor.hex); table.remove(favourites, #favourites)
for i = 1, #favourites do favouritesContainer.children[i].colors.default.background = favourites[i]; favouritesContainer.children[i].colors.pressed.background = 0x0 end
savefavourites()
saveFavoutites()
drawAll()
end
end

View File

@ -1,356 +0,0 @@
----------------------------------------- Libraries -----------------------------------------
-- _G.GUI, package.loaded.GUI = nil, nil
local computer = require("computer")
local buffer = require("doubleBuffering")
local GUI = require("GUI")
local unicode = require("unicode")
local event = require("event")
----------------------------------------- Constants -----------------------------------------
local windows = {}
windows.alignment = GUI.alignment
windows.colors = {
background = 0xEEEEEE,
title = {
background = 0xDDDDDD,
text = 0x262626,
},
tabBar = {
background = 0xDDDDDD,
text = 0x262626,
selectedTab = {
background = 0xCCCCCC,
text = 0x262626,
}
},
}
----------------------------------------- Universal window event handlers -----------------------------------------
local function executeObjectMethod(method, ...)
if method then method(...) end
end
local function buttonHandler(window, object, objectIndex, eventData)
if object.switchMode then
object.pressed = not object.pressed
window:draw(); buffer.draw()
executeObjectMethod(object.onTouch, eventData)
else
object.pressed = true
window:draw(); buffer.draw()
os.sleep(0.2)
object.pressed = false
window:draw(); buffer.draw()
executeObjectMethod(object.onTouch, eventData)
end
end
local function tabBarTabHandler(window, object, objectIndex, eventData)
object.parent.parent.selectedTab = objectIndex
window:draw(); buffer.draw()
executeObjectMethod(object.parent.parent.onTabSwitched, object.parent.parent.selectedTab, eventData)
end
local function inputTextBoxHandler(window, object, objectIndex, eventData)
object:input()
window:draw(); buffer.draw()
executeObjectMethod(object.onInputFinished, object.text, eventData)
end
local function textBoxScrollHandler(window, object, objectIndex, eventData)
if eventData[5] == 1 then
object:scrollUp()
window:draw(); buffer.draw()
else
object:scrollDown()
window:draw(); buffer.draw()
end
end
local function horizontalSliderHandler(window, object, objectIndex, eventData)
local clickPosition = eventData[3] - object.x + 1
object.value = object.minimumValue + (clickPosition * (object.maximumValue - object.minimumValue) / object.width)
window:draw(); buffer.draw()
executeObjectMethod(object.onValueChanged, object.value, eventData)
end
local function switchHandler(window, object, objectIndex, eventData)
object.state = not object.state
window:draw(); buffer.draw()
executeObjectMethod(object.onStateChanged, object.state, eventData)
end
local function comboBoxHandler(window, object, objectIndex, eventData)
object:selectItem()
executeObjectMethod(object.onItemSelected, object.items[object.currentItem], eventData)
end
local function menuItemHandler(window, object, objectIndex, eventData)
object.pressed = true
window:draw(); buffer.draw()
executeObjectMethod(object.onTouch, eventData)
object.pressed = false
window:draw(); buffer.draw()
end
local function scrollBarHandler(window, object, objectIndex, 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
object.value = newValue
executeObjectMethod(object.onTouch, eventData)
window:draw(); buffer.draw()
end
local function treeViewHandler(window, object, objectIndex, eventData)
if eventData[1] == "touch" then
local fileIndex = eventData[4] - object.y + object.fromFile - 1
if object.fileList[fileIndex] then
if object.fileList[fileIndex].isDirectory then
if object.directoriesToShowContent[object.fileList[fileIndex].path] then
object.directoriesToShowContent[object.fileList[fileIndex].path] = nil
else
object.directoriesToShowContent[object.fileList[fileIndex].path] = true
end
object:updateFileList()
object:draw(); buffer.draw()
else
object.currentFile = object.fileList[fileIndex].path
object:draw(); buffer.draw()
executeObjectMethod(object.onFileSelected, object.currentFile, eventData)
end
end
elseif eventData[1] == "scroll" then
if eventData[5] == 1 then
if object.fromFile > 1 then
object.fromFile = object.fromFile - 1
object:draw(); buffer.draw()
end
else
if object.fromFile < #object.fileList then
object.fromFile = object.fromFile + 1
object:draw(); buffer.draw()
end
end
end
end
local function colorSelectorHandler(window, object, objectIndex, eventData)
object.pressed = true
object:draw(); buffer.draw()
object.color = require("palette").show("auto", "auto", object.color) or object.color
object.pressed = false
object:draw(); buffer.draw()
executeObjectMethod(object.onTouch, eventData)
end
function windows.handleEventData(window, eventData)
if eventData[1] == "touch" then
local object, objectIndex = window:getClickedObject(eventData[3], eventData[4])
if object then
if object.type == GUI.objectTypes.button then
buttonHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.tabBarTab then
tabBarTabHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.inputTextBox then
inputTextBoxHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.horizontalSlider then
horizontalSliderHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.switch then
switchHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.comboBox then
comboBoxHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.menuItem then
menuItemHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.scrollBar then
scrollBarHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.treeView then
treeViewHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.colorSelector then
colorSelectorHandler(window, object, objectIndex, eventData)
elseif object.onTouch then
executeObjectMethod(object.onTouch, eventData)
end
else
executeObjectMethod(window.onTouch, eventData)
end
elseif eventData[1] == "scroll" then
local object, objectIndex = window:getClickedObject(eventData[3], eventData[4])
if object then
if object.type == GUI.objectTypes.textBox then
textBoxScrollHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.scrollBar then
scrollBarHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.treeView then
treeViewHandler(window, object, objectIndex, eventData)
elseif object.onScroll then
executeObjectMethod(object.onScroll, eventData)
end
else
executeObjectMethod(window.onScroll, eventData)
end
elseif eventData[1] == "drag" then
local object, objectIndex = window:getClickedObject(eventData[3], eventData[4])
if object then
if object.type == GUI.objectTypes.horizontalSlider then
horizontalSliderHandler(window, object, objectIndex, eventData)
elseif object.type == GUI.objectTypes.scrollBar then
scrollBarHandler(window, object, objectIndex, eventData)
elseif object.onDrag then
executeObjectMethod(object.onDrag, eventData)
end
else
executeObjectMethod(window.onDrag, eventData)
end
elseif eventData[1] == "drop" then
local object, objectIndex = window:getClickedObject(eventData[3], eventData[4])
if object then
if object.onDrag then
executeObjectMethod(object.onDrop, eventData)
end
else
executeObjectMethod(window.onDrop, eventData)
end
elseif eventData[1] == "key_down" then
executeObjectMethod(window.onKeyDown, eventData)
elseif eventData[1] == "key_up" then
executeObjectMethod(window.onKeyUp, eventData)
end
executeObjectMethod(window.onAnyEvent, eventData)
end
function windows.handleEvents(window, pullTime)
while true do
window:handleEventData({event.pull(pullTime)})
if window.dataToReturn then
local data = window.dataToReturn
window = nil
return table.unpack(data)
end
end
end
----------------------------------------- Window actions -----------------------------------------
function windows.returnData(window, ...)
window.dataToReturn = {...}
computer.pushSignal("windowAction")
end
function windows.close(window)
windows.returnData(window, nil)
end
----------------------------------------- Window creation -----------------------------------------
function windows.correctWindowCoordinates(x, y, width, height, minimumWidth, minimumHeight)
width = minimumWidth and math.max(width, minimumWidth) or width
height = minimumHeight and math.max(height, minimumHeight) or height
x = (x == "auto" and math.floor(buffer.screen.width / 2 - width / 2)) or x
y = (y == "auto" and math.floor(buffer.screen.height / 2 - height / 2)) or y
return x, y, width, height
end
local function drawWindow(window)
if window.onDrawStarted then window.onDrawStarted() end
window:drawMethodOutOfWindowsLibrary()
if window.drawShadow then GUI.windowShadow(window.x, window.y, window.width, window.height, 50) end
if window.onDrawFinished then window.onDrawFinished() end
end
local function newWindow(x, y, width, height, minimumWidth, minimumHeight)
x, y, width, height = windows.correctWindowCoordinates(x, y, width, height, minimumWidth, minimumHeight)
local window = GUI.container(x, y, width, height)
window.minimumWidth = minimumWidth
window.minimumHeight = minimumHeight
window.drawShadow = false
window.drawMethodOutOfWindowsLibrary = window.draw
window.draw = drawWindow
window.handleEventData = windows.handleEventData
window.handleEvents = windows.handleEvents
window.close = windows.close
window.returnData = windows.returnData
return window
end
----------------------------------------- Window patterns -----------------------------------------
function windows.empty(x, y, width, height, minimumWidth, minimumHeight)
return newWindow(x, y, width, height, minimumWidth, minimumHeight)
end
function windows.fullScreen()
return newWindow(1, 1, buffer.screen.width, buffer.screen.height)
end
function windows.tabbed(x, y, width, height, minimumWidth, minimumHeight, ...)
local tabs = {...}
local window = newWindow(x, y, width, height, minimumWidth, minimumHeight)
window:addPanel(1, 1, window.width, window.height, 0xEEEEEE).disabled = true
window:addTabBar(1, 1, window.width, 3, 1, 0xDDDDDD, 0x262626, 0xCCCCCC, 0x262626, ...)
window:addWindowActionButtons(2, 1, false)
return window
end
----------------------------------------- Playground -----------------------------------------
-- local myWindow = windows.empty(2, 2, 60, 30, 60, 30)
-- myWindow:addColorSelector(2, 2, 30, 3, 0xFF00FF, "Text")
-- myWindow:draw()
-- buffer.draw()
-- myWindow:handleEvents()
-- local myWindow = windows.empty(2, 2, 20, 40, 20, 40)
-- myWindow:addTreeView(1, 1, myWindow.width, myWindow.height, 0xDDDDDD, 0x2D2D2D, 0x2D2D2D, 0xEEEEEE, 0x555555, 0x444444, 0x00DBFF, "/")
-- myWindow:draw()
-- buffer.draw()
-- myWindow:handleEvents()
-- local myWindow = windows.empty(2, 2, 60, 20, 60, 20)
-- local scrollBar = myWindow:addScrollBar(1, 1, 20, 1, 0x444444, 0x00DBFF, 1, 100, 50, 20, 4, true)
-- scrollBar.onTouch = function()
-- buffer.text(4, 1, 0xFFFFFF, "Value: " .. scrollBar.value)
-- end
-- myWindow:draw()
-- buffer.draw()
-- myWindow:handleEvents()
----------------------------------------- End of shit -----------------------------------------
return windows