Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Possibility

How do I make buttons and edit fields?

This topic is 6611 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I have been making a tile based game, and I am using VC++ and DirectX and I have a decent tile engine so far, but I now need to know how to make buttons that a user can click on with a mouse, like to end the turn or to click on unit to select. Currently, i have it that if they hit Enter they end their turn, and if they hit space, it cycles through the units. But that is not very good, it would be much better that if I allowed for clicking on a unit to select it and clicking on a nice looking button that would look 'depressed' when clicked on and so for. Oh, and something else I will need to know how to do later, is how to make like an edit box, a field I can have a user enter a number or name into. So does anyone know of any "Detailed" tutorials or articles on the web about this? I read the Developing a GUI here on Gamedev but it was so unspecific and to general, it had no real code only covered advanced window implementation so it was no help Thanks Possibility Edited by - Possibility on 4/13/00 10:40:00 PM

Share this post


Link to post
Share on other sites
Advertisement
I''ve not touched upon edit fields or ''real'' GUI elements, so I''ll just cover the basics of what I have done so far.

To select units, I can click on them, or drag a box around them. The algorithm for click-selecting would be:

If mouse is clicked:
Get onscreen mouse cooordinates
If they are on the sidebar, ignore for now
Translate them to tile coordinates (eg. subtract camera position in world, divide by tile width)
Check that tile to get the first selectable ''thing'' on it
Select it if one exists

The selection box is a little harder. It comes in 2 parts:

If mouse button pressed:
Get onscreen mouse cooordinates
If they are on the sidebar, ignore for now
Transform to game pixel-level coordinates (ie. distance from map origin in pixels rather than tiles)
Store for future reference

If mouse button released:
Get onscreen mouse cooordinates
If they are on the sidebar, ignore for now
Transform to game pixel-level coordinates
If they are not significantly different from the stored mouseDown variables, treat this as a click and not a drag
Since they are different, generate a rectangle from your start position and end position
Throw that rectangle to a bounding box collision detection algorithm to determine all the selectable stuff inside it
Mark that stuff as selected


Hope that makes sense... You can probably see where the 2 above routines can be partially combined and/or merged with other routines, they are just shown separate for clarity.

As for a conventional GUI, you probably need a linked list of rectangular regions, sorted by Z-order, so you can loop through them top to bottom. As soon as you find the rectangle that your mouse is in, you know which GUI object has to react to your mouse actions. How you deal with that can be up to each object, which could all have MouseOver(), MouseLeftClick(), MouseRightClick() functions.

Share this post


Link to post
Share on other sites
quote:

If they are not significantly different from the stored mouseDown variables, treat this as a click and not a drag


You described virtually the same procedure that I use to draw highlight rectangles, but I don''t understand the step that I quoted from you. What if the player is trying to slowly highlight units? Wouldn''t the result be he isn''t able to highlight them? Just how many pixels off are you meaning by "not significantly different" ?

Share this post


Link to post
Share on other sites
No, they can still highlight slowly, as the part you quoted is only executed when they release the mouse button. It doesn''t matter if it takes 0.1 seconds or 100 seconds to drag that box When the mouse is released, that is when it checks to see how far the mouse has moved since the mouse was depressed, however long ago it was. The value I use is 4 pixels or more constitutes a drag, which I think is the same as the MS Windows amount, incidentally.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!