tcl1

cwu 1.0b - a graphical API for ComputerCraft

Jun 6th, 2014
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.66 KB | None | 0 0
  1. function version() return "cwu 1.0 - by ntnick" end
  2.  
  3. function core_resColors()
  4.   term.setTextColour(colours.white)
  5.   term.setBackgroundColour(colours.black)
  6. end
  7. function screenH() local x, y = term.getSize() return {x,y} end
  8. function object_textButton(x,y,tCol,bCol,text)
  9.   term.setCursorPos(x,y)
  10.   term.setTextColour(tCol)
  11.   term.setBackgroundColour(bCol)
  12.   term.write(text)
  13.   term.setTextColour(colours.white)
  14.   term.setBackgroundColour(colours.black)
  15. end
  16. function object_button(x,y,buttonCol,buttonWidth)
  17.   term.setCursorPos(x,y)
  18.   term.setTextColour(buttonCol)
  19.   term.setBackgroundColour(buttonCol)
  20.   local cwu_bin_objects_iTxt = ""
  21.   for i=1, buttonWidth do
  22.     cwu_bin_objects_iTxt = cwu_bin_objects_iTxt.."d"
  23.   end
  24.   term.write(cwu_bin_objects_iTxt)
  25.   cwu_bin_objects_iTxt = nil
  26.   term.setTextColour(colours.white)
  27.   term.setBackgroundColour(colours.black)
  28. end
  29. function object_img(imgX,imgY,imgPath)
  30.   if(fs.exists(imgPath) == false) then
  31.     error("cwu-1.0: object_img: "..imgPath.." does not exist")
  32.   end
  33.   local cwu_bin_objects_o_imgPath = paintutils.loadImage(imgPath)
  34.   paintutils.drawImage(cwu_bin_objects_o_imgPath,x,y)
  35.   cwu_bin_objects_o_imgPath = nil
  36. end
  37. function object_textLabel(x,y,bCol,tCol,text)
  38.   term.setTextColour(tCol)
  39.   term.setBackgroundColour(bCol)
  40.   term.setCursorPos(x,y)
  41.   term.write(text)
  42.   term.setTextColour(colours.white)
  43.   term.setBackgroundColour(colours.black)
  44. end
  45. function object_animation(images,fps,animX,animY)
  46.   for i=1, #images do
  47.     local cwu_bin_objects_o_animationFrame = paintutils.loadImage(images[i])
  48.     paintutils.drawImage(cwu_bin_objects_o_animationFrame,animX,animY)
  49.     sleep(fps)
  50.     cwu_bin_objects_o_animationFrame = nil
  51.   end
  52. end
  53. function graphics_bColor(col)
  54.   local cwu_bin_graphics_w,cwu_bin_graphics_h = term.getSize()
  55.   term.setTextColour(col); term.setBackgroundColour(col)
  56.   for i=1, cwu_bin_graphics_h do
  57.     for j=1, cwu_bin_graphics_w do
  58.       term.setCursorPos(i,j)
  59.       term.write("o")
  60.     end
  61.   end
  62.   cwu_bin_graphics_w = nil
  63.   cwu_bin_graphics_h = nil
  64.   term.setTextColour(colours.white)
  65.   term.setBackgroundColour(colours.black)
  66. end
  67. function mtl_newWindow(posX,posY,sizeX,sizeY,color)
  68.   local cwu_bin_mtl_window = window.create(posX,posY,sizeX,sizeY)
  69.   cwu_bin_mtl_window.setBackgroundColour(color)
  70.   cwu_bin_mtl_window.clear()
  71.   return cwu_bin_mtl_window
  72. end
  73. function object_clock(x,y,bcol,tcol)
  74.   local cwu_bin_objects_clock_time = os.time()
  75.   term.setTextColour(tcol)
  76.   term.setBackgroundColour(bcol)
  77.   term.setCursorPos(x,y)
  78.  
  79.   term.write(cwu_bin_objects_clock_time)
  80.   term.setTextColour(colours.white)
  81.   term.setBackgroundColour(colours.black)
  82.   cwu_bin_objects_clock_time = nil
  83. end
  84. function object_textField(x,y,len,bCol,tCol)
  85.    term.setCursorPos(x,y)
  86.    term.setBackgroundColour(bCol)
  87.    term.setTextColour(tCol)
  88.    local cwu_bin_objects_tf_keys = 0
  89.    local cwu_bin_objects_tf_val  = x
  90.    local cwu_bin_objects_tf_cur  = x
  91.    local cwu_bin_typedText       = ""
  92.    for i=1, len do
  93.      term.setCursorPos(i,y)
  94.      term.setTextColour(bCol)
  95.      term.write("i")
  96.    end
  97.    term.setTextColour(tCol)
  98.    while true do
  99.      -- os.pullEventRaw isn't needed here..
  100.      local char, e = os.pullEvent("char")
  101.      term.setCursorPos(cwu_bin_objects_tf_cur,y)
  102.      cwu_bin_objects_tf_cur = cwu_bin_objects_tf_cur + 1
  103.      cwu_bin_objects_tf_keys = cwu_bin_objects_tf_keys + 1
  104.      term.write(e)
  105.      cwu_bin_typedText = cwu_bin_typedText..e
  106.      if(cwu_bin_objects_tf_keys == len) then
  107.        return cwu_bin_typedText
  108.      end
  109.    end
  110. end
  111.  
  112. -- window utilities
  113.  
  114. function mtl_appendText(window,text,tCol)
  115.   window.setTextColour(tCol)
  116.   window.write(text)
  117. end
Add Comment
Please, Sign In to add comment