Advertisement
guitarplayer616

Its an actual cursor

Jun 14th, 2015
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.87 KB | None | 0 0
  1. term.clear()
  2. w,h = term.getSize()
  3. local x,y = term.getCursorPos()
  4. local str = ""
  5. local posX,posY --= nil,nil
  6. local elements = {}
  7.   --"x,y" = {"string",colors.text,colors.back}
  8.  
  9.  
  10. function draw(words,x,y,col,back)
  11.   words = tostring(words) or ""
  12.   col = col or colors.white
  13.   back = back or colors.black
  14.   if x and y then
  15.     term.setCursorPos(x,y)
  16.     posX,posY = x,y
  17.     for i=1,#words do
  18.       posX,posY = tostring(posX),tostring(posY)
  19.       local coord = posX..","..posY
  20.       elements[coord] = {words:sub(i,i),col,back}
  21.       posX = tonumber(posX) + 1
  22.     end
  23.   end
  24.   term.setTextColor(col)
  25.   term.setBackgroundColor(back)
  26.   write(words)
  27.   posX,posY = nil,nil
  28. end
  29.  
  30. draw("string",7,5,colors.green,colors.white)
  31. draw("here's more",14,5,colors.purple,colors.grey)
  32.  
  33. --[[term.setCursorPos(1,7)
  34.  
  35. for i,v in pairs(elements) do
  36.   write(i.." : ")
  37.   for k=1,#v do
  38.     write(tostring(v[k]).." ")
  39.   end
  40. end
  41.  
  42. for i,v in pairs(elements) do
  43.   local half = i:find(",")
  44.   draw(v[1],i:sub(1,half-1),i:sub(half+1)+1,v[2],v[3])
  45. end]]
  46.  
  47.  
  48. function clearMove(k,l)
  49.   for i,v in pairs(elements) do
  50.     local half = i:find(",")
  51.     local px = tonumber(i:sub(1,half-1))
  52.     local py = tonumber(i:sub(half+1))
  53.     if k == px and l == py then
  54.       draw(v[1],x,y,v[2],v[3])
  55.     else
  56.       draw(" ",x,y)
  57.     end
  58.   end
  59. end
  60.  
  61. while true do
  62.   e = {os.pullEvent()}
  63.   if (e[1] == "mouse_drag" or e[1] == "mouse_click") and e[2] == 2 then
  64.     clearMove(x,y)
  65.     x,y = e[3],e[4]
  66.     for i,v in pairs(elements) do
  67.       i = tostring(i)
  68.       local half = i:find(",")
  69.       if tostring(x) == i:sub(1,half-1) then
  70.         --if tostring(y) == i:sub(half+1) then
  71.           str = "I"
  72.         --end
  73.       else
  74.         str = "^"
  75.       end
  76.     end
  77.   elseif e[1] == "mouse_click" and e[2] == 1 then
  78.     clearMove(x,y)
  79.     x,y = e[3],e[4]
  80.     str = "*"
  81.   end
  82.   draw(str,x,y)
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement