Beispiel #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;
}
Beispiel #2
0
 GWEN_CONTROL_INLINE(PageControl, GUnit)
 {
     Gwen::Controls::PageControl* control = new Gwen::Controls::PageControl(this);
     control->SetSize(500, 300);
     control->SetPageCount(5);
     control->onPageChanged.Add(this, &ThisClass::OnPageChanged);
     control->onFinish.Add(this, &ThisClass::OnFinish);
     // Page 0
     {
         Gwen::Controls::Button* pButton = new Gwen::Controls::Button(control->GetPage(0));
         pButton->Dock(Pos::Fill);
         pButton->SetText("This button is fill docked on page 0");
     }
     // Page 1
     {
         Gwen::Controls::Button* pButton = new Gwen::Controls::Button(control->GetPage(1));
         pButton->Dock(Pos::Top);
         pButton->SetText("This button is top docked on page 1");
     }
     // Page 2
     {
         Gwen::Controls::Button* pButton = new Gwen::Controls::Button(control->GetPage(2));
         pButton->SetSize(400, 1000);
         pButton->SetPos(50, 50);
         pButton->SetText("This button is long to test scrolling (page 2)");
     }
 }
void GwenParameterInterface::registerButtonParameter(ButtonParams& params)
{
	
	Gwen::Controls::Button* button = new Gwen::Controls::Button(m_gwenInternalData->m_demoPage->GetPage());
	MyButtonEventHandler* handler = new MyButtonEventHandler(params.m_callback,params.m_buttonId,params.m_userPointer);
	button->SetText(params.m_name);
	button->onPress.Add( handler, &MyButtonEventHandler::onButtonPress );

	m_paramInternalData->m_buttons.push_back(button);
	m_paramInternalData->m_buttonEventHandlers.push_back(handler);

	button->SetPos( 5, m_gwenInternalData->m_curYposition );
	button->SetWidth(220);
	
	m_gwenInternalData->m_curYposition+=22;

}
void	GwenUserInterface::registerToggleButton(int buttonId, const char* name)
{
	assert(m_data);
	assert(m_data->m_demoPage);

	Gwen::Controls::Button* but = new Gwen::Controls::Button(m_data->m_demoPage->GetPage());
	
	///some heuristic to find the button location
	int ypos = m_data->m_handlers.size()*20;
	but->SetPos(10, ypos );
	but->SetWidth( 100 );
	//but->SetBounds( 200, 30, 300, 200 );
	
	MyButtonHander* handler = new MyButtonHander(m_data, buttonId);
	m_data->m_handlers.push_back(handler);
	but->onToggle.Add(handler, &MyButtonHander::onButtonA);
	but->SetIsToggle(true);
	but->SetToggleState(false);
	but->SetText(name);

}