示例#1
0
AngelUIHandle UserInterface::AddButton(const String& label, Vec2i position, void (*callback)(), bool center, const String& font, Vec2i padding)
{
	Gwen::Controls::Button* button = new Gwen::Controls::Button(AngelCanvas);
	if (font != "")
	{
		button->SetFont(Gwen::Utility::StringToUnicode(font), 20, false);
	}
	button->SetText(label);
	button->SetPadding(Gwen::Padding(padding.X, padding.Y, padding.X, padding.Y));
	button->SizeToContents();
	if (center)
	{
		Gwen::Point size = button->GetSize();
		button->SetPos(position.X - (size.x / 2), position.Y - (size.y / 2));
	}
	else
	{
		button->SetPos(position.X, position.Y);
	}

	button->onPress.Add(&handler, &EventHandler::OnPress);
	handler.AddButtonCallback(button, callback);
	
	_elements.insert(button);
	
	return button;
}
示例#2
0
AngelUIHandle UserInterface::ShowChoiceBox(const String& choiceLabel, const StringList& labels, void (*callback)(int), const String& font, Vec2i padding, bool modal)
{
	Gwen::Controls::WindowControl* box = new Gwen::Controls::WindowControl(AngelCanvas);

	box->SetTitle(choiceLabel);

	Gwen::TextObject fontTextObject = Gwen::Utility::StringToUnicode(font);

	Vec2i maxSize;
	std::vector<Gwen::Controls::Button*> buttons;

	for	(unsigned int i=0; i < labels.size(); i++)
	{
		Gwen::Controls::Button* button = new Gwen::Controls::Button(box);
		buttons.push_back(button);
		if (font != "")
		{
			button->SetFont(fontTextObject, 20, false);
		}
		button->SetText(labels[i]);
		button->SetPadding(Gwen::Padding(padding.X, padding.Y, padding.X, padding.Y));
		button->SizeToContents();
		Gwen::Point size = button->GetSize();
		if (maxSize.X < size.x)
		{
			maxSize.X = size.x;
		}
		if (maxSize.Y < size.y)
		{
			maxSize.Y = size.y;
		}
		
		button->onPress.Add(&handler, &EventHandler::OnPress);
	}

	for (unsigned int i=0; i < buttons.size(); i++)
	{
		buttons[i]->SetPos(maxSize.X / 2 - (buttons[i]->GetSize().x / 2), i * (maxSize.Y + padding.Y));
	}

	box->SetSize(maxSize.X + (padding.X * 2), buttons.size() * (maxSize.Y + padding.Y) + (padding.Y * 3));
	box->SetPos((AngelCanvas->GetSize().x / 2) - (box->GetSize().x / 2), (AngelCanvas->GetSize().y / 2) - (box->GetSize().y / 2));

	if (modal)
	{
		box->MakeModal();
	}
	box->SetDeleteOnClose(true);
	box->SetClosable(false);

	handler.AddChoiceCallback(box, callback);

	_elements.insert(box);

	return box;
}