Added ImGui-SFML

This commit is contained in:
trotFunky 2019-05-23 02:23:49 +02:00
parent 52ccc0b426
commit de4024154c
2 changed files with 91 additions and 2 deletions

View file

@ -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)

View file

@ -5,12 +5,44 @@
#include <gtest/gtest.h>
#include <iostream>
#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<sf::Uint8>(color[0] * 255.f);
bgColor.g = static_cast<sf::Uint8>(color[1] * 255.f);
bgColor.b = static_cast<sf::Uint8>(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);