The API can be downloaded from pastebin: pFHeia96
Touchpoint is also available via packman, with the command: packman install touchpoint
Methods:
--# create a new instance of buttons on the top monitor (assumes API loaded as "touchpoint").
--# you can also not specify a side, and the touchpoint instance will use the current terminal and watch for mouse_click events (ComputerCraft 1.6+ only).
t = touchpoint.new("top")
--# add a button to the instance
t:add("label", function() doStuffButNotRequiredForEventsMode() end, 2, 2, 28, 11, colors.red, colors.lime)
--# coordinates are minX, minY, maxX, maxY.
--# uses red for inactive color and green for active color.
--# draw the set of buttons in the instance
t:draw()
--# catch and handle monitor touch events on buttons to transform them to button_click events
--# (does not require functions when creating buttons, you can pass nil instead)
event, p1, p2, p3, p4, p5 = t:handleEvents(os.pullEvent())
--# or instead handle the button clicks by calling the buttons' functions.
t:run()
--# change a button from inactive color to active or vice versa
t:toggleButton("label")
--# briefly toggle a button's state, then change it back
t:flash("label")
--# change a button's label
t:rename("label", "newLabel")
Different pages of buttons are relatively easy to achieve by simply creating multiple instances and drawing the desired page's instance on the screen and using it to handle events.
Here is a quick example program that controls a redstone output on each of the left and right sides:
Spoiler
--# load the touchpoint API
os.loadAPI("touchpoint")
--# intialize a new button set on the top monitor
local t = touchpoint.new("top")
--# add two buttons
t:add("left", nil, 2, 2, 14, 11, colors.red, colors.lime)
t:add("right", nil, 16, 2, 28, 11, colors.red, colors.lime)
--# draw the buttons
t:draw()
while true do
--# handleEvents will convert monitor_touch events to button_click if it was on a button
local event, p1 = t:handleEvents(os.pullEvent())
if event == "button_click" then
--# p1 will be "left" or "right", since those are the button labels
--# toggle the button that was clicked.
t:toggleButton(p1)
--# and toggle the redstone output on that side.
rs.setOutput(p1, not rs.getOutput(p1))
end
end
A note: One can also fully specify the text characters of the button by providing a table for the label. The table should contain exactly the text of the button, in numerical indices, top to bottom. Each index should be as long as the button is wide. A label entry should be present in the table, which should be a single string to be used as the name of the button. For example:
local buttonName = {
" ",
" A button ",
" label ",
" ",
label = "a button"
}
t:add(buttonName, nil, 2, 2, 11, 5, colors.red, colors.lime)