|
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 |
| - |
14 |
| - if (!ImGui::SFML::Init(window)) { |
15 |
| - return 1; |
16 |
| - } |
17 |
| - |
18 |
| - sf::RenderWindow childWindow(sf::VideoMode(640, 480), "ImGui-SFML Child window"); |
19 |
| - childWindow.setFramerateLimit(60); |
20 |
| - |
21 |
| - if (!ImGui::SFML::Init(childWindow)) { |
22 |
| - return 1; |
23 |
| - } |
24 |
| - |
25 |
| - sf::Clock deltaClock; |
26 |
| - while (window.isOpen()) { |
27 |
| - // Main window event processing |
28 |
| - sf::Event event; |
29 |
| - while (window.pollEvent(event)) { |
30 |
| - ImGui::SFML::ProcessEvent(window, event); |
31 |
| - if (event.type == sf::Event::Closed) { |
32 |
| - if (childWindow.isOpen()) { |
33 |
| - childWindow.close(); |
34 |
| - } |
35 |
| - window.close(); |
36 |
| - ImGui::SFML::Shutdown(); // will shutdown all windows |
37 |
| - return 0; // return here so that we don't call Update/Render |
38 |
| - } |
39 |
| - } |
40 |
| - |
41 |
| - // Child window event processing |
42 |
| - if (childWindow.isOpen()) { |
43 |
| - while (childWindow.pollEvent(event)) { |
44 |
| - ImGui::SFML::ProcessEvent(childWindow, event); |
45 |
| - if (event.type == sf::Event::Closed) { |
46 |
| - childWindow.close(); |
47 |
| - ImGui::SFML::Shutdown(childWindow); |
48 |
| - } |
49 |
| - } |
50 |
| - } |
51 |
| - |
52 |
| - // Update |
53 |
| - const sf::Time dt = deltaClock.restart(); |
54 |
| - ImGui::SFML::Update(window, dt); |
55 |
| - if (childWindow.isOpen()) { |
56 |
| - ImGui::SFML::Update(childWindow, dt); |
57 |
| - } |
58 |
| - |
59 |
| - // Add ImGui widgets in the first window |
60 |
| - ImGui::SFML::SetCurrentWindow(window); |
61 |
| - ImGui::Begin("Hello, world!"); |
62 |
| - ImGui::Button("Look at this pretty button"); |
63 |
| - ImGui::End(); |
64 |
| - ImGui::ShowDemoWindow(); |
65 |
| - // Add ImGui widgets in the child window |
66 |
| - if (childWindow.isOpen()) { |
67 |
| - ImGui::SFML::SetCurrentWindow(childWindow); |
68 |
| - ImGui::Begin("Works in a second window!"); |
69 |
| - ImGui::Button("Example button"); |
70 |
| - ImGui::End(); |
71 |
| - } |
72 |
| - |
73 |
| - // Main window drawing |
74 |
| - sf::CircleShape shape(100.f); |
75 |
| - shape.setFillColor(sf::Color::Green); |
76 |
| - |
77 |
| - window.clear(); |
78 |
| - window.draw(shape); |
79 |
| - ImGui::SFML::Render(window); |
80 |
| - window.display(); |
81 |
| - |
82 |
| - // Child window drawing |
83 |
| - if (childWindow.isOpen()) { |
84 |
| - sf::CircleShape shape2(50.f); |
85 |
| - shape2.setFillColor(sf::Color::Red); |
86 |
| - |
87 |
| - childWindow.clear(); |
88 |
| - childWindow.draw(shape2); |
89 |
| - ImGui::SFML::Render(childWindow); |
90 |
| - childWindow.display(); |
91 |
| - } |
92 |
| - } |
93 |
| - |
94 |
| - return 0; |
95 |
| -} |
0 commit comments