//! Adds a button to the tool bar
	IGUIButton* CGUIToolBar::addButton(SINT32 id, const wchar_t* text, const wchar_t* tooltiptext,
		ITexture* img, ITexture* pressed, bool isPushButton,
		bool useAlphaChannel)
	{
		ButtonX += 3;

		rect<SINT32> rectangle(ButtonX, 2, ButtonX + 1, 3);
		if (img)
		{
			const dimension2du &size = img->getOriginalSize();
			rectangle.LowerRightCorner.x = rectangle.UpperLeftCorner.x + size.Width + 8;
			rectangle.LowerRightCorner.y = rectangle.UpperLeftCorner.y + size.Height + 6;
		}

		if (text)
		{
			IGUISkin* skin = Environment->getSkin();
			IGUIFont * font = skin->getFont(EGDF_BUTTON);
			if (font)
			{
				dimension2d<UINT32> dim = font->getDimension(text);
				if ((SINT32)dim.Width > rectangle.getWidth())
					rectangle.LowerRightCorner.x = rectangle.UpperLeftCorner.x + dim.Width + 8;
				if ((SINT32)dim.Height > rectangle.getHeight())
					rectangle.LowerRightCorner.y = rectangle.UpperLeftCorner.y + dim.Height + 6;
			}
		}

		ButtonX += rectangle.getWidth();

		IGUIButton* button = new CGUIButton(Environment, this, id, rectangle);
		button->drop();

		if (text)
			button->setText(text);

		if (tooltiptext)
			button->setToolTipText(tooltiptext);

		if (img)
			button->setImage(img);

		if (pressed)
			button->setPressedImage(pressed);

		if (isPushButton)
			button->setIsPushButton(isPushButton);

		if (useAlphaChannel)
			button->setUseAlphaChannel(useAlphaChannel);

		return button;
	}
Esempio n. 2
0
void Universe::ClientGUIInit()
{
	clientEventReceiver = new ClientEventReceiver();
	render->device->setEventReceiver((IEventReceiver*)clientEventReceiver);
	
	int btnsSize = 48;

	//Window toggle buttons
	/*
	IGUIButton* btn;
	btn = guienv->addButton(rect< s32 >(0, render->screenHeight - 32, 64, render->screenHeight), NULL, InventoryToggleButton, L"Inventory", NULL);
	btn->setIsPushButton(true);
	btn = guienv->addButton(rect< s32 >(64, render->screenHeight - 32, 64 + 64, render->screenHeight), NULL, SkillsToggleButton, L"Skills", NULL);
	btn->setIsPushButton(true);
	btn = guienv->addButton(rect< s32 >(64 + 64, render->screenHeight - 32, 64 + 64 + 64, render->screenHeight), NULL, QuestsToggleButton, L"Quests", NULL);
	btn->setIsPushButton(true);
	*/
	IGUIButton* btn;
	btn = guienv->addButton(rect< s32 >(0, render->screenHeight - btnsSize, btnsSize, render->screenHeight), NULL, InventoryToggleButton, NULL, L"Inventory");
	btn->setIsPushButton(true);
	btn->setUseAlphaChannel(true);
	btn->setImage(render->driver->getTexture("res/inventory_icon.png"));
	btn = guienv->addButton(rect< s32 >(btnsSize, render->screenHeight - btnsSize, btnsSize + btnsSize, render->screenHeight), NULL, SkillsToggleButton, NULL, L"Skills");
	btn->setIsPushButton(true);
	btn->setUseAlphaChannel(true);
	btn->setImage(render->driver->getTexture("res/skills_icon.png"));
	btn = guienv->addButton(rect< s32 >(btnsSize + btnsSize, render->screenHeight - btnsSize, btnsSize + btnsSize + btnsSize, render->screenHeight), NULL, QuestsToggleButton, NULL, L"Quests");
	btn->setIsPushButton(true);
	btn->setUseAlphaChannel(true);
	btn->setImage(render->driver->getTexture("res/quests_icon.png"));

	//Chat
	IGUIChatBox* cb = new IGUIChatBox(guienv, NULL, ChatBox, ChatEditBox, ChatInputEditBox, rect< s32 >(0, 128, 256, 128 + 256 + 24));
	guienv->getRootGUIElement()->addChild(cb);

	//Hotkey
	int slotsCount = 9;
	IGUIIconTable* tbl3 = new IGUIIconTable(guienv, NULL, HotkeyBar, rect< s32 >(320, render->screenHeight - btnsSize, 320 + slotsCount * btnsSize + (slotsCount - 1) * 2, render->screenHeight), slotsCount, 1);
	guienv->getRootGUIElement()->addChild(tbl3);
}