예제 #1
0
FormPanel::FormPanel(tgui::Gui &gui, const sf::Vector2f &size, const sf::Vector2f &pos) {

    m_formTabs = std::make_shared<tgui::Tab>();
    m_formTabs->setPosition(tgui::bindWidth(gui) * 0.2f, tgui::bindHeight(gui) * 0.025f);
    m_formTabs->setSize(tgui::bindWidth(gui) * 0.6f, tgui::bindHeight(gui) * 0.05f);

    m_panel = std::make_shared<tgui::Panel>();
    m_panel->setBackgroundColor(sf::Color(155, 155, 155, 255));
    m_panel->setSize(tgui::bindWidth(gui) * 0.6f, tgui::bindHeight(gui) * (1.f - 0.075f));
    m_panel->setPosition(tgui::bindWidth(gui) * 0.2f, tgui::bindHeight(gui) * 0.075f);

    gui.add(m_formTabs);
    gui.add(m_panel);

    m_formTabs->connect("TabSelected", [&](sf::String val) {

        if (m_app_forms) {

            for (auto &form : *m_app_forms) {
                if (form->getName() == val) {
                    m_activeForm = form;
                }
            }
        }
    });

}
예제 #2
0
파일: TestXPF.cpp 프로젝트: wpbest/XPF
void loadWidgets(tgui::Gui& gui)
{
	// Load the theme for the edit boxes and button
	tgui::Theme::Ptr theme = std::make_shared<tgui::Theme>("../../widgets/Black.txt");

	// Get a bound version of the window size
	// Passing this to setPosition or setSize will make the widget automatically update when the view of the gui changes
	auto windowWidth = tgui::bindWidth(gui);
	auto windowHeight = tgui::bindHeight(gui);

	// Create the background image (picture is of type tgui::Picture::Ptr or std::shared_widget<Picture>)
	tgui::Picture::Ptr picture = std::make_shared<tgui::Picture>("../xubuntu_bg_aluminium.jpg");
	picture->setSize(tgui::bindMax(800, windowWidth), tgui::bindMax(600, windowHeight));
	gui.add(picture);

	// Create the username edit box
	tgui::EditBox::Ptr editBoxUsername = theme->load("EditBox");
	editBoxUsername->setSize(windowWidth * 2 / 3, windowHeight / 8);
	editBoxUsername->setPosition(windowWidth / 6, windowHeight / 6);
	editBoxUsername->setDefaultText("Username");
	gui.add(editBoxUsername, "Username");

	// Create the password edit box (we will copy the previously created edit box)
	tgui::EditBox::Ptr editBoxPassword = tgui::EditBox::copy(editBoxUsername);
	editBoxPassword->setPosition(windowWidth / 6, windowHeight * 5 / 12);
	editBoxPassword->setPasswordCharacter('*');
	editBoxPassword->setDefaultText("Password");
	gui.add(editBoxPassword, "Password");

	// Create the login button
	tgui::Button::Ptr button = theme->load("Button");
	button->setSize(windowWidth / 2, windowHeight / 6);
	button->setPosition(windowWidth / 4, windowHeight * 7 / 10);
	button->setText("Login");
	gui.add(button);

	// Call the login function when the button is pressed
	button->connect("pressed", login, editBoxUsername, editBoxPassword);
}
void setup(sf::RenderWindow& s, sf::Event& e, sf::Text& t, sf::Font& tf, sf::Text& v, tgui::ListBox::Ptr& res, tgui::ListBox::Ptr& mode, tgui::EditBox::Ptr& c1, tgui::EditBox::Ptr& c2, tgui::Button::Ptr& b, tgui::Gui& sg)
{
	tf.loadFromFile("sansation.ttf");

	//WINDOW
	s.setFramerateLimit(10);

	//TITLE
	t.setFont(tf);
	t.setPosition(-5, 0);
	t.setStyle(sf::Text::Underlined);
	t.setString(" GRAVITY SIMULATOR ");
	t.setCharacterSize(30);

	//VERSIONTEXT
	v.setFont(tf);
	v.setColor(sf::Color(51, 255, 255));
	v.setPosition(247, 33);
	v.setString("v1.0");
	v.setCharacterSize(25);

	//GUI
	sg.setFont(tf);
	sg.add(res);
	sg.add(mode);
	sg.add(c1);
	sg.add(c2);
	sg.add(b);

	//VIDEOMODE
	mode->setScrollbar(nullptr);
	mode->setPosition(20, 80);
	mode->setItemHeight(15);
	mode->setSize(95, 30);
	mode->setTextSize(15);
	mode->addItem("FULLSCREEN");
	mode->addItem("WINDOWED");
	mode->setSelectedItemByIndex(0);

	//RESOLUTIONS
	res->setScrollbar(nullptr);
	res->setPosition(20, 115);
	res->setItemHeight(15);
	res->setTextSize(15);

	res->addItem("2560 x 1440");
	res->addItem("1920 x 1080");
	res->addItem("1366 x 768");
	res->addItem("CUSTOM");
	res->setSize(95, res->getItemCount() * 15);

	//CUSTOM RESOLUTION
	c1->setDefaultText("X");
	c1->setPosition(125, 140);
	c1->setSize(50, 15);
	c1->setTextSize(15);
	c1->setMaximumCharacters(4);
	
	c2->setDefaultText("Y");
	c2->setPosition(125, 160);
	c2->setSize(50, 15);
	c2->setTextSize(15);
	c2->setMaximumCharacters(4);

	//STARTBUTTON
	b->setPosition(185, 140);
	b->setSize(95, 35);
	b->setText("START");
	b->setTextSize(15);
	b->connect("pressed", start, res, mode, c1, c2);

}
void CreateFormWindow::open(tgui::Gui &gui) {

    if (m_open)
        return;

    m_open = true;
    m_gui = &gui;

    // create window
    {
        m_childWindow = std::make_shared<tgui::ChildWindow>();

        m_childWindow->setSize(300, 200);
        m_childWindow->setPosition((tgui::bindWidth(gui) * 0.5f) - tgui::bindWidth(m_childWindow) * 0.5f,
                                   (tgui::bindHeight(gui) * 0.5f) - tgui::bindHeight(m_childWindow));
        m_childWindow->setTitle("Create Form");

        m_childWindow->connect("Closed", [&]() {

            gui.remove(m_childWindow);

            m_open = false;

        });

        gui.add(m_childWindow);
    }

    // Create window UI
    {
        // Create confirm button
        {
            m_ui.m_confirmButton = std::make_shared<tgui::Button>();

            m_ui.m_confirmButton->setSize(tgui::bindWidth(m_childWindow) * 0.2f,
                                          tgui::bindHeight(m_childWindow) * 0.1f);

            m_ui.m_confirmButton->setPosition(tgui::bindWidth(m_childWindow) * 0.7f,
                                              tgui::bindHeight(m_childWindow) * 0.8f);

            m_ui.m_confirmButton->setText("Confirm");

            m_ui.m_confirmButton->connect("Pressed", [&](){
                // TODO connect confirm button to proper action
            });

            m_childWindow->add(m_ui.m_confirmButton);
        }

        // Create cancel button
        {
            m_ui.m_cancelButton = std::make_shared<tgui::Button>();

            m_ui.m_cancelButton->setSize(tgui::bindWidth(m_childWindow) * 0.2f, tgui::bindHeight(m_childWindow) * 0.1f);

            m_ui.m_cancelButton->setPosition(tgui::bindWidth(m_childWindow) * 0.1f,
                                             tgui::bindHeight(m_childWindow) * 0.8f);

            m_ui.m_cancelButton->setText("Cancel");

            m_ui.m_cancelButton->connect("Pressed", [&]() {

                m_gui->remove(m_childWindow);
                m_open = false;

            });

            m_childWindow->add(m_ui.m_cancelButton);
        }

        // Create name input
        {
            m_ui.m_nameInput = std::make_shared<tgui::EditBox>();

            m_ui.m_nameInput->setSize(tgui::bindWidth(m_childWindow) * 0.8f, tgui::bindHeight(m_childWindow) * 0.2f);
            m_ui.m_nameInput->setPosition(
                    tgui::bindWidth(m_childWindow) * 0.5f - (tgui::bindWidth(m_ui.m_nameInput) * 0.5f),
                    tgui::bindHeight(m_childWindow) * 0.2f);

            m_childWindow->add(m_ui.m_nameInput);
        }

        // Create name input label
        {
            m_ui.m_nameInputLabel = std::make_shared<tgui::Label>();

            m_ui.m_nameInputLabel->setText("Name");

            m_ui.m_nameInputLabel->setPosition(tgui::bindLeft(m_ui.m_nameInput), tgui::bindTop(m_ui.m_nameInput) -
                                                                                 tgui::bindHeight(
                                                                                         m_ui.m_nameInputLabel));

            m_childWindow->add(m_ui.m_nameInputLabel);
        }
    }

}
예제 #5
0
파일: main.cpp 프로젝트: WendyHanzer/4s
void guiDraw(sf::RenderWindow& window, tgui::Gui& gui)
{
	window.pushGLStates();
	gui.draw();
	window.popGLStates();
} //guiDraw