Example #1
0
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());
}
Example #2
0
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;
}