Lwccgl 1.0.1 - Lightweight Computercraft G...
Tiin57 29 Jul 2013
So, after almost 6 months of complete absence from actual Computercraft-related Lua programming, I have returned.
No, it's not incredible. No, it's not almighty.
However, it is quite nifty, and I like it.
Now, anyways. This thing has a terrible name, yes?
Well, it stands for "Light-Weight ComputerCraft Graphics Library". Yes, I got the inspiration from LWJGL. No, you may not judge me.
I know that it's not impressive, but it works.
Example (with the API saved as 'lwccgl'):
Now for documentation.
THIS IS AN OBJECT-ORIENTED API.
Base API functions:
Button object:
Circle object:
By the way, I do have a small license:
You may use this API however the hell you want.
I'd like it if you told me about your use of it, though.
Pastebin:
http://pastebin.com/4C3L6QFi
Get the API:
pastebin get 4C3L6QFi lwccgl
Changelog:
Don't expect this to be all.
Also:
PLEASE, FOR THE LOVE OF ALL DIVINE THINGS, REPORT YOUR BUGS!
No, it's not incredible. No, it's not almighty.
However, it is quite nifty, and I like it.
Now, anyways. This thing has a terrible name, yes?
Well, it stands for "Light-Weight ComputerCraft Graphics Library". Yes, I got the inspiration from LWJGL. No, you may not judge me.
I know that it's not impressive, but it works.
Example (with the API saved as 'lwccgl'):
os.loadAPI('lwccgl') local circle = lwccgl.add_circle(8, 8, 7, colors.blue) circle:draw() local button = lwccgl.add_button(4, 4, 5, 2, colors.yellow, "Test") button:draw() button:input() print("You pressed the button!")
Now for documentation.
THIS IS AN OBJECT-ORIENTED API.
Base API functions:
-- Creates a button object and returns it. -- The color and text parameters can be left out. button = lwccgl.add_button(x, y, width, height, color, text) -- Creates a circle object and returns it. -- The color parameter can be left out. circle = lwccgl.add_circle(centerX, centerY, radius, color)
Button object:
-- Renders the button. draw() -- Waits for the button to be clicked. input()
Circle object:
-- Renders the circle. draw()
By the way, I do have a small license:
You may use this API however the hell you want.
I'd like it if you told me about your use of it, though.
Pastebin:
http://pastebin.com/4C3L6QFi
Get the API:
pastebin get 4C3L6QFi lwccgl
Changelog:
Spoiler
Don't expect this to be all.
Also:
PLEASE, FOR THE LOVE OF ALL DIVINE THINGS, REPORT YOUR BUGS!
Yevano 29 Jul 2013
Just a bit of criticism: It is currently not possible to wait for input for multiple buttons without using coroutines. You could fix this by switching over to callbacks or making input waiting global for all buttons.
Other than that, I'm glad to see OO design.
Other than that, I'm glad to see OO design.
theoriginalbit 29 Jul 2013
Also, you know that LWJGL is "Lightweight Java Game Library" right? xD
Yevano 29 Jul 2013
theoriginalbit, on 29 July 2013 - 10:40 PM, said:
Also, you know that LWJGL is "Lightweight Java Game Library" right? xD
I was thinking the exact same thing.
Also I edited this out of my first post, but to change the wording a little: Is this going to have actual drawing features later on, or is this more of a gui lib than a graphics lib?
Tiin57 29 Jul 2013
Yevano, on 29 July 2013 - 10:39 PM, said:
It is currently not possible to wait for input for multiple buttons without using coroutines. You could fix this by switching over to callbacks or making input waiting global for all buttons.
theoriginalbit, on 29 July 2013 - 10:40 PM, said:
Also, you know that LWJGL is "Lightweight Java Game Library" right? xD
Yevano, on 29 July 2013 - 10:44 PM, said:
Is this going to have actual drawing features later on, or is this more of a gui lib than a graphics lib?
jesusthekiller 30 Jul 2013
Since LoadAPI just runs file and you have to run initialize() after loading file can't you just add "initialize()" at the end of API?
ardera 02 Aug 2013
some gui features like lists, panels, windows, checkboxes etc. would be nice
FPJarva 08 Aug 2013
Wouldn't it be better to add the input() as an object oriented function?
local button = lwccgl.add_button(4, 4, 5, 2, colors.yellow, "Test") button:draw() function button:input() print("You clicked the button!") endIt just makes more sense, then you can have the button do multiple things upon being clicked rather than waiting for it to be clicked.
star_trekguy 14 Aug 2013
This is a useful little api. I did actually use it for an advanced monitor touch screen key-code entry system. Here is a picture:
I had to add a function after your 'input' function to allow one loop to check all the buttons, instead of blocking for each button:
Here is the code to make the buttons work:
If you want to use it, just change the monitor name and redstone outputs to what you need.
Spoiler
I had to add a function after your 'input' function to allow one loop to check all the buttons, instead of blocking for each button:
button['checkClick'] = function(self, x, y) if not self.drawn then return false end if ( x >= self.startX ) and ( x <= self.startX + self.width ) and ( y >= self.startY ) and ( y <= self.startY + self.height ) then return true end return false end
Here is the code to make the buttons work:
Spoiler
If you want to use it, just change the monitor name and redstone outputs to what you need.
LeB0ucEtMistere 15 Aug 2013
Mhhh that's totally the kind of API I love easy to use, usefull and full of sens i'll use it for my buttons panel, with a little bit of parallels, it will be perfect for holding several buttons at the same time
thanks for your work keep it up
thanks for your work keep it up