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

Draw A Line For Each Column

Started by makerimages, 31 October 2013 - 08:20 AM
makerimages #1
Posted 31 October 2013 - 09:20 AM
Hi, I have thi pieceof API code

windowSystem

local window=nil;
function createWindow(title,x,y,w,h,closeable,text)
window=
{
  titlew=title;
  x=x;
  y=y;
  W=w;
  H=h;
  ca=closeable;
  text=text;
}
return window
end
function drawWindow(windowp)
term.setCursorPos(window.x,window.y)
term.setBackgroundColor(colors.lightGray)
for i=0, windowp.W do
  term.setCursorPos(windowp.x+i,windowp.y)
  print(" ")
  term.setCursorPos(windowp.x+i,windowp.y+windowp.H)
  print(" ")
end
for j=0, windowp.H do
  term.setCursorPos(windowp.x,windowp.y+j)
  print(" ")
  term.setCursorPos(windowp.x+windowp.W,windowp.y+j)
  print(" ")
end
for k=0, windowp.H-2 do
  term.setBackgroundColor(colors.white)
  term.setCursorPos(windowp.x+1,windowp.y+1+k)
  print(" ")
  term.setBackgroundColor(colors.lightGray)
end
term.setCursorPos(windowp.x+windowp.W/2-string.len(windowp.titlew)/2,windowp.y)
term.setTextColor(colors.gray)
print(windowp.titlew)
if(windowp.ca) then
  term.setBackgroundColor(colors.red)
  term.setCursorPos(windowp.x+windowp.W+1,windowp.y)
  print("X")
  term.setBackgroundColor(colors.white)
end
term.setCursorPos(windowp.x+2,windowp.y+2)

for i in string.gmatch(windowp.text,"[^\n]+") do
  term.setBackgroundColor(colors.white)
   print(i)
	x,y=term.getCursorPos()
	if i== " " then
	 term.setCursorPos(windowp.x+1,y)
	  end
end
end


a window Is created

local window=windowSystem.createWindow("About this Device",21,3,20,14,true,"Version:"..afData[1].."\n \n \n \n System:"..afData[2])
and the for k=0 block in drawWindow draws a white column at the specified position(windowp.x+1, windowp.y+k), I would like to have the entire inside of a window(from windowp.x to windowp.W-2) to be with a white bg, how can I achieve that?
TheOddByte #2
Posted 31 October 2013 - 04:50 PM
Do you mean something like this?
Example function

--[[
	@description	"Draws a box from starting value to finish values"

@param		  sX,	number
@param		  fX,	number
@param		  sY,	number
@param		  fY,	number
@param	  bColor,	color

--]]
function drawBox(sX,fX,sY,fY,bColor)

	if bColor ~= nil then
		term.setBackgroundColor(bColor)
else
   error("nil bColor",2)
	end


		local str = ""

	for x = sX, fX do
		str = str.." "
	end

   for y = sY, fY do
	   term.setCursorPos(sX,y)
	   write(str)
   end  
end

This is what I personally use to draw boxes/windows


Here's an example usage of it

local w,h = term.getSize()
term.setBackgroundColor(colors.black)
term.clear()
drawBox(2,w - 1,2,h - 1,colors.white)
And this would look like this
makerimages #3
Posted 01 November 2013 - 08:05 AM
works, ty!