1

Say I was building a simple game and I had a menu with Play, Settings, Music etc. All laid out in the middle of the screen, how would I check if the mouse was over one of those areas and if the mouse clicked while over one of those areas?

Other people have asked similar things to this but I cannot find a working example or a clear solution to my question.

enter image description here

evilhoomans42
  • 75
  • 1
  • 7

2 Answers2

0

For clicking and mouse input, there are libraries/APIs that give user input (such as GLFW with Opengl). It really depends on what platform you're using. Then, you can convert your mouse XY position to a position relative to the window, and see whether or not its XY is greater than the bottom left XY of the GUI and less than the top right XY.

Ezaren
  • 1
0

I am no expert in GUI in C++ because C++ GUI is not efficient. But to be making a clickable button, you may not want to do all those hard works. All you need to find is how to add a button from some libraries and bind that button to certain function. That’s how things work.

  • Additionally, you should have provided information regarding to what you have tried and the problem you are facing to give others less headaches
Kyi Zet
  • 49
  • 2
  • 11
  • I am unsure of what to try as I don't know a function for getting the mouse input and I cannot find one also do you have a more specific example/answer – evilhoomans42 Jan 25 '20 at 04:34