Jump to content




Lwccgl 1.0.1 - Lightweight Computercraft Graphics Library


14 replies to this topic

#1 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 29 July 2013 - 07:30 PM

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!

#2 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 29 July 2013 - 10:39 PM

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.

#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 29 July 2013 - 10:40 PM

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

#4 Yevano

  • Members
  • 376 posts
  • LocationUSA

Posted 29 July 2013 - 10:44 PM

View Posttheoriginalbit, 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?

#5 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 29 July 2013 - 10:47 PM

View PostYevano, 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.

View Posttheoriginalbit, 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

View PostYevano, 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.

#6 jesusthekiller

  • Banned
  • 562 posts
  • LocationWrocław, Poland

Posted 30 July 2013 - 06:59 AM

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? :)

#7 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 30 July 2013 - 08:00 AM

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

#8 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 30 July 2013 - 09:46 AM

Moving towards graphics with add_circle()!

#9 jesusthekiller

  • Banned
  • 562 posts
  • LocationWrocław, Poland

Posted 30 July 2013 - 10:20 AM

Cool :)

#10 ardera

  • Members
  • 503 posts
  • LocationGermany

Posted 02 August 2013 - 05:13 AM

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

#11 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 02 August 2013 - 06:23 AM

Yeah, everything is on pause during Modjam. :D

#12 Kamefrede

  • Members
  • 30 posts
  • LocationPortugal,porto

Posted 03 August 2013 - 12:03 PM

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

#13 FPJarva

  • New Members
  • 2 posts

Posted 08 August 2013 - 08:44 AM

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.

#14 star_trekguy

  • New Members
  • 1 posts

Posted 14 August 2013 - 09:48 PM

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.

#15 LeB0ucEtMistere

  • Members
  • 10 posts

Posted 15 August 2013 - 02:21 PM

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users