Added: Add lua function to have an icon at left of menu option

--HG--
branch : compatibility-develop
This commit is contained in:
ulukyn@gmail.com 2016-12-10 21:58:15 +01:00
parent 3d84a68df4
commit bd7b703f3a
2 changed files with 46 additions and 2 deletions

View file

@ -191,6 +191,7 @@ namespace NLGUI
int luaGetLineFromId(CLuaState &ls);
int luaIsSeparator(CLuaState &ls);
int luaAddLine(CLuaState &ls);
int luaAddIconLine(CLuaState &ls);
int luaAddLineAtIndex(CLuaState &ls);
int luaAddSeparator(CLuaState &ls);
int luaAddSeparatorAtIndex(CLuaState &ls);
@ -210,6 +211,7 @@ namespace NLGUI
REFLECT_LUA_METHOD("addSubMenu", luaAddSubMenu);
REFLECT_LUA_METHOD("isSeparator", luaIsSeparator);
REFLECT_LUA_METHOD("addLine", luaAddLine); // name, ah, ah_params, id
REFLECT_LUA_METHOD("addIconLine", luaAddIconLine); // name, ah, ah_params, id, texture
REFLECT_LUA_METHOD("addLineAtIndex", luaAddLineAtIndex); // index, name, ah, ah_params, id
REFLECT_LUA_METHOD("addSeparator", luaAddSeparator);
REFLECT_LUA_METHOD("addSeparatorAtIndex", luaAddSeparatorAtIndex);
@ -278,6 +280,7 @@ namespace NLGUI
*/
CGroupSubMenu *cloneMenu(CGroupSubMenu *appendToMenu, CGroupMenu *newFather, CInterfaceGroup *initGroup = NULL) const;
void initOptions(CInterfaceGroup *parent);
CViewBitmap *createIcon(CInterfaceElement *parentPos, const std::string &texture);
CViewBitmap *createCheckBox(bool checked);
CViewBitmap *createRightArrow(CInterfaceElement *parentPos, bool center);
};

View file

@ -381,6 +381,22 @@ namespace NLGUI
return true;
}
// ------------------------------------------------------------------------------------------------
CViewBitmap *CGroupSubMenu::createIcon(CInterfaceElement *parentPos, const string &texture)
{
// Add an icon to the line
CViewBitmap *pVB = new CViewBitmap(CViewBase::TCtorParam());
pVB->setSerializable( false );
pVB->setParent (this);
pVB->setParentPos (parentPos);
pVB->setParentPosRef (Hotspot_ML);
pVB->setPosRef (Hotspot_MR);
pVB->setTexture(texture);
pVB->setModulateGlobalColor(false);
pVB->setX (-2);
addView (pVB);
return pVB;
}
// ------------------------------------------------------------------------------------------------
CViewBitmap *CGroupSubMenu::createCheckBox(bool checked)
@ -1226,13 +1242,22 @@ namespace NLGUI
pV->setCheckBox(checkBox);
}
CViewBitmap *icon = NULL;
if (!texture.empty())
{
if (_GroupList->getNumChildren() == 1)
pV->setX(20);
icon = createIcon(pV, texture);
}
tmp.ViewText = pV;
tmp.Separator = NULL;
tmp.AHName = ah;
tmp.AHParams = params;
tmp.Cond = cond;
tmp.CheckBox = checkBox;
tmp.RightArrow = NULL;
tmp.RightArrow = icon;
if (id.empty())
tmp.Id = NLMISC::toString (_Lines.size());
else
@ -1772,7 +1797,23 @@ namespace NLGUI
addLine(arg1, ls.toString(2), ls.toString(3), ls.toString(4));
return 0;
}
// ------------------------------------------------------------------------------------------------
int CGroupSubMenu::luaAddIconLine(CLuaState &ls)
{
const char *funcName = "addIconLine";
CLuaIHM::checkArgCount(ls, funcName, 5);
CLuaIHM::checkArgTypeUCString(ls, funcName, 1);
CLuaIHM::checkArgType(ls, funcName, 2, LUA_TSTRING);
CLuaIHM::checkArgType(ls, funcName, 3, LUA_TSTRING);
CLuaIHM::checkArgType(ls, funcName, 4, LUA_TSTRING);
CLuaIHM::checkArgType(ls, funcName, 5, LUA_TSTRING);
ucstring arg1;
nlverify(CLuaIHM::getUCStringOnStack(ls, 1, arg1));
addLine(arg1, ls.toString(2), ls.toString(3), ls.toString(4), string(), ls.toString(5));
return 0;
}
// ------------------------------------------------------------------------------------------------
int CGroupSubMenu::luaAddLineAtIndex(CLuaState &ls)
{