Spoiler
content =
{
page1 =
{
background = nil,
visible = true,
setBackground = function(path)
background = paintutils.loadImage(path)
end,
getBackground = function()
return background
end,
getPageContent = function()
return pageContent
end,
setVisable = function(vis)
visible = vis
end,
pageContent =
{
buttons = {},
labels = {},
images = {},
getButtons = function()
return content.page1.pageContent.buttons
end,
addButton = function(text,xpos,ypos,wid,high,c,tc,f)
content.page1.pageContent.buttons[#content.page1.pageContent.buttons+1] =
{name = text,x = xpos,y = ypos
,width = wid,height = high,color = c
,textcolor = tc, buttonFunction = f}
return #content.page1.pageContent.buttons-1
end,
drawButton = function(index)
b = content.page1.pageContent.buttons[index]
drawing.fillArea(b.color,b.x,b.y,b.width,b.height)
drawing.writeTextCentered(b.name,b.x,b.y,b.width,b.height,b.textcolor,b.color)
end,
getLabels = function()
return content.page1.pageContent.labels
end,
addLabel = function(text,xpos,ypos,c,tc)
content.page1.pageContent.labels[#content.page1.pageContent.labels+1] =
{name = text,x = xpos,y = ypos,labelLength = l,centred = cent,color = c,textcolor = tc}
end,
setLabelText = function(index,text)
content.page1.pageContent.buttons[index].name = text
end,
drawLabel = function(index)
--print("page 1 ",#content.page1.pageContent.labels)
sleep(1)
b = content.page1.pageContent.labels[index]
drawing.fillArea(b.color,b.x,b.y,b.labelLength,1)
if(b.centred)then
drawing.writeTextCentered(b.name,b.x,b.y,b.labelLength,1,b.textcolor,b.color)
else
draw.writeText(b.name,b.x,b.y,b.textcolor,b.color)
end
end,
addImage = function(i,xpos,ypos)
images[#content.page1.pageContent.images] = {image = i,x = xpos,y = ypos}
end,
getImages = function()
return images
end
}
},
page2 =
{
background = nil,
visible = false,
setBackground = function(path)
background = paintutils.loadImage(path)
end,
getBackground = function()
return background
end,
getPageContent = function()
return pageContent
end,
setVisable = function(vis)
visible = vis
end,
pageContent =
{
buttons = {},
labels = {},
images = {},
getButtons = function()
return content.page2.pageContent.buttons
end,
addButton = function(text,xpos,ypos,wid,high,c,tc,f)
content.page2.pageContent.buttons[#content.page2.pageContent.buttons+1] =
{name = text,x = xpos,y = ypos
,width = wid,height = high,color = c
,textcolor = tc, buttonFunction = f}
return #content.page2.pageContent.buttons-1
end,
drawButton = function(index)
b = content.page2.pageContent.buttons[index]
drawing.fillArea(b.color,b.x,b.y,b.width,b.height)
drawing.writeTextCentered(b.name,b.x,b.y,b.width,b.height,b.textcolor,b.color)
end,
getLabels = function()
return content.page2.pageContent.labels
end,
addLabel = function(text,xpos,ypos,c,tc)
content.page1.pageContent.labels[#content.page1.pageContent.labels+1] =
{name = text,x = xpos,y = ypos,labelLength = l,centred = cent,color = c,textcolor = tc}
end,
setLabelText = function(index,text)
content.page2.pageContent.buttons[index].name = text
end,
drawLabel = function(index)
--print("page 2 ",#content.page2.pageContent.labels)
sleep(1)
b = content.page1.pageContent.labels[index]
drawing.fillArea(b.color,b.x,b.y,b.labelLength,1)
if(b.centred)then
drawing.writeTextCentered(b.name,b.x,b.y,b.labelLength,1,b.textcolor,b.color)
else
draw.writeText(b.name,b.x,b.y,b.textcolor,b.color)
end
end,
addImage = function(i,xpos,ypos)
images[#content.page2.pageContent.images] = {image = i,x = xpos,y = ypos}
end,
getImages = function()
return images
end
}
},
pages =
{
content.page1,
content.page2
}
}
drawing =
{
drawImage = function(image,x,y)
paintutils.drawImage(image,x,y)
end,
fillArea = function(color,xpos,ypos,wid,high)
term.setCursorPos(1,1)
--print("<",currentPage.visible,">",xpos,",",ypos,",",wid)
--sleep(1)
term.setBackgroundColor(color)
for y=ypos,ypos+high-1,1 do
for x=xpos,xpos+wid-1,1 do
term.setCursorPos(x,y)
write(" ")
end
end
end,
writeText = function(text,x,y,color,bgcolor)
term.setBackgroundColor(color)
term.setCursorPos(x,y)
write(text)
end,
writeTextCentered = function(text,x,y,wid,high,color,bgcolor)
term.setCursorPos(x+(wid-#text)/2,y+high/2)
term.setTextColor(color)
term.setBackgroundColor(bgcolor)
term.write(text)
end,
clear = function()
term.setBackgroundColor(colors.black)
term.clear()
term.setCursorPos(1,1)
end
}
function drawPageContent()
showButtons(currentPage.pageContent.getButtons())
showLabels(currentPage.pageContent.getLabels())
end
function showButtons(button)
for x=1,#button,1 do
currentPage.pageContent.drawButton(x)
end
end
function showLabels(label)
for x=1,#label,1 do
currentPage.pageContent.drawLabel(x)
end
end
function analyseClick(xpos,ypos)
buttons = currentPage.pageContent.getButtons()
for i=1,#buttons,1 do
if(xpos>=buttons[i].x and xpos<=buttons[i].x+buttons[i].width) then
if(ypos>=buttons[i].y and ypos<=buttons[i].y+buttons[i].height) then
buttons[i].buttonFunction()
end
end
end
end
running = true
currentPage = content.pages[1]
local termWidth,termHeight = term.getSize()
content.page1.setBackground("page1")
content.page2.setBackground("page2")
content.page1.pageContent.addButton("test",15,15,6,3,colors.blue,colors.black,function()end)
content.page1.pageContent.addButton("Exit",termWidth-5,1,6,3,colors.red,colors.white,function() running = false end)
content.page1.pageContent.addButton("test2",30,5,7,3,colors.green,colors.black,function()end)
content.page1.pageContent.addButton("Next Page",termWidth-10,termHeight-2,11,3,colors.orange,colors.white,function() currentPage = content.pages[2] end)
content.page2.pageContent.addButton("Next Page",termWidth-10,termHeight-2,11,3,colors.orange,colors.white,function() currentPage = content.pages[1] end)
content.page2.pageContent.addLabel("0",5,5,4,true,colors.white,colors.black)
content.page2.pageContent.addButton("/\\",5,4,4,1,colors.gray,colors.black,function() content.page2.pageContent.labels[1].setLabelText(tostring(tonumber(currentPage.pageContent.buttons[2].name)+1))end)
content.page2.pageContent.addButton("\\/",5,6,4,1,colors.gray,colors.black,function() content.page2.pageContent.labels[1].setLabelText(tostring(tonumber(currentPage.pageContent.buttons[2].name)-1))end)
while running do
drawing.clear()
drawing.drawImage(currentPage.getBackground(),1,1)
drawPageContent()
event, button, x, y = os.pullEvent("mouse_click")
analyseClick(x,y)
end
drawing.clear()