From de4024154c2c971710126ae5725af3f70309cc62 Mon Sep 17 00:00:00 2001 From: trotFunky Date: Thu, 23 May 2019 02:23:49 +0200 Subject: [PATCH] Added ImGui-SFML --- xmlParser/CMakeLists.txt | 13 +++++- xmlParser/gTestXMLParser.cpp | 80 ++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/xmlParser/CMakeLists.txt b/xmlParser/CMakeLists.txt index c0d5b84..d2d788e 100644 --- a/xmlParser/CMakeLists.txt +++ b/xmlParser/CMakeLists.txt @@ -22,6 +22,11 @@ endif() find_path(PugiXML_INCLUDE_DIR pugixml.hpp) +find_package(ImGui-SFML REQUIRED) +if(NOT ImGui-SFML_FOUND) + message(FATAL "ImGui-SFML non trouvé") +endif() + add_library(xmlParser SHARED Circle.cpp Circle.h @@ -35,7 +40,9 @@ add_library(xmlParser SHARED target_link_libraries(xmlParser sfml-window sfml-graphics - pugixml) + sfml-system + pugixml + ImGui-SFML::ImGui-SFML) target_compile_options(xmlParser PRIVATE -Wall -Wpedantic -Wextra) @@ -47,5 +54,7 @@ target_link_libraries(gTestXMLParser gtest sfml-graphics sfml-window - pugixml) + sfml-system + pugixml + ImGui-SFML::ImGui-SFML) target_link_options(gTestXMLParser PRIVATE -pthread) \ No newline at end of file diff --git a/xmlParser/gTestXMLParser.cpp b/xmlParser/gTestXMLParser.cpp index 23534d3..62e4947 100644 --- a/xmlParser/gTestXMLParser.cpp +++ b/xmlParser/gTestXMLParser.cpp @@ -5,12 +5,44 @@ #include #include +#include "imgui.h" +#include "imgui-SFML.h" + #include "Circle.h" #include "xmlParser.h" #include "SFML/Graphics.hpp" #include "Group.h" +class ImGui_F : public ::testing::Test +{ +protected: + + sf::RenderWindow* window; + + sf::Color bgColor; + + sf::Clock deltaClock; + + float color[3] = { 0.f, 0.f, 0.f }; + + // let's use char array as buffer, see next part + // for instructions on using std::string with ImGui + char windowTitle[255]; + + void SetUp() override + { + window = new sf::RenderWindow(sf::VideoMode(640, 480), ""); + window->setVerticalSyncEnabled(true); + ImGui::SFML::Init(*window); + + strcpy(windowTitle,"ImGui + SFML = <3"); + + window->setTitle(windowTitle); + window->resetGLStates(); // call it if you only draw ImGui. Otherwise not needed. + } +}; + TEST(xmlParserInits,initEmptyCircle) { xmlParser::Circle cercle = xmlParser::Circle(); @@ -191,6 +223,54 @@ TEST(drawFace,drawFace) } } +TEST_F(ImGui_F,ImGui_Example) +{ + while (window->isOpen()) { + sf::Event event; + while (window->pollEvent(event)) { + ImGui::SFML::ProcessEvent(event); + + if (event.type == sf::Event::Closed) { + window->close(); + } + } + + ImGui::SFML::Update(*window, deltaClock.restart()); + + ImGui::Begin("Sample window"); // begin window + + // Background color edit + if (ImGui::ColorEdit3("Background color", color)) { + // this code gets called if color value changes, so + // the background color is upgraded automatically! + bgColor.r = static_cast(color[0] * 255.f); + bgColor.g = static_cast(color[1] * 255.f); + bgColor.b = static_cast(color[2] * 255.f); + } + + // Window title text edit + ImGui::InputText("Window title", windowTitle, 255); + + if (ImGui::Button("Update window title")) { + // this code gets if user clicks on the button + // yes, you could have written if(ImGui::InputText(...)) + // but I do this to show how buttons work :) + window->setTitle(windowTitle); + } + ImGui::End(); // end window + + window->clear(bgColor); // fill background with color + ImGui::SFML::Render(*window); + window->display(); + } + + ImGui::SFML::Shutdown(); +} + +TEST_F(ImGui_F,ImGui_Perso) +{ + // TODO : Copy examples to create new shapes 'n stuff +} int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc,argv);