Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --TouchPc API--
- button = {}
- CurrentPage = 2
- pp = peripheral.isPresent("top")
- if pp then
- m = peripheral.wrap("top")
- end
- floppy = false --Currently does nothing, but is going to be used in a later release to be able to save and retrieve the status on each button on load/exit--
- function ChangePeripheral()
- end
- function CreateButton(Id,MinX,MaxX,MinY,MaxY,Text,Function,Color,State,Page,...)
- -- Create a list of buttons and their variables --
- button[Id] = {}
- button[Id][1] = MinX
- button[Id][2] = MaxX
- button[Id][3] = MinY
- button[Id][4] = MaxY
- button[Id][5] = Text
- button[Id][6] = Function
- button[Id][7] = Color
- button[Id][8] = State
- button[Id][9] = Page
- button[Id][10] = ...
- end
- function CheckButtons() --eventc is used to define whether it is a monitor event or a terminal event.--
- -- Checks if the the player clicked a button--
- --Change it to be able to distinguish what page the button is on
- if pp == true then
- event, side, x, y = os.pullEvent("monitor_touch")
- else
- event, side, x, y = os.pullEvent("mouse_click")
- end
- for i = 1, table.getn(button) do
- if x >= button[i][1] and x <= button[i][2] and y >= button[i][3] and y <= button[i][4] and button[1][9] == CurrentPage then
- if button[i][8] == "on" then
- button[i][8] = "off"
- button[i][10]()
- elseif button[i][8] == "off" then
- button[i][8] = "on"
- button[i][6]()
- elseif button[i][8] == "none" then
- button[i][6]()
- end
- sleep(0.1)
- end
- end
- end
- function DrawButton()
- --draws the button on the screen--
- for i = 1, table.getn(button) do
- if button[i][9] == CurrentPage then
- if pp == true then
- m.setBackgroundColor(button[i][7])
- else
- term.setBackgroundColor(button[i][7])
- end
- for y = button[i][3], button[i][4] do
- for x = button[i][1], button[i][2] do
- if pp == true then
- m.setCursorPos(x,y)
- m.write(" ")
- else
- term.setCursorPos(x,y)
- term.write(" ")
- end
- end
- end
- end
- end
- end
- function NextPage(PageNumber)
- --for when you use a too many buttons to be shown in one screen--
- end
- function DialogBox(message)
- --enables the use of dialog boxes--
- end
- function SaveTo(info,file)
- -- in the case you would like to save a information to a file(especially useful to save dialog box messages) --
- end
- --only on offical release--
- --os.pullEvent = os.pullEventRaw--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement