window.redraw

From ComputerCraft Wiki
Jump to: navigation, search


Grid Redstone.png  Function window.redraw
A function available to window-based terminal objects created via the window API, which re-renders everything that has been rendered via the window in concern (assuming it is visible). This includes content rendered via child windows.

Generally this is handy if one window has written content over the top of the top of another (of which it is not a child), and you wish to bring the content of the covered window back to the fore-front of your display.

You need not call this function when simply making a window visible or when moving / resizing it; they call it automatically. Redrawing a window also restores its cursor.
Syntax window.redraw()
Returns None
Part of ComputerCraft
API term

Examples

Grid paper.png  Example
Draws a checkerboard pattern in a large window, then bounces a smaller window over the top of it, without needing to manually reconstruct the areas rendered over (Ctrl + T to exit):
Code
local xSize, ySize = term.getSize()

-- Draw a checkerboard pattern in a window that covers the screen:
local checkerWindow = window.create(term.current(), 1, 1, xSize, ySize)
for i=1,ySize do
	checkerWindow.setCursorPos(1,i)
	for j=1,xSize do
		checkerWindow.setBackgroundColor(bit.band(i+j,1) == 1 and colours.white or colours.black)
		checkerWindow.write(" ")
	end
end

-- Define a small window at the top left of the display:
local smallWindow = window.create(term.current(), 1, 1, 5, 1)
smallWindow.write("BOING")

-- Bounce the small window around the screen:
local xDir, yDir, xPos, yPos = 1, 1, 1, 1

while true do
	sleep(0.5)
	
	xPos = xPos + xDir
	yPos = yPos + yDir
	
	checkerWindow.redraw()
	smallWindow.reposition(xPos, yPos)
	
	if xPos == 1 then xDir = 1 end
	if yPos == 1 then yDir = 1 end
	if xPos == xSize - 4 then xDir = -1 end
	if yPos == ySize then yDir = -1 end
end
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox