From ad03c601add058433eb6be42648a94ff5794c064 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Sun, 20 Oct 2019 17:09:44 +0200 Subject: [PATCH] add frame duplicate --- src/canvas_layer.cpp | 20 ++++++++++++++++++++ src/canvas_layer.h | 2 ++ src/node.cpp | 24 ++++++++++++++++++++++++ src/node.h | 4 ++++ src/node_panel_animation.cpp | 4 ++++ src/rtt.cpp | 8 ++++++++ src/rtt.h | 1 + 7 files changed, 63 insertions(+) diff --git a/src/canvas_layer.cpp b/src/canvas_layer.cpp index 3e48d24..8b93861 100644 --- a/src/canvas_layer.cpp +++ b/src/canvas_layer.cpp @@ -244,6 +244,11 @@ void Layer::remove_frame(int frame) m_frame_index = glm::clamp(m_frame_index, 0, (int)m_frames.size() - 1); } +void Layer::duplicate_frame(int frame) +{ + m_frames.insert(m_frames.begin() + frame + 1, m_frames[frame].clone()); +} + int Layer::total_duration() const noexcept { int duration = 0; @@ -436,3 +441,18 @@ void LayerFrame::clear(const glm::vec4& c) glClearColor(cc[0], cc[1], cc[2], cc[3]); }); } + +LayerFrame LayerFrame::clone() const noexcept +{ + LayerFrame dup; + dup.m_duration = m_duration; + dup.w = w; + dup.h = h; + for (int i = 0; i < 6; i++) + { + dup.m_rtt[i] = m_rtt[i].clone(); + dup.m_dirty_box[i] = m_dirty_box[i]; + dup.m_dirty_face[i] = m_dirty_face[i]; + } + return dup; +} diff --git a/src/canvas_layer.h b/src/canvas_layer.h index d773620..527cdf1 100644 --- a/src/canvas_layer.h +++ b/src/canvas_layer.h @@ -23,6 +23,7 @@ struct LayerFrame bool create(int width, int height, int duration = 1); bool resize(int width, int height); void clear(const glm::vec4& c); + LayerFrame clone() const noexcept; }; class Layer @@ -62,6 +63,7 @@ public: bool create(int width, int height, std::string name); bool add_frame(); void remove_frame(int frame); + void duplicate_frame(int frame); int total_duration() const noexcept; void goto_frame(int frame) noexcept; void clear(const glm::vec4& c, int frame = -1); diff --git a/src/node.cpp b/src/node.cpp index 5571656..dc81f9f 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -813,6 +813,30 @@ void Node::SetSize(glm::vec2 value) app_redraw(); } +void Node::SetMinSize(float w, float h) +{ + SetMinWidth(w); + SetMinHeight(h); +} + +void Node::SetMinSize(glm::vec2 value) +{ + SetMinWidth(value.x); + SetMinHeight(value.y); +} + +void Node::SetMaxSize(float w, float h) +{ + SetMaxWidth(w); + SetMaxHeight(h); +} + +void Node::SetMaxSize(glm::vec2 value) +{ + SetMaxWidth(value.x); + SetMaxHeight(value.y); +} + void Node::SetMaxWidth(float value) { YGNodeStyleSetMaxWidth(y_node, value); diff --git a/src/node.h b/src/node.h index 3583641..73b4062 100644 --- a/src/node.h +++ b/src/node.h @@ -156,6 +156,10 @@ public: void SetHeightP(float value); void SetSize(glm::vec2 value); void SetSize(float w, float h); + void SetMinSize(float w, float h); + void SetMaxSize(float w, float h); + void SetMinSize(glm::vec2 value); + void SetMaxSize(glm::vec2 value); void SetMaxWidth(float value); void SetMaxWidthP(float value); void SetMaxHeight(float value); diff --git a/src/node_panel_animation.cpp b/src/node_panel_animation.cpp index e818b40..111bff4 100644 --- a/src/node_panel_animation.cpp +++ b/src/node_panel_animation.cpp @@ -45,6 +45,10 @@ void NodePanelAnimation::init_controls() Canvas::I->layer().add_frame(); load_layers(); }; + btn_duplicate->on_click = [this](Node*) { + Canvas::I->layer().duplicate_frame(m_selected_frame_index); + load_layers(); + }; btn_remove->on_click = [this](Node*) { Canvas::I->layer_with_id(m_selected_frame_layer_id)->remove_frame(m_selected_frame_index); load_layers(); diff --git a/src/rtt.cpp b/src/rtt.cpp index 8cdd5b0..e0aac8d 100644 --- a/src/rtt.cpp +++ b/src/rtt.cpp @@ -174,6 +174,14 @@ void RTT::copy(const RTT& source, const glm::vec4& rect) }); } +RTT RTT::clone() const noexcept +{ + RTT dup; + dup.create(w, h); + dup.copy(*this); + return dup; +} + bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format, bool depth_buffer /*= false*/) { GLenum status = 0; diff --git a/src/rtt.h b/src/rtt.h index a9b6075..05e495a 100644 --- a/src/rtt.h +++ b/src/rtt.h @@ -29,6 +29,7 @@ public: void copy(const RTT& source); // copy a region void copy(const RTT& source, const glm::vec4& rect); + RTT clone() const noexcept; bool resize(int width, int height); bool create(int width, int height, int tex = -1, GLint internal_format = GL_RGBA8, bool depth_buffer = false); bool recreate() { return create(w, h); }