mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2025-12-20 02:59:20 +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 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 lineFrom = 1
|
||||
local lines = {}
|
||||
local input = ""
|
||||
|
||||
disp.draw = function(disp)
|
||||
local x, y = disp.x, disp.y
|
||||
display.draw = function(display)
|
||||
local x, y = display.x, display.y
|
||||
for i = lineFrom, #lines do
|
||||
screen.drawText(x, y, 0xFFFFFF, lines[i])
|
||||
y = y + 1
|
||||
@ -27,13 +27,13 @@ disp.draw = function(disp)
|
||||
screen.drawText(x + unicode.len(text), y, 0x00A8FF, "┃")
|
||||
end
|
||||
|
||||
window.addLine = function(value)
|
||||
local value = text.wrap(value, disp.width)
|
||||
window.addLine = function(window, value)
|
||||
local value = text.wrap(value, display.width)
|
||||
|
||||
for i = 1, #value do
|
||||
table.insert(lines, value[i])
|
||||
|
||||
if #lines - lineFrom + 1 > disp.height - 1 then
|
||||
if #lines - lineFrom + 1 > display.height - 1 then
|
||||
lineFrom = lineFrom + 1
|
||||
end
|
||||
end
|
||||
@ -53,18 +53,19 @@ window.eventHandler = function(workspace, window, ...)
|
||||
end
|
||||
|
||||
workspace:draw()
|
||||
|
||||
elseif e[1] == "key_down" and GUI.focusedObject == window then
|
||||
-- Return
|
||||
if e[4] == 28 then
|
||||
window.addLine("> " .. input)
|
||||
window:addLine("> " .. input)
|
||||
input = ""
|
||||
|
||||
-- Backspace
|
||||
elseif e[4] == 14 then
|
||||
input = unicode.sub(input, 1, -2)
|
||||
-- Printable character
|
||||
elseif not keyboard.isControl(e[3]) then
|
||||
local char = unicode.char(e[3])
|
||||
|
||||
input = input .. char
|
||||
input = input .. unicode.char(e[3])
|
||||
end
|
||||
|
||||
workspace:draw()
|
||||
@ -73,21 +74,13 @@ window.eventHandler = function(workspace, window, ...)
|
||||
overrideWindowEventHandler(workspace, window, ...)
|
||||
end
|
||||
|
||||
local overrideWindowRemove = window.remove
|
||||
window.remove = function(...)
|
||||
system.consoleWindow = nil
|
||||
|
||||
overrideWindowRemove(...)
|
||||
end
|
||||
|
||||
window.onResize = function(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
|
||||
|
||||
---------------------------------------------------------------------------------
|
||||
|
||||
system.consoleWindow = window
|
||||
|
||||
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))
|
||||
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
|
||||
@ -2912,19 +2928,16 @@ end
|
||||
-- Global print() function for debugging
|
||||
_G.print = function(...)
|
||||
if not system.consoleWindow then
|
||||
local result, data = loadfile(paths.system.applicationConsole)
|
||||
|
||||
if result then
|
||||
result, data = xpcall(result, debug.traceback)
|
||||
|
||||
if not result then
|
||||
GUI.alert(data)
|
||||
return
|
||||
end
|
||||
else
|
||||
GUI.alert(data)
|
||||
return
|
||||
system.consoleWindow = system.addConsoleWindow()
|
||||
|
||||
local overrideWindowRemove = system.consoleWindow.remove
|
||||
system.consoleWindow.remove = function(...)
|
||||
system.consoleWindow = nil
|
||||
|
||||
overrideWindowRemove(...)
|
||||
end
|
||||
|
||||
workspace:draw()
|
||||
end
|
||||
|
||||
local args, arg = {...}
|
||||
@ -2943,7 +2956,7 @@ _G.print = function(...)
|
||||
|
||||
args = table.concat(args, " ")
|
||||
|
||||
system.consoleWindow.addLine(args)
|
||||
system.consoleWindow:addLine(args)
|
||||
system.consoleWindow:focus()
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user