←  APIs and Utilities

ComputerCraft | Programmable Computers for Minecraft

»

Lwccgl 1.0.1 - Lightweight Computercraft G...

Tiin57's Photo 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'):
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. :D

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!
Quote

Yevano's Photo 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.
Quote

theoriginalbit's Photo theoriginalbit 29 Jul 2013

Also, you know that LWJGL is "Lightweight Java Game Library" right? xD
Quote

Yevano's Photo 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. :P

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?
Quote

Tiin57's Photo 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.
Right, still trying to figure that one out.

 theoriginalbit, on 29 July 2013 - 10:40 PM, said:

Also, you know that LWJGL is "Lightweight Java Game Library" right? xD
Hence the allusion to LWJGL in the OP. Trust me, I know :D

 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?
It will have graphical and gui features.
Quote

jesusthekiller's Photo 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? :)
Quote

Tiin57's Photo Tiin57 30 Jul 2013

Right, updated OP and pastebin with that change. Thanks.
Quote

Tiin57's Photo Tiin57 30 Jul 2013

Moving towards graphics with add_circle()!
Quote

jesusthekiller's Photo jesusthekiller 30 Jul 2013

Cool :)
Quote

ardera's Photo ardera 02 Aug 2013

some gui features like lists, panels, windows, checkboxes etc. would be nice :)
Quote

Tiin57's Photo Tiin57 02 Aug 2013

Yeah, everything is on pause during Modjam. :D
Quote

Kamefrede's Photo Kamefrede 03 Aug 2013

Nice api i like it might use it for something later on
Quote

FPJarva's Photo 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!")
end
It just makes more sense, then you can have the button do multiple things upon being clicked rather than waiting for it to be clicked.
Quote

star_trekguy's Photo 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:

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.
Quote

LeB0ucEtMistere's Photo LeB0ucEtMistere 15 Aug 2013

Mhhh that's totally the kind of API I love :D easy to use, usefull and full of sens :P 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
Quote