From ComputerCraft Wiki
Revision as of 12:31, 9 April 2014 by Bomb Bloke (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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


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):
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
	for j=1,xSize do
		checkerWindow.setBackgroundColor(,1) == 1 and colours.white or
		checkerWindow.write(" ")

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

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

while true do
	xPos = xPos + xDir
	yPos = yPos + yDir
	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