From 267a60ef305cf411f42866e2d4d0a13b5754f21a Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Tue, 19 Jan 2016 11:43:38 +0100 Subject: [PATCH] Better loading of editor toolbox icons --- include/Engine/Editor/EditorGUI.h | 1 + src/Engine/Editor/EditorGUI.cpp | 51 +++++++++++++------------------ 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/include/Engine/Editor/EditorGUI.h b/include/Engine/Editor/EditorGUI.h index f28b95cf..9d2712e1 100644 --- a/include/Engine/Editor/EditorGUI.h +++ b/include/Engine/Editor/EditorGUI.h @@ -88,6 +88,7 @@ private: boost::filesystem::path fileOpenDialog(); boost::filesystem::path fileSaveDialog(); const std::string formatEntityName(EntityWrapper entity); + GLuint tryLoadTexture(std::string filePath); // Entity file handling methods void entityImport(World* world); diff --git a/src/Engine/Editor/EditorGUI.cpp b/src/Engine/Editor/EditorGUI.cpp index 68a136c3..1bf0f9e9 100644 --- a/src/Engine/Editor/EditorGUI.cpp +++ b/src/Engine/Editor/EditorGUI.cpp @@ -35,46 +35,30 @@ void EditorGUI::drawTools() return; } - GLuint translateIcon = 0; - try { - translateIcon = ResourceManager::Load("Textures/Icons/Translate.png")->m_Texture; - } catch (const std::exception&) { } - GLuint rotateIcon = 0; - try { - rotateIcon = ResourceManager::Load("Textures/Icons/Rotate.png")->m_Texture; - } catch (const std::exception&) { } - GLuint scaleIcon = 0; - try { - scaleIcon = ResourceManager::Load("Textures/Icons/Scale.png")->m_Texture; - } catch (const std::exception&) { } + // Translate widget button + ImGui::ImageButton((void*)tryLoadTexture("Textures/Icons/Translate.png"), ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0)); + // Rotate widget button + ImGui::SameLine(); + ImGui::ImageButton((void*)tryLoadTexture("Textures/Icons/Rotate.png"), ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0)); + // Scale widget button + ImGui::SameLine(); + ImGui::ImageButton((void*)tryLoadTexture("Textures/Icons/Scale.png"), ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0)); - ImGui::ImageButton((void*)translateIcon, ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0)); - ImGui::SameLine(); - ImGui::ImageButton((void*)rotateIcon, ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0)); - ImGui::SameLine(); - ImGui::ImageButton((void*)scaleIcon, ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0)); ImGui::SameLine(); ImGui::ItemSize(ImVec2(5, 0)); + + // Play button ImGui::SameLine(); - - GLuint playIcon = 0; - try { - playIcon = ResourceManager::Load("Textures/Icons/Play.png")->m_Texture; - } catch (const std::exception&) { } - GLuint pauseIcon = 0; - try { - pauseIcon = ResourceManager::Load("Textures/Icons/Pause.png")->m_Texture; - } catch (const std::exception&) { } - static bool paused = false; - if (ImGui::ImageButton((void*)playIcon, ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0), -1, ImVec4(0, 0, 0, 0), (!paused) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1))) { + if (ImGui::ImageButton((void*)tryLoadTexture("Textures/Icons/Play.png"), ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0), -1, ImVec4(0, 0, 0, 0), (!paused) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1))) { Events::Resume e; e.World = m_World; m_EventBroker->Publish(e); paused = false; } + // Pause button ImGui::SameLine(); - if (ImGui::ImageButton((void*)pauseIcon, ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0), -1, ImVec4(0, 0, 0, 0), (paused) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1))) { + if (ImGui::ImageButton((void*)tryLoadTexture("Textures/Icons/Pause.png"), ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0), -1, ImVec4(0, 0, 0, 0), (paused) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1))) { Events::Pause e; e.World = m_World; m_EventBroker->Publish(e); @@ -526,6 +510,15 @@ const std::string EditorGUI::formatEntityName(EntityWrapper entity) return name.str(); } +GLuint EditorGUI::tryLoadTexture(std::string filePath) +{ + GLuint texture = 0; + try { + texture = ResourceManager::Load(filePath)->m_Texture; + } catch (const std::exception&) { } + return texture; +} + void EditorGUI::entityImport(World* world) { boost::filesystem::path filePath = fileOpenDialog();