diff options
author | Eugene Sandulenko | 2019-10-13 23:41:18 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2019-10-13 23:48:42 +0200 |
commit | df93f8a65802b1ecd126a51f9edf58ce813a7f2a (patch) | |
tree | 71f36a9c5953a8baf2c5b300c92bc1ff0be540aa /graphics/macgui | |
parent | cdbcb296090cd0c5ff8c6a04b7184e7b45b7188a (diff) | |
download | scummvm-rg350-df93f8a65802b1ecd126a51f9edf58ce813a7f2a.tar.gz scummvm-rg350-df93f8a65802b1ecd126a51f9edf58ce813a7f2a.tar.bz2 scummvm-rg350-df93f8a65802b1ecd126a51f9edf58ce813a7f2a.zip |
GRAPHICS: MACGUI: Process tab symbol in Windows menus
Diffstat (limited to 'graphics/macgui')
-rw-r--r-- | graphics/macgui/macmenu.cpp | 94 | ||||
-rw-r--r-- | graphics/macgui/macmenu.h | 3 |
2 files changed, 97 insertions, 0 deletions
diff --git a/graphics/macgui/macmenu.cpp b/graphics/macgui/macmenu.cpp index 87298e2be1..9594aee3da 100644 --- a/graphics/macgui/macmenu.cpp +++ b/graphics/macgui/macmenu.cpp @@ -257,6 +257,9 @@ MacMenu *MacMenu::createMenuFromPEexe(Common::PEResources &exe, MacWindowManager } } } + + menu->processTabs(); + delete menuData; if (gDebugLevel > 5) @@ -556,6 +559,97 @@ const Common::String MacMenu::getAcceleratorString(MacMenuItem *item, const char return Common::String::format("%s%c%c", prefix, (_wm->_fontMan->hasBuiltInFonts() ? '^' : '\x11'), item->shortcut); } +void MacMenu::processTabs() { + for (uint i = 0; i < _items.size(); i++) + processSubmenuTabs(_items[i]->submenu); +} + +void MacMenu::processSubmenuTabs(MacMenuSubMenu *submenu) { + if (submenu == nullptr) + return; + + for (uint i = 0; i < submenu->items.size(); i++) { + MacMenuSubMenu *menu = submenu->items[i]->submenu; + + if (menu != nullptr) + processSubmenuTabs(menu); + } + + int maxWidth = 0; + bool haveTabs = false; + + Common::U32String tabSymbol("\t"); + + // First, we replace \t with one space, and thus, obtain + // the widest string + for (uint i = 0; i < submenu->items.size(); i++) { + MacMenuItem *item = submenu->items[i]; + if (item->unicodeText.empty()) + continue; + + int pos = item->unicodeText.find(tabSymbol); + + if (pos == Common::U32String::npos) + continue; + + // Sanity check + if (pos == 0 || pos >= item->unicodeText.size()) + error("Malformed menu: tab position"); + + if (item->unicodeText.find(tabSymbol, pos + 1) != Common::U32String::npos) + error("Malformed menu: extra tab"); + + haveTabs = true; + + Common::U32String start(item->unicodeText.c_str(), &item->unicodeText.c_str()[pos]); + Common::U32String end(&item->unicodeText.c_str()[pos + 1]); + Common::U32String res; + + res = start; + res += Common::U32String(" "); + res += end; + + int width = _font->getStringWidth(res); + if (width > maxWidth) { + maxWidth = width; + } + } + + if (!haveTabs) + return; + + // Now expand each tab to the relevant width + // And yes, right edge is going to be uneven + for (uint i = 0; i < submenu->items.size(); i++) { + MacMenuItem *item = submenu->items[i]; + if (item->unicodeText.empty()) + continue; + + int pos = item->unicodeText.find(tabSymbol); + + if (pos == Common::U32String::npos) + continue; + + Common::U32String start(item->unicodeText.c_str(), &item->unicodeText.c_str()[pos]); + Common::U32String end(&item->unicodeText.c_str()[pos + 1]); + Common::U32String res; + Common::U32String spaces(" "); + int width; + + do { + res = start; + res += spaces; + res += end; + + width = _font->getStringWidth(res); + + spaces += spaces[0]; + } while (width < maxWidth); + + item->unicodeText = res; + } +} + int MacMenu::calcSubMenuWidth(MacMenuSubMenu *submenu) { int maxWidth = 0; if (submenu == nullptr) diff --git a/graphics/macgui/macmenu.h b/graphics/macgui/macmenu.h index 49606f1f9a..e7c172c3fb 100644 --- a/graphics/macgui/macmenu.h +++ b/graphics/macgui/macmenu.h @@ -94,6 +94,9 @@ private: private: const Font *getMenuFont(); const Common::String getAcceleratorString(MacMenuItem *item, const char *prefix); + void processTabs(); + void processSubmenuTabs(MacMenuSubMenu *submenu); + int calcSubMenuWidth(MacMenuSubMenu *menu); void calcSubMenuBounds(MacMenuSubMenu *menu, int x, int y); void renderSubmenu(MacMenuSubMenu *menu, bool recursive = true); |