Now that I've come back to it I was trying to familiarize myself with what everything was supposed to do again and discovered something that I spent almost and hour trying to solve but had no luck. I'm going to try to explain the problem after I paste the code:
Button API:
Spoiler
button = {}
--mon = peripheral.wrap("left")
mon = term
function fillTable(name, xmin, xmax, ymin, ymax, text, color)
button[name] = {}
button[name]["text"] = text
button[name]["xmin"] = xmin
button[name]["xmax"] = xmax
button[name]["ymin"] = ymin
button[name]["ymax"] = ymax
button[name]["color"] = color
end
function createBox(name)
tableData = button[name]
currentY = tableData["ymin"]
while currentY ~= tableData["ymax"] do
mon.setCursorPos(tableData["xmin"], currentY)
for i = 1,tableData["xmax"] do
write(" ")
end
currentY = currentY +1
end
end
function createButton(name)
tableData = button[name]
mon.setBackgroundColor(tableData["color"])
xLoc = tableData["xmin"] + (math.ceil((tableData["xmax"] - string.len(tableData["text"]))/2))
yLoc = math.ceil((tableData["ymax"]+tableData["ymin"])/2)-1
createBox(name)
mon.setCursorPos(xLoc,yLoc)
mon.write(tableData["text"])
end
Program I'm using to test API:
Spoiler
os.loadAPI("btn")
btn.fillTable("Test1",9,14,4,9,"Test 1",colors.blue)
btn.createButton("Test1")
term.setCursorPos(1,1)
Program I'm using to find coordinates on screen:
Spoiler
while true do
term.setCursorPos(1,1)
term.clearLine()
term.setCursorPos(1,1)
event, button, x, y =os.pullEvent("mouse_click")
if x == nil or y == nil then
print("What")
end
write(x..":"..y)
sleep(.8)
end
So my problem is with drawing the boxes to the correct size. The dimensions are all off. For example:
In my test program I set the x and y like so:
xMin: 9
xMax: 14
yMin: 4
yMax: 9
I believe this should make the dimensions of the button 6x6 however they end up being 14x5. The width of the button(which is associated with x) is 8 off and the length( which is associated with y) is 1 off. When I use my program for finding coordinates these are the coordinates of the corners:
Top Left: 9:4
Bottom Left: 9:8
Top Right: 22:4
Bottom Right: 22:8
Just from looking at the top and bottom right I can immediately tell that something is wrong. 22? I don't even know where that came from. As far as I know the x coordinate on the right side should be the xMax which is 14. And then there is that 8 on the bottom. Shouldn't that be the yMax which is 9?
After looking at all of this, I know that there is something seriously wrong with my createBox() function which is what draws the buttons before the text is added. This will cause serious problems when I start working on finding where the user clicked and what button they clicked, if the button isn't where it's supposed to be. Before I finish the post I would like to say that I'm not the best at math or Lua so I very well could be completely wrong. I could also be completely over thinking this(which I do often) and there is actually a very easy fix.
All help is appreciated!
Thanks! :D/>