Skip to content

Commit

Permalink
texturev: Added load/save settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
bkaradzic committed Nov 29, 2017
1 parent f88c44a commit 81ded16
Showing 1 changed file with 63 additions and 6 deletions.
69 changes: 63 additions & 6 deletions tools/texturev/texturev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
*/

#include "common.h"

#include <bgfx/bgfx.h>

#include <bx/commandline.h>
#include <bx/os.h>
#include <bx/easing.h>
#include <bx/file.h>
#include <bx/filepath.h>
#include <bx/uint32_t.h>
#include <bx/math.h>
#include <bx/easing.h>
#include <bx/os.h>
#include <bx/process.h>
#include <bx/settings.h>
#include <bx/uint32_t.h>

#include <entry/entry.h>
#include <entry/input.h>
#include <entry/cmd.h>
Expand All @@ -19,9 +25,6 @@

#include <dirent.h>

#include <bx/file.h>
#include <bx/process.h>

#include <tinystl/allocator.h>
#include <tinystl/vector.h>
namespace stl = tinystl;
Expand Down Expand Up @@ -228,6 +231,7 @@ struct View
, m_files(false)
, m_sdf(false)
{
load();
}

~View()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::string> FileList;
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 81ded16

Please sign in to comment.