Jump to content




Easy Mouse GUI


  • You cannot reply to this topic
14 replies to this topic

#1 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 13 October 2012 - 10:39 AM

I have been messing around with the new mouse support and I made this really cool function.
Here is a example program with it.
local running = true
--[[Menu Functions]]--
local function stop()
  running = false
end
local function hey()
  print("Hey")
end
--[[Menu Table]]--
local buttons = {
  [1] = {buttonType = 1, startX = 1, endX = 1, startY = 1, endY = 1, buttonText = "&", command = hey},
  [2] = {buttonType = 2, startX = 2, endX = 5, startY = 2, endY = 5, buttonText = "Hello", command = stop}
}
--[[Main Function]]--
function menu(menu)
  for k,v in ipairs(menu) do
    term.setCursorPos(menu[k].startX, menu[k].startY)
    print(menu[k].buttonText)
  end
  while running do
    event, p1, p2, p3 = os.pullEvent()
    if event == "click" then
	  for k,v in ipairs(menu) do
	    if p3 == menu[k].buttonType then
		  if p1 >= menu[k].startX and p1 <= menu[k].endX and p2 >= menu[k].startY and p2 <= menu[k].endY then
		    menu[k].command()
		  end 
	    end
	  end
    end
  end 
end
term.clear()
menu(buttons)
It is pretty simple but very awesome!

#2 Exerro

  • Members
  • 801 posts

Posted 13 October 2012 - 03:58 PM

what does it do? does it actually detect clicks?

#3 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 13 October 2012 - 04:00 PM

View Postawsumben13, on 13 October 2012 - 03:58 PM, said:

what does it do? does it actually detect clicks?
Well what it does is first print the text that is defined as a var in table. Then it waits for a mouse click then it checks if that click was made with the cords set in the table. If all those are right it runs the function defined in the table.
It is quite simple but it is the first mouse function I have seen on the forums.

#4 Tiin57

    Java Lunatic

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

Posted 13 October 2012 - 04:01 PM

WHOA. HOLD UP. New mouse support? Holy mother of God, thank you! My prayers have been answered! (If this is a troll, I will reach through the screen and slap you.)

#5 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 13 October 2012 - 04:08 PM

View Posttiin57, on 13 October 2012 - 04:01 PM, said:

WHOA. HOLD UP. New mouse support? Holy mother of God, thank you! My prayers have been answered! (If this is a troll, I will reach through the screen and slap you.)
In the snapshot gold computers have mouse support.
It returns the event "click". Test it in the Lua prompt and see how it works.

#6 Lettuce

  • Members
  • 210 posts
  • LocationIn your fridge.

Posted 13 October 2012 - 04:45 PM

Wait, snapshot? Where do I get that? That sounds AWESOME.

#7 Kadecamz

  • New Members
  • 113 posts

Posted 13 October 2012 - 05:03 PM

hi.
Will it work when editing programs?

also, can you make a GUI api?

#8 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 13 October 2012 - 05:27 PM

View PostKadecamz, on 13 October 2012 - 05:03 PM, said:

hi.
Will it work when editing programs?

also, can you make a GUI api?
Well to make a GUI just copy the function and add a table with the vars that are used in the above code and add functions for each selection.
I plan on making something a lot more complex for CommuteOS though.

#9 Exerro

  • Members
  • 801 posts

Posted 13 October 2012 - 07:22 PM

omg how do you get the snapshot this looks amazing...does it track the mouse as you move it so you can have it do stuff with hovering?

#10 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 13 October 2012 - 07:47 PM

View Postawsumben13, on 13 October 2012 - 07:22 PM, said:

omg how do you get the snapshot this looks amazing...does it track the mouse as you move it so you can have it do stuff with hovering?
Well it is a beta not a snapshot. Go to the beta testing section in the forums.
There is no function to get the mouse position so you can only tell when a mouse is clicked.

#11 Exerro

  • Members
  • 801 posts

Posted 13 October 2012 - 08:17 PM

View PostHuman, on 13 October 2012 - 07:47 PM, said:

Well it is a beta not a snapshot. Go to the beta testing section in the forums.
There is no function to get the mouse position so you can only tell when a mouse is clicked.
ok...thanks i got it and its flipping amazing! this will open up so many possibilities

#12 Lettuce

  • Members
  • 210 posts
  • LocationIn your fridge.

Posted 13 October 2012 - 09:17 PM

Did that just get added? Like, how did I never see that? Checkin' it out too...

#13 ChaddJackson12

  • Members
  • 264 posts

Posted 14 October 2012 - 12:29 AM

This seems to be very awesome. Also, I didn't know that there was a "click" event for computercraft

#14 Exerro

  • Members
  • 801 posts

Posted 14 October 2012 - 02:18 PM

View PostChaddJackson12, on 14 October 2012 - 12:29 AM, said:

This seems to be very awesome. Also, I didn't know that there was a "click" event for computercraft
the click event is new in the beta release...its awesome but i think there are a couple of bugs :l

#15 ardera

  • Members
  • 503 posts
  • LocationGermany

Posted 14 October 2012 - 03:22 PM

View Posttiin57, on 13 October 2012 - 04:01 PM, said:

WHOA. HOLD UP. New mouse support? Holy mother of God, thank you! My prayers have been answered! (If this is a troll, I will reach through the screen and slap you.)

Oh no.......
I made an mouse support for 1.4/1.42... It has 2 big files and is for CommuteOS... But if the mouse is now added I can delete them...





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users