Skip to content

Instantly share code, notes, and snippets.

@Groogy
Last active December 13, 2015 18:48
Show Gist options
  • Save Groogy/4957519 to your computer and use it in GitHub Desktop.
Save Groogy/4957519 to your computer and use it in GitHub Desktop.
void GUI::Button::activate()
{
GUI::Component::activate();
if(mIsToggle)
mSprite.setTexture(mPressedTexture)
if (mCallback)
mCallback();
if(!mIsToggle)
deactivate();
}
void GUI::Button::deactivate()
{
GUI::Component::deactivate();
if(mIsToggle)
mSprite.setTexture(mNormalTexture);
}
auto backButton = std::make_shared<GUI::Button>(fontHolder, textureHolder);
backButton->setText("Back");
backButton->setCallback([this]() {
mStateStack.pop();
});
auto moveLeftBindingLabel = std::make_shared<GUI::Label>(KeyBindings::getName(Player::MoveLeft), fontHolder);
auto moveLeftBindingButton = std::make_shared<GUI::Button>(fontHolder, textureHolder);
moveLeftBindingButton->setText("Move Left");
moveLeftBindingButton->setToggle(true);
moveLeftBindingButton->setEventCallback([moveLeftBindingLabel, moveLeftBindingButton](const sf::Event& event) {
if(event.type == sf::Event::KeyReleased)
{
Player::setBinding(event.key.code, Player::MoveLeft); // <--- Pseudo code
moveLeftBindingLabel.setText(KeyBindings::getName(Player::MoveLeft)); // <--- Pseudo code
moveLeftBindingButton.deactivate();
}
});
mGUIContainer.pack(backButton);
mGUIContainer.pack(moveLeftBindingLabel);
mGUIContainer.pack(moveLeftBindingButton);
// Without setEventCallback and manage it in the same state.
auto moveLeftBindingButton = std::make_shared<GUI::Button>(fontHolder, textureHolder);
moveLeftBindingButton->setText("Move Left");
moveLeftBindingButton->setToggle(true);
moveLeftBindingButton->setCallback([this]() {
mIsbindingKey = true;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment