Updates:
6/14/2012 - Allowed the menu to be relocated.
6/15/2012 - Removed all non standard function calls from my code. (Thank you Duoas)
6/18/2012 - Menu v2 released!
New features include calling functions from each option directly. No more messy code just to run your menu. Just select Play, and you're on your way.
It looks pretty cool, but im getting these errors:
F:\C++\Menu\_VP_MENU.cpp||In member function 'int Menu::Play(int)':|
F:\C++\Menu\_VP_MENU.cpp|18|error: 'VP_ClearScreen' was not declared in this scope|
F:\C++\Menu\_VP_MENU.cpp|38|error: 'VP_GoToXY' was not declared in this scope|
F:\C++\Menu\_VP_MENU.cpp|56|error: 'VP_GoToXY' was not declared in this scope|
||=== Build finished: 3 errors, 0 warnings ===|
Sorry about that. I have updated my main post with both header.h and header.cpp. I also included a sample use of the class in the main.cpp Example to save people the headache of writing their own.
I included detailed instructions, and some of the code hasn't been fully implemented yet, and there is still room for improvement, as there is in just about any code.
Can anyone suggest any improvements upon my code? Simple or complex, I don't care. I know it's not perfect, but every little thing would be greatly appreciated.
Yes, I do know that, but the menu is set on a loop, that way when, let's say the user selects the first option, which is play tetris, you play tetris and once tetris is done, you will return to the main menu. You can prevent the menu from looping by simply removing the do while loop. But that is the best way I can think of to show all the features of the menu class, and in my opinion, the way it would be used te most.
I'll have to change the string include then.
And yes, I know win32 API is much simpler, but this is the best I can do with the console.
I might be implementing that tonight actually. I want to be able to select positions in the nine popular positions, top, center, bottom, left, center, right. I also set it up so that it aligns that way as well, as if you had center align, or right align.
Another implementation I just thought about is invidiual colors for each menu, but a lot of people might not care about that. It's still something I'm thinking about though. Even possibly allowing different characters to be used to indicate specific letters should be a certain color, using !1 for white text, #1 for white background and then using ## or some other way to allow the symbol to be used without being mistaken for a color. More as an escape character.
Concerning the nine popular positions, does this mean your menu would be 3 selections across and 3 down, instead of being listed vertically? Or even 4 or 5 across or down even? That would make an interesting onscreen menu. And the only reason I see for using different colors in the menu, would be so you highlight the letter that the user presses, to activate the choice line, or can use the enter key, after menu keyboard selection. I think that would work very nicely.
If you get the menu positioning worked out today, or even tomorrow, I, for one, would be very happy to see the results, as I'm sure a few of the other programmers that are watching your thread, would be too.
I've only just begun on the title and separator part, but the options and selectors should be done shortly.
As for the colors, I don't think it will be a highly requested feature, just one more thing that can be done. But I could implement something similar to how windows API is set up. Put an ampersand in front of a character to signify the key to press. For example, "My &1st option" would display:
My 1st option
And allows the user to press the 1 to automatically select that option. Two ampersands would display a single ampersand, but I would have to set up a default color for the user to press, maybe a blue or green.
I just completed it. I was tutoring someone last night and was unable to finish it until tonight. Hope you guys enjoy. I tested it a little bit, but if you notice anything wrong with anything in the menu, don't hesitate to point it out.
The original post has been updated to reflect the new URL.
This seems very cool, ill have to implement this in my little console game i've been creating here: http://www.cplusplus.com/forum/lounge/73282/
Sadly i dont have access to my programming computer right now, but im wondering what your menu could do better for(if you have the extra time, i encourage you to try out my game and laugh at my current menu). Im definitely interested in using your menu though, thanks!
Mine still isnt compiling, im getting a headache amount of errors trying to get this to work. Can you put up a link to a zip of the files that you knows works?
Yeah, I'm working on setting up the account to store my .zip and source files. You're using Code::Blocks on WinOS right? Can you give me a general example of your errors?
I added in your updated menu class, and then looked through main.cpp, to see how you implemented the improved menu system, and didn't see any change. After then looking at the menu class again, did I see a way to use it. I then added in the command to center it mid screen, and it worked beautifully. Nicely done. Now the fun part. Seeing if I can incorporate your that menu system into one of my programs.
I'm sorry for the headache for everyone that has been having issues. I'm updating my original post now to include a downloadable .zip to make it easier for everyone else. Included is the lib folder with the three required files, and a bin folder with a copy of my test example.
I have everything updated, looking good, and have updated all of my links in my first post. I have removed ALL non standard function calls that I'm personally aware of (thanks Duoas), and have created a better example for the menu class.
Hey guys, just wanted to give you a heads up that there is going to be a new release of the menu coming in the, hopefully, very near future. It implements some new features in C++11 so since some people's compilers may not yet still support it, I'm leaving my original menu up.
The update will first consist of a way to pass functions to the menu so that when the user selects an option from the menu, the menu class will automatically call that function. It will save you lines of coding when implementing the menu.
Another hopeful addition will be to add radio style options in the menu. Think more of the lines as an on/off switch. And also be able to accept other settings such as setting a difficulty in a game from easy, medium, hard, etc and allowing numbers 1-10.
Currently just implementing the function calls, but that should be done shortly.
The new additions to your menu class, sound very interesting, and I would be happy to be able to try them out, when completed. My problem, though, is I don't know which compilers are C++11 compliant. I use Microsoft Visual Studio 2008 Express Edition, and have, but haven't installed, Microsoft Visual Studio 2010 Express. Can either of these be used? Or should I look at a different one?
I don't believe VC++10 supports much C++11, mainly since the C++11 standard was released in 2011. However, it might be able to support it, try to #include <functional> into a project and see if the compiler can find it. If it does, you should be fine, if not, you might need to upgrade.
I personally use the MinGW release 4.6.2 which supports, most if not all, of the C++11 standard. I use this with the latest nightly build over at Code::Blocks. It's a bit of a hassle to set up, but definitely well worth the added features in my opinion.
Edit: You may need to see if your compiler has an option for C++0x or C++11 support through the command line. The gcc's line is -std=c++0x.