Beispiel #1
0
    TGUI_API std::shared_ptr<DataIO::Node> saveButton(Button::Ptr button)
    {
        auto node = saveWidget(button);

        if (!button->getText().isEmpty())
            SET_PROPERTY("Text", Serializer::serialize(button->getText()));

        SET_PROPERTY("TextSize", tgui::to_string(button->getTextSize()));
        return node;
    }
Beispiel #2
0
void Toolgrid::filter(const std::string& word)
{
    for(std::vector<Widget::List>::iterator sit=sorted_.begin();
        sit != sorted_.end(); ++sit)
    {
    for( Widget::List::iterator it=(*sit).begin();it!=(*sit).end();++it)
    {
        Button::Ptr b = Widget::as<Button>(*it);
        if(b->getLabel().substr(0, word.size()) == word)
            b->show();
        else
            b->hide();
    }
    }
}
Beispiel #3
0
    TGUI_API Widget::Ptr loadButton(std::shared_ptr<DataIO::Node> node, Widget::Ptr widget = nullptr)
    {
        Button::Ptr button;
        if (widget)
            button = std::static_pointer_cast<Button>(widget);
        else
            button = std::make_shared<Button>();

        loadWidget(node, button);
        if (node->propertyValuePairs["text"])
            button->setText(DESERIALIZE_STRING("text"));
        if (node->propertyValuePairs["textsize"])
            button->setTextSize(tgui::stoi(node->propertyValuePairs["textsize"]->value));

        return button;
    }
Beispiel #4
0
    void MessageBox::addButton(const sf::String& caption)
    {
        Button::Ptr button;
        if (!getTheme() || m_buttonClassName.empty())
            button = std::make_shared<Button>();
        else
            button = getTheme()->internalLoad(getPrimaryLoadingParameter(), m_buttonClassName);

        button->setTextSize(m_textSize);
        button->setText(caption);
        button->connect("Pressed", [=](){ m_callback.text = caption; sendSignal("ButtonPressed", caption); });

        add(button, "#TGUI_INTERNAL$MessageBoxButton$" + caption + "#");
        m_buttons.push_back(button);

        rearrange();
    }
Beispiel #5
0
    MessageBox::MessageBox(const MessageBox& messageBoxToCopy) :
        ChildWindow      {messageBoxToCopy},
        m_loadedThemeFile(messageBoxToCopy.m_loadedThemeFile), // Did not compile in VS2013 when using braces
        m_buttonClassName(messageBoxToCopy.m_buttonClassName), // Did not compile in VS2013 when using braces
        m_textSize       {messageBoxToCopy.m_textSize}
    {
        m_label = Label::copy(messageBoxToCopy.m_label);
        add(m_label, "#TGUI_INTERNAL$MessageBoxText#");

        for (auto it = messageBoxToCopy.m_buttons.begin(); it != messageBoxToCopy.m_buttons.end(); ++it)
        {
            Button::Ptr button = Button::copy(*it);
            button->disconnectAll();
            button->connect("Pressed", [=]() { m_callback.text = button->getText(); sendSignal("ButtonPressed", button->getText()); });

            m_buttons.push_back(button);
        }
    }
Beispiel #6
0
void Toolgrid::add(const std::string& label,
               boost::function<void(const std::string&)> callback)
{
    std::string copy = label;
    while(copy.size() > kMaxCharacters)
    {
        copy.erase(copy.begin()+copy.size()/2);
    }
    if(copy.size() != label.size())
        copy.insert(copy.begin()+copy.size()/2, '*');
    Button::Ptr b = addChild<Button>(
                boost::make_shared<Button>(sf::Vector2f(kButtonSize, 20), copy, callback, label));
    b->setPosition(sf::Vector2f(100+offset_x_*kXOffsetSize, 30 + offset_y_*kYOffsetSize));
    offset_x_++;
    if(offset_x_ >= column_)
    {
        offset_x_ = 0;
        offset_y_++;
    }
}
Beispiel #7
0
	void Message::MakeChoiceMessage() {
		Box::Ptr box = Box::Create(Box::Orientation::VERTICAL, 0);
		box->Pack(Label::Create(Message_));
		Box::Ptr buttonBox = Box::Create(Box::Orientation::HORIZONTAL, 0);
		{
			Box::Ptr spacer = Box::Create();
			spacer->SetRequisition(sf::Vector2f(10, 10));
			buttonBox->Pack(spacer, true, true);
		}
		Button::Ptr abort = Button::Create("Abort");
		abort->SetRequisition(sf::Vector2f(50, 10));
		abort->GetSignal(Button::OnLeftClick).Connect(std::bind(&Message::Abort, this));
		buttonBox->Pack(abort, false, false);
		Button::Ptr confirm = Button::Create("Confirm");
		confirm->SetRequisition(sf::Vector2f(50, 10));
		confirm->GetSignal(Button::OnLeftClick).Connect(std::bind(&Message::Confirm, this));
		buttonBox->Pack(confirm, false, false);
		{
			Box::Ptr spacer = Box::Create();
			spacer->SetRequisition(sf::Vector2f(10, 10));
			buttonBox->Pack(spacer, true, true);
		}
		box->Pack(buttonBox);
		Win->Add(box);
		Module::Get()->QueueEvent(Event("SCREEN_ADD_WINDOW", Win));
	}
Beispiel #8
0
	void Message::MakeOkMessage() {
		Box::Ptr box = Box::Create(Box::Orientation::VERTICAL, 0);
		box->Pack(Label::Create(Message_));
		Box::Ptr buttonBox = Box::Create(Box::Orientation::HORIZONTAL, 0);
		{
			Box::Ptr spacer = Box::Create();
			spacer->SetRequisition(sf::Vector2f(10, 10));
			buttonBox->Pack(spacer, true, true);
		}
		Button::Ptr ok = Button::Create("OK");
		ok->GetSignal(Button::OnLeftClick).Connect(std::bind(&Message::Ok, this));
		ok->SetRequisition(sf::Vector2f(50, 10));
		buttonBox->Pack(ok, false, false);
		box->Pack(buttonBox, false, false);
		{
			Box::Ptr spacer = Box::Create();
			spacer->SetRequisition(sf::Vector2f(10, 10));
			buttonBox->Pack(spacer, true, true);
		}

		Win->Add(box);
		Module::Get()->QueueEvent(Event("SCREEN_ADD_WINDOW", Win));
	}
Beispiel #9
0
void Control::InitWindow( const glm::ivec2 Size )
{
	Win = Window::Create();
	Win->SetStyle( 0 );
	Win->SetRequisition( sf::Vector2f( Size.x, Size.y ) );

	// main box, vertical
	Box::Ptr box( Box::Create( Box::Orientation::VERTICAL, 5.0f ) );
	Box::Ptr buttonBox( Box::Create( Box::Orientation::HORIZONTAL, 5.0f ) );
	buttonBox->SetRequisition({ (float)Size.x, 0});

		BtnMnMnWin =  ToggleButton::Create(  "MainMenu [Esc]" );
		BtnIPanWin =  ToggleButton::Create( "InfoPanel [F1]" );
		BtnSimPause = ToggleButton::Create(     "Pause [F2]" );
		BtnDbgWin =   ToggleButton::Create(   "Console [F3]" );
		BtnGraBoWin = ToggleButton::Create( "GraphBook [F4]" );
		BtnSimReset =       Button::Create(     "Reset [F5]" );
		BtnSimSingleFrame = Button::Create(     ">|" );
		BtnSimFrames = Button::Create(     ">>|" );
		SclTickSlider = sfg::Scale::Create();

		Box::Ptr boxTickSlider = Box::Create( Box::Orientation::HORIZONTAL, 5.0f );
		boxTickSlider->SetRequisition({ 100, 30 });
		SclTickSlider->SetRequisition({ 100, 20 });
		SclTickSlider->SetIncrements(1,500);
		SclTickSlider->SetValue(0);
		SclTickSlider->Show(Engine::getCfg()->get<bool>("sim.paused"));
		SclTickSlider->GetSignal(sfg::Scale::OnMouseLeftRelease).Connect( std::bind( &Control::TickSliderReleased, this) );
		SclTickSlider->GetSignal(sfg::Scale::OnMouseMove).Connect( std::bind( &Control::TickSliderLabelUpdate, this) );
		TickScaleDisplay = Entry::Create( "0 / 0" );
		TickScaleDisplay->SetRequisition({ 100, 0 });
		TickScaleDisplay->SetState( Widget::State::INSENSITIVE );

		boxTickSlider->Pack( SclTickSlider, true, true );
		boxTickSlider->Pack( TickScaleDisplay, false, false );

		Box::Ptr framesframe( Box::Create( Box::Orientation::HORIZONTAL, 0 ) );
			Framesdisplay = Entry::Create();
			Framesdisplay->SetRequisition( { 60, 0 } );
			//Framesdisplay->SetState( Widget::State::INSENSITIVE );
			Framesdisplay->SetText( boost::lexical_cast<std::string>( Frames ) );
			textchangeavoidrecursive = false;
			Framesdisplay->GetSignal( Entry::OnTextChanged ).Connect( std::bind( &Control::EntryTextChange , this ));
			Framesdisplay->GetSignal( Entry::OnGainFocus ).Connect( std::bind( &Control::EntryGainFocus , this ));
			Framesdisplay->GetSignal( Entry::OnLostFocus ).Connect( std::bind( &Control::EntryLostFocus , this ));
			Button::Ptr down = Button::Create( "<" );
			Button::Ptr up   = Button::Create( ">" );
				down->GetSignal( Button::OnLeftClick ).Connect( std::bind( &Control::BtnFramesDownClick, this ));
				down->GetSignal( Button::OnLeftClick ).Connect( std::bind( &Screen::OnHandledEvent, Screen::get() ));
				up->GetSignal(   Button::OnLeftClick ).Connect( std::bind( &Control::BtnFramesUpClick, this ));
				up->GetSignal(   Button::OnLeftClick ).Connect( std::bind( &Screen::OnHandledEvent, Screen::get() ));

			framesframe->Pack( down, false, false );
			framesframe->Pack( Framesdisplay, false, false );
			framesframe->Pack( up, false, false );

		//init the first look of the buttons BEFORE they are connected with their actions.
		BtnDbgWin->SetActive( true );
		BtnIPanWin->SetActive( true );
		BtnSimPause->SetActive( true );

		BtnDbgWin->GetSignal(   ToggleButton::OnToggle ).Connect( std::bind( &Control::BtnDbgWinClick, this ));
		BtnDbgWin->GetSignal(   ToggleButton::OnToggle ).Connect( std::bind( &Screen::OnHandledEvent, Screen::get() ));
		BtnIPanWin->GetSignal(  ToggleButton::OnToggle ).Connect( std::bind( &Control::BtnIPanWinClick, this ));
		BtnIPanWin->GetSignal(  ToggleButton::OnToggle ).Connect( std::bind( &Screen::OnHandledEvent, Screen::get() ));
		BtnMnMnWin->GetSignal(  ToggleButton::OnToggle ).Connect( std::bind( &Control::BtnMnMnWinClick, this ));
		BtnMnMnWin->GetSignal(  ToggleButton::OnToggle ).Connect( std::bind( &Screen::OnHandledEvent, Screen::get() ));
		BtnGraBoWin->GetSignal( ToggleButton::OnToggle ).Connect( std::bind( &Control::BtnGraBoWinClick, this ));
		BtnGraBoWin->GetSignal( ToggleButton::OnToggle ).Connect( std::bind( &Screen::OnHandledEvent, Screen::get() ));
			simPauseConnectionSerial =
		BtnSimPause->GetSignal( ToggleButton::OnToggle ).Connect( std::bind( &Control::BtnSimPauseClick, this ));
		BtnSimPause->GetSignal( ToggleButton::OnToggle ).Connect( std::bind( &Screen::OnHandledEvent, Screen::get() ));
		BtnSimReset->GetSignal( Button::OnLeftClick    ).Connect( std::bind( &Control::BtnSimResetClick, this ));
		BtnSimReset->GetSignal( Button::OnLeftClick    ).Connect( std::bind( &Screen::OnHandledEvent, Screen::get() ));
		BtnSimSingleFrame->GetSignal( Button::OnLeftClick    ).Connect( std::bind( &Control::BtnSimSingleFrameClick, this ));
		BtnSimSingleFrame->GetSignal( Button::OnLeftClick    ).Connect( std::bind( &Screen::OnHandledEvent, Screen::get() ));
		BtnSimFrames->GetSignal( Button::OnLeftClick    ).Connect( std::bind( &Control::BtnSimFramesClick, this ));
		BtnSimFrames->GetSignal( Button::OnLeftClick    ).Connect( std::bind( &Screen::OnHandledEvent, Screen::get() ));

		buttonBox->Pack( BtnMnMnWin,  false, false );
		buttonBox->Pack( BtnIPanWin,  false, false );
		buttonBox->Pack( BtnSimPause, false, false );
		buttonBox->Pack( BtnDbgWin,   false, false );
		buttonBox->Pack( BtnGraBoWin, false, false );
		buttonBox->Pack( BtnSimReset, false, false );
		buttonBox->Pack( framesframe, false, false );
		buttonBox->Pack( BtnSimSingleFrame, false, false );
		buttonBox->Pack( BtnSimFrames, false, false );
		box->Pack( boxTickSlider, true, true );
		box->Pack( buttonBox, false, false );

	Win->Add( box );
	Win->SetTitle( "Control" );
	updatePosition();

	Module::Get()->QueueEvent( Event( "SCREEN_ADD_WINDOW", Win ) );
}