Skip to content

Commit 98517d2

Browse files
committed
wip
1 parent a61ab13 commit 98517d2

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed

examples/minimal/main.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "imgui.h" // necessary for ImGui::*, imgui-SFML.h doesn't include imgui.h
2+
3+
#include "imgui-SFML.h" // for ImGui::SFML::* functions and SFML-specific overloads
4+
5+
#include <SFML/Graphics/CircleShape.hpp>
6+
#include <SFML/Graphics/RenderWindow.hpp>
7+
#include <SFML/System/Clock.hpp>
8+
#include <SFML/Window/Event.hpp>
9+
10+
int main() {
11+
sf::RenderWindow window(sf::VideoMode(640, 480), "ImGui + SFML = <3");
12+
window.setFramerateLimit(60);
13+
ImGui::SFML::Init(window);
14+
15+
sf::CircleShape shape(100.f);
16+
shape.setFillColor(sf::Color::Green);
17+
18+
sf::Clock deltaClock;
19+
while (window.isOpen()) {
20+
sf::Event event;
21+
while (window.pollEvent(event)) {
22+
ImGui::SFML::ProcessEvent(window, event);
23+
24+
if (event.type == sf::Event::Closed) {
25+
window.close();
26+
}
27+
}
28+
29+
ImGui::SFML::Update(window, deltaClock.restart());
30+
31+
ImGui::ShowDemoWindow();
32+
33+
ImGui::Begin("Hello, world!");
34+
ImGui::Button("Look at this pretty button");
35+
ImGui::End();
36+
37+
window.clear();
38+
window.draw(shape);
39+
ImGui::SFML::Render(window);
40+
window.display();
41+
}
42+
43+
ImGui::SFML::Shutdown();
44+
45+
return 0;
46+
}

examples/multiple_windows/main.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#include "imgui.h" // necessary for ImGui::*, imgui-SFML.h doesn't include imgui.h
2+
3+
#include "imgui-SFML.h" // for ImGui::SFML::* functions and SFML-specific overloads
4+
5+
#include <SFML/Graphics/CircleShape.hpp>
6+
#include <SFML/Graphics/RenderWindow.hpp>
7+
#include <SFML/System/Clock.hpp>
8+
#include <SFML/Window/Event.hpp>
9+
10+
int main() {
11+
sf::RenderWindow window(sf::VideoMode(1280, 720), "ImGui + SFML = <3");
12+
window.setFramerateLimit(60);
13+
ImGui::SFML::Init(window);
14+
15+
sf::RenderWindow childWindow(sf::VideoMode(640, 480), "ImGui-SFML Child window");
16+
childWindow.setFramerateLimit(60);
17+
ImGui::SFML::Init(childWindow);
18+
19+
sf::Clock deltaClock;
20+
while (window.isOpen()) {
21+
// Main window event processing
22+
sf::Event event;
23+
while (window.pollEvent(event)) {
24+
ImGui::SFML::ProcessEvent(window, event);
25+
if (event.type == sf::Event::Closed) {
26+
if (childWindow.isOpen()) {
27+
childWindow.close();
28+
}
29+
window.close();
30+
ImGui::SFML::Shutdown(); // will shutdown all windows
31+
return 0; // return here so that we don't call Update/Render
32+
}
33+
}
34+
35+
// Child window event processing
36+
if (childWindow.isOpen()) {
37+
while (childWindow.pollEvent(event)) {
38+
ImGui::SFML::ProcessEvent(childWindow, event);
39+
if (event.type == sf::Event::Closed) {
40+
childWindow.close();
41+
ImGui::SFML::Shutdown(childWindow);
42+
}
43+
}
44+
}
45+
46+
// Update
47+
const sf::Time dt = deltaClock.restart();
48+
ImGui::SFML::Update(window, dt);
49+
if (childWindow.isOpen()) {
50+
ImGui::SFML::Update(childWindow, dt);
51+
}
52+
53+
// Add ImGui widgets in the first window
54+
ImGui::SFML::SetCurrentWindow(window);
55+
ImGui::Begin("Hello, world!");
56+
ImGui::Button("Look at this pretty button");
57+
ImGui::End();
58+
ImGui::ShowDemoWindow();
59+
// Add ImGui widgets in the child window
60+
if (childWindow.isOpen()) {
61+
ImGui::SFML::SetCurrentWindow(childWindow);
62+
ImGui::Begin("Works in a second window!");
63+
ImGui::Button("Example button");
64+
ImGui::End();
65+
}
66+
67+
// Main window drawing
68+
sf::CircleShape shape(100.f);
69+
shape.setFillColor(sf::Color::Green);
70+
71+
window.clear();
72+
window.draw(shape);
73+
ImGui::SFML::Render(window);
74+
window.display();
75+
76+
// Child window drawing
77+
if (childWindow.isOpen()) {
78+
sf::CircleShape shape2(50.f);
79+
shape2.setFillColor(sf::Color::Red);
80+
81+
childWindow.clear();
82+
childWindow.draw(shape2);
83+
ImGui::SFML::Render(childWindow);
84+
childWindow.display();
85+
}
86+
}
87+
88+
return 0;
89+
}

0 commit comments

Comments
 (0)