From 2e283d27676605144a5a3683dbdc844244786715 Mon Sep 17 00:00:00 2001 From: 20kdc Date: Thu, 12 Apr 2018 11:26:31 +0100 Subject: [PATCH] Update KTC1 draft, add palette 'suggestion' mechanism, and write a usable draft of us-evrst --- KTC1.md | 2 +- code/apps/sys-everest.lua | 16 ++++++++++++++++ repository/docs/us-evrst | 40 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/KTC1.md b/KTC1.md index 984c821..18dee8f 100644 --- a/KTC1.md +++ b/KTC1.md @@ -14,7 +14,7 @@ A 256-colour palette is assumed, and it is assumed that the palette is provided A KTC1 block is one OpenComputers character (2x4 pixels), and is 4 bytes long. -The format amounts to a foreground palette index, a background palette index, +The format amounts to a background palette index, a foreground palette index, and a Unicode character index in the Basic Multilingual Plane. The unicode character is displayed with the given colours at the position of the diff --git a/code/apps/sys-everest.lua b/code/apps/sys-everest.lua index 7b74d92..9133c29 100644 --- a/code/apps/sys-everest.lua +++ b/code/apps/sys-everest.lua @@ -500,6 +500,22 @@ everestProvider(function (pkg, pid, sendSig) if y == 0 then return end handleSpan(surf, x, y + 1, text, bg, fg) end, + recommendPalette = function (pal) + neo.ensureType(pal, "table") + if neo.dead then return 0 end + if not focusState then return 0 end + local m = monitors[surf[1]] + if not m then return 0 end + local cb, rb = m[1]() + if not cb then return 0 end + if rb then + monitorResetBF(m) + end + for k, v in ipairs(pal) do + local ok = pcall(cb.setPaletteColor, k - 1, v) + if not ok then return k - 1 end + end + end, close = function () if neo.dead then return end local os1 = surfaces[1] diff --git a/repository/docs/us-evrst b/repository/docs/us-evrst index 9b79c80..58eadb2 100644 --- a/repository/docs/us-evrst +++ b/repository/docs/us-evrst @@ -13,6 +13,46 @@ Implementing this API, by definition, heavily restricted unless the user uses the Advanced Settings panel. +The API gives you a function: + (w, h, title) -> window + +This function creates a window. + +Window fields: + + id: Window ID. + setSize(w, h): Changes the size of + the window, and sends the line + events (even if the size doesn't + change) + getDepth(): Returns the depth of the + screen the window is on. + span(x, y, text, bg, fg): Draws a + span onto the screen. + This function will error if the + Everest instance is dead. + (Others won't.) + recommendPalette(pal): If the window + is focused, sets the first #pal + palette entries to the given RGB + values. + This is meant only as a hint to + Everest, and may be ignored. + Returns 0. + close(): Close the window. + +Events: + + api, id, "key", ka, kc, down + api, id, "touch"/"drag"/"drop", + lx, ly, ix, iy, button + api, id, "scroll", + lx, ly, ix, iy, amount + api, id, "clipboard", text + api, id, "close" + api, id, "focus", hasFocus + api, id, "line", lineIndex + -- This is released into the public domain. -- No warranty is provided,