mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2025-12-20 11:09:21 +01:00
Ивентовая приложуха
This commit is contained in:
parent
2d2b6a320d
commit
fdf6f7b5d9
@ -9,14 +9,14 @@ local text = require("Text")
|
|||||||
|
|
||||||
local workspace, window, menu = system.addWindow(GUI.filledWindow(1, 1, 82, 28, 0x000000))
|
local workspace, window, menu = system.addWindow(GUI.filledWindow(1, 1, 82, 28, 0x000000))
|
||||||
|
|
||||||
local disp = window:addChild(GUI.object(2, 4, 1, 1))
|
local display = window:addChild(GUI.object(2, 4, 1, 1))
|
||||||
local cursorX, cursorY = 1, 1
|
local cursorX, cursorY = 1, 1
|
||||||
local lineFrom = 1
|
local lineFrom = 1
|
||||||
local lines = {}
|
local lines = {}
|
||||||
local input = ""
|
local input = ""
|
||||||
|
|
||||||
disp.draw = function(disp)
|
display.draw = function(display)
|
||||||
local x, y = disp.x, disp.y
|
local x, y = display.x, display.y
|
||||||
for i = lineFrom, #lines do
|
for i = lineFrom, #lines do
|
||||||
screen.drawText(x, y, 0xFFFFFF, lines[i])
|
screen.drawText(x, y, 0xFFFFFF, lines[i])
|
||||||
y = y + 1
|
y = y + 1
|
||||||
@ -27,13 +27,13 @@ disp.draw = function(disp)
|
|||||||
screen.drawText(x + unicode.len(text), y, 0x00A8FF, "┃")
|
screen.drawText(x + unicode.len(text), y, 0x00A8FF, "┃")
|
||||||
end
|
end
|
||||||
|
|
||||||
window.addLine = function(value)
|
window.addLine = function(window, value)
|
||||||
local value = text.wrap(value, disp.width)
|
local value = text.wrap(value, display.width)
|
||||||
|
|
||||||
for i = 1, #value do
|
for i = 1, #value do
|
||||||
table.insert(lines, value[i])
|
table.insert(lines, value[i])
|
||||||
|
|
||||||
if #lines - lineFrom + 1 > disp.height - 1 then
|
if #lines - lineFrom + 1 > display.height - 1 then
|
||||||
lineFrom = lineFrom + 1
|
lineFrom = lineFrom + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -53,18 +53,19 @@ window.eventHandler = function(workspace, window, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
workspace:draw()
|
workspace:draw()
|
||||||
|
|
||||||
elseif e[1] == "key_down" and GUI.focusedObject == window then
|
elseif e[1] == "key_down" and GUI.focusedObject == window then
|
||||||
-- Return
|
-- Return
|
||||||
if e[4] == 28 then
|
if e[4] == 28 then
|
||||||
window.addLine("> " .. input)
|
window:addLine("> " .. input)
|
||||||
input = ""
|
input = ""
|
||||||
|
|
||||||
-- Backspace
|
-- Backspace
|
||||||
elseif e[4] == 14 then
|
elseif e[4] == 14 then
|
||||||
input = unicode.sub(input, 1, -2)
|
input = unicode.sub(input, 1, -2)
|
||||||
|
-- Printable character
|
||||||
elseif not keyboard.isControl(e[3]) then
|
elseif not keyboard.isControl(e[3]) then
|
||||||
local char = unicode.char(e[3])
|
input = input .. unicode.char(e[3])
|
||||||
|
|
||||||
input = input .. char
|
|
||||||
end
|
end
|
||||||
|
|
||||||
workspace:draw()
|
workspace:draw()
|
||||||
@ -73,21 +74,13 @@ window.eventHandler = function(workspace, window, ...)
|
|||||||
overrideWindowEventHandler(workspace, window, ...)
|
overrideWindowEventHandler(workspace, window, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
local overrideWindowRemove = window.remove
|
|
||||||
window.remove = function(...)
|
|
||||||
system.consoleWindow = nil
|
|
||||||
|
|
||||||
overrideWindowRemove(...)
|
|
||||||
end
|
|
||||||
|
|
||||||
window.onResize = function(newWidth, newHeight)
|
window.onResize = function(newWidth, newHeight)
|
||||||
window.backgroundPanel.width, window.backgroundPanel.height = newWidth, newHeight
|
window.backgroundPanel.width, window.backgroundPanel.height = newWidth, newHeight
|
||||||
disp.width, disp.height = newWidth - 2, newHeight - 3
|
display.width, display.height = newWidth - 2, newHeight - 3
|
||||||
end
|
end
|
||||||
|
|
||||||
---------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------
|
||||||
|
|
||||||
system.consoleWindow = window
|
|
||||||
|
|
||||||
window.onResize(window.width, window.height)
|
window.onResize(window.width, window.height)
|
||||||
workspace:draw()
|
|
||||||
|
return window
|
||||||
BIN
Applications/Events.app/Icon.pic
Normal file
BIN
Applications/Events.app/Icon.pic
Normal file
Binary file not shown.
52
Applications/Events.app/Main.lua
Normal file
52
Applications/Events.app/Main.lua
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
|
||||||
|
local GUI = require("GUI")
|
||||||
|
local system = require("System")
|
||||||
|
local screen = require("Screen")
|
||||||
|
local text = require("Text")
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local workspace, window, menu = system.addWindow(GUI.filledWindow(1, 1, 82, 28, 0x000000))
|
||||||
|
|
||||||
|
local display = window:addChild(GUI.object(2, 4, 1, 1))
|
||||||
|
local lines = {}
|
||||||
|
|
||||||
|
display.draw = function(display)
|
||||||
|
if #lines == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local y = display.y + display.height - 1
|
||||||
|
|
||||||
|
for i = #lines, math.max(#lines - display.height, 1), -1 do
|
||||||
|
screen.drawText(display.x, y, 0xFFFFFF, lines[i])
|
||||||
|
y = y - 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
display.eventHandler = function(workspace, display, e1, ...)
|
||||||
|
if e1 then
|
||||||
|
local wrappedLines = text.wrap(table.concat({e1, ...}, " "), display.width)
|
||||||
|
|
||||||
|
for i = 1, #wrappedLines do
|
||||||
|
local line = wrappedLines[i]:gsub(" ", " ")
|
||||||
|
table.insert(lines, line)
|
||||||
|
|
||||||
|
if #lines > display.height then
|
||||||
|
table.remove(lines, 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
workspace:draw()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
window.onResize = function(newWidth, newHeight)
|
||||||
|
window.backgroundPanel.width, window.backgroundPanel.height = newWidth, newHeight
|
||||||
|
display.width, display.height = newWidth - 2, newHeight - 4
|
||||||
|
end
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
window.onResize(window.width, window.height)
|
||||||
|
workspace:draw()
|
||||||
@ -2898,6 +2898,22 @@ function system.addBlurredOrDefaultPanel(container, x, y, width, height)
|
|||||||
return container:addChild(userSettings.interfaceBlurEnabled and GUI.blurredPanel(x, y, width, height, userSettings.interfaceBlurRadius, 0x0, userSettings.interfaceBlurTransparency) or GUI.panel(x, y, width, height, 0x2D2D2D))
|
return container:addChild(userSettings.interfaceBlurEnabled and GUI.blurredPanel(x, y, width, height, userSettings.interfaceBlurRadius, 0x0, userSettings.interfaceBlurTransparency) or GUI.panel(x, y, width, height, 0x2D2D2D))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function system.addConsoleWindow()
|
||||||
|
local result, data = loadfile(paths.system.applicationConsole)
|
||||||
|
|
||||||
|
if result then
|
||||||
|
result, data = xpcall(result, debug.traceback)
|
||||||
|
|
||||||
|
if not result then
|
||||||
|
GUI.alert(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
return data
|
||||||
|
else
|
||||||
|
GUI.alert(data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Keeping temporary file's last modified timestamp as boot timestamp
|
-- Keeping temporary file's last modified timestamp as boot timestamp
|
||||||
@ -2912,19 +2928,16 @@ end
|
|||||||
-- Global print() function for debugging
|
-- Global print() function for debugging
|
||||||
_G.print = function(...)
|
_G.print = function(...)
|
||||||
if not system.consoleWindow then
|
if not system.consoleWindow then
|
||||||
local result, data = loadfile(paths.system.applicationConsole)
|
system.consoleWindow = system.addConsoleWindow()
|
||||||
|
|
||||||
if result then
|
local overrideWindowRemove = system.consoleWindow.remove
|
||||||
result, data = xpcall(result, debug.traceback)
|
system.consoleWindow.remove = function(...)
|
||||||
|
system.consoleWindow = nil
|
||||||
|
|
||||||
if not result then
|
overrideWindowRemove(...)
|
||||||
GUI.alert(data)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
else
|
|
||||||
GUI.alert(data)
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
workspace:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
local args, arg = {...}
|
local args, arg = {...}
|
||||||
@ -2943,7 +2956,7 @@ _G.print = function(...)
|
|||||||
|
|
||||||
args = table.concat(args, " ")
|
args = table.concat(args, " ")
|
||||||
|
|
||||||
system.consoleWindow.addLine(args)
|
system.consoleWindow:addLine(args)
|
||||||
system.consoleWindow:focus()
|
system.consoleWindow:focus()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user