diff --git a/inventoryManager.lua b/inventoryManager.lua index edd6e7a..bcba147 100644 --- a/inventoryManager.lua +++ b/inventoryManager.lua @@ -96,33 +96,36 @@ end -- Drawing helpers ------------------------------------------------- +-- Drawing target (set to offscreen buffer in drawDashboard) +local draw = nil + local function monWrite(x, y, text, fg, bg) - mon.setCursorPos(x, y) - if fg then mon.setTextColor(fg) end - if bg then mon.setBackgroundColor(bg) end - mon.write(text) + draw.setCursorPos(x, y) + if fg then draw.setTextColor(fg) end + if bg then draw.setBackgroundColor(bg) end + draw.write(text) end local function monFill(y, color) - local w, _ = mon.getSize() - mon.setCursorPos(1, y) - mon.setBackgroundColor(color) - mon.write(string.rep(" ", w)) + local w, _ = draw.getSize() + draw.setCursorPos(1, y) + draw.setBackgroundColor(color) + draw.write(string.rep(" ", w)) end local function monCenter(y, text, fg, bg) - local w, _ = mon.getSize() + local w, _ = draw.getSize() local x = math.floor((w - #text) / 2) + 1 monWrite(x, y, text, fg, bg) end local function monBar(x, y, width, ratio, barColor, bgColor) local filled = math.floor(ratio * width) - mon.setCursorPos(x, y) - mon.setBackgroundColor(barColor) - mon.write(string.rep(" ", filled)) - mon.setBackgroundColor(bgColor) - mon.write(string.rep(" ", width - filled)) + draw.setCursorPos(x, y) + draw.setBackgroundColor(barColor) + draw.write(string.rep(" ", filled)) + draw.setBackgroundColor(bgColor) + draw.write(string.rep(" ", width - filled)) end local function drawButton(x, y, text, fg, bg, padLeft, padRight) @@ -146,8 +149,10 @@ local function drawDashboard() local w, h = mon.getSize() touchZones = {} - mon.setBackgroundColor(colors.black) - mon.clear() + -- Create offscreen buffer (invisible) + draw = window.create(mon, 1, 1, w, h, false) + draw.setBackgroundColor(colors.black) + draw.clear() -- ===== Title bar ===== monFill(1, colors.blue) @@ -310,6 +315,9 @@ local function drawDashboard() -- Bottom accent monFill(h, colors.blue) monCenter(h, " Tap item to order ", colors.lightBlue, colors.blue) + + -- Flush buffer to monitor in one go + draw.setVisible(true) end -------------------------------------------------