1 #include "optionitemmenu.h"
2 #include "menu.h"
3 #include "clock.h"
4
5 /** @brief Default constructor.
6 *
7 * The target is the Menu instance to handle.
8 *
9 * Activation is a simple call to the Menus operator(), its return value
10 * is then returned without further ado.
11 *
12 * @param[in,out] menu_ Pointer to the Menu instance to handle.
13 * @param[in] title_ The title of the option to display.
14 * @param[in] titleIdx_ Index value of the submitted title. -1 means @a title_ is fixed.
15 * @param[in] color Regular display color of the title.
16 * @param[in] top_ Top position of the display area.
17 * @param[in] left_ Left position of the display area.
18 * @param[in] width_ Width of the display area.
19 * @param[in] height_ Height of the display area.
20 * @param[in] padding_ Padding of the title and buttons to the display area.
21 **/
OptionItemMenu(Menu * menu_,const char * title_,int32_t titleIdx_,int32_t color_,int32_t top_,int32_t left_,int32_t width_,int32_t height_,int32_t padding_)22 OptionItemMenu::OptionItemMenu(
23 Menu* menu_,
24 const char* title_,
25 int32_t titleIdx_,
26 int32_t color_,
27 int32_t top_, int32_t left_, int32_t width_, int32_t height_,
28 int32_t padding_) :
29 OptionItemBase(ET_MENU,
30 title_ ? title_ : menu_ ? menu_->getTitle() : nullptr,
31 titleIdx_,
32 nullptr, color_,
33 TC_NONE, nullptr,
34 top_, left_, width_, height_, padding_, 0),
35 menu(menu_)
36 {
37 // Both action or player must be set
38 assert ( menu_ && "A nullptr menu_ makes no sense...");
39 // As the title is displayed as text, textOnly must be set:
40 this->textOnly = true;
41 }
42
43
44 /// @brief default dtor only setting nullptr values. No further action needed.
~OptionItemMenu()45 OptionItemMenu::~OptionItemMenu()
46 {
47 menu = nullptr;
48 }
49
50
51 /* ----------------------
52 * --- Public methods ---
53 * ----------------------
54 */
55
56 /** @brief activate the sub menu
57 *
58 * This calls operator() on the menu.
59 *
60 * Note: The parameters are defined by OptionItemBase but unused
61 * here.
62 *
63 * @return The return code of the sub menu.
64 **/
activate(int32_t,int32_t,int32_t,int32_t)65 int32_t OptionItemMenu::activate(int32_t, int32_t, int32_t, int32_t)
66 {
67 // Remove parent menu timer
68 WIN_CLOCK_REMOVE
69
70 int32_t result = (*menu)();
71
72 // Changes are displayed at once:
73 this->drawn = false;
74 this->display(false);
75
76 // Re-add parent menu timer
77 WIN_CLOCK_INIT
78
79 return result;
80 }
81
82
83 /// @brief returns always true
canGoDown()84 bool OptionItemMenu::canGoDown()
85 {
86 return true;
87 }
88
89
90 /// @brief returns always true
canGoUp()91 bool OptionItemMenu::canGoUp()
92 {
93 return true;
94 }
95
96
97 /** @brief display the sub menu title
98 *
99 * @param[in] show_full If set to true, title and buttons are redrawn.
100 **/
display(bool show_full)101 void OptionItemMenu::display(bool show_full)
102 {
103 this->displayMenu(menu);
104
105 // Show decorations if wanted:
106 if (show_full)
107 this->displayDeco();
108 }
109
110
111 /// @brief return true, the menu must be able to return an exit code.
isExitButton()112 bool OptionItemMenu::isExitButton()
113 {
114 return true;
115 }
116
117
118 /// @brief simply calls setLanguage(false) on the target menu
setLanguage()119 void OptionItemMenu::setLanguage()
120 {
121 if (menu)
122 menu->setLanguage(false);
123 }
124