From 7d1cb180bf0ee8001b41d1a6b2af95d1a420febc Mon Sep 17 00:00:00 2001 From: LDDestroier Date: Thu, 18 Apr 2019 18:17:49 -0400 Subject: [PATCH] Added cursor transformation function --- lddterm-cc.lua | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lddterm-cc.lua b/lddterm-cc.lua index d0bd034..df48d79 100644 --- a/lddterm-cc.lua +++ b/lddterm-cc.lua @@ -1,6 +1,3 @@ --- LDDTerm for ComputerCraft --- Basically a replacement for the Window API but different - local lddterm = {} local scr_x, scr_y @@ -8,6 +5,7 @@ lddterm.alwaysRender = true -- renders after any and all screen-changing functi lddterm.useColors = true -- normal computers do not allow color, but this variable doesn't do anything yet lddterm.baseTerm = term.current() -- will draw to this terminal lddterm.transformation = nil -- will modify the current buffer as an NFT image before rendering +lddterm.cursorTransformation = nil -- will modify the cursor position lddterm.drawFunction = nil -- will draw using this function instead of basic NFT drawing lddterm.adjustX = 0 -- moves entire screen X lddterm.adjustY = 0 -- moves entire screen Y @@ -85,11 +83,20 @@ lddterm.checkWindowOverlap = function(window, ...) end local fixCursorPos = function() + local cx, cy if lddterm.windows[1] then - lddterm.baseTerm.setCursorPos( - -1 + lddterm.windows[1].cursor[1] + lddterm.windows[1].x, - lddterm.windows[1].cursor[2] + lddterm.windows[1].y - 1 - ) + if lddterm.cursorTransformation then + cx, cy = lddterm.cursorTransformation(lddterm.windows[1].cursor[1], lddterm.windows[1].cursor[2]) + lddterm.baseTerm.setCursorPos( + cx + lddterm.windows[1].x - 1, + cy + lddterm.windows[1].y - 1 + ) + else + lddterm.baseTerm.setCursorPos( + -1 + lddterm.windows[1].cursor[1] + lddterm.windows[1].x, + lddterm.windows[1].cursor[2] + lddterm.windows[1].y - 1 + ) + end end end