SHARE
TWEET

drawtext.lua

a guest Mar 29th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local c = require("component")
  2. --local gpu2 = c.proxy(c.get("009"))
  3. --local screen2 = c.get("2ed")
  4. --gpu2.bind(screen2)
  5. --Variables--
  6. local pass = false
  7. --Global Variables--
  8. drawT = {}
  9. drawT.lastStringLen = nil
  10. drawT.x = 1
  11. drawT.count = 1
  12. ---------------------
  13.  
  14.  
  15. function drawText(setString,gpu2p)
  16.   local maxX,maxY = gpu2p.getResolution()
  17.   local out = type(setString)
  18.   local y,w,h,newString
  19.   y = drawT.count
  20.   --print("maxX/Y:"..maxX.."/"..maxY.."|stringType:"..out.."|y:"..y) -- print for info
  21.    
  22.   if drawT.lastStringLen then  -- Addiere die länge vom letzten string zu jetzigem und entferne vielleicht die lastStringLen
  23.   --print("from laststring add x")           -- print for info
  24.     drawT.x = drawT.x+drawT.lastStringLen
  25.   end
  26.   local function copy()
  27.   if out == "string" then
  28.     if setString:find("\n") then
  29.       if y == maxY and passed == true then
  30.         w = maxX
  31.         h = maxY
  32.         gpu2p.copy(1,2,w,h-1,0,-1)
  33.         --print("copied")                   -- print for info
  34.         gpu2p.fill(1,maxY,maxX,maxY," ")
  35.       end
  36.     end
  37.   end
  38.   end
  39.   --print(setString)
  40.   if type(setString) == "number" then
  41.     newString = tostring(setString)
  42.   elseif type(setString) == "string" then
  43.     newString = string.gsub(setString,"\n","")
  44.   else
  45.     newString = setString
  46.   end
  47.   --print(newString,setString)
  48.  
  49.   gpu2p.set(drawT.x,y,newString)
  50.  
  51.   copy()
  52.  
  53.                                  -- wenn der input ein string ist
  54.     if out == "string" then
  55.       if setString:find("\n") then    -- wenn der string "\n" beinhaltet dann gehe runter zur der nächsten zeile
  56.         drawT.x = 1
  57.         if y < maxY then
  58.           drawT.count = drawT.count+1
  59.      --     print("count added:"..drawT.count) --print for info
  60.         else
  61.         passed = true
  62.         end
  63.         drawT.lastStringLen = nil
  64.       else
  65.     --   print("no \\n in there so carry lastStringLen") -- print for info
  66.        drawT.lastStringLen = string.len(newString)
  67.       end
  68.     elseif out == "number" then
  69.       drawT.lastStringLen = string.len(newString)
  70.     end
  71.  
  72.  
  73.  
  74.  
  75.  
  76.   -- printing info section --
  77.   --local justprinten
  78.   --if not drawT.lastStringLen then            -- print for info
  79.   --  justprinten = "nil"                      -- print for info
  80.   --else                                       -- print for info
  81.   --  justprinten = drawT.lastStringLen        -- print for info
  82.   --end                                        -- print for info
  83.   --print("LastStrLen:"..justprinten.."|x:"..drawT.x.."|count:"..drawT.count)   -- print for info
  84. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top