#pragma once #include "node_border.h" #include "node_text.h" #include "node_checkbox.h" #include "node_slider.h" #include "node_button_custom.h" #include "node_combobox.h" #include "node_scroll.h" #include "action.h" #include "canvas_layer.h" class NodeLayer : public NodeBorder { public: std::function on_selected; std::function on_visibility_changed; std::function on_highlight; bool m_selected = false; glm::vec4 m_color_normal = glm::vec4(.4, .4, .4, 1); glm::vec4 m_color_selected = glm::vec4(.3, .3, .3, 1); glm::vec4 m_color_hover = glm::vec4(.5, .5, .5, 1); std::string m_label_text; NodeText* m_label; NodeCheckBox* m_visibility; virtual Node* clone_instantiate() const override; virtual void clone_children(Node* dest) const override; virtual void clone_copy(Node* dest) const override; virtual void init() override; virtual void parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr) override; virtual void loaded() override; virtual kEventResult handle_event(Event* e) override; virtual void draw() override; void set_name(const char* s); }; class NodePanelLayer : public Node { NodeButtonCustom* btn_add; NodeButtonCustom* btn_remove; NodeButtonCustom* btn_up; NodeButtonCustom* btn_down; NodeButtonCustom* btn_duplicate; int id_counter = 0; public: std::function on_popup_close; std::function on_layer_change; std::function on_layer_opacity_changed; std::function on_layer_visibility_changed; std::function on_layer_alpha_lock_changed; std::function on_layer_highlight_changed; std::function on_layer_blend_mode_changed; std::function on_layer_delete; std::function on_layer_duplicate; std::function layer, int index)> on_layer_add; std::function on_layer_order; NodeLayer* m_current_layer = nullptr; std::vector m_layers; NodeScroll* m_layers_container; NodeSliderH* m_opacity; NodeCheckBox* m_alpha_lock; NodeComboBox* m_blend_mode; virtual Node* clone_instantiate() const override; virtual void init() override; virtual kEventResult handle_event(Event* e) override; void merge(int src_index, int dst_index, bool create_history); void add_layer(bool add_history = true, bool create_events = false); NodeLayer* add_layer(const char* name, bool add_history = true, bool create_events = false, std::shared_ptr layer = nullptr, std::shared_ptr layer_node = nullptr, int index = -1); NodeLayer* get_layer_at(int index); void remove_layer(NodeLayer* layer, bool add_history = true); void handle_layer_opacity(NodeLayer* target, float value); void handle_layer_visibility(NodeLayer* target, bool visible); void handle_layer_alpha_lock(NodeLayer* target, bool locked); void handle_layer_highlight(NodeLayer* target, bool highlight); void handle_layer_blend_mode(NodeLayer* target, int mode); void handle_layer_selected(NodeLayer* target); void save_history(); void clear(); void update_attributes(); }; struct ActionLayerChange : public Action { struct LayerState { bool visible; float alpha; bool lock; int blend_mode; }; NodePanelLayer* m_panel; std::vector m_layers; virtual void run() override { } virtual Action* get_redo() override; virtual void undo() override; virtual size_t memory() override { return 0; } }; class ActionLayerAdd : public Action { public: NodePanelLayer* m_panel; std::shared_ptr m_layer_node; int m_layer_order; uint32_t m_layer_id; virtual void run() override { } virtual Action* get_redo() override; virtual void undo() override; virtual size_t memory() override { return 0; } }; class ActionLayerRemove : public Action { public: NodePanelLayer* m_panel; std::shared_ptr m_layer_node; std::shared_ptr m_layer; int m_layer_order; virtual void run() override { } virtual Action* get_redo() override; virtual void undo() override; virtual size_t memory() override { return 0; } }; class ActionLayerMove : public Action { public: NodePanelLayer* m_panel; std::shared_ptr m_layer_node; int m_offset; virtual void run() override { } virtual Action* get_redo() override; virtual void undo() override; virtual size_t memory() override { return 0; } }; struct ActionLayerMerge : public Action { std::shared_ptr m_snap; std::shared_ptr m_layer; std::shared_ptr m_layer_node; std::shared_ptr m_panel; int m_src_index = 0; // removed layer int m_dst_index = 0; std::array m_dirty_box; std::array m_dirty_face; virtual void run() override { } virtual size_t memory() override { return m_snap->memsize(); } virtual void undo() override; virtual Action* get_redo() override; };