From 81ded1629078d06a3a8434846999d292817f00b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 28 Nov 2017 19:18:46 -0800 Subject: [PATCH] texturev: Added load/save settings. --- tools/texturev/texturev.cpp | 71 +++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/tools/texturev/texturev.cpp b/tools/texturev/texturev.cpp index dfa4370ac..adcdea67a 100644 --- a/tools/texturev/texturev.cpp +++ b/tools/texturev/texturev.cpp @@ -4,13 +4,19 @@ */ #include "common.h" + #include + #include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include + #include #include #include @@ -19,9 +25,6 @@ #include -#include -#include - #include #include namespace stl = tinystl; @@ -228,6 +231,7 @@ struct View , m_files(false) , m_sdf(false) { + load(); } ~View() @@ -568,6 +572,10 @@ struct View { m_help ^= true; } + else if (0 == bx::strCmp(_argv[1], "save") ) + { + save(); + } else if (0 == bx::strCmp(_argv[1], "info") ) { m_info ^= true; @@ -652,6 +660,48 @@ struct View } } + void load() + { + bx::FilePath filePath(bx::Dir::Home); + filePath.join(".config/bgfx/texturev.ini"); + + bx::Settings settings(entry::getAllocator() ); + + bx::FileReader reader; + if (bx::open(&reader, filePath) ) + { + bx::read(&reader, settings); + bx::close(&reader); + + if (!bx::fromString(&m_transitionTime, settings.get("view/transition") ) ) + { + m_transitionTime = 1.0f; + } + } + } + + void save() + { + bx::FilePath filePath(bx::Dir::Home); + filePath.join(".config/bgfx/texturev.ini"); + + if (bx::makeAll(filePath.getPath() ) ) + { + bx::Settings settings(entry::getAllocator() ); + + char tmp[256]; + bx::toString(tmp, sizeof(tmp), m_transitionTime); + settings.set("view/transition", tmp); + + bx::FileWriter writer; + if (bx::open(&writer, filePath) ) + { + bx::write(&writer, settings); + bx::close(&writer); + } + } + } + bx::FilePath m_path; typedef stl::vector FileList; @@ -1350,6 +1400,13 @@ int _main_(int _argc, char** _argv) cmdExec("view rgb a"); } + ImGui::Separator(); + + if (ImGui::MenuItem("Save Options") ) + { + cmdExec("view save"); + } + ImGui::EndMenu(); }