corrects PopupMenu::checkItem() not checking the item. also prepends m to member variables for the MenuItem class to correct a few more locals hiding classvar reports.

This commit is contained in:
Azaezel 2018-03-12 14:30:49 -05:00
parent 0a09aaba2e
commit 9141d37ca2
4 changed files with 91 additions and 85 deletions

View file

@ -1369,19 +1369,19 @@ void GuiMenuBar::buildWindowAcceleratorMap(WindowInputGenerator &inputGenerator)
{ {
for (U32 item = 0; item < mMenuList[i].popupMenu->mMenuItems.size(); item++) for (U32 item = 0; item < mMenuList[i].popupMenu->mMenuItems.size(); item++)
{ {
if (!mMenuList[i].popupMenu->mMenuItems[item].accelerator) if (!mMenuList[i].popupMenu->mMenuItems[item].mAccelerator)
{ {
mMenuList[i].popupMenu->mMenuItems[item].accelerator = 0; mMenuList[i].popupMenu->mMenuItems[item].mAccelerator = 0;
continue; continue;
} }
EventDescriptor accelEvent; EventDescriptor accelEvent;
ActionMap::createEventDescriptor(mMenuList[i].popupMenu->mMenuItems[item].accelerator, &accelEvent); ActionMap::createEventDescriptor(mMenuList[i].popupMenu->mMenuItems[item].mAccelerator, &accelEvent);
//now we have a modifier, and a key, add them to the canvas //now we have a modifier, and a key, add them to the canvas
inputGenerator.addAcceleratorKey(this, mMenuList[i].popupMenu->mMenuItems[item].cmd, accelEvent.eventCode, accelEvent.flags); inputGenerator.addAcceleratorKey(this, mMenuList[i].popupMenu->mMenuItems[item].mCMD, accelEvent.eventCode, accelEvent.flags);
mMenuList[i].popupMenu->mMenuItems[item].acceleratorIndex = mCurAcceleratorIndex; mMenuList[i].popupMenu->mMenuItems[item].mAcceleratorIndex = mCurAcceleratorIndex;
mCurAcceleratorIndex++; mCurAcceleratorIndex++;
} }
} }
@ -1403,7 +1403,7 @@ void GuiMenuBar::acceleratorKeyPress(U32 index)
for(U32 item = 0; item < mMenuList[i].popupMenu->mMenuItems.size(); item++) for(U32 item = 0; item < mMenuList[i].popupMenu->mMenuItems.size(); item++)
{ {
if(mMenuList[i].popupMenu->mMenuItems[item].acceleratorIndex == index) if(mMenuList[i].popupMenu->mMenuItems[item].mAcceleratorIndex == index)
{ {
// first, call the script callback for menu selection: // first, call the script callback for menu selection:
onMenuSelect_callback(mMenuList[i].popupMenu->getId(), mMenuList[i].text); onMenuSelect_callback(mMenuList[i].popupMenu->getId(), mMenuList[i].text);
@ -1454,7 +1454,7 @@ void GuiMenuBar::insert(SimObject* pObject, S32 pos)
newMenu.drawBitmapOnly = false; newMenu.drawBitmapOnly = false;
newMenu.drawBorder = true; newMenu.drawBorder = true;
newMenu.bitmapIndex = -1; newMenu.bitmapIndex = -1;
newMenu.text = menu->barTitle; newMenu.text = menu->mBarTitle;
newMenu.visible = true; newMenu.visible = true;
newMenu.popupMenu = menu; newMenu.popupMenu = menu;

View file

@ -100,7 +100,7 @@ GuiPopupMenuTextListCtrl::GuiPopupMenuTextListCtrl()
void GuiPopupMenuTextListCtrl::onRenderCell(Point2I offset, Point2I cell, bool selected, bool mouseOver) void GuiPopupMenuTextListCtrl::onRenderCell(Point2I offset, Point2I cell, bool selected, bool mouseOver)
{ {
//check if we're a real entry, or if it's a divider //check if we're a real entry, or if it's a divider
if (mPopup->mMenuItems[cell.y].isSpacer) if (mPopup->mMenuItems[cell.y].mIsSpacer)
{ {
S32 yp = offset.y + mCellSize.y / 2; S32 yp = offset.y + mCellSize.y / 2;
GFX->getDrawUtil()->drawLine(offset.x + 5, yp, offset.x + mCellSize.x - 5, yp, ColorI(128, 128, 128)); GFX->getDrawUtil()->drawLine(offset.x + 5, yp, offset.x + mCellSize.x - 5, yp, ColorI(128, 128, 128));
@ -214,8 +214,8 @@ void GuiPopupMenuTextListCtrl::onMouseUp(const GuiEvent &event)
if (item) if (item)
{ {
if (item->enabled) if (item->mEnabled)
dAtob(Con::executef(mPopup, "onSelectItem", Con::getIntArg(getSelectedCell().y), item->text.isNotEmpty() ? item->text : "")); dAtob(Con::executef(mPopup, "onSelectItem", Con::getIntArg(getSelectedCell().y), item->mText.isNotEmpty() ? item->mText : ""));
} }
} }
@ -247,9 +247,9 @@ void GuiPopupMenuTextListCtrl::onCellHighlighted(Point2I cell)
{ {
MenuItem *list = &mPopup->mMenuItems[selectionIndex]; MenuItem *list = &mPopup->mMenuItems[selectionIndex];
if (list->isSubmenu && list->subMenu != nullptr) if (list->mIsSubmenu && list->mSubMenu != nullptr)
{ {
list->subMenu->showPopup(getRoot(), getPosition().x + mCellSize.x, getPosition().y + (selectionIndex * mCellSize.y)); list->mSubMenu->showPopup(getRoot(), getPosition().x + mCellSize.x, getPosition().y + (selectionIndex * mCellSize.y));
} }
} }
} }

View file

@ -46,14 +46,20 @@ public:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
PopupMenu::PopupMenu() PopupMenu::PopupMenu()
{ {
bitmapIndex = -1; mMenuItems = NULL;
mMenuBarCtrl = nullptr;
barTitle = StringTable->EmptyString(); mBarTitle = StringTable->EmptyString();
mBounds = RectI(0, 0, 64, 64);
mVisible = true;
mMenuBarCtrl = nullptr; mBitmapIndex = -1;
mTextList = nullptr; mDrawBitmapOnly = false;
mDrawBorder = false;
isSubmenu = false; mTextList = nullptr;
mIsSubmenu = false;
} }
PopupMenu::~PopupMenu() PopupMenu::~PopupMenu()
@ -76,7 +82,7 @@ void PopupMenu::initPersistFields()
{ {
Parent::initPersistFields(); Parent::initPersistFields();
addField("barTitle", TypeCaseString, Offset(barTitle, PopupMenu), ""); addField("barTitle", TypeCaseString, Offset(mBarTitle, PopupMenu), "");
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -134,28 +140,28 @@ S32 PopupMenu::insertItem(S32 pos, const char *title, const char* accelerator, c
String titleString = title; String titleString = title;
MenuItem newItem; MenuItem newItem;
newItem.id = pos; newItem.mID = pos;
newItem.text = titleString; newItem.mText = titleString;
newItem.cmd = cmd; newItem.mCMD = cmd;
if (titleString.isEmpty() || titleString == String("-")) if (titleString.isEmpty() || titleString == String("-"))
newItem.isSpacer = true; newItem.mIsSpacer = true;
else else
newItem.isSpacer = false; newItem.mIsSpacer = false;
if (accelerator[0]) if (accelerator[0])
newItem.accelerator = dStrdup(accelerator); newItem.mAccelerator = dStrdup(accelerator);
else else
newItem.accelerator = NULL; newItem.mAccelerator = NULL;
newItem.visible = true; newItem.mVisible = true;
newItem.isChecked = false; newItem.mIsChecked = false;
newItem.acceleratorIndex = 0; newItem.mAcceleratorIndex = 0;
newItem.enabled = !newItem.isSpacer; newItem.mEnabled = !newItem.mIsSpacer;
newItem.isSubmenu = false; newItem.mIsSubmenu = false;
newItem.subMenu = nullptr; newItem.mSubMenu = nullptr;
newItem.subMenuParentMenu = nullptr; newItem.mSubMenuParentMenu = nullptr;
mMenuItems.push_back(newItem); mMenuItems.push_back(newItem);
@ -166,11 +172,11 @@ S32 PopupMenu::insertSubMenu(S32 pos, const char *title, PopupMenu *submenu)
{ {
S32 itemPos = insertItem(pos, title, "", ""); S32 itemPos = insertItem(pos, title, "", "");
mMenuItems[itemPos].isSubmenu = true; mMenuItems[itemPos].mIsSubmenu = true;
mMenuItems[itemPos].subMenu = submenu; mMenuItems[itemPos].mSubMenu = submenu;
mMenuItems[itemPos].subMenuParentMenu = this; mMenuItems[itemPos].mSubMenuParentMenu = this;
submenu->isSubmenu = true; submenu->mIsSubmenu = true;
return itemPos; return itemPos;
} }
@ -181,15 +187,15 @@ bool PopupMenu::setItem(S32 pos, const char *title, const char* accelerator, con
for (U32 i = 0; i < mMenuItems.size(); i++) for (U32 i = 0; i < mMenuItems.size(); i++)
{ {
if (mMenuItems[i].text == titleString) if (mMenuItems[i].mText == titleString)
{ {
mMenuItems[i].id = pos; mMenuItems[i].mID = pos;
mMenuItems[i].cmd = cmd; mMenuItems[i].mCMD = cmd;
if (accelerator && accelerator[0]) if (accelerator && accelerator[0])
mMenuItems[i].accelerator = dStrdup(accelerator); mMenuItems[i].mAccelerator = dStrdup(accelerator);
else else
mMenuItems[i].accelerator = NULL; mMenuItems[i].mAccelerator = NULL;
return true; return true;
} }
} }
@ -211,7 +217,7 @@ void PopupMenu::enableItem(S32 pos, bool enable)
if (mMenuItems.size() < pos || pos < 0) if (mMenuItems.size() < pos || pos < 0)
return; return;
mMenuItems[pos].enabled = enable; mMenuItems[pos].mEnabled = enable;
} }
void PopupMenu::checkItem(S32 pos, bool checked) void PopupMenu::checkItem(S32 pos, bool checked)
@ -219,24 +225,24 @@ void PopupMenu::checkItem(S32 pos, bool checked)
if (mMenuItems.size() < pos || pos < 0) if (mMenuItems.size() < pos || pos < 0)
return; return;
if (checked && mMenuItems[pos].checkGroup != -1) if (checked && mMenuItems[pos].mCheckGroup != -1)
{ {
// first, uncheck everything in the group: // first, uncheck everything in the group:
for (U32 i = 0; i < mMenuItems.size(); i++) for (U32 i = 0; i < mMenuItems.size(); i++)
if (mMenuItems[i].checkGroup == mMenuItems[pos].checkGroup && mMenuItems[i].isChecked) if (mMenuItems[i].mCheckGroup == mMenuItems[pos].mCheckGroup && mMenuItems[i].mIsChecked)
mMenuItems[i].isChecked = false; mMenuItems[i].mIsChecked = false;
} }
mMenuItems[pos].isChecked; mMenuItems[pos].mIsChecked = checked;
} }
void PopupMenu::checkRadioItem(S32 firstPos, S32 lastPos, S32 checkPos) void PopupMenu::checkRadioItem(S32 firstPos, S32 lastPos, S32 checkPos)
{ {
for (U32 i = 0; i < mMenuItems.size(); i++) for (U32 i = 0; i < mMenuItems.size(); i++)
{ {
if (mMenuItems[i].id >= firstPos && mMenuItems[i].id <= lastPos) if (mMenuItems[i].mID >= firstPos && mMenuItems[i].mID <= lastPos)
{ {
mMenuItems[i].isChecked = false; mMenuItems[i].mIsChecked = false;
} }
} }
} }
@ -246,7 +252,7 @@ bool PopupMenu::isItemChecked(S32 pos)
if (mMenuItems.size() < pos || pos < 0) if (mMenuItems.size() < pos || pos < 0)
return false; return false;
return mMenuItems[pos].isChecked; return mMenuItems[pos].mIsChecked;
} }
U32 PopupMenu::getItemCount() U32 PopupMenu::getItemCount()
@ -305,7 +311,7 @@ void PopupMenu::showPopup(GuiCanvas *owner, S32 x /* = -1 */, S32 y /* = -1 */)
if (!backgroundCtrl || !mTextList) if (!backgroundCtrl || !mTextList)
return; return;
if (!isSubmenu) if (!mIsSubmenu)
{ {
//if we're a 'parent' menu, then tell the background to clear out all existing other popups //if we're a 'parent' menu, then tell the background to clear out all existing other popups
@ -354,11 +360,11 @@ void PopupMenu::showPopup(GuiCanvas *owner, S32 x /* = -1 */, S32 y /* = -1 */)
for (U32 i = 0; i < mMenuItems.size(); i++) for (U32 i = 0; i < mMenuItems.size(); i++)
{ {
if (!mMenuItems[i].visible) if (!mMenuItems[i].mVisible)
continue; continue;
S32 iTextWidth = font->getStrWidth(mMenuItems[i].text.c_str()); S32 iTextWidth = font->getStrWidth(mMenuItems[i].mText.c_str());
S32 iAcceleratorWidth = mMenuItems[i].accelerator ? font->getStrWidth(mMenuItems[i].accelerator) : 0; S32 iAcceleratorWidth = mMenuItems[i].mAccelerator ? font->getStrWidth(mMenuItems[i].mAccelerator) : 0;
if (iTextWidth > textWidth) if (iTextWidth > textWidth)
textWidth = iTextWidth; textWidth = iTextWidth;
@ -378,7 +384,7 @@ void PopupMenu::showPopup(GuiCanvas *owner, S32 x /* = -1 */, S32 y /* = -1 */)
for (U32 i = 0; i < mMenuItems.size(); i++) for (U32 i = 0; i < mMenuItems.size(); i++)
{ {
if (!mMenuItems[i].visible) if (!mMenuItems[i].mVisible)
continue; continue;
char buf[512]; char buf[512];
@ -386,17 +392,17 @@ void PopupMenu::showPopup(GuiCanvas *owner, S32 x /* = -1 */, S32 y /* = -1 */)
// If this menu item is a submenu, then set the isSubmenu to 2 to indicate // If this menu item is a submenu, then set the isSubmenu to 2 to indicate
// an arrow should be drawn. Otherwise set the isSubmenu normally. // an arrow should be drawn. Otherwise set the isSubmenu normally.
char isSubmenu = 1; char isSubmenu = 1;
if (mMenuItems[i].isSubmenu) if (mMenuItems[i].mIsSubmenu)
isSubmenu = 2; isSubmenu = 2;
char bitmapIndex = 1; char bitmapIndex = 1;
if (mMenuItems[i].bitmapIndex >= 0 && (mMenuItems[i].bitmapIndex * 3 <= profile->mBitmapArrayRects.size())) if (mMenuItems[i].mBitmapIndex >= 0 && (mMenuItems[i].mBitmapIndex * 3 <= profile->mBitmapArrayRects.size()))
bitmapIndex = mMenuItems[i].bitmapIndex + 2; bitmapIndex = mMenuItems[i].mBitmapIndex + 2;
dSprintf(buf, sizeof(buf), "%c%c\t%s\t%s", bitmapIndex, isSubmenu, mMenuItems[i].text.c_str(), mMenuItems[i].accelerator ? mMenuItems[i].accelerator : ""); dSprintf(buf, sizeof(buf), "%c%c\t%s\t%s", bitmapIndex, isSubmenu, mMenuItems[i].mText.c_str(), mMenuItems[i].mAccelerator ? mMenuItems[i].mAccelerator : "");
mTextList->addEntry(entryCount, buf); mTextList->addEntry(entryCount, buf);
if (!mMenuItems[i].enabled) if (!mMenuItems[i].mEnabled)
mTextList->setEntryActive(entryCount, false); mTextList->setEntryActive(entryCount, false);
entryCount++; entryCount++;
@ -437,8 +443,8 @@ void PopupMenu::hidePopupSubmenus()
{ {
for (U32 i = 0; i < mMenuItems.size(); i++) for (U32 i = 0; i < mMenuItems.size(); i++)
{ {
if (mMenuItems[i].subMenu != nullptr) if (mMenuItems[i].mSubMenu != nullptr)
mMenuItems[i].subMenu->hidePopup(); mMenuItems[i].mSubMenu->hidePopup();
} }
} }

View file

@ -34,27 +34,27 @@ class GuiPopupMenuBackgroundCtrl;
struct MenuItem // an individual item in a pull-down menu struct MenuItem // an individual item in a pull-down menu
{ {
String text; // the text of the menu item String mText; // the text of the menu item
U32 id; // a script-assigned identifier U32 mID; // a script-assigned identifier
char *accelerator; // the keyboard accelerator shortcut for the menu item char *mAccelerator; // the keyboard accelerator shortcut for the menu item
U32 acceleratorIndex; // index of this accelerator U32 mAcceleratorIndex; // index of this accelerator
bool enabled; // true if the menu item is selectable bool mEnabled; // true if the menu item is selectable
bool visible; // true if the menu item is visible bool mVisible; // true if the menu item is visible
S32 bitmapIndex; // index of the bitmap in the bitmap array S32 mBitmapIndex; // index of the bitmap in the bitmap array
S32 checkGroup; // the group index of the item visa vi check marks - S32 mCheckGroup; // the group index of the item visa vi check marks -
// only one item in the group can be checked. // only one item in the group can be checked.
bool isSubmenu; // This menu item has a submenu that will be displayed bool mIsSubmenu; // This menu item has a submenu that will be displayed
bool isChecked; bool mIsChecked;
bool isSpacer; bool mIsSpacer;
bool isMenubarEntry; bool mIsMenubarEntry;
PopupMenu* subMenuParentMenu; // For a submenu, this is the parent menu PopupMenu* mSubMenuParentMenu; // For a submenu, this is the parent menu
PopupMenu* subMenu; PopupMenu* mSubMenu;
String cmd; String mCMD;
}; };
// PopupMenu represents a menu. // PopupMenu represents a menu.
@ -72,16 +72,16 @@ protected:
GuiMenuBar* mMenuBarCtrl; GuiMenuBar* mMenuBarCtrl;
StringTableEntry barTitle; StringTableEntry mBarTitle;
RectI bounds; RectI mBounds;
bool visible; bool mVisible;
S32 bitmapIndex; // Index of the bitmap in the bitmap array (-1 = no bitmap) S32 mBitmapIndex; // Index of the bitmap in the bitmap array (-1 = no bitmap)
bool drawBitmapOnly; // Draw only the bitmap and not the text bool mDrawBitmapOnly; // Draw only the bitmap and not the text
bool drawBorder; // Should a border be drawn around this menu (usually if we only have a bitmap, we don't want a border) bool mDrawBorder; // Should a border be drawn around this menu (usually if we only have a bitmap, we don't want a border)
bool isSubmenu; bool mIsSubmenu;
//This is the gui control that renders our popup //This is the gui control that renders our popup
GuiPopupMenuTextListCtrl *mTextList; GuiPopupMenuTextListCtrl *mTextList;
@ -175,8 +175,8 @@ public:
virtual bool onMessageReceived(StringTableEntry queue, const char* event, const char* data ); virtual bool onMessageReceived(StringTableEntry queue, const char* event, const char* data );
virtual bool onMessageObjectReceived(StringTableEntry queue, Message *msg ); virtual bool onMessageObjectReceived(StringTableEntry queue, Message *msg );
bool isVisible() { return visible; } bool isVisible() { return mVisible; }
void setVisible(bool isVis) { visible = isVis; } void setVisible(bool isVis) { mVisible = isVis; }
GuiMenuBar* getMenuBarCtrl(); GuiMenuBar* getMenuBarCtrl();
}; };