00001
00002
00003
00004
00005
00006
00007
00009
00010
00011
00012
00013
00014
00015
00016 #include "boot_menu.h"
00017
00018 using namespace std;
00019 using namespace hoa_video;
00020
00021 namespace hoa_boot {
00022
00023
00024 hoa_video::MenuWindow * BootMenu::_menu_window = 0;
00025 BootMode * BootMenu::_boot_mode = 0;
00026
00027
00028 BootMenu::BootMenu(BootMenu * parent, bool windowed, BootMode * boot_mode) :
00029 _parent_menu(parent),
00030 _is_windowed(windowed)
00031 {
00032
00033 if (boot_mode != 0)
00034 _boot_mode = boot_mode;
00035
00036 SetWindowed(_is_windowed);
00037
00038
00039 _InitWindow();
00040 }
00041
00042
00043 BootMenu::~BootMenu()
00044 {
00045 if (_menu_window)
00046 {
00047 _menu_window->Destroy();
00048 delete _menu_window;
00049 _menu_window = 0;
00050 }
00051 }
00052
00053
00054
00055 void BootMenu::AddOption(const hoa_utils::ustring & text, void (BootMode::*confirm_function)(), void (BootMode::*left_function)(), void (BootMode::*right_function)(), void (BootMode::*up_function)(), void (BootMode::*down_function)())
00056 {
00057 _current_menu.AddOption(text);
00058
00059
00060 if (!_is_windowed)
00061 _current_menu.SetSize(_current_menu.GetNumberOptions(), 1);
00062 else
00063 _current_menu.SetSize(1, _current_menu.GetNumberOptions());
00064
00065 if (_current_menu.GetNumberOptions() == 1)
00066 {
00067 _current_menu.SetSelection(0);
00068 }
00069
00070
00071 _confirm_handlers.push_back(confirm_function);
00072 _left_handlers.push_back(left_function);
00073 _right_handlers.push_back(right_function);
00074 _up_handlers.push_back(up_function);
00075 _down_handlers.push_back(down_function);
00076 }
00077
00078
00079
00080 void BootMenu::SetOptionText(uint32 index, const hoa_utils::ustring & text)
00081 {
00082 _current_menu.SetOptionText(index, text);
00083 }
00084
00085
00086 void BootMenu::EnableOption(int32 index, bool enable)
00087 {
00088 _current_menu.EnableOption(index, enable);
00089 }
00090
00091
00092
00093 void BootMenu::SetWindowed(bool windowed)
00094 {
00095 _is_windowed = windowed;
00096
00097 if (!_is_windowed)
00098 {
00099 _current_menu.SetFont("default");
00100 _current_menu.SetCellSize(150.0f, 70.0f);
00101 _current_menu.SetPosition(552.0f, 50.0f);
00102 _current_menu.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
00103 _current_menu.SetOptionAlignment(VIDEO_X_LEFT, VIDEO_Y_CENTER);
00104 _current_menu.SetSelectMode(VIDEO_SELECT_SINGLE);
00105 _current_menu.SetHorizontalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
00106 _current_menu.SetCursorOffset(-50.0f, 28.0f);
00107 _current_menu.SetSize(_current_menu.GetNumberOptions(), 1);
00108 }
00109 else
00110 {
00111 _current_menu.SetFont("default");
00112 _current_menu.SetCellSize(210.0f, 50.0f);
00113 _current_menu.SetPosition(512.0f, 200.0f);
00114 _current_menu.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
00115 _current_menu.SetOptionAlignment(VIDEO_X_LEFT, VIDEO_Y_CENTER);
00116 _current_menu.SetSelectMode(VIDEO_SELECT_SINGLE);
00117 _current_menu.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
00118 _current_menu.SetCursorOffset(-50.0f, 28.0f);
00119 _current_menu.SetSize(1, _current_menu.GetNumberOptions());
00120 _current_menu.SetOwner(_menu_window);
00121 }
00122 }
00123
00124
00125
00126 void BootMenu::SetParent(BootMenu * parent)
00127 {
00128 _parent_menu = parent;
00129 }
00130
00131
00132
00133 void BootMenu::SetTextDensity(float density)
00134 {
00135 if (_is_windowed)
00136 _current_menu.SetCellSize(210.0f, density);
00137 else
00138 _current_menu.SetCellSize(density, 50.0f);
00139 }
00140
00141
00142
00143 int32 BootMenu::GetEvent()
00144 {
00145 _current_menu.Update();
00146 return _current_menu.GetEvent();
00147 }
00148
00149
00150
00151 BootMenu * BootMenu::GetParent() const
00152 {
00153 return _parent_menu;
00154 }
00155
00156
00157
00158 bool BootMenu::IsWindowed() const
00159 {
00160 return _is_windowed;
00161 }
00162
00163
00164
00165 bool BootMenu::IsSelectionEnabled() const
00166 {
00167 return _current_menu.IsEnabled(_current_menu.GetSelection()) &&
00168 _confirm_handlers.at(_current_menu.GetSelection()) != 0;
00169 }
00170
00171
00172
00173 bool BootMenu::Draw()
00174 {
00175 _menu_window->Draw();
00176
00177 VideoManager->EnableScissoring(false);
00178 _current_menu.Draw();
00179 return true;
00180
00181 VideoManager->EnableScissoring(true);
00182 }
00183
00184
00185
00186 void BootMenu::ConfirmPressed()
00187 {
00188 _current_menu.HandleConfirmKey();
00189
00190 int32 selection = _current_menu.GetSelection();
00191 if (selection != -1 && !_confirm_handlers.empty())
00192 {
00193 void (BootMode::*confirm_function)() = _confirm_handlers.at(selection);
00194 if (confirm_function != 0)
00195 {
00196 (_boot_mode->*confirm_function)();
00197 }
00198 }
00199 }
00200
00201
00202
00203 void BootMenu::LeftPressed()
00204 {
00205 _current_menu.HandleLeftKey();
00206
00207 int32 selection = _current_menu.GetSelection();
00208 if (selection != -1 && !_left_handlers.empty())
00209 {
00210 void (BootMode::*left_function)() = _left_handlers.at(selection);
00211 if (left_function != 0)
00212 {
00213 (_boot_mode->*left_function)();
00214 }
00215 }
00216 }
00217
00218
00219
00220 void BootMenu::RightPressed()
00221 {
00222 _current_menu.HandleRightKey();
00223
00224 int32 selection = _current_menu.GetSelection();
00225 if (selection != -1)
00226 {
00227 void (BootMode::*right_function)() = _right_handlers.at(selection);
00228 if (right_function != 0 && !_right_handlers.empty())
00229 {
00230 (_boot_mode->*right_function)();
00231 }
00232 }
00233 }
00234
00235
00236
00237 void BootMenu::UpPressed()
00238 {
00239 _current_menu.HandleUpKey();
00240
00241 int32 selection = _current_menu.GetSelection();
00242 if (selection != -1)
00243 {
00244 void (BootMode::*up_function)() = _up_handlers.at(selection);
00245 if (up_function != 0 && !_up_handlers.empty())
00246 {
00247 (_boot_mode->*up_function)();
00248 }
00249 }
00250 }
00251
00252
00253
00254 void BootMenu::DownPressed()
00255 {
00256 _current_menu.HandleDownKey();
00257
00258 int32 selection = _current_menu.GetSelection();
00259 if (selection != -1)
00260 {
00261 void (BootMode::*down_function)() = _down_handlers.at(selection);
00262 if (down_function != 0 && !_down_handlers.empty())
00263 {
00264 (_boot_mode->*down_function)();
00265 }
00266 }
00267 }
00268
00269
00270
00271 void BootMenu::CancelPressed()
00272 {
00273 _current_menu.HandleCancelKey();
00274 }
00275
00276
00277
00278 void BootMenu::UpdateWindow(int32 frameTime)
00279 {
00280 if (_menu_window)
00281 _menu_window->Update(frameTime);
00282 }
00283
00284
00285
00286 void BootMenu::ShowWindow(bool toggle)
00287 {
00288 if (toggle)
00289 _menu_window->Show();
00290 else
00291 _menu_window->Hide();
00292 }
00293
00294
00295
00296 void BootMenu::_InitWindow()
00297 {
00298 if (_menu_window == 0)
00299 {
00300 _menu_window = new hoa_video::MenuWindow();
00301 _menu_window->Create(1024.0f, 400.0f);
00302 _menu_window->SetPosition(0.0f, 560.0f);
00303 _menu_window->SetDisplayMode(VIDEO_MENU_EXPAND_FROM_CENTER);
00304 _menu_window->Hide();
00305 }
00306 }
00307
00308
00309 }