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

Sapi: Simple Api, Gui, Event Help And More Too Be Added

Started by DarkEspeon, 21 August 2013 - 08:42 PM
DarkEspeon #1
Posted 21 August 2013 - 10:42 PM
SAPI: Simple API
I made this out of the need of an all purpose API, and, lacking a better name for this, called it Simple API or SAPI. This adds buttons, scrollbars, switches, event handling and more. This was written in lua oop, so all functions will be called with a ":" not a "."
Please note that all objects are self contained and self drawn and event handled through use of two functions included with this api

1 Setting Up API:
For the sake of convinience and to use this api as I document it below, DO NOT USE OS.LOADAPI!!!! Please use shell.run(<Whatever you called SAPI here>)! This will make it easier to use, and again, will allow use exactly as below. If you ignore this warning, don't complain about the code in the documentation below not working! Thank you.

2 Documentation
Spoiler2.1 First Things First:
Loading the API
This should be obvious to all who read section one, posting it so that noone gets confused, use shell.run not os.loadapi.

2.2 Labels:
Creates a new label as variable x:
x = CCLabel:New(<XPosition>, <YPosition>, <Text>[,<TextColor>[,<BackgroundColor>]])
Adds label to the "render" list:
CCInterfaceEntities:AddLabel(x)

2.3 Buttons:
Creates a new button as variable x:
x = CCButton:New(<XPostion>, <YPosition>, <TextInsideButton>, <OnClickAction>, [<TextColor>[,<BackgroundColor>[,<OnClickColor>]]])
Adds button to the "render" list:
CCInterfaceEntities.AddButton(x)

2.4 ScrollBars:
Creates a new Horizontal ScrollBar as variable x:
x = CCHorizontalScrollBar:New(<XPostion>, <YPosition>, <Height>, <Min>, <Max>, <Name>[,<BarColor>[,<BackgroundColor>[,<LabelColor>]]])
Creates a new Vertical ScrollBar as variable x:
x = CCVerticalScrollBar:New(<XPostion>, <YPosition>, <Width>, <Min>, <Max>, <Name>[,<BarColor>[,<BackgroundColor>[,<LabelColor>]]])
Adds either to the "render" list:
CCInterfaceEntities.AddScrollBar(x)

2.5 Switches:
Creates a new Horizontal Switch as variable x:
 x = CCHorizontalSwitch:New(<XPostition>, <YPosition>, <Name>[,<SwitchColor>[,<BackgroundColor>]])
Creates a new Vertical Switch as variable x:
 x = CCVerticalSwitch:New(<XPostition>, <YPosition>, <Name>[,<SwitchColor>[,<BackgroundColor>]])
Adds either to the "render" list:
CCInterfaceEntities.AddSwitch(x)

2.6 EventBuffer:
Creates the EventBuffer as variable x:
x = CCEventBuffer:New([<IsBuffered>[,<TABLE:BufferedEvents(eventnames as strings)>]])
Gets event formated as mentioned below:
[code]EventData = x:PullEvent()
Returns if buffered:
Bool = x:IsBuffer()
Toggles Buffer:
x:ToggleBuffer()
Gets latest entry in buffer and removes event(if buffer is true):
event = x:GetLast()
Gets earliest entry in buffer and removes event(MAY CAUSE LAG IF BUFFER IS LARGE US AT OWN RISK)(if buffer is true):
event = x:GetFirst()
Clears buffer:
x:Clear()


2.7 InterfaceEntities:
Creates the InterfaceEntity as variable x:
x = CCInterfaceEntities:New()
Adds Entity to the List:
x.AddButton(button) OR
x.AddScrollBar(scrollbar) OR
x.AddSwitch(switch) OR
x.AddLabel(label)
Toggles visibility of all InterfaceEntities:
x.ToggleAll()

2.8 Drawing:
Draws a string on the screen:
CCDrawing:DrawCharacters(<X>, <Y>, <String>[,<TextColor>[,<BackgroundColor>[,<Monitor>]]])
Draws an area of specified Characters on screen:
CCDrawing:DrawArea(<X>, <Y>, <Width>, <Height>, <CharactertoFillWith>[,<TextColor>[,<BackgroundColor>[,<Monitor>]]])


2.9 Term function additions(british spellings too)
Each listed function should be obvious how it works
term.colorPrint(Str, TxtColor, BgColor)
term.colorWrite(Str, TxtColor, BgColor)
term.cPrint(Str)
term.cWrite(Str)
term.cColorPrint(Str, TxtColor, BgColor)
term.cColorWrite(Str, TxtColor, BgColor)


Changelog: here


Please leave comments and what you guys think should be added next.
To Be Added:
Nothing Planned As Of Yet

Get it here

File is simply Called SAPI.
Thanks!
Zudo #2
Posted 22 August 2013 - 01:33 AM
Microsoft made the "Speech Application Programming Interface" :D/>
Anyway, this is pretty good!
DarkEspeon #3
Posted 28 August 2013 - 02:57 PM
Updated to PR3, added some more stuff, also had to remove the built in event handler function, so you have to write your own, and your own screen drawing since i added the ablility to toggle if it is visible or not. Would love some feed back from you guys on if this is useful or not… will add some screenshots soon.