From 3f7112d5c9a97aead70616ab5ecde5f0efe41968 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 3 Oct 2019 21:50:54 +0200 Subject: GRAPHICS: MACGUI: Refactor some code --- graphics/macgui/macmenu.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'graphics/macgui') diff --git a/graphics/macgui/macmenu.cpp b/graphics/macgui/macmenu.cpp index 9d05c76fc3..7ed4f3162f 100644 --- a/graphics/macgui/macmenu.cpp +++ b/graphics/macgui/macmenu.cpp @@ -102,6 +102,8 @@ struct MacMenuSubMenu { for (uint i = 0; i < subitems.size(); i++) delete subitems[i]; } + + int ytoItem(int y) { return MIN((y - bbox.top) / kMenuDropdownItemHeight, subitems.size() - 1); } }; MacMenuSubItem::~MacMenuSubItem() { @@ -837,7 +839,7 @@ bool MacMenu::mouseClick(int x, int y) { if (_menustack.size() > 0 && _menustack.back()->bbox.contains(x, y)) { MacMenuSubMenu *menu = _menustack.back(); - int numSubItem = MIN((y - menu->bbox.top) / kMenuDropdownItemHeight, menu->subitems.size() - 1); + int numSubItem = menu->ytoItem(y); if (numSubItem != _activeSubItem) { _activeSubItem = numSubItem; @@ -870,8 +872,7 @@ bool MacMenu::mouseClick(int x, int y) { MacMenuSubMenu *menu = _menustack.back(); - _activeSubItem = MIN((y - menu->bbox.top) / kMenuDropdownItemHeight, menu->subitems.size() - 1); - menu->highlight = _activeSubItem; + _activeSubItem = menu->highlight = menu->ytoItem(y); _contentIsDirty = true; -- cgit v1.2.3