Spoiler
Hello guys! Today I will be releasing an API for monitors that I made a couple months ago. I've polished it up a bit so it can be released. This is my first time making an 'object-oriented' API. So please if you have any constructive critism, suggestion or question, feel free to post.
What?
This API allows you to divide up monitors into sections. Sections are basically like virtual monitors. All sections come with the standard functions that monitors can use. On top of that, this API adds a few extra functions for simple things such as drawing borders, filling up a section and creating hitboxes. The hitbox system is another very useful part of the API. The hitboxes will allow you to make your sections interactive by making it easier for you to create buttons.
Why?
I made this when I was playing on a modded server with my friends. Me and my friend had a base but we had to control everything manually. So I thought to myself, "Why not make a control panel using my favourite mod - ComputerCraft?" In the process of making the program, I realized that there were a lot of things updating and redrawing at the same time. For example, I had multiple graphs that were updating every 0.5 seconds. This made the program flickery and inefficient. I was clearing the whole monitor each time I wanted to redraw the graphs. So I thought, "Why not only clear the area where the graph is and then redraw it?" I tried that but it made the code more complicated and harder to read so I decided to turn it into an API.
Here is the result of the program when using the API. (Ignore the graph values - currently they are being fed dummy values.)
Spoiler
http://quickscreen.e...557EC6C21F97B4Bhttp://quickscreen.e...555C40F2D7ED398
http://quickscreen.e...9DC03E4697E22C2
http://quickscreen.e...115670AE41EFBD2
"You are not allowed to use that image extension on this community."
Documentation:
- monAPI
+ wrapMonitor(string side) [[ Use this instead of peripheral.wrap; all the function are still available. ]]
+ getHitbox(int x, int y) [[ Returns the name of the hitbox and the sectionID the hitbox is in. Returns nil if no hitbox was detected at the specified co-ordinates. ]]
+ createSection(int startX, int startY, int endX, int endY) [[ Creates a section. ]]
+ drawBorder(string horChar, string verChar, string cornerChar) [[ Draws a border on the edges of the section. ]]
+ fill(string char) [[ Fills the whole section with the specified character (background colour can be set using setBackgroundColour beforehand). ]]
+ getSectionID() [[ Returns the sectionID. ]]
+ registerHitbox(string name, int startX, int startY, int endX, int endY) [[ Registers a hitbox at the specified positions. ]]
+ clearHitbox() [[ Clears all hitboxes (for that section). ]]
+ delete() [[ Deletes the section. ]]
| All of the standard functions that are available for monitors except scroll, setCursorBlink and setTextScale.
| All the standard functions for the monitor that you would get if you used peripheral.wrap(string side).
Example:
The documentation might've been a lot to take in so here is a simple example. This example creates 3 sections. One at the top corner, one in the middle and one near the bottom corner. I tried to demonstrate most of the functions availabe in this example including the hitbox system.
Here is the code:
http://pastebin.com/2fAkJV1K
Here is a short video demonstrating the program:
[media]http://www.youtube.com/watch?v=fqt4jTcR8Kw[/media]
Download:
pastebin get 2npxyPdn MonAPI
Changelog:
- v1.0 - Initial release.
To-do:
- Add support for scroll() (possibly)
- Add support for setCursorBlink()