1 ///////////////////////////////////////////////////////////////////////////////
2 //            Copyright (C) 2004-2010 by The Allacrost Project
3 //                         All Rights Reserved
4 //
5 // This code is licensed under the GNU GPL version 2. It is free software
6 // and you may modify it and/or redistribute it under the terms of this license.
7 // See http://www.gnu.org/copyleft/gpl.html for details.
8 ///////////////////////////////////////////////////////////////////////////////
9 
10 /** ****************************************************************************
11 *** \file    boot_menu.h
12 *** \author  Viljami Korhonen, mindflayer@allacrost.org
13 *** \brief   Header file for the boot menus
14 *** ***************************************************************************/
15 
16 #ifndef __BOOT_MENU__
17 #define __BOOT_MENU__
18 
19 #include "defs.h"
20 #include "utils.h"
21 
22 #include "video.h"
23 #include "gui.h"
24 
25 namespace hoa_boot {
26 
27 namespace private_boot {
28 
29 /** ****************************************************************************
30 *** \brief Used for the construction and operation of all boot mode menus
31 ***
32 *** This class is an extension of the OptionBox class found in the GUI code. Its
33 *** primary feature is that it utilizes function pointers to the BootMode class,
34 *** which makes this class incredibly flexible and versatile. The way it works
35 *** is to keep several containers of function pointers, where the size of these
36 *** containers are equal to the number of options in the menu. The function pointers
37 *** are invoked on the selected option when an input command is received. For example,
38 *** if the second option is selected and a confirm press is registered, the appropriate
39 *** function pointed to for that option and that input event will be called. Other
40 *** than this simple yet powerful feature, this class operates and acts exactly the same
41 *** as a standard OptionBox object.
42 ***
43 *** \note There are some OptionBox methods which should not be used for this class. Particularly
44 *** any methods that add or remove options should be avoided because they do not know to modify
45 *** the function pointer containers appropriately. Use only the methods specific to this class
46 *** to add or remove options.
47 *** ***************************************************************************/
48 class BootMenu : public hoa_gui::OptionBox {
49 public:
BootMenu()50 	BootMenu()
51 		{}
52 
~BootMenu()53 	~BootMenu()
54 		{}
55 
56 	/** \brief Adds a new option to the menu with the desired function pointers attached
57 	*** \param text A text representing the new option
58 	*** \param *up_function BootMode handler function for up input events
59 	*** \param *down_function BootMode handler function for down input events
60 	*** \param *confirm_function BootMode handler function for confirm input events
61 	*** \param *left_function BootMode handler function for left input events
62 	*** \param *right_function BootMode handler function for right input events
63 	**/
64 	void AddOption(const hoa_utils::ustring & text, void (BootMode::*confirm_function)() = NULL,
65 		void (BootMode::*up_function)() = NULL,   void (BootMode::*down_function)() = NULL,
66 		void (BootMode::*left_function)() = NULL, void (BootMode::*right_function)() = NULL);
67 
68 	//! \brief
69 	//@{
70 	void InputConfirm();
71 	void InputUp();
72 	void InputDown();
73 	void InputLeft();
74 	void InputRight();
75 	//@}
76 
77 private:
78 	//! \brief Confirm input handlers for all options in the menu
79 	std::vector<void (BootMode::*)()> _confirm_handlers;
80 
81 	//! \brief Up input handlers for all options in the menu
82 	std::vector<void (BootMode::*)()> _up_handlers;
83 
84 	//! \brief Down input handlers for all options in the menu
85 	std::vector<void (BootMode::*)()> _down_handlers;
86 
87 	//! \brief Left input handlers for all options in the menu
88 	std::vector<void (BootMode::*)()> _left_handlers;
89 
90 	//! \brief Right input handlers for all options in the menu
91 	std::vector<void (BootMode::*)()> _right_handlers;
92 }; // class BootMenu : public hoa_video::OptionBox
93 
94 } // namespace private_boot
95 
96 } // namespace hoa_boot
97 
98 #endif // __BOOT_MENU__
99