diff options
-rw-r--r-- | engines/wage/gui.h | 2 | ||||
-rw-r--r-- | engines/wage/menu.cpp | 51 | ||||
-rw-r--r-- | engines/wage/menu.h | 5 |
3 files changed, 57 insertions, 1 deletions
diff --git a/engines/wage/gui.h b/engines/wage/gui.h index c5c1aada0b..335af862ab 100644 --- a/engines/wage/gui.h +++ b/engines/wage/gui.h @@ -68,6 +68,8 @@ enum { kMenuLeftMargin = 7, kMenuSpacing = 13, kMenuPadding = 6, + kMenuDropdownPadding = 6, + kMenuDropdownItemHeight = 19, kMenuItemHeight = 20, kBorderWidth = 17, kDesktopArc = 7, diff --git a/engines/wage/menu.cpp b/engines/wage/menu.cpp index ef3d723df6..c63c39b846 100644 --- a/engines/wage/menu.cpp +++ b/engines/wage/menu.cpp @@ -67,10 +67,13 @@ struct MenuSubItem { MenuSubItem(const char *t, int a, int s = 0, char sh = 0, bool e = true) : text(t), action(a), style(s), shortcut(sh), enabled(e) {} }; +typedef Common::Array<MenuSubItem *> SubItemArray; + struct MenuItem { Common::String name; - Common::Array<MenuSubItem *> subitems; + SubItemArray subitems; Common::Rect bbox; + Common::Rect subbbox; MenuItem(const char *n) : name(n) {} }; @@ -161,6 +164,8 @@ Menu::Menu(Gui *gui) : _gui(gui) { _items[i]->bbox.bottom = y + _font->getFontHeight(); } + calcMenuBounds(_items[i]); + x += w + kMenuSpacing; } @@ -186,6 +191,50 @@ const Graphics::Font *Menu::getMenuFont() { return _gui->getFont("Chicago-12", Graphics::FontManager::kBigGUIFont); } +const char *Menu::getAcceleratorString(MenuSubItem *item) { + static char res[20]; + *res = 0; + + if (item->shortcut != 0) + sprintf(res, " \u2318%c", item->shortcut); + + return res; +} + +int Menu::calculateMenuWidth(MenuItem *menu) { + int maxWidth = 0; + for (int i = 0; i < menu->subitems.size(); i++) { + MenuSubItem *item = menu->subitems[i]; + if (item->text != NULL) { + Common::String text(item->text); + Common::String acceleratorText(getAcceleratorString(item)); + if (acceleratorText.size()) { + text += acceleratorText; + } + + int width = _font->getStringWidth(text); + if (width > maxWidth) { + maxWidth = width; + } + } + } + return maxWidth; +} + +void Menu::calcMenuBounds(MenuItem *menu) { + // TODO: cache maxWidth + int maxWidth = calculateMenuWidth(menu); + int x1 = menu->bbox.left - kMenuDropdownPadding; + int y1 = menu->bbox.bottom; + int x2 = x1 + maxWidth + kMenuDropdownPadding * 3; + int y2 = y1 + menu->subitems.size() * kMenuDropdownItemHeight; + + menu->subbbox.left = x1; + menu->subbbox.top = y1; + menu->subbbox.right = x2; + menu->subbbox.bottom = y2; +} + void Menu::render() { Common::Rect r(_bbox); Patterns p; diff --git a/engines/wage/menu.h b/engines/wage/menu.h index 0a8c498be9..a6b5db2405 100644 --- a/engines/wage/menu.h +++ b/engines/wage/menu.h @@ -51,6 +51,7 @@ namespace Wage { struct MenuItem; +struct MenuSubItem; class Menu { public: @@ -70,6 +71,10 @@ private: private: const Graphics::Font *getMenuFont(); + const char *getAcceleratorString(MenuSubItem *item); + int calculateMenuWidth(MenuItem *menu); + void calcMenuBounds(MenuItem *menu); + Common::Array<MenuItem *> _items; const Graphics::Font *_font; |