SHARE
TWEET

drawtext.lua

a guest Mar 22nd, 2019 77 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.   if out == "string" then
  27.     if setString:find("\n") then
  28.       if y == maxY and passed == true then
  29.         w = maxX
  30.         h = maxY
  31.         gpu2p.copy(1,2,w,h-1,0,-1)
  32.         --print("copied")                   -- print for info
  33.         gpu2p.fill(1,maxY,maxX,maxY," ")
  34.       end
  35.     end
  36.   end
  37.  
  38.   --print(setString)
  39.   if type(setString) == "number" then
  40.     newString = tostring(setString)
  41.   elseif type(setString) == "string" then
  42.     newString = string.gsub(setString,"\n","")
  43.   else
  44.     newString = setString
  45.   end
  46.   --print(newString,setString)
  47.  
  48.   gpu2p.set(drawT.x,y,newString)
  49.  
  50.  
  51.  
  52.                                  -- wenn der input ein string ist
  53.     if out == "string" then
  54.       if setString:find("\n") then    -- wenn der string "\n" beinhaltet dann gehe runter zur der nächsten zeile
  55.         drawT.x = 1
  56.         if y < maxY then
  57.           drawT.count = drawT.count+1
  58.      --     print("count added:"..drawT.count) --print for info
  59.         else
  60.         passed = true
  61.         end
  62.         drawT.lastStringLen = nil
  63.       else
  64.     --   print("no \\n in there so carry lastStringLen") -- print for info
  65.        drawT.lastStringLen = string.len(newString)
  66.       end
  67.     elseif out == "number" then
  68.       drawT.lastStringLen = string.len(newString)
  69.     end
  70.  
  71.  
  72.  
  73.  
  74.  
  75.   -- printing info section --
  76.   --local justprinten
  77.   --if not drawT.lastStringLen then            -- print for info
  78.   --  justprinten = "nil"                      -- print for info
  79.   --else                                       -- print for info
  80.   --  justprinten = drawT.lastStringLen        -- print for info
  81.   --end                                        -- print for info
  82.   --print("LastStrLen:"..justprinten.."|x:"..drawT.x.."|count:"..drawT.count)   -- print for info
  83. 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