save and restore layers image when context is lost in Android

This commit is contained in:
2017-04-29 21:30:40 +01:00
parent 2e47ccb0c6
commit fa49d9ee09
17 changed files with 210 additions and 69 deletions

View File

@@ -101,6 +101,8 @@ public:
auto i = m_layouts.find(id);
return i == m_layouts.end() ? nullptr : i->second.get();
}
void restore_context();
void clear_context();
//Node& operator[](const char* ids) { return m_layouts[const_hash(ids)]; }
};
@@ -222,10 +224,13 @@ public:
virtual void restore_context()
{
for (auto& c : m_children)
{
c->restore_context();
}
};
virtual void clear_context()
{
for (auto& c : m_children)
c->clear_context();
}
void update(float width, float height, float zoom);
void update();
void update_internal(const glm::vec2& origin, const glm::mat4& proj);
@@ -482,6 +487,7 @@ public:
{
if (!m_path.empty() && TextureManager::load(m_path.c_str()))
{
//LOG("load image node %s", m_path.c_str());
auto tex_sz = TextureManager::get(m_tex_id).size();
m_off = m_region.xy / tex_sz;
m_sz = (m_region.zw - m_region.xy) / tex_sz;
@@ -885,6 +891,7 @@ public:
i += strlen(s) + 1;
}
file.close();
TextureManager::load("data/spritesheet.png");
}
virtual Node* clone_instantiate() const override { return new NodeIcon(); }
virtual void clone_copy(Node* dest) const override
@@ -1700,7 +1707,13 @@ public:
{
NodeBorder::restore_context();
init_controls();
m_rtt.create(m_rtt.getWidth(), m_rtt.getHeight());
if (m_size.x > 0 && m_size.y > 0)
m_rtt.create(m_size.x, m_size.y);
}
virtual void clear_context() override
{
NodeBorder::clear_context();
m_rtt.destroy();
}
void draw_stroke()
{
@@ -1856,6 +1869,7 @@ class NodeCanvas : public Node
float m_zoom_start;
bool method = true;
public:
std::string data_path;
std::unique_ptr<ui::Canvas> m_canvas;
ui::Brush m_brush;
Sampler m_sampler;
@@ -1876,7 +1890,15 @@ public:
Node::restore_context();
m_canvas->create(512, 512);
m_sampler.create();
//m_canvas->clear();
m_face_plane.create<1>(2, 2);
m_canvas->snapshot_restore();
}
virtual void clear_context() override
{
Node::clear_context();
m_canvas->snapshot_save(data_path);
m_canvas->clear_context();
}
virtual void draw() override
{