diff --git a/modules/paint/actions/cut_action.cpp b/modules/paint/actions/cut_action.cpp index 8b86d9117..2d1130e19 100644 --- a/modules/paint/actions/cut_action.cpp +++ b/modules/paint/actions/cut_action.cpp @@ -56,7 +56,7 @@ void CutAction::set_mouse_start_pos_set(const bool val) { mouse_start_pos_set = val; } -bool CutAction::can_commit() { +bool CutAction::_can_commit() { return false; //ugly way of handling a cut } diff --git a/modules/paint/actions/cut_action.h b/modules/paint/actions/cut_action.h index eaa4c5a05..8ca36891c 100644 --- a/modules/paint/actions/cut_action.h +++ b/modules/paint/actions/cut_action.h @@ -45,7 +45,7 @@ public: bool get_mouse_start_pos_set(); void set_mouse_start_pos_set(const bool val); - bool can_commit(); + bool _can_commit(); void do_action_old(PaintCanvasOld *canvas, const Array &data); void commit_action_old(PaintCanvasOld *canvas); diff --git a/modules/paint/actions/line_action.cpp b/modules/paint/actions/line_action.cpp index 9a529bee5..e578c3bff 100644 --- a/modules/paint/actions/line_action.cpp +++ b/modules/paint/actions/line_action.cpp @@ -98,7 +98,7 @@ void LineAction::commit_action_old(PaintCanvasOld *canvas) { mouse_start_pos_set = false; } -bool LineAction::can_commit() { +bool LineAction::_can_commit() { return true; } diff --git a/modules/paint/actions/line_action.h b/modules/paint/actions/line_action.h index e12ddafef..9857c13d2 100644 --- a/modules/paint/actions/line_action.h +++ b/modules/paint/actions/line_action.h @@ -41,7 +41,7 @@ public: void do_action_old(PaintCanvasOld *canvas, const Array &data); void commit_action_old(PaintCanvasOld *canvas); - bool can_commit(); + bool _can_commit(); LineAction(); ~LineAction(); diff --git a/modules/paint/actions/multiline_action.cpp b/modules/paint/actions/multiline_action.cpp index df009ce99..aaff38e89 100644 --- a/modules/paint/actions/multiline_action.cpp +++ b/modules/paint/actions/multiline_action.cpp @@ -28,7 +28,7 @@ SOFTWARE. #include "../deprecated/paint_canvas_layer.h" #include "../paint_utilities.h" -bool MultiLineAction::can_commit() { +bool MultiLineAction::_can_commit() { return false; } diff --git a/modules/paint/actions/multiline_action.h b/modules/paint/actions/multiline_action.h index 4e5c41def..2b455642f 100644 --- a/modules/paint/actions/multiline_action.h +++ b/modules/paint/actions/multiline_action.h @@ -33,7 +33,7 @@ class MultiLineAction : public PaintAction { GDCLASS(MultiLineAction, PaintAction); public: - bool can_commit(); + bool _can_commit(); void do_action_old(PaintCanvasOld *canvas, const Array &data); //void commit_action_old(PaintCanvasOld *canvas); diff --git a/modules/paint/actions/paint_action.cpp b/modules/paint/actions/paint_action.cpp index 5624a4cdb..451fcf903 100644 --- a/modules/paint/actions/paint_action.cpp +++ b/modules/paint/actions/paint_action.cpp @@ -28,6 +28,18 @@ SOFTWARE. #include "../deprecated/paint_canvas_layer.h" #include "core/object/object.h" +#include "../nodes/paint_canvas.h" + +PaintCanvas *PaintAction::get_canvas() { + return _canvas; +} +void PaintAction::set_canvas(PaintCanvas *canvas) { + _canvas = canvas; +} +void PaintAction::set_canvas_bind(Node *canvas) { + set_canvas(Object::cast_to(canvas)); +} + Dictionary PaintAction::get_action_data_undo() { return action_data_undo; } @@ -123,6 +135,10 @@ void PaintAction::redo_action_old(PaintCanvasOld *canvas) { } bool PaintAction::can_commit() { + return call("_can_commit"); +} + +bool PaintAction::_can_commit() { return !redo_cells.empty(); } @@ -259,6 +275,30 @@ void PaintAction::draw_points(PaintCanvasOld *canvas, const PoolVector2iArray &p } } +void PaintAction::do_action(const Array &data) { + call("_do_action", data); +} +void PaintAction::commit_action() { + call("_commit_action"); +} + +void PaintAction::undo_action() { + call("_undo_action"); +} +void PaintAction::redo_action() { + call("_redo_action"); +} + +void PaintAction::_do_action(const Array &data) { +} +void PaintAction::_commit_action() { +} + +void PaintAction::_undo_action() { +} +void PaintAction::_redo_action() { +} + PaintAction::PaintAction() { } @@ -302,11 +342,26 @@ void PaintAction::_bind_methods() { ClassDB::bind_method(D_METHOD("set_preview_colors", "value"), &PaintAction::set_preview_colors); ADD_PROPERTY(PropertyInfo(Variant::POOL_COLOR_ARRAY, "preview_colors"), "set_preview_colors", "get_preview_colors"); - //ClassDB::bind_method(D_METHOD("get_layer"), &PaintAction::get_layer); - //ClassDB::bind_method(D_METHOD("set_layer", "value"), &PaintAction::set_layer); - //ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "layer", PROPERTY_HINT_RESOURCE_TYPE, "PaintCanvasLayer", 0), "set_layer", "get_layer"); - ClassDB::bind_method(D_METHOD("get_action_data"), &PaintAction::get_action_data); ClassDB::bind_method(D_METHOD("set_action_data", "value"), &PaintAction::set_action_data); ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "action_data"), "set_action_data", "get_action_data"); + + BIND_VMETHOD(MethodInfo("_do_action", PropertyInfo(Variant::ARRAY, "data"))); + BIND_VMETHOD(MethodInfo("_commit_action")); + BIND_VMETHOD(MethodInfo("_undo_action")); + BIND_VMETHOD(MethodInfo("_redo_action")); + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::BOOL, "ret"), "_can_commit")); + + ClassDB::bind_method(D_METHOD("do_action", "data"), &PaintAction::do_action); + ClassDB::bind_method(D_METHOD("commit_action"), &PaintAction::commit_action); + ClassDB::bind_method(D_METHOD("undo_action"), &PaintAction::undo_action); + ClassDB::bind_method(D_METHOD("redo_action"), &PaintAction::redo_action); + + ClassDB::bind_method(D_METHOD("_do_action", "data"), &PaintAction::do_action); + ClassDB::bind_method(D_METHOD("_commit_action"), &PaintAction::commit_action); + ClassDB::bind_method(D_METHOD("_undo_action"), &PaintAction::undo_action); + ClassDB::bind_method(D_METHOD("_redo_action"), &PaintAction::redo_action); + + ClassDB::bind_method(D_METHOD("can_commit"), &PaintAction::get_action_data); + ClassDB::bind_method(D_METHOD("_can_commit"), &PaintAction::get_action_data); } diff --git a/modules/paint/actions/paint_action.h b/modules/paint/actions/paint_action.h index ef6aa8934..3ea52fee6 100644 --- a/modules/paint/actions/paint_action.h +++ b/modules/paint/actions/paint_action.h @@ -34,12 +34,18 @@ SOFTWARE. #include "core/variant/variant.h" class PaintCanvasOld; +class PaintCanvas; class PaintCanvasLayer; +class Node; class PaintAction : public Resource { GDCLASS(PaintAction, Resource); public: + PaintCanvas *get_canvas(); + void set_canvas(PaintCanvas *canvas); + void set_canvas_bind(Node *canvas); + Dictionary get_action_data_undo(); void set_action_data_undo(const Dictionary &val); @@ -67,6 +73,7 @@ public: PoolColorArray get_preview_colors(); void set_preview_colors(const PoolColorArray &val); + //deprecated Ref get_layer(); void set_layer(const Ref &val); @@ -79,7 +86,20 @@ public: virtual void undo_action_old(PaintCanvasOld *canvas); virtual void redo_action_old(PaintCanvasOld *canvas); - virtual bool can_commit(); + void do_action(const Array &data); + void commit_action(); + + void undo_action(); + void redo_action(); + + virtual void _do_action(const Array &data); + virtual void _commit_action(); + + virtual void _undo_action(); + virtual void _redo_action(); + + bool can_commit(); + virtual bool _can_commit(); virtual PoolVector2iArray get_x_sym_points(const int canvas_width, const Vector2i &pixel); virtual PoolVector2iArray get_y_sym_points(const int canvas_height, const Vector2i &pixel); @@ -110,6 +130,8 @@ public: protected: static void _bind_methods(); + + PaintCanvas *_canvas; }; #endif diff --git a/modules/paint/actions/rect_action.cpp b/modules/paint/actions/rect_action.cpp index 148dc45aa..0ca7d881e 100644 --- a/modules/paint/actions/rect_action.cpp +++ b/modules/paint/actions/rect_action.cpp @@ -105,7 +105,7 @@ void RectAction::commit_action_old(PaintCanvasOld *canvas) { mouse_start_pos_set = false; } -bool RectAction::can_commit() { +bool RectAction::_can_commit() { return true; } diff --git a/modules/paint/actions/rect_action.h b/modules/paint/actions/rect_action.h index cc14c7f99..9ade547fe 100644 --- a/modules/paint/actions/rect_action.h +++ b/modules/paint/actions/rect_action.h @@ -41,7 +41,7 @@ public: void do_action_old(PaintCanvasOld *canvas, const Array &data); void commit_action_old(PaintCanvasOld *canvas); - bool can_commit(); + bool _can_commit(); RectAction(); ~RectAction();