Renamed do and undo methods in PaintAction.

This commit is contained in:
Relintai 2022-11-15 11:49:03 +01:00
parent b05babe4b2
commit c2e8a32c90
26 changed files with 78 additions and 77 deletions

View File

@ -35,8 +35,8 @@ void BrightenAction::set_brighten_color(const float val) {
brighten_color = val; brighten_color = val;
} }
void BrightenAction::do_action(PaintCanvasOld *canvas, const Array &data) { void BrightenAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action(canvas, data); PaintAction::do_action_old(canvas, data);
PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]); PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]);

View File

@ -36,7 +36,7 @@ public:
float get_brighten_color(); float get_brighten_color();
void set_brighten_color(const float val); void set_brighten_color(const float val);
void do_action(PaintCanvasOld *canvas, const Array &data); void do_action_old(PaintCanvasOld *canvas, const Array &data);
BrightenAction(); BrightenAction();
~BrightenAction(); ~BrightenAction();

View File

@ -29,8 +29,8 @@ SOFTWARE.
#include "../deprecated/paint_canvas_layer.h" #include "../deprecated/paint_canvas_layer.h"
#include "../paint_utilities.h" #include "../paint_utilities.h"
void BrushAction::do_action(PaintCanvasOld *canvas, const Array &data) { void BrushAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action(canvas, data); PaintAction::do_action_old(canvas, data);
PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]); PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]);
int brush_type = data[3]; int brush_type = data[3];

View File

@ -33,7 +33,7 @@ class BrushAction : public PaintAction {
GDCLASS(BrushAction, PaintAction); GDCLASS(BrushAction, PaintAction);
public: public:
void do_action(PaintCanvasOld *canvas, const Array &data); void do_action_old(PaintCanvasOld *canvas, const Array &data);
BrushAction(); BrushAction();
~BrushAction(); ~BrushAction();

View File

@ -28,8 +28,8 @@ SOFTWARE.
#include "../deprecated/paint_canvas_layer.h" #include "../deprecated/paint_canvas_layer.h"
#include "../paint_utilities.h" #include "../paint_utilities.h"
void BucketAction::do_action(PaintCanvasOld *canvas, const Array &data) { void BucketAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action(canvas, data); PaintAction::do_action_old(canvas, data);
Vector2i pos = data[0]; Vector2i pos = data[0];

View File

@ -33,7 +33,7 @@ class BucketAction : public PaintAction {
GDCLASS(BucketAction, PaintAction); GDCLASS(BucketAction, PaintAction);
public: public:
void do_action(PaintCanvasOld *canvas, const Array &data); void do_action_old(PaintCanvasOld *canvas, const Array &data);
BucketAction(); BucketAction();
~BucketAction(); ~BucketAction();

View File

@ -60,8 +60,8 @@ bool CutAction::can_commit() {
return false; //ugly way of handling a cut return false; //ugly way of handling a cut
} }
void CutAction::do_action(PaintCanvasOld *canvas, const Array &data) { void CutAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action(canvas, data); PaintAction::do_action_old(canvas, data);
if (!mouse_start_pos_set) { if (!mouse_start_pos_set) {
mouse_start_pos = data[0]; mouse_start_pos = data[0];
@ -91,7 +91,7 @@ void CutAction::do_action(PaintCanvasOld *canvas, const Array &data) {
} }
} }
void CutAction::commit_action(PaintCanvasOld *canvas) { void CutAction::commit_action_old(PaintCanvasOld *canvas) {
canvas->clear_preview_layer(); canvas->clear_preview_layer();
Vector2i p = mouse_start_pos; Vector2i p = mouse_start_pos;
Vector2i s = mouse_end_pos - mouse_start_pos; Vector2i s = mouse_end_pos - mouse_start_pos;

View File

@ -47,8 +47,8 @@ public:
bool can_commit(); bool can_commit();
void do_action(PaintCanvasOld *canvas, const Array &data); void do_action_old(PaintCanvasOld *canvas, const Array &data);
void commit_action(PaintCanvasOld *canvas); void commit_action_old(PaintCanvasOld *canvas);
CutAction(); CutAction();
~CutAction(); ~CutAction();

View File

@ -35,8 +35,8 @@ void DarkenAction::set_dark_factor(const float val) {
dark_factor = val; dark_factor = val;
} }
void DarkenAction::do_action(PaintCanvasOld *canvas, const Array &data) { void DarkenAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action(canvas, data); PaintAction::do_action_old(canvas, data);
PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]); PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]);

View File

@ -36,7 +36,7 @@ public:
float get_dark_factor(); float get_dark_factor();
void set_dark_factor(const float val); void set_dark_factor(const float val);
void do_action(PaintCanvasOld *canvas, const Array &data); void do_action_old(PaintCanvasOld *canvas, const Array &data);
DarkenAction(); DarkenAction();
~DarkenAction(); ~DarkenAction();

View File

@ -42,8 +42,8 @@ void LineAction::set_mouse_start_pos_set(const bool val) {
mouse_start_pos_set = val; mouse_start_pos_set = val;
} }
void LineAction::do_action(PaintCanvasOld *canvas, const Array &data) { void LineAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action(canvas, data); PaintAction::do_action_old(canvas, data);
if (!mouse_start_pos_set) { if (!mouse_start_pos_set) {
mouse_start_pos = data[0]; mouse_start_pos = data[0];
@ -74,7 +74,7 @@ void LineAction::do_action(PaintCanvasOld *canvas, const Array &data) {
} }
} }
void LineAction::commit_action(PaintCanvasOld *canvas) { void LineAction::commit_action_old(PaintCanvasOld *canvas) {
canvas->clear_preview_layer(); canvas->clear_preview_layer();
for (int i = 0; i < preview_cells.size(); ++i) { for (int i = 0; i < preview_cells.size(); ++i) {

View File

@ -39,8 +39,8 @@ public:
bool get_mouse_start_pos_set(); bool get_mouse_start_pos_set();
void set_mouse_start_pos_set(const bool val); void set_mouse_start_pos_set(const bool val);
void do_action(PaintCanvasOld *canvas, const Array &data); void do_action_old(PaintCanvasOld *canvas, const Array &data);
void commit_action(PaintCanvasOld *canvas); void commit_action_old(PaintCanvasOld *canvas);
bool can_commit(); bool can_commit();
LineAction(); LineAction();

View File

@ -32,8 +32,8 @@ bool MultiLineAction::can_commit() {
return false; return false;
} }
void MultiLineAction::do_action(PaintCanvasOld *canvas, const Array &data) { void MultiLineAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action(canvas, data); PaintAction::do_action_old(canvas, data);
PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]); PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]);

View File

@ -35,8 +35,8 @@ class MultiLineAction : public PaintAction {
public: public:
bool can_commit(); bool can_commit();
void do_action(PaintCanvasOld *canvas, const Array &data); void do_action_old(PaintCanvasOld *canvas, const Array &data);
//void commit_action(PaintCanvasOld *canvas); //void commit_action_old(PaintCanvasOld *canvas);
MultiLineAction(); MultiLineAction();
~MultiLineAction(); ~MultiLineAction();

View File

@ -105,18 +105,18 @@ void PaintAction::set_action_data(const Dictionary &val) {
action_data = val; action_data = val;
} }
void PaintAction::do_action(PaintCanvasOld *canvas, const Array &data) { void PaintAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
layer = canvas->get_active_layer(); layer = canvas->get_active_layer();
} }
void PaintAction::commit_action(PaintCanvasOld *canvas) { void PaintAction::commit_action_old(PaintCanvasOld *canvas) {
} }
void PaintAction::undo_action(PaintCanvasOld *canvas) { void PaintAction::undo_action_old(PaintCanvasOld *canvas) {
for (int idx = 0; idx < undo_cells.size(); ++idx) { for (int idx = 0; idx < undo_cells.size(); ++idx) {
canvas->_set_pixel_v(layer, undo_cells[idx], undo_colors[idx]); canvas->_set_pixel_v(layer, undo_cells[idx], undo_colors[idx]);
} }
} }
void PaintAction::redo_action(PaintCanvasOld *canvas) { void PaintAction::redo_action_old(PaintCanvasOld *canvas) {
for (int idx = 0; idx < redo_cells.size(); ++idx) { for (int idx = 0; idx < redo_cells.size(); ++idx) {
canvas->_set_pixel_v(layer, redo_cells[idx], redo_colors[idx]); canvas->_set_pixel_v(layer, redo_cells[idx], redo_colors[idx]);
} }

View File

@ -73,11 +73,12 @@ public:
Dictionary get_action_data(); Dictionary get_action_data();
void set_action_data(const Dictionary &val); void set_action_data(const Dictionary &val);
virtual void do_action(PaintCanvasOld *canvas, const Array &data); virtual void do_action_old(PaintCanvasOld *canvas, const Array &data);
virtual void commit_action(PaintCanvasOld *canvas); virtual void commit_action_old(PaintCanvasOld *canvas);
virtual void undo_action_old(PaintCanvasOld *canvas);
virtual void redo_action_old(PaintCanvasOld *canvas);
virtual void undo_action(PaintCanvasOld *canvas);
virtual void redo_action(PaintCanvasOld *canvas);
virtual bool can_commit(); virtual bool can_commit();
virtual PoolVector2iArray get_x_sym_points(const int canvas_width, const Vector2i &pixel); virtual PoolVector2iArray get_x_sym_points(const int canvas_width, const Vector2i &pixel);

View File

@ -34,8 +34,8 @@ SOFTWARE.
//arr.append(_selection_colors); //arr.append(_selection_colors);
//arr.append(_cut_pos); //arr.append(_cut_pos);
//arr.append(_cut_size); //arr.append(_cut_size);
void PasteCutAction::do_action(PaintCanvasOld *canvas, const Array &data) { void PasteCutAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action(canvas, data); PaintAction::do_action_old(canvas, data);
PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]); PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]);
Vector2i cut_pos = data[4]; Vector2i cut_pos = data[4];

View File

@ -33,7 +33,7 @@ class PasteCutAction : public PaintAction {
GDCLASS(PasteCutAction, PaintAction); GDCLASS(PasteCutAction, PaintAction);
public: public:
void do_action(PaintCanvasOld *canvas, const Array &data); void do_action_old(PaintCanvasOld *canvas, const Array &data);
PasteCutAction(); PasteCutAction();
~PasteCutAction(); ~PasteCutAction();

View File

@ -29,8 +29,8 @@ SOFTWARE.
#include "../paint_utilities.h" #include "../paint_utilities.h"
#include "core/string/print_string.h" #include "core/string/print_string.h"
void PencilAction::do_action(PaintCanvasOld *canvas, const Array &data) { void PencilAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action(canvas, data); PaintAction::do_action_old(canvas, data);
Color c = data[2]; Color c = data[2];

View File

@ -33,7 +33,7 @@ class PencilAction : public PaintAction {
GDCLASS(PencilAction, PaintAction); GDCLASS(PencilAction, PaintAction);
public: public:
void do_action(PaintCanvasOld *canvas, const Array &data); void do_action_old(PaintCanvasOld *canvas, const Array &data);
void _set_pixel(PaintCanvasOld *canvas, Vector2i pixel, Color color); void _set_pixel(PaintCanvasOld *canvas, Vector2i pixel, Color color);

View File

@ -28,8 +28,8 @@ SOFTWARE.
#include "../deprecated/paint_canvas_layer.h" #include "../deprecated/paint_canvas_layer.h"
#include "../paint_utilities.h" #include "../paint_utilities.h"
void RainbowAction::do_action(PaintCanvasOld *canvas, const Array &data) { void RainbowAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action(canvas, data); PaintAction::do_action_old(canvas, data);
PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]); PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]);

View File

@ -33,7 +33,7 @@ class RainbowAction : public PaintAction {
GDCLASS(RainbowAction, PaintAction); GDCLASS(RainbowAction, PaintAction);
public: public:
void do_action(PaintCanvasOld *canvas, const Array &data); void do_action_old(PaintCanvasOld *canvas, const Array &data);
RainbowAction(); RainbowAction();
~RainbowAction(); ~RainbowAction();

View File

@ -42,8 +42,8 @@ void RectAction::set_mouse_start_pos_set(const bool val) {
mouse_start_pos_set = val; mouse_start_pos_set = val;
} }
void RectAction::do_action(PaintCanvasOld *canvas, const Array &data) { void RectAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action(canvas, data); PaintAction::do_action_old(canvas, data);
if (!mouse_start_pos_set) { if (!mouse_start_pos_set) {
mouse_start_pos = data[0]; mouse_start_pos = data[0];
@ -89,7 +89,7 @@ void RectAction::do_action(PaintCanvasOld *canvas, const Array &data) {
preview_colors.append(tc); preview_colors.append(tc);
} }
} }
void RectAction::commit_action(PaintCanvasOld *canvas) { void RectAction::commit_action_old(PaintCanvasOld *canvas) {
canvas->clear_preview_layer(); canvas->clear_preview_layer();
for (int idx = 0; idx < preview_cells.size(); ++idx) { for (int idx = 0; idx < preview_cells.size(); ++idx) {

View File

@ -39,8 +39,8 @@ public:
bool get_mouse_start_pos_set(); bool get_mouse_start_pos_set();
void set_mouse_start_pos_set(const bool val); void set_mouse_start_pos_set(const bool val);
void do_action(PaintCanvasOld *canvas, const Array &data); void do_action_old(PaintCanvasOld *canvas, const Array &data);
void commit_action(PaintCanvasOld *canvas); void commit_action_old(PaintCanvasOld *canvas);
bool can_commit(); bool can_commit();
RectAction(); RectAction();

View File

@ -256,7 +256,7 @@ void PaintWindow::_input(const Ref<InputEvent> &event) {
if (brush_mode == Tools::CUT) { if (brush_mode == Tools::CUT) {
if (iemb->get_button_index() == BUTTON_LEFT && !iemb->is_pressed()) { if (iemb->get_button_index() == BUTTON_LEFT && !iemb->is_pressed()) {
commit_action(); commit_action_old();
} }
} }
@ -273,7 +273,7 @@ void PaintWindow::_input(const Ref<InputEvent> &event) {
arr.append(last_cell_mouse_position); arr.append(last_cell_mouse_position);
arr.append(_selected_color); arr.append(_selected_color);
do_action(arr); do_action_old(arr);
} }
} break; } break;
case Tools::COLORPICKER: { case Tools::COLORPICKER: {
@ -302,7 +302,7 @@ void PaintWindow::_input(const Ref<InputEvent> &event) {
} break; } break;
case Tools::PASTECUT: { case Tools::PASTECUT: {
if (iemb->get_button_index() == BUTTON_RIGHT && iemb->is_pressed()) { if (iemb->get_button_index() == BUTTON_RIGHT && iemb->is_pressed()) {
commit_action(); commit_action_old();
set_brush(Tools::PAINT); set_brush(Tools::PAINT);
} }
} break; } break;
@ -385,10 +385,10 @@ void PaintWindow::_process(float delta) {
void PaintWindow::_handle_shortcuts(const int scancode) { void PaintWindow::_handle_shortcuts(const int scancode) {
switch (scancode) { switch (scancode) {
case K_UNDO: case K_UNDO:
undo_action(); undo_action_old();
break; break;
case K_REDO: case K_REDO:
redo_action(); redo_action_old();
break; break;
case K_PENCIL: case K_PENCIL:
set_brush(Tools::PAINT); set_brush(Tools::PAINT);
@ -595,7 +595,7 @@ void PaintWindow::brush_process() {
arr.append(last_cell_mouse_position); arr.append(last_cell_mouse_position);
arr.append(_selected_color); arr.append(_selected_color);
do_action(arr); do_action_old(arr);
} break; } break;
case Tools::BRUSH: { case Tools::BRUSH: {
Array arr; Array arr;
@ -606,7 +606,7 @@ void PaintWindow::brush_process() {
arr.append(selected_brush_prefab); arr.append(selected_brush_prefab);
arr.append(brush_size_slider->get_value()); arr.append(brush_size_slider->get_value());
do_action(arr); do_action_old(arr);
} break; } break;
case Tools::LINE: { case Tools::LINE: {
Array arr; Array arr;
@ -615,7 +615,7 @@ void PaintWindow::brush_process() {
arr.append(last_cell_mouse_position); arr.append(last_cell_mouse_position);
arr.append(_selected_color); arr.append(_selected_color);
do_action(arr); do_action_old(arr);
} break; } break;
case Tools::RECT: { case Tools::RECT: {
Array arr; Array arr;
@ -624,7 +624,7 @@ void PaintWindow::brush_process() {
arr.append(last_cell_mouse_position); arr.append(last_cell_mouse_position);
arr.append(_selected_color); arr.append(_selected_color);
do_action(arr); do_action_old(arr);
} break; } break;
case Tools::DARKEN: { case Tools::DARKEN: {
Array arr; Array arr;
@ -633,7 +633,7 @@ void PaintWindow::brush_process() {
arr.append(last_cell_mouse_position); arr.append(last_cell_mouse_position);
arr.append(_selected_color); arr.append(_selected_color);
do_action(arr); do_action_old(arr);
} break; } break;
case Tools::BRIGHTEN: { case Tools::BRIGHTEN: {
Array arr; Array arr;
@ -642,7 +642,7 @@ void PaintWindow::brush_process() {
arr.append(last_cell_mouse_position); arr.append(last_cell_mouse_position);
arr.append(_selected_color); arr.append(_selected_color);
do_action(arr); do_action_old(arr);
} break; } break;
case Tools::COLORPICKER: { case Tools::COLORPICKER: {
} break; } break;
@ -653,7 +653,7 @@ void PaintWindow::brush_process() {
arr.append(last_cell_mouse_position); arr.append(last_cell_mouse_position);
arr.append(_selected_color); arr.append(_selected_color);
do_action(arr); do_action_old(arr);
} break; } break;
case Tools::PASTECUT: { case Tools::PASTECUT: {
Array arr; Array arr;
@ -665,7 +665,7 @@ void PaintWindow::brush_process() {
arr.append(_cut_pos); arr.append(_cut_pos);
arr.append(_cut_size); arr.append(_cut_size);
do_action(arr); do_action_old(arr);
} break; } break;
case Tools::RAINBOW: { case Tools::RAINBOW: {
Array arr; Array arr;
@ -673,7 +673,7 @@ void PaintWindow::brush_process() {
arr.append(cell_mouse_position); arr.append(cell_mouse_position);
arr.append(last_cell_mouse_position); arr.append(last_cell_mouse_position);
do_action(arr); do_action_old(arr);
} break; } break;
default: { default: {
} break; } break;
@ -696,7 +696,7 @@ void PaintWindow::brush_process() {
arr.append(last_cell_mouse_position); arr.append(last_cell_mouse_position);
arr.append(Color(1, 1, 1, 0)); arr.append(Color(1, 1, 1, 0));
do_action(arr); do_action_old(arr);
} break; } break;
case Tools::BRUSH: { case Tools::BRUSH: {
Array arr; Array arr;
@ -707,14 +707,14 @@ void PaintWindow::brush_process() {
arr.append(selected_brush_prefab); arr.append(selected_brush_prefab);
arr.append(brush_size_slider->get_value()); arr.append(brush_size_slider->get_value());
do_action(arr); do_action_old(arr);
} break; } break;
default: { default: {
} break; } break;
} }
} else { } else {
if (_current_action.is_valid() && _current_action->can_commit()) { if (_current_action.is_valid() && _current_action->can_commit()) {
commit_action(); commit_action_old();
paint_canvas->update(); paint_canvas->update();
} }
} }
@ -732,21 +732,21 @@ void PaintWindow::_on_Save_pressed() {
paint_save_file_dialog->popup_centered(); paint_save_file_dialog->popup_centered();
} }
void PaintWindow::do_action(const Array &data) { void PaintWindow::do_action_old(const Array &data) {
if (_current_action.is_null()) { if (_current_action.is_null()) {
//print("clear redo"); //print("clear redo");
_redo_history.clear(); _redo_history.clear();
} }
_current_action->do_action(paint_canvas, data); _current_action->do_action_old(paint_canvas, data);
} }
void PaintWindow::commit_action() { void PaintWindow::commit_action_old() {
if (!_current_action.is_valid()) { if (!_current_action.is_valid()) {
return; return;
} }
//print("commit action") //print("commit action")
_current_action->commit_action(paint_canvas); _current_action->commit_action_old(paint_canvas);
//Ref<PaintAction> action = _current_action->duplicate(true); //Ref<PaintAction> action = _current_action->duplicate(true);
//action->layer = _current_action->layer; //action->layer = _current_action->layer;
@ -773,7 +773,7 @@ void PaintWindow::commit_action() {
} break; } break;
} }
} }
void PaintWindow::redo_action() { void PaintWindow::redo_action_old() {
if (_redo_history.empty()) { if (_redo_history.empty()) {
//print("nothing to redo"); //print("nothing to redo");
return; return;
@ -787,12 +787,12 @@ void PaintWindow::redo_action() {
} }
_actions_history.push_back(action); _actions_history.push_back(action);
action->redo_action(paint_canvas); action->redo_action_old(paint_canvas);
paint_canvas->update(); paint_canvas->update();
//print("redo action"); //print("redo action");
} }
void PaintWindow::undo_action() { void PaintWindow::undo_action_old() {
if (_actions_history.empty()) { if (_actions_history.empty()) {
return; return;
} }
@ -805,7 +805,7 @@ void PaintWindow::undo_action() {
} }
_redo_history.push_back(action); _redo_history.push_back(action);
action->undo_action(paint_canvas); action->undo_action_old(paint_canvas);
update(); update();
paint_canvas->update(); paint_canvas->update();

View File

@ -139,10 +139,10 @@ public:
void _on_Save_pressed(); void _on_Save_pressed();
void do_action(const Array &data); void do_action_old(const Array &data);
void commit_action(); void commit_action_old();
void redo_action(); void redo_action_old();
void undo_action(); void undo_action_old();
Ref<PaintAction> get_action(); Ref<PaintAction> get_action();