This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
MadBudderKing's profile picture

term.redirect refering to the Window, Not the screen itself

Started by MadBudderKing, 10 May 2014 - 07:21 PM
MadBudderKing #1
Posted 10 May 2014 - 09:21 PM
–First off I dont know if this may be a bug or if its meant to be like this, but bassicly heres the suggestion.

When you create a window, and redirect to it using term.redirect, the position of the mouse click and drag refer to the computer screen, not the window.
It should be able though to get the Cursor Pos From the window. I mean by the window starts at 2,2 on the computer screen. But 1,1 on the window is located at 2,2 on the computer screen.

If this is found to be a bug - Please move this to the bug thread.
Though Im just posting it in here, because im just thinking that its somekind of un-added feature.
Thanks -MadBudder
Wojbie #2
Posted 10 May 2014 - 09:34 PM
Yea sadly you need to make your own code to handle this kind of situation. You can find basic example of it if you take a look at multi-shell code.
apemanzilla #3
Posted 13 May 2014 - 08:23 PM
I wrote a nice little method for it a few days ago when I hit the same exact problem.

It returns x and y respectively of the coords passed to it if they lie on the window, otherwise returns nothing if the coords passed are NOT on the window.

You can see the code for the function in one of my APIs here and an example usage here. I've also converted it to a gist if you prefer to see just the definition, here.


local example = window.create(term.current(),5,5,10,7)
term.redirect(example)
local e, a, b, c = os.pullEvent("mouse_click")
print(adjustForWindow(b,c,example)
term.redirect(term.native())
Edited on 13 May 2014 - 06:27 PM