本文整理汇总了C++中MenuItem::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ MenuItem::addChild方法的具体用法?C++ MenuItem::addChild怎么用?C++ MenuItem::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MenuItem
的用法示例。
在下文中一共展示了MenuItem::addChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createMenuItemAt
void MapAreaLayer::createMenuItemAt(int index) {
MenuItem* squareMenuItem =
MenuItemImage::create("square.png",
"square.png",
CC_CALLBACK_1(MapAreaLayer::mapAreaMenuItemCallback, this));
squareMenuItem->setPosition(Vec2((30 + 60) * (index % 3 + 1) + 60 * (index % 3),
25 + (15 + 60) * (index / 3 + 1) + 60 * (index / 3)));
mMenu->addChild(squareMenuItem);
MapArea* area = MapManager::getInstance()->areaAt(mSize, index);
for(int i = 0 ; i < 3 ; i++) {
float x = 34 + 23 * i + 3;
string fileName = (area->getStars() > i) ? "stary.png" : "starb.png";
Sprite* starSprite = Sprite::create(fileName);
starSprite->setPosition(Vec2(x, 5));
squareMenuItem->addChild(starSprite);
}
string numchar = area->getCharacterStr();
Label* charLabel =
Label::createWithSystemFont(numchar + "\nCharacter",
"Arial",
17);
charLabel->setAlignment(TextHAlignment::CENTER);
charLabel->setPosition(Vec2(60, 35));
charLabel->setColor(Color3B(10, 11, 255));
squareMenuItem->addChild(charLabel);
Label* dotsLabel =
Label::createWithSystemFont("..............",
"Arial",
16);
dotsLabel->setAlignment(TextHAlignment::CENTER);
dotsLabel->setPosition(Vec2(60, 70));
dotsLabel->setColor(Color3B(10, 11, 255));
squareMenuItem->addChild(dotsLabel);
int time = area->getTime();
int click = area->getClick();
string inforStr = "Play now!";
if(time > 3 && click >= area->getCharacter()) {
inforStr = area->getTimeStr() + "s & "
+ area->getCharacterStr() + " click";
}
Label* infoLabel =
Label::createWithSystemFont(inforStr,
"Arial",
15);
infoLabel->setAlignment(TextHAlignment::CENTER);
infoLabel->setPosition(Vec2(60, 80));
infoLabel->setColor(Color3B(10, 11, 255));
squareMenuItem->addChild(infoLabel);
squareMenuItem->setTag(area->getCharacter());
}
示例2: add
GtkWidget* MenuManager::add(const std::string& insertPath,
const std::string& name,
eMenuItemType type,
const std::string& caption,
const std::string& icon,
const std::string& eventName)
{
MenuItem* found = _root->find(insertPath);
if (found != NULL) {
// Allocate a new MenuItem
MenuItem* newItem = new MenuItem(found);
newItem->setName(name);
newItem->setCaption(caption);
newItem->setType(type);
newItem->setIcon(icon);
newItem->setEvent(eventName);
// Cast the parent onto a GtkWidget* (a menu item)
GtkWidget* parentItem = *found;
// Retrieve the submenu widget from the item
GtkWidget* parent = gtk_menu_item_get_submenu(GTK_MENU_ITEM(parentItem));
//GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(_menu));
gtk_menu_shell_append(GTK_MENU_SHELL(parent), *newItem);
// Add the child to the <found> parent, AFTER its GtkWidget* operator
// was invoked, otherwise the parent tries to instantiate it before it's actually
// added.
found->addChild(newItem);
return *newItem;
}
else {
globalErrorStream() << "MenuItem: " << insertPath << " already exists.\n";
}
return NULL;
}