diff --git a/snippets/CMakeLists.txt b/snippets/CMakeLists.txt index e15085c..a03ef56 100644 --- a/snippets/CMakeLists.txt +++ b/snippets/CMakeLists.txt @@ -40,6 +40,7 @@ endif() add_executable(compte_mots compte_mots.cpp) add_library(polynomial SHARED Polynomial.cpp Polynomial.tpp) +#target_link_libraries(polynomial -static) if(GTest_FOUND) add_executable(polynomialTest gTestPolynomial.cpp) diff --git a/xmlParser/CMakeLists.txt b/xmlParser/CMakeLists.txt index d2d788e..e1acc4e 100644 --- a/xmlParser/CMakeLists.txt +++ b/xmlParser/CMakeLists.txt @@ -22,11 +22,6 @@ 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 @@ -40,11 +35,7 @@ add_library(xmlParser SHARED target_link_libraries(xmlParser sfml-window sfml-graphics - sfml-system - pugixml - ImGui-SFML::ImGui-SFML) - -target_compile_options(xmlParser PRIVATE -Wall -Wpedantic -Wextra) + pugixml) add_executable(gTestXMLParser gTestXMLParser.cpp) target_compile_options(gTestXMLParser PRIVATE -pthread) @@ -54,7 +45,5 @@ target_link_libraries(gTestXMLParser gtest sfml-graphics sfml-window - sfml-system - pugixml - ImGui-SFML::ImGui-SFML) + pugixml) target_link_options(gTestXMLParser PRIVATE -pthread) \ No newline at end of file diff --git a/xmlParser/Circle.cpp b/xmlParser/Circle.cpp index 343d535..d320994 100644 --- a/xmlParser/Circle.cpp +++ b/xmlParser/Circle.cpp @@ -9,7 +9,7 @@ namespace xmlParser Circle::Circle(std::string label, float x, float y, float r, const sf::Color& color) : DrawingElement(std::move(label),x,y,color), r(2) { - shape = std::unique_ptr(new sf::CircleShape(r)); + shape = new sf::CircleShape(r); shape->setPosition(x-r,y-r); shape->setFillColor(color); } @@ -20,11 +20,16 @@ namespace xmlParser { label = "Test Circle"; } - shape = std::unique_ptr(new sf::CircleShape(r)); + shape = new sf::CircleShape(r); shape->setPosition(x-r,y-r); shape->setFillColor(color); } + void Circle::draw(sf::RenderWindow& window) + { + window.draw(*(dynamic_cast(shape))); + } + float Circle::getR() const { return r; @@ -33,18 +38,13 @@ namespace xmlParser void Circle::setR(float newR) { r = newR; - dynamic_cast(shape.get())->setRadius(r); + dynamic_cast(shape)->setRadius(r); shape->setPosition(x-r,y-r); } - const std::string Circle::toString(int indent) const + const std::string Circle::toString() const { std::stringstream string; - for(int i = 0;isetPosition(x,-y); } @@ -57,7 +52,7 @@ namespace xmlParser { y = newY; - if(shape) + if(shape != nullptr) { shape->setPosition(x,-y); } @@ -88,9 +83,17 @@ namespace xmlParser color = strToColor(stringColor); } + const std::string DrawingElement::toString() const + { + std::stringstream string; + string << label << " at x:" << getX() << " y:" << getY(); + string << " | color:" << getStringColor(); + return(string.str()); + } + std::ostream& operator<<(std::ostream& ostream, const DrawingElement& element) { - ostream << element.toString(0); + ostream << element.toString(); return(ostream); } } \ No newline at end of file diff --git a/xmlParser/DrawingElement.h b/xmlParser/DrawingElement.h index a52956f..acb5356 100644 --- a/xmlParser/DrawingElement.h +++ b/xmlParser/DrawingElement.h @@ -20,13 +20,12 @@ namespace xmlParser { public: - // TODO : S'arranger pour n'avoir que des constructeurs sensés : pas de constructeur vide/résultat non évident explicit DrawingElement(std::string label = "Test DrawingElement", float x = 0, float y = 1, const sf::Color& = sf::Color::Yellow); explicit DrawingElement(const pugi::xml_node&); - virtual void draw(sf::RenderWindow&); + virtual void draw(sf::RenderWindow&) = 0; void draw(sf::RenderWindow&, float referenceX, float referenceY); std::string label; @@ -42,7 +41,7 @@ namespace xmlParser void setColor(const sf::Color& newColor); void setColor(const std::string& stringColor); - virtual const std::string toString(int indent) const = 0; + virtual const std::string toString() const; friend std::ostream& operator<<(std::ostream&,const DrawingElement&); @@ -52,7 +51,7 @@ namespace xmlParser sf::Color color; - std::unique_ptr shape; + sf::Shape* shape; }; } diff --git a/xmlParser/Group.cpp b/xmlParser/Group.cpp index a9735b6..9ac432f 100644 --- a/xmlParser/Group.cpp +++ b/xmlParser/Group.cpp @@ -6,7 +6,7 @@ namespace xmlParser { - Group::Group(std::string label, float x, float y, const sf::Color& color) : DrawingElement(std::move(label),x,y,color), drawingElements() + Group::Group(std::string label, float x, float y, const sf::Color& color) : DrawingElement(std::move(label),x,y,color), drawingElements({}) {} Group::Group(const pugi::xml_node& node) : DrawingElement(node) @@ -32,7 +32,7 @@ namespace xmlParser !strncmp(childNode.name(),"Group",5) ? dynamic_cast(new Group(childNode)) : nullptr; if(newElement != nullptr) { - drawingElements.emplace(std::make_pair(newElement->label,std::move(std::unique_ptr(newElement)))); + drawingElements.insert(std::make_pair(newElement->label,newElement)); } } } @@ -42,13 +42,13 @@ namespace xmlParser std::transform(elements.begin(),elements.end(),std::inserter(drawingElements,drawingElements.begin()), [](std::pair pair) { - return(std::make_pair(pair.first,std::move(std::unique_ptr(pair.second)))); + return(pair); }); } bool Group::addDrawingElement(DrawingElement* drawingElement) { - return(drawingElements.insert(std::make_pair(drawingElement->label,std::move(std::unique_ptr(drawingElement)))).second); + return(drawingElements.insert(std::make_pair(drawingElement->label,drawingElement)).second); } bool Group::removeDrawingElement(const std::string& label) @@ -58,7 +58,7 @@ namespace xmlParser DrawingElement* Group::getDrawingElement(const std::string& label) { - return(drawingElements.at(label).get()); + return(drawingElements.at(label)); } void Group::draw(sf::RenderWindow& window) @@ -69,20 +69,15 @@ namespace xmlParser } } - const std::string Group::toString(int indent) const + const std::string Group::toString() const { std::stringstream string; - for(int i = 0;itoString(indent+1) << std::endl; + string << "\t" << *(element.second) << std::endl; } return(string.str()); } diff --git a/xmlParser/Group.h b/xmlParser/Group.h index 1d7b2c7..99c7a42 100644 --- a/xmlParser/Group.h +++ b/xmlParser/Group.h @@ -34,9 +34,9 @@ namespace xmlParser void draw(sf::RenderWindow&) override; - const std::string toString(int indent) const override; + const std::string toString() const override; private: - std::map> drawingElements; + std::map drawingElements; }; } diff --git a/xmlParser/gTestXMLParser.cpp b/xmlParser/gTestXMLParser.cpp index 62e4947..23534d3 100644 --- a/xmlParser/gTestXMLParser.cpp +++ b/xmlParser/gTestXMLParser.cpp @@ -5,44 +5,12 @@ #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(); @@ -223,54 +191,6 @@ 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);