turtle5204

CC Window API

Aug 9th, 2014
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. -- HAX0R'S Easy Windowing API
  2.  
  3. local fccv = os.version()
  4. local ver = fccv:sub(fccv:len()-2, fccv:len())
  5.  
  6.  
  7.  
  8. local queue = {}
  9.  
  10. if tonumber(ver) < 1.6 then
  11.  error("Incompatbile with CC 1.5 and below!")
  12. end
  13.  
  14.  
  15.  
  16. function makeWindow(name, x, y, width, height, program)
  17.  
  18.  local x = window.create(term.native(), x, y, width, true)
  19.  
  20.  for a=1, #queue do
  21.   if queue[a]["name"] == name then
  22.    error("A window with the name '"..name.."' already exists!")  
  23.  end
  24.  
  25.  table.insert( {
  26.  ["name"] = name,
  27.  ["queue"] = {},
  28.  ["redirect"] = x
  29.  } )
  30.  
  31.  for i=1, #queue do
  32.   if queue[i]["name"] == name then
  33.    table.insert(queue[i]["queue"], program)
  34.   end
  35.  end
  36.  
  37.  return true
  38. end
  39.  
  40. function addProgram(winName, program)
  41.  for i=1, #queue do
  42.   if queue[i]["name"] == name then
  43.    table.insert(queue[i]["queue"], program)
  44.   end
  45.  end
  46. end
  47.  
  48. function runQueue(name)
  49.  for a=1, #queue do
  50.   if queue[a]["name"] == name then
  51.    for b=1, #queue[a]["queue"] do
  52.     term.redirect(queue[a]["redirect"])
  53.     os.run({}, queue[a]["queue"][b])
  54.     term.redirect(term.native())
  55.    end
  56.   end
  57.  end
  58. end
  59.  
  60. function moveWindow(name, x, y)
  61.  for a=1, #queue do
  62.   if queue[a]["name"] == name then
  63.    queue[a]["redirect"].reposition(x, y)
  64.   end
  65.  end
  66. end
  67.  
  68. function getPosition(name)
  69.  for a=1, #queue do
  70.   if queue[a]["name"] == name then
  71.    local w, h = queue[a]["redirect"].getPosition()
  72.    return w, h
  73.   end
  74.  end
  75.  return nil
  76. end
  77.  
  78.  
  79. function resizeWindow(name, w, h)
  80.  for a=1, #queue do
  81.   if queue[a]["name"] == name then
  82.    local x, y = getPosition(name)
  83.    queue[a]["redirect"].reposition(x, y, w, h)
  84.   end
  85.  end
  86. end
Add Comment
Please, Sign In to add comment