Skip to content

Commit f5a1e27

Browse files
committed
fix(ux): imgui warning on button having same id, keyboard was conflicting while typing (interpreted as actions)
1 parent 67a611d commit f5a1e27

File tree

8 files changed

+19
-19
lines changed

8 files changed

+19
-19
lines changed

include/Scene/Interactive/SceneInteractive.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ namespace Raytracer {
160160
void addSelectableSkybox(const std::filesystem::directory_entry &entry);
161161
void addSelectableScene(const std::filesystem::directory_entry &entry);
162162

163-
void guiColoredSquare(const Color &color);
163+
void guiColoredSquare(const Color &color, int id);
164164
#endif
165165

166166
/////////////////////////////////
@@ -199,7 +199,6 @@ namespace Raytracer {
199199
float m_selectedPrimitiveTransparency;
200200
#endif
201201
bool m_addToCurrentScene = false;
202-
bool m_isWriting = false;
203202
size_t m_renderResolution;
204203
size_t m_imageHeight;
205204
size_t m_imageWidth;

src/scene/interactive/handleEvents.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
namespace Raytracer {
1313
void SceneInteractive::handleEvents(void)
1414
{
15-
if (m_isWriting)
15+
#ifdef BONUS
16+
if (ImGui::IsAnyItemActive())
1617
resetActions();
18+
#endif
1719

1820
while (const std::optional<sf::Event> event = m_window.pollEvent()) {
1921
#ifdef BONUS
20-
ImGui::SFML::ProcessEvent(m_window, *event);
22+
ImGui::SFML::ProcessEvent(m_window, *event);
2123
#endif
2224

2325
if (event->is<sf::Event::Closed>()) {
@@ -36,18 +38,21 @@ namespace Raytracer {
3638
m_needRendering = true;
3739
}
3840

39-
if (!m_isWriting) {
41+
#ifdef BONUS
42+
if (!ImGui::IsAnyItemActive()) {
43+
#endif
4044
if (const auto* keyReleased = event->getIf<sf::Event::KeyReleased>()) {
4145
applyKeyReleasedActions(keyReleased->code);
4246
}
4347
if (const auto* keyPressed = event->getIf<sf::Event::KeyPressed>()) {
4448
applyKeyPressedActions(keyPressed->code);
4549
}
50+
if (m_interacCam.handleInput(*event, m_actions)) {
51+
// Handle camera input
52+
}
53+
#ifdef BONUS
4654
}
47-
48-
if (!m_isWriting && m_interacCam.handleInput(*event, m_actions)) {
49-
// Handle camera input
50-
}
55+
#endif
5156

5257
if (const auto* mouseReleased = event->getIf<sf::Event::MouseButtonReleased>()) {
5358
if (mouseReleased->button == sf::Mouse::Button::Right) {

src/scene/interactive/imgui/commonEditing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
namespace Raytracer
1111
{
12-
void SceneInteractive::guiColoredSquare(const Color &color)
12+
void SceneInteractive::guiColoredSquare(const Color &color, int id)
1313
{
14-
ImGui::ColorButton(" ", ImVec4(color.getR(),
14+
ImGui::ColorButton(std::to_string(id).c_str(), ImVec4(color.getR(),
1515
color.getG(), color.getB(), 1.0f),
1616
ImGuiColorEditFlags_InputRGB);
1717
}

src/scene/interactive/imgui/guiMenuBar.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ namespace Raytracer
3939

4040
void SceneInteractive::guiMenuBar(void)
4141
{
42-
m_isWriting = false;
4342
if (ImGui::BeginMenuBar()) {
4443
// Save scene to .cfg
4544
if (ImGui::BeginMenu("Save as ...")) {
46-
m_isWriting = true;
4745
std::string hint("custom_scene.cfg");
4846
if (ImGui::InputTextWithHint(" File name (press ENTER to save)",
4947
hint.c_str(), m_saveFileBuf, FILE_BUF_SIZE,
@@ -57,7 +55,6 @@ namespace Raytracer
5755
}
5856

5957
if (ImGui::BeginMenu("Load scene")) {
60-
m_isWriting = true;
6158
if (ImGui::InputTextWithHint(" File name (press ENTER to load)",
6259
"scenes/custom_scene.cfg", m_loadFileBuf, FILE_BUF_SIZE,
6360
ImGuiInputTextFlags_EnterReturnsTrue)) {
@@ -88,7 +85,6 @@ namespace Raytracer
8885
}
8986

9087
if (ImGui::BeginMenu("Skybox path")) {
91-
m_isWriting = true;
9288
Skybox &skybox = m_scene->getSkybox();
9389
bool skyboxHasTexture = skybox.hasTexture();
9490
if (ImGui::Checkbox("Has texture", &skyboxHasTexture)) {

src/scene/interactive/imgui/inventory/guiInventoryTab.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace Raytracer
2929
switch (material->getType()) {
3030
case MaterialType::SOLID: {
3131
ImGui::SameLine();
32-
guiColoredSquare(static_cast<MaterialSolid *>(material.get())->getColor());
32+
guiColoredSquare(static_cast<MaterialSolid *>(material.get())->getColor(), i);
3333
break;
3434
}
3535
case MaterialType::TEXTURE:

src/scene/interactive/imgui/light/guiLightTab.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace Raytracer
3535
if (ImGui::Selectable(name.c_str(), m_selectedObject == i))
3636
m_selectedObject = i;
3737
ImGui::SameLine();
38-
guiColoredSquare(light->getColor());
38+
guiColoredSquare(light->getColor(), i);
3939
i++;
4040
}
4141
}

src/scene/interactive/imgui/obj/guiObjTab.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Raytracer
2525
m_selectedObject = i;
2626
if (obj->getMaterial()->getType() == MaterialType::SOLID) {
2727
ImGui::SameLine();
28-
guiColoredSquare(static_cast<MaterialSolid *>(obj->getMaterial().get())->getColor());
28+
guiColoredSquare(static_cast<MaterialSolid *>(obj->getMaterial().get())->getColor(), i);
2929
}
3030
i++;
3131
}

src/scene/interactive/imgui/primitives/guiPrimitiveTab.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Raytracer
2828
m_selectedObject = i;
2929
if (prim->getMaterial()->getType() == MaterialType::SOLID) {
3030
ImGui::SameLine();
31-
guiColoredSquare(static_cast<MaterialSolid *>(prim->getMaterial().get())->getColor());
31+
guiColoredSquare(static_cast<MaterialSolid *>(prim->getMaterial().get())->getColor(), i);
3232
}
3333
i++;
3434
}

0 commit comments

Comments
 (0)