Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
The Simon

OpenGlasses Button API

Recommended Posts

Hello everyone! Direwo... eh, not quite right.

Well, OpenGlasses for 1.12 is out! And I noticed there were no public button API for it, so I made one myself!

I have a few functions built-in to make it easier to change stuff, but it was created with simplicity in mind. So if you simply just initialize a button and bind a function to it, it won't do any fancy stuff except for activating the function when you press it, so you have to add your own functionality to it:

3d8e7c6ea70368e7380a6e0884f47e72.gif

 

But with a little bit of extra code:

04c14e1852118c5b37749b6571376011.gif

 

Ok, not that big a difference, you guys are probably more creative than me!

 

I also have a concept called "groups". When creating a button, you can specify what group it should be in. So if you want to change the color of all the buttons to the left side to pink, you can do that.

Functions (in no particular order):

--Needs to be called before creating any buttons, works as a reset also:
gButtonAPI4.initialize()

--Creating a new button element:
gButtonAPI4.createNewButton(name,group,display,x,y,w,h,color: table,transparently,callback: function)

--Has to be inside of your main loop:
gButtonAPI4.update()

--Prints all registered groups:
gButtonAPI4.printGroups()

--Change the visibility of the button/group:
gButtonAPI4.visibility(button/group,boolean)

--Change the color of the button/group:
gButtonAPI4.Color(button/group[,color: table])--None for default color.

--Same as color, but changes the label:
gButtonAPI4.Label(button/group[,text])--None for default label.

--Add a button to a group:
gButtons.addToGroup(button,group)

 

 

 

If you don't want to make a new function for each new button, you can then bind them all to the same function. And add a parameter to your function, the name of the button that was clicked will be returned:

local function btniF(buttonx)
  gButtons.Color(buttonx,{0,255,0})
  print("I am " .. buttonx .. "!")
  os.sleep(0.5)
  gButtons.Color(buttonx)
end

 

I added a Demo program that shows most of the library's functions. Oh, btw, I like the number 4. It's not like this is my fourth attempt creating this or anything!

Write a reply if you have any questions, this was my first attempt to create a usable library.

gButtonAPI4.lua

gButtonsDemo.lua

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.