Skip to content

Instantly share code, notes, and snippets.

@Flaze07
Created July 10, 2017 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Flaze07/7b10a4762523180a0169f49848d648cb to your computer and use it in GitHub Desktop.
Save Flaze07/7b10a4762523180a0169f49848d648cb to your computer and use it in GitHub Desktop.
#include <SFGUI/SFGUI.hpp>
#include <SFGUI/Widgets.hpp>
#include <SFML/Graphics.hpp>
int main()
{
enum class Option {none, rectangle, circle};
Option option = Option::none;
sf::RenderWindow win{sf::VideoMode{400, 400}, "sfgui test"};
sfg::SFGUI sfgui;
auto window = sfg::Window::Create();
window->SetTitle("select option");
auto box = sfg::Box::Create(sfg::Box::Orientation::VERTICAL);
auto option1 = sfg::RadioButton::Create("rectangle");
auto option2 = sfg::RadioButton::Create("circle", option1->GetGroup());
auto button_select = [&option1, &option2, &option] {
if (option1->IsActive())
{
option = Option::rectangle;
}
else if (option2->IsActive())
{
option = Option::circle;
}
};
option1->GetSignal(sfg::ToggleButton::OnToggle).Connect(button_select);
option2->GetSignal(sfg::ToggleButton::OnToggle).Connect(button_select);
box->Pack(option1);
box->Pack(option2);
window->Add(box);
sf::RectangleShape rect{sf::Vector2f{20, 20}};
rect.setOrigin(10, 10);
rect.setPosition(200, 200);
rect.setFillColor(sf::Color::White);
while (win.isOpen())
{
sf::Event event;
while (win.pollEvent(event))
{
window->HandleEvent(event);
if (event.type == sf::Event::Closed) win.close();
}
window->Update( 0.f );
win.clear();
win.resetGLStates();
sfgui.Display(win);
win.resetGLStates();
if (option == Option::rectangle)
{
win.draw(rect);
}
win.display();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment