| 234 | } |
| 235 | |
| 236 | IMenuPanel *MenuManager::RenderMenu(int client, menu_states_t &md, ItemOrder order) |
| 237 | { |
| 238 | IBaseMenu *menu = md.menu; |
| 239 | |
| 240 | if (!menu) |
| 241 | { |
| 242 | return NULL; |
| 243 | } |
| 244 | |
| 245 | struct |
| 246 | { |
| 247 | unsigned int position; |
| 248 | ItemDrawInfo draw; |
| 249 | } drawItems[10]; |
| 250 | |
| 251 | /* Figure out how many items to draw */ |
| 252 | IMenuStyle *style = menu->GetDrawStyle(); |
| 253 | unsigned int pgn = menu->GetPagination(); |
| 254 | unsigned int maxItems = style->GetMaxPageItems(); |
| 255 | bool exitButton = (menu->GetMenuOptionFlags() & MENUFLAG_BUTTON_EXIT) == MENUFLAG_BUTTON_EXIT; |
| 256 | bool novoteButton = (menu->GetMenuOptionFlags() & MENUFLAG_BUTTON_NOVOTE) == MENUFLAG_BUTTON_NOVOTE; |
| 257 | |
| 258 | if (pgn != MENU_NO_PAGINATION) |
| 259 | { |
| 260 | maxItems = pgn; |
| 261 | } |
| 262 | else if (exitButton) |
| 263 | { |
| 264 | maxItems--; |
| 265 | } |
| 266 | |
| 267 | if (novoteButton) |
| 268 | { |
| 269 | maxItems--; |
| 270 | } |
| 271 | |
| 272 | /* This is very not allowed! */ |
| 273 | if (maxItems < 2) |
| 274 | { |
| 275 | return NULL; |
| 276 | } |
| 277 | |
| 278 | unsigned int totalItems = menu->GetItemCount(); |
| 279 | unsigned int startItem = 0; |
| 280 | |
| 281 | /* For pagination, find the starting point. */ |
| 282 | if (pgn != MENU_NO_PAGINATION) |
| 283 | { |
| 284 | if (order == ItemOrder_Ascending) |
| 285 | { |
| 286 | startItem = md.lastItem; |
| 287 | /* This shouldn't happen with well-coded menus. |
| 288 | * If the item is out of bounds, switch the order to |
| 289 | * Items_Descending and make us start from the top. |
| 290 | */ |
| 291 | if (startItem >= totalItems) |
| 292 | { |
| 293 | startItem = totalItems - 1; |
no test coverage detected