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;
}
void BrightenAction::do_action(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action(canvas, data);
void BrightenAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action_old(canvas, data);
PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]);

View File

@ -36,7 +36,7 @@ public:
float get_brighten_color();
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();

View File

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

View File

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

View File

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

View File

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

View File

@ -60,8 +60,8 @@ bool CutAction::can_commit() {
return false; //ugly way of handling a cut
}
void CutAction::do_action(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action(canvas, data);
void CutAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action_old(canvas, data);
if (!mouse_start_pos_set) {
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();
Vector2i p = mouse_start_pos;
Vector2i s = mouse_end_pos - mouse_start_pos;

View File

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

View File

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

View File

@ -36,7 +36,7 @@ public:
float get_dark_factor();
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();

View File

@ -42,8 +42,8 @@ void LineAction::set_mouse_start_pos_set(const bool val) {
mouse_start_pos_set = val;
}
void LineAction::do_action(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action(canvas, data);
void LineAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action_old(canvas, data);
if (!mouse_start_pos_set) {
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();
for (int i = 0; i < preview_cells.size(); ++i) {

View File

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

View File

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

View File

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

View File

@ -105,18 +105,18 @@ void PaintAction::set_action_data(const Dictionary &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();
}
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) {
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) {
canvas->_set_pixel_v(layer, redo_cells[idx], redo_colors[idx]);
}

View File

@ -73,11 +73,12 @@ public:
Dictionary get_action_data();
void set_action_data(const Dictionary &val);
virtual void do_action(PaintCanvasOld *canvas, const Array &data);
virtual void commit_action(PaintCanvasOld *canvas);
virtual void do_action_old(PaintCanvasOld *canvas, const Array &data);
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 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(_cut_pos);
//arr.append(_cut_size);
void PasteCutAction::do_action(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action(canvas, data);
void PasteCutAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action_old(canvas, data);
PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]);
Vector2i cut_pos = data[4];

View File

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

View File

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

View File

@ -33,7 +33,7 @@ class PencilAction : public PaintAction {
GDCLASS(PencilAction, PaintAction);
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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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