Jump to content
  • Advertisement


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


How to make your own buttons and edit boxes?

This topic is 6796 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

Share this post

Link to post
Share on other sites
Here''s one way to have buttons

typedef struct
int x1, y1, x2, y2;
char caption[16];
void (*call_this_when_pressed) (void);
} button_t;

(alternatively, you can use bitmaps for the button display, this is a minor detail)

somewhere in the source, you need this:

button_t buttons_array[NUM_BUTTONS];

you can initialize it in the source code, or load in the parameters from a file, though i don''t see the use of the latter if it''s only for a user interface for a game.

every frame, you would check if the mouse cursor is within the bounds of the buttons (go through one by one). if so, you would "highlight" it (draw text in bold, or draw the appropriate bitmap). i won''t get into the mouse clicking routines, but it should be relatively straight forward to determine when a mouse button has been pressed and released (a "click"). when this happens, call the function call_this_when_pressed() . You can have it respond differently to each mouse button if you want. You just need more function pointers.

Hope this is of help

Share this post

Link to post
Share on other sites
Hi !!

If you just have a few buttons in your game I would go with foofighters idea. If you have a lot more buttons, checkboxed, dropdownlists, and so on I would create a mini-MFC library which does all that for you.

I would go with messages. So, you will have a hierarchie. At the base there is the mainwnd. If someone clicks a button then the button sends a Message BM_CLICKED (or so) to it''s parent wnd. If this parent wnd does not know what to do with this message it sends the message further to its parent, until a wnd is reached which does something with the message.

Check out MFC for further information on that. But it''s a lot of work to create something like that, and it really just matters if you have a lot of buttons and different controls. With a few controls give foofighters idea a try, cause it''s simply, fast and easy to implement.


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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!