-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a61ab13
commit 98517d2
Showing
2 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |