App::I static singleton to pointer

This commit is contained in:
2019-07-11 18:08:17 +02:00
parent 92dd00d910
commit b89274e7a6
33 changed files with 417 additions and 412 deletions

View File

@@ -48,8 +48,8 @@ bool NodeButtonBrush::read(BinaryStreamReader& r)
d.value<Serializer::CString>("high_path", high_path);
d.value<Serializer::CString>("thumb_path", thumb_path);
d.value<Serializer::Boolean>("m_user_brush", m_user_brush);
high_path = str_replace(high_path, "{data_path}", App::I.data_path);
thumb_path = str_replace(thumb_path, "{data_path}", App::I.data_path);
high_path = str_replace(high_path, "{data_path}", App::I->data_path);
thumb_path = str_replace(thumb_path, "{data_path}", App::I->data_path);
return true;
}
@@ -60,9 +60,9 @@ void NodeButtonBrush::write(BinaryStreamWriter& w) const
d.name = L"Brush class";
d.props["brush_name"] = std::make_shared<Serializer::CString>(brush_name);
d.props["high_path"] = std::make_shared<Serializer::CString>(
str_replace(high_path, App::I.data_path, "{data_path}"));
str_replace(high_path, App::I->data_path, "{data_path}"));
d.props["thumb_path"] = std::make_shared<Serializer::CString>(
str_replace(thumb_path, App::I.data_path, "{data_path}"));
str_replace(thumb_path, App::I->data_path, "{data_path}"));
d.props["m_user_brush"] = std::make_shared<Serializer::Boolean>(m_user_brush);
w << d;
}
@@ -78,7 +78,7 @@ void NodePanelBrush::init()
m_btn_add = find<NodeButtonCustom>("btn-add");
m_btn_add->on_click = [this](Node*) {
App::I.pick_file({ "JPG", "PNG" }, [this](std::string path) {
App::I->pick_file({ "JPG", "PNG" }, [this](std::string path) {
std::string name, base, ext;
std::regex r(R"((.*)[\\/]([^\\/]+)\.(\w+)$)");
std::smatch m;
@@ -90,8 +90,8 @@ void NodePanelBrush::init()
Image img;
if (!m_dir_name.empty() && img.load_file(path))
{
std::string path_high = App::I.data_path + "/" + m_dir_name + "/" + name + ".png";
std::string path_thumb = App::I.data_path + "/" + m_dir_name + "/thumbs/" + name + ".png";
std::string path_high = App::I->data_path + "/" + m_dir_name + "/" + name + ".png";
std::string path_thumb = App::I->data_path + "/" + m_dir_name + "/thumbs/" + name + ".png";
//img = img.resize_squared(glm::u8vec4(255));
if (m_dir_name == "brushes")
@@ -170,11 +170,11 @@ void NodePanelBrush::init()
m_container = find<NodeScroll>("brushes");
if (Asset::exist(App::I.data_path + "/settings/" + m_dir_name + ".bin") && !restore())
if (Asset::exist(App::I->data_path + "/settings/" + m_dir_name + ".bin") && !restore())
{
auto mb = App::I.message_box("Brushes", "Could not read brush textures file, it will be deleted.", true);
auto mb = App::I->message_box("Brushes", "Could not read brush textures file, it will be deleted.", true);
mb->btn_ok->on_click = [this, mb](Node*) {
Asset::delete_file(App::I.data_path + "/settings/" + m_dir_name + ".bin");
Asset::delete_file(App::I->data_path + "/settings/" + m_dir_name + ".bin");
mb->destroy();
};
mb->btn_cancel->on_click = [mb](Node*) {
@@ -202,11 +202,11 @@ void NodePanelBrush::init()
brush->on_click = std::bind(&NodePanelBrush::handle_click, this, std::placeholders::_1);
}
auto custom_icons = Asset::list_files(App::I.data_path + "/" + m_dir_name, ".*\\.png$");
auto custom_icons = Asset::list_files(App::I->data_path + "/" + m_dir_name, ".*\\.png$");
for (auto& i : custom_icons)
{
std::string path_thumb = App::I.data_path + "/" + m_dir_name + "/thumbs/" + i;
std::string path_high = App::I.data_path + "/" + m_dir_name + "/" + i;
std::string path_thumb = App::I->data_path + "/" + m_dir_name + "/thumbs/" + i;
std::string path_high = App::I->data_path + "/" + m_dir_name + "/" + i;
NodeButtonBrush* brush = new NodeButtonBrush;
m_container->add_child(brush);
brush->init();
@@ -287,7 +287,7 @@ std::string NodePanelBrush::get_thumb_path(int index) const
bool NodePanelBrush::save()
{
std::ofstream f(App::I.data_path + "/settings/" + m_dir_name + ".bin", std::ios::binary);
std::ofstream f(App::I->data_path + "/settings/" + m_dir_name + ".bin", std::ios::binary);
if (f.good())
{
BinaryStreamWriter sw;
@@ -310,7 +310,7 @@ bool NodePanelBrush::save()
bool NodePanelBrush::restore()
{
Asset f;
auto path = App::I.data_path + "/settings/" + m_dir_name + ".bin";
auto path = App::I->data_path + "/settings/" + m_dir_name + ".bin";
if (f.open(path.c_str()))
{
f.read_all();
@@ -457,11 +457,11 @@ void NodePanelBrushPreset::init()
save();
};
if (Asset::exist(App::I.data_path + "/settings/presets.bin") && !restore())
if (Asset::exist(App::I->data_path + "/settings/presets.bin") && !restore())
{
auto mb = App::I.message_box("Presets", "Could not read brush presets file, it will be deleted.", true);
auto mb = App::I->message_box("Presets", "Could not read brush presets file, it will be deleted.", true);
mb->btn_ok->on_click = [mb](Node*) {
Asset::delete_file(App::I.data_path + "/settings/presets.bin");
Asset::delete_file(App::I->data_path + "/settings/presets.bin");
mb->destroy();
};
mb->btn_cancel->on_click = [mb](Node*) {
@@ -509,7 +509,7 @@ void NodePanelBrushPreset::handle_click(Node* target)
bool NodePanelBrushPreset::save()
{
std::ofstream f(App::I.data_path + "/settings/presets.bin", std::ios::binary);
std::ofstream f(App::I->data_path + "/settings/presets.bin", std::ios::binary);
if (f.good())
{
BinaryStreamWriter sw;
@@ -532,7 +532,7 @@ bool NodePanelBrushPreset::save()
bool NodePanelBrushPreset::restore()
{
Asset f;
auto path = App::I.data_path + "/settings/presets.bin";
auto path = App::I->data_path + "/settings/presets.bin";
if (f.open(path.c_str()))
{
f.read_all();