Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vittorioromeo committed Dec 22, 2021
1 parent a61ab13 commit 98517d2
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 0 deletions.
46 changes: 46 additions & 0 deletions examples/minimal/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "imgui.h" // necessary for ImGui::*, imgui-SFML.h doesn't include imgui.h

#include "imgui-SFML.h" // for ImGui::SFML::* functions and SFML-specific overloads

#include <SFML/Graphics/CircleShape.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/Window/Event.hpp>

int main() {
sf::RenderWindow window(sf::VideoMode(640, 480), "ImGui + SFML = <3");
window.setFramerateLimit(60);
ImGui::SFML::Init(window);

sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);

sf::Clock deltaClock;
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
ImGui::SFML::ProcessEvent(window, event);

if (event.type == sf::Event::Closed) {
window.close();
}
}

ImGui::SFML::Update(window, deltaClock.restart());

ImGui::ShowDemoWindow();

ImGui::Begin("Hello, world!");
ImGui::Button("Look at this pretty button");
ImGui::End();

window.clear();
window.draw(shape);
ImGui::SFML::Render(window);
window.display();
}

ImGui::SFML::Shutdown();

return 0;
}
89 changes: 89 additions & 0 deletions examples/multiple_windows/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include "imgui.h" // necessary for ImGui::*, imgui-SFML.h doesn't include imgui.h

#include "imgui-SFML.h" // for ImGui::SFML::* functions and SFML-specific overloads

#include <SFML/Graphics/CircleShape.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/Window/Event.hpp>

int main() {
sf::RenderWindow window(sf::VideoMode(1280, 720), "ImGui + SFML = <3");
window.setFramerateLimit(60);
ImGui::SFML::Init(window);

sf::RenderWindow childWindow(sf::VideoMode(640, 480), "ImGui-SFML Child window");
childWindow.setFramerateLimit(60);
ImGui::SFML::Init(childWindow);

sf::Clock deltaClock;
while (window.isOpen()) {
// Main window event processing
sf::Event event;
while (window.pollEvent(event)) {
ImGui::SFML::ProcessEvent(window, event);
if (event.type == sf::Event::Closed) {
if (childWindow.isOpen()) {
childWindow.close();
}
window.close();
ImGui::SFML::Shutdown(); // will shutdown all windows
return 0; // return here so that we don't call Update/Render
}
}

// Child window event processing
if (childWindow.isOpen()) {
while (childWindow.pollEvent(event)) {
ImGui::SFML::ProcessEvent(childWindow, event);
if (event.type == sf::Event::Closed) {
childWindow.close();
ImGui::SFML::Shutdown(childWindow);
}
}
}

// Update
const sf::Time dt = deltaClock.restart();
ImGui::SFML::Update(window, dt);
if (childWindow.isOpen()) {
ImGui::SFML::Update(childWindow, dt);
}

// Add ImGui widgets in the first window
ImGui::SFML::SetCurrentWindow(window);
ImGui::Begin("Hello, world!");
ImGui::Button("Look at this pretty button");
ImGui::End();
ImGui::ShowDemoWindow();
// Add ImGui widgets in the child window
if (childWindow.isOpen()) {
ImGui::SFML::SetCurrentWindow(childWindow);
ImGui::Begin("Works in a second window!");
ImGui::Button("Example button");
ImGui::End();
}

// Main window drawing
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);

window.clear();
window.draw(shape);
ImGui::SFML::Render(window);
window.display();

// Child window drawing
if (childWindow.isOpen()) {
sf::CircleShape shape2(50.f);
shape2.setFillColor(sf::Color::Red);

childWindow.clear();
childWindow.draw(shape2);
ImGui::SFML::Render(childWindow);
childWindow.display();
}
}

return 0;
}

0 comments on commit 98517d2

Please sign in to comment.