Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("./lib/draw")
- os.loadAPI("./lib/window")
- --local m = peripheral.wrap("right")
- --m.clear()
- term.clear()
- --window.setOutput(m)
- local winT = window.windowTable
- --register a new window by setting it up as below and reister it with window:register(order)
- local w1 = window.Window:new()
- w1:setPos(4,5)
- w1:setSize(30,10)
- --w1:setVisible(true)
- w1:register(2)
- w1:setText("Ultralong Text just to show how well this actually works!!! Lorem ipsum dolor blablah... Maybe I'll implement a linefeed option somehow. And a \"cut at spaces\" option")
- w1:setTitle("Text")
- local w2 = window.Window:new()
- w2:setPos(16,7)
- w2:setSize(25,12)
- w2:setColor(colors.lime)
- --w2:setVisible(true)
- w2:register(1)
- w2:setText("Another Test Text, just to see if overlapping works as intended!")
- local w3 = window.Window:new()
- w3:setPos(20,3)
- w3:setSize(15,8)
- w3:setColor(colors.orange)
- w3:register(3)
- local w4 = window.Window:new()
- w4:setPos(23,10)
- w4:setSize(10,9)
- w4:setColor(colors.red)
- w4:register(1)
- w4:setText("Test Textwrap in Window (cutting y already implemented!)")
- -- for k,v in pairs(winT) do
- -- print(v.uuid)
- -- os.pullEvent("key")
- -- end
- -- sleep(3)
- while true do
- sleep(0.02) --short sleep time to reduce screen flickering
- term.clear()
- --debug stuff
- term.setCursorPos(1,1)
- print("TSize: "..#winT)
- --
- window.drawWindows() --draws all windows in WindowTable
- local ev, btn, cx,cy = os.pullEvent()
- if ev == "mouse_click" then
- for i=1, #winT do --Runs through WIndows from front to back to prevent covered windows from triggering
- if(winT[i]:isClicked(cx,cy))then --If window is clicked, register it as front window.
- winT[i]:register(1)
- break
- end
- end
- elseif ev == "mouse_drag" then --Beware! messy code!
- tVars = {winT[1]:getClick(lx,ly)} --gets the click coordinates within the window, assumes top window because it's lazier this way
- if tVars[1] then
- if tVars[3] == 1 then --some math or rather if statements to determine if the window is dragged at the top
- wx, wy = winT[1]:getPos()
- winT[1]:setPos( wx + (cx-lx), wy + (cy-ly) )
- elseif tVars[2] == winT[1].xs and tVars[3] == winT[1].ys then --same idea, just the right lower corner this time (resizing)
- if not (winT[1].xs < 15 and cx-lx < 0) then
- winT[1].xs = winT[1].xs + (cx-lx)
- end
- if not (winT[1].ys < 5 and cy-ly < 0) then
- winT[1].ys = winT[1].ys + (cy-ly)
- --TODO: Add functions to alter size and stuff.
- end
- end
- end
- end
- lx, ly = cx, cy --backs up the click to scan for differences for drag
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement