diff --git a/sfml-tgui/.gitignore b/sfml-tgui/.gitignore new file mode 100644 index 0000000..1d754d8 --- /dev/null +++ b/sfml-tgui/.gitignore @@ -0,0 +1,3 @@ +themes/ +fonts/ +libtgui.so* diff --git a/sfml-tgui/build.sh b/sfml-tgui/build.sh new file mode 100755 index 0000000..63bc575 --- /dev/null +++ b/sfml-tgui/build.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +rm ./a.out + +g++ \ + -Wl,-rpath=. \ + -I/home/user/Downloads/TGUI-1.1.0/include/ \ + -L./ \ + main.cpp \ + -ltgui \ + -lsfml-graphics -lsfml-window -lsfml-system + +./a.out diff --git a/sfml-tgui/main.cpp b/sfml-tgui/main.cpp new file mode 100644 index 0000000..8d11b2d --- /dev/null +++ b/sfml-tgui/main.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include + +int main() { + sf::RenderWindow window{{800, 600}, "TGUI example w/ SFML_GRAPHICS backend"}; + sf::Event event; + + tgui::Gui gui{window}; + tgui::Font m_tguiFont("fonts/Cuprum/Cuprum-Regular.ttf"); + tgui::Font::setGlobalFont(m_tguiFont); + + tgui::Theme::setDefault("themes/Black.txt"); + + auto top_panel = tgui::Panel::create(); + auto main_panel = tgui::Panel::create(); + auto footer_panel = tgui::Panel::create(); + + auto menu_bar = tgui::MenuBar::create(); + menu_bar->addMenu("File"); + menu_bar->addMenuItem("Load"); + menu_bar->addMenuItem("Save"); + + top_panel->setHeight("50px"); + footer_panel->setHeight("30px"); + + top_panel->setAutoLayout(tgui::AutoLayout::Top); + main_panel->setAutoLayout(tgui::AutoLayout::Fill); + footer_panel->setAutoLayout(tgui::AutoLayout::Bottom); + + tgui::Button::Ptr button = tgui::Button::create("Привет"); + button->onPress([&] { printf("ololo\n"); }); + button->setHeight("30px"); + tgui::Button::Ptr button2 = tgui::Button::create("Закрыть"); + button2->setAutoLayout(tgui::AutoLayout::Fill); + button2->onPress([&] { window.close(); }); + + auto picture = tgui::Picture::create("CLI_Logo_small.png"); + + auto editBox = tgui::EditBox::create(); + + top_panel->add(button); + main_panel->add(picture); + footer_panel->add(button2); + + gui.add(menu_bar); + gui.add(top_panel); + gui.add(main_panel); + gui.add(footer_panel); + + + // gui.mainLoop(); + while (window.isOpen()) { + while (window.pollEvent(event)) { + // while (window.waitEvent(event)) { + gui.handleEvent(event); + + if (event.type == sf::Event::Closed) + window.close(); + } + + window.clear({240, 240, 240}); + gui.draw(); + window.display(); + } + + printf("Пока\n"); +}