Removed most of the deprecated classes from the paint module.

This commit is contained in:
Relintai 2022-11-20 21:11:40 +01:00
parent 0539b70aee
commit 5c9aa754d7
48 changed files with 2 additions and 5198 deletions

View File

@ -19,11 +19,6 @@ module_env.add_source_files(env.modules_sources,"actions/pencil_action.cpp")
module_env.add_source_files(env.modules_sources,"actions/rainbow_action.cpp") module_env.add_source_files(env.modules_sources,"actions/rainbow_action.cpp")
module_env.add_source_files(env.modules_sources,"actions/rect_action.cpp") module_env.add_source_files(env.modules_sources,"actions/rect_action.cpp")
module_env.add_source_files(env.modules_sources,"deprecated/dialogs/paint_canvas_dialog.cpp")
module_env.add_source_files(env.modules_sources,"deprecated/dialogs/paint_change_grid_size_dialog.cpp")
module_env.add_source_files(env.modules_sources,"deprecated/dialogs/paint_load_file_dialog.cpp")
module_env.add_source_files(env.modules_sources,"deprecated/dialogs/paint_save_file_dialog.cpp")
module_env.add_source_files(env.modules_sources,"ui/paint_canvas_outline.cpp") module_env.add_source_files(env.modules_sources,"ui/paint_canvas_outline.cpp")
module_env.add_source_files(env.modules_sources,"ui/paint_canvas_background.cpp") module_env.add_source_files(env.modules_sources,"ui/paint_canvas_background.cpp")
module_env.add_source_files(env.modules_sources,"ui/paint_selection_box.cpp") module_env.add_source_files(env.modules_sources,"ui/paint_selection_box.cpp")
@ -45,14 +40,6 @@ module_env.add_source_files(env.modules_sources,"nodes/paint_node.cpp")
module_env.add_source_files(env.modules_sources,"nodes/paint_canvas.cpp") module_env.add_source_files(env.modules_sources,"nodes/paint_canvas.cpp")
module_env.add_source_files(env.modules_sources,"nodes/paint_project.cpp") module_env.add_source_files(env.modules_sources,"nodes/paint_project.cpp")
module_env.add_source_files(env.modules_sources,"deprecated/paint_canvas_layer.cpp")
module_env.add_source_files(env.modules_sources,"deprecated/paint_canvas.cpp")
module_env.add_source_files(env.modules_sources,"deprecated/paint_layer_button.cpp")
module_env.add_source_files(env.modules_sources,"deprecated/paint_window.cpp")
module_env.add_source_files(env.modules_sources,"deprecated/paint_navbar.cpp")
module_env.add_source_files(env.modules_sources,"deprecated/paint_settings.cpp")
if 'TOOLS_ENABLED' in env["CPPDEFINES"]: if 'TOOLS_ENABLED' in env["CPPDEFINES"]:
module_env.add_source_files(env.modules_sources,"paint_editor_plugin.cpp") module_env.add_source_files(env.modules_sources,"paint_editor_plugin.cpp")
module_env.add_source_files(env.modules_sources,"paint_editor_plugin_old.cpp")
module_env.add_source_files(env.modules_sources,"editor/paint_inspector_plugin.cpp") module_env.add_source_files(env.modules_sources,"editor/paint_inspector_plugin.cpp")

View File

@ -24,8 +24,6 @@ SOFTWARE.
#include "brighten_action.h" #include "brighten_action.h"
#include "../deprecated/paint_canvas.h"
#include "../deprecated/paint_canvas_layer.h"
#include "../paint_utilities.h" #include "../paint_utilities.h"
#include "../nodes/paint_canvas.h" #include "../nodes/paint_canvas.h"
@ -37,40 +35,6 @@ void BrightenAction::set_brighten_color(const float val) {
brighten_color = val; brighten_color = val;
} }
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]);
for (int i = 0; i < pixels.size(); ++i) {
Vector2i pixel = pixels[i];
Color col = canvas->get_pixel_v(pixel);
if (canvas->is_alpha_locked() && col.a < 0.00001) {
continue;
}
Color brightened_color = col.lightened(brighten_color);
if (undo_cells.contains(pixel)) {
canvas->set_pixel_v(pixel, brightened_color);
redo_cells.append(pixel);
redo_colors.append(brightened_color);
continue;
}
undo_colors.append(col);
undo_cells.append(pixel);
canvas->set_pixel_v(pixel, brightened_color);
redo_cells.append(pixel);
redo_colors.append(brightened_color);
}
}
void BrightenAction::_do_action(const Array &data) { void BrightenAction::_do_action(const Array &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

@ -27,8 +27,6 @@ SOFTWARE.
#include "paint_action.h" #include "paint_action.h"
class PaintCanvasOld;
class BrightenAction : public PaintAction { class BrightenAction : public PaintAction {
GDCLASS(BrightenAction, PaintAction); GDCLASS(BrightenAction, PaintAction);
@ -36,8 +34,6 @@ 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_old(PaintCanvasOld *canvas, const Array &data);
void _do_action(const Array &data); void _do_action(const Array &data);
BrightenAction(); BrightenAction();

View File

@ -25,49 +25,10 @@ SOFTWARE.
#include "brush_action.h" #include "brush_action.h"
#include "../bush_prefabs.h" #include "../bush_prefabs.h"
#include "../deprecated/paint_canvas.h"
#include "../deprecated/paint_canvas_layer.h"
#include "../paint_utilities.h" #include "../paint_utilities.h"
#include "../nodes/paint_canvas.h" #include "../nodes/paint_canvas.h"
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];
int brush_size = data[4];
PoolVector2iArray brush = BrushPrefabs::get_brush(static_cast<BrushPrefabs::Type>(brush_type), brush_size);
Color tcolor = data[2];
for (int i = 0; i < pixels.size(); ++i) {
Vector2i pixel = pixels[i];
for (int j = 0; j < brush.size(); ++j) {
Vector2i off = brush[j];
Vector2i p = pixel + off;
if (undo_cells.contains(p)) {
continue;
}
Color col = canvas->get_pixel_v(p);
if (canvas->is_alpha_locked() && col.a < 0.00001) {
continue;
}
undo_colors.append(col);
undo_cells.append(p);
canvas->set_pixel_v(p, tcolor);
redo_cells.append(p);
redo_colors.append(tcolor);
}
}
}
void BrushAction::_do_action(const Array &data) { void BrushAction::_do_action(const Array &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

@ -27,14 +27,10 @@ SOFTWARE.
#include "paint_action.h" #include "paint_action.h"
class PaintCanvasOld;
class BrushAction : public PaintAction { class BrushAction : public PaintAction {
GDCLASS(BrushAction, PaintAction); GDCLASS(BrushAction, PaintAction);
public: public:
void do_action_old(PaintCanvasOld *canvas, const Array &data);
void _do_action(const Array &data); void _do_action(const Array &data);
BrushAction(); BrushAction();

View File

@ -24,47 +24,10 @@ SOFTWARE.
#include "bucket_action.h" #include "bucket_action.h"
#include "../deprecated/paint_canvas.h"
#include "../deprecated/paint_canvas_layer.h"
#include "../paint_utilities.h" #include "../paint_utilities.h"
#include "../nodes/paint_canvas.h" #include "../nodes/paint_canvas.h"
void BucketAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action_old(canvas, data);
Vector2i pos = data[0];
Color col = canvas->get_pixel_v(pos);
Color col2 = data[2];
if (col == col2) {
return;
}
PoolVector2iArray pixels = canvas->select_same_color(pos.x, pos.y);
for (int i = 0; i < pixels.size(); ++i) {
Vector2i pixel = pixels[i];
if (undo_cells.contains(pixel)) {
continue;
}
if (canvas->is_alpha_locked() && col.a < 0.0001) {
continue;
}
undo_cells.append(pixel);
undo_colors.append(col);
canvas->set_pixel_v(pixel, col2);
redo_cells.append(pixel);
redo_colors.append(col2);
}
}
void BucketAction::_do_action(const Array &data) { void BucketAction::_do_action(const Array &data) {
Vector2i pos = data[0]; Vector2i pos = data[0];

View File

@ -27,14 +27,10 @@ SOFTWARE.
#include "paint_action.h" #include "paint_action.h"
class PaintCanvasOld;
class BucketAction : public PaintAction { class BucketAction : public PaintAction {
GDCLASS(BucketAction, PaintAction); GDCLASS(BucketAction, PaintAction);
public: public:
void do_action_old(PaintCanvasOld *canvas, const Array &data);
void _do_action(const Array &data); void _do_action(const Array &data);
BucketAction(); BucketAction();

View File

@ -24,8 +24,6 @@ SOFTWARE.
#include "cut_action.h" #include "cut_action.h"
#include "../deprecated/paint_canvas.h"
#include "../deprecated/paint_canvas_layer.h"
#include "../paint_utilities.h" #include "../paint_utilities.h"
#include "../nodes/paint_canvas.h" #include "../nodes/paint_canvas.h"
@ -62,81 +60,6 @@ bool CutAction::_can_commit() {
return false; //ugly way of handling a cut return false; //ugly way of handling a cut
} }
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];
mouse_start_pos_set = true;
}
mouse_end_pos = data[0];
preview_cells.clear();
preview_colors.clear();
canvas->clear_preview_layer();
Vector2i p = mouse_start_pos;
Vector2i s = mouse_end_pos - mouse_start_pos;
PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(p, p + Vector2i(s.x, 0));
pixels.append_array(PaintUtilities::get_pixels_in_line(p, p + Vector2i(0, s.y)));
pixels.append_array(PaintUtilities::get_pixels_in_line(p + s, p + s + Vector2i(0, -s.y)));
pixels.append_array(PaintUtilities::get_pixels_in_line(p + s, p + s + Vector2i(-s.x, 0)));
for (int i = 0; i < pixels.size(); ++i) {
Vector2i pixel = pixels[i];
canvas->set_preview_pixel_v(pixel, selection_color);
preview_cells.append(pixel);
preview_colors.append(selection_color);
}
}
void CutAction::commit_action_old(PaintCanvasOld *canvas) {
canvas->clear_preview_layer();
Vector2i p = mouse_start_pos;
Vector2i s = mouse_end_pos - mouse_start_pos;
int ex = ABS(s.x) + 1;
int ey = ABS(s.y) + 1;
for (int x = 0; x < ex; ++x) {
for (int y = 0; y < ey; ++y) {
int px = x;
int py = y;
if (s.x < 0) {
px *= -1;
}
if (s.y < 0) {
py *= -1;
}
Vector2i pos = p + Vector2i(px, py);
if (!canvas->validate_pixel_v(pos)) {
continue;
}
Color color = canvas->get_pixel_v(pos);
if (color.a < 0.0001) {
continue;
}
redo_cells.append(pos);
redo_colors.append(color);
canvas->set_pixel_v(pos, Color(1, 1, 1, 0));
undo_cells.append(pos);
undo_colors.append(Color(1, 1, 1, 0));
}
}
}
void CutAction::_do_action(const Array &data) { void CutAction::_do_action(const Array &data) {
if (!mouse_start_pos_set) { if (!mouse_start_pos_set) {
mouse_start_pos = data[0]; mouse_start_pos = data[0];

View File

@ -27,8 +27,6 @@ SOFTWARE.
#include "paint_action.h" #include "paint_action.h"
class PaintCanvasOld;
class CutAction : public PaintAction { class CutAction : public PaintAction {
GDCLASS(CutAction, PaintAction); GDCLASS(CutAction, PaintAction);
@ -47,9 +45,6 @@ public:
bool _can_commit(); bool _can_commit();
void do_action_old(PaintCanvasOld *canvas, const Array &data);
void commit_action_old(PaintCanvasOld *canvas);
void _do_action(const Array &data); void _do_action(const Array &data);
void _commit_action(); void _commit_action();

View File

@ -24,8 +24,6 @@ SOFTWARE.
#include "darken_action.h" #include "darken_action.h"
#include "../deprecated/paint_canvas.h"
#include "../deprecated/paint_canvas_layer.h"
#include "../paint_utilities.h" #include "../paint_utilities.h"
#include "../nodes/paint_canvas.h" #include "../nodes/paint_canvas.h"
@ -37,40 +35,6 @@ void DarkenAction::set_dark_factor(const float val) {
dark_factor = val; dark_factor = val;
} }
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]);
for (int i = 0; i < pixels.size(); ++i) {
Vector2i pixel = pixels[i];
if (!canvas->validate_pixel_v(pixel)) {
continue;
}
Color col = canvas->get_pixel_v(pixel);
if (canvas->is_alpha_locked() && col.a < 0.001) {
continue;
}
Color darkened_color = col.darkened(dark_factor);
canvas->set_pixel_v(pixel, darkened_color);
redo_cells.append(pixel);
redo_colors.append(darkened_color);
if (undo_cells.contains(pixel)) {
continue;
}
undo_colors.append(col);
undo_cells.append(pixel);
}
}
void DarkenAction::_do_action(const Array &data) { void DarkenAction::_do_action(const Array &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,6 @@ 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_old(PaintCanvasOld *canvas, const Array &data);
void _do_action(const Array &data); void _do_action(const Array &data);
DarkenAction(); DarkenAction();

View File

@ -24,8 +24,6 @@ SOFTWARE.
#include "line_action.h" #include "line_action.h"
#include "../deprecated/paint_canvas.h"
#include "../deprecated/paint_canvas_layer.h"
#include "../paint_utilities.h" #include "../paint_utilities.h"
#include "../nodes/paint_canvas.h" #include "../nodes/paint_canvas.h"
@ -44,62 +42,6 @@ void LineAction::set_mouse_start_pos_set(const bool val) {
mouse_start_pos_set = val; mouse_start_pos_set = val;
} }
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];
mouse_start_pos_set = true;
}
preview_cells.resize(0);
preview_colors.resize(0);
canvas->clear_preview_layer();
PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], mouse_start_pos);
for (int i = 0; i < pixels.size(); ++i) {
Vector2i pixel = pixels[i];
Color col = canvas->get_pixel_v(pixel);
if (canvas->is_alpha_locked() && col.a < 0.00001) {
continue;
}
Color nc = data[2];
canvas->set_preview_pixel_v(pixel, nc);
preview_cells.append(pixel);
preview_colors.append(nc);
}
}
void LineAction::commit_action_old(PaintCanvasOld *canvas) {
canvas->clear_preview_layer();
for (int i = 0; i < preview_cells.size(); ++i) {
Vector2i pc = preview_cells[i];
if (!canvas->validate_pixel_v(pc)) {
continue;
}
Color pcol = preview_colors[i];
undo_cells.append(pc);
undo_colors.append(canvas->get_pixel_v(pc));
canvas->set_pixel_v(pc, pcol);
redo_cells.append(pc);
redo_colors.append(pcol);
}
mouse_start_pos_set = false;
}
void LineAction::_do_action(const Array &data) { void LineAction::_do_action(const Array &data) {
if (!mouse_start_pos_set) { if (!mouse_start_pos_set) {
mouse_start_pos = data[0]; mouse_start_pos = data[0];

View File

@ -27,8 +27,6 @@ SOFTWARE.
#include "paint_action.h" #include "paint_action.h"
class PaintCanvasOld;
class LineAction : public PaintAction { class LineAction : public PaintAction {
GDCLASS(LineAction, PaintAction); GDCLASS(LineAction, PaintAction);
@ -39,9 +37,6 @@ 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_old(PaintCanvasOld *canvas, const Array &data);
void commit_action_old(PaintCanvasOld *canvas);
void _do_action(const Array &data); void _do_action(const Array &data);
void _commit_action(); void _commit_action();
bool _can_commit(); bool _can_commit();

View File

@ -24,8 +24,6 @@ SOFTWARE.
#include "multiline_action.h" #include "multiline_action.h"
#include "../deprecated/paint_canvas.h"
#include "../deprecated/paint_canvas_layer.h"
#include "../paint_utilities.h" #include "../paint_utilities.h"
#include "../nodes/paint_canvas.h" #include "../nodes/paint_canvas.h"
@ -34,32 +32,6 @@ bool MultiLineAction::_can_commit() {
return false; return false;
} }
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]);
for (int i = 0; i < pixels.size(); ++i) {
Vector2i pixel = pixels[i];
Color col = canvas->get_pixel_v(pixel);
if (undo_cells.contains(pixel) || !canvas->validate_pixel_v(pixel) || (canvas->is_alpha_locked() && col.a < 0.0001)) {
continue;
}
undo_colors.append(col);
undo_cells.append(pixel);
Color tpx = data[2];
canvas->set_pixel_v(pixel, tpx);
redo_cells.append(pixel);
redo_colors.append(tpx);
}
}
void MultiLineAction::_do_action(const Array &data) { void MultiLineAction::_do_action(const Array &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

@ -27,15 +27,12 @@ SOFTWARE.
#include "paint_action.h" #include "paint_action.h"
class PaintCanvasOld;
class MultiLineAction : public PaintAction { class MultiLineAction : public PaintAction {
GDCLASS(MultiLineAction, PaintAction); GDCLASS(MultiLineAction, PaintAction);
public: public:
bool _can_commit(); bool _can_commit();
void do_action_old(PaintCanvasOld *canvas, const Array &data);
void _do_action(const Array &data); void _do_action(const Array &data);
MultiLineAction(); MultiLineAction();

View File

@ -24,8 +24,6 @@ SOFTWARE.
#include "paint_action.h" #include "paint_action.h"
#include "../deprecated/paint_canvas.h"
#include "../deprecated/paint_canvas_layer.h"
#include "core/object/object.h" #include "core/object/object.h"
#include "../nodes/paint_canvas.h" #include "../nodes/paint_canvas.h"
@ -103,13 +101,6 @@ void PaintAction::set_preview_colors(const PoolColorArray &val) {
preview_colors = val; preview_colors = val;
} }
Ref<PaintCanvasLayer> PaintAction::get_layer() {
return layer;
}
void PaintAction::set_layer(const Ref<PaintCanvasLayer> &val) {
layer = val;
}
Dictionary PaintAction::get_action_data() { Dictionary PaintAction::get_action_data() {
return action_data; return action_data;
} }
@ -117,23 +108,6 @@ void PaintAction::set_action_data(const Dictionary &val) {
action_data = val; action_data = val;
} }
void PaintAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
layer = canvas->get_active_layer();
}
void PaintAction::commit_action_old(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_old(PaintCanvasOld *canvas) {
for (int idx = 0; idx < redo_cells.size(); ++idx) {
canvas->_set_pixel_v(layer, redo_cells[idx], redo_colors[idx]);
}
}
PoolVector2iArray PaintAction::get_x_sym_points(const int canvas_width, const Vector2i &pixel) { PoolVector2iArray PaintAction::get_x_sym_points(const int canvas_width, const Vector2i &pixel) {
int p = canvas_width - pixel.x; int p = canvas_width - pixel.x;
@ -246,74 +220,6 @@ PoolVector2iArray PaintAction::get_points(const Vector2i &pixel) {
return points; return points;
} }
PoolVector2iArray PaintAction::get_points_old(PaintCanvasOld *canvas, const Vector2i &pixel) {
PoolVector2iArray points;
if (canvas->symmetry_x && canvas->symmetry_y) {
PoolVector2iArray sym_points = get_xy_sym_points(canvas->get_canvas_width(), canvas->get_canvas_height(), pixel);
for (int i = 0; i < sym_points.size(); ++i) {
Vector2i point = sym_points[i];
if (undo_cells.contains(point) || !canvas->validate_pixel_v(point)) {
continue;
}
if (canvas->is_alpha_locked() && canvas->get_pixel_v(pixel) == Color(0, 0, 0, 0)) {
continue;
}
points.append(point);
}
} else if (canvas->symmetry_y) {
PoolVector2iArray sym_points = get_y_sym_points(canvas->get_canvas_height(), pixel);
for (int i = 0; i < sym_points.size(); ++i) {
Vector2i point = sym_points[i];
if (undo_cells.contains(point) || !canvas->validate_pixel_v(point)) {
continue;
}
if (canvas->is_alpha_locked() && canvas->get_pixel_v(pixel) == Color(0, 0, 0, 0)) {
continue;
}
points.append(point);
}
} else if (canvas->symmetry_x) {
PoolVector2iArray sym_points = get_x_sym_points(canvas->get_canvas_width(), pixel);
for (int i = 0; i < sym_points.size(); ++i) {
Vector2i point = sym_points[i];
if (undo_cells.contains(point) || !canvas->validate_pixel_v(point)) {
continue;
}
if (canvas->is_alpha_locked() && canvas->get_pixel_v(pixel) == Color(0, 0, 0, 0)) {
continue;
}
points.append(point);
}
} else {
if (undo_cells.contains(pixel) || !canvas->validate_pixel_v(pixel)) {
//empty
return points;
}
if (canvas->is_alpha_locked() && canvas->get_pixel_v(pixel) == Color(0, 0, 0, 0)) {
//empty
return points;
}
points.append(pixel);
}
return points;
}
void PaintAction::draw_points(const PoolVector2iArray &point_arr, const PoolColorArray &color_arr) { void PaintAction::draw_points(const PoolVector2iArray &point_arr, const PoolColorArray &color_arr) {
for (int i = 0; i < point_arr.size(); ++i) { for (int i = 0; i < point_arr.size(); ++i) {
Vector2i pixel = point_arr[i]; Vector2i pixel = point_arr[i];
@ -334,26 +240,6 @@ void PaintAction::draw_points(const PoolVector2iArray &point_arr, const PoolColo
} }
} }
void PaintAction::draw_points_old(PaintCanvasOld *canvas, const PoolVector2iArray &point_arr, const PoolColorArray &color_arr) {
for (int i = 0; i < point_arr.size(); ++i) {
Vector2i pixel = point_arr[i];
Color col = color_arr[i];
if (canvas->is_alpha_locked() && col.a < 0.00001) {
continue;
}
undo_cells.append(pixel);
undo_colors.append(col);
canvas->set_pixel_v(pixel, col);
redo_cells.append(pixel);
redo_colors.append(col);
}
}
void PaintAction::do_action(const Array &data) { void PaintAction::do_action(const Array &data) {
call("_do_action", data); call("_do_action", data);
} }

View File

@ -27,15 +27,13 @@ SOFTWARE.
#include "core/object/resource.h" #include "core/object/resource.h"
#include "core/containers/pool_vector.h"
#include "core/math/vector2i.h"
#include "core/variant/array.h" #include "core/variant/array.h"
#include "core/variant/dictionary.h" #include "core/variant/dictionary.h"
#include "core/math/vector2i.h"
#include "core/containers/pool_vector.h"
#include "core/variant/variant.h" #include "core/variant/variant.h"
class PaintCanvasOld;
class PaintCanvas; class PaintCanvas;
class PaintCanvasLayer;
class Node; class Node;
class PaintAction : public Resource { class PaintAction : public Resource {
@ -73,19 +71,9 @@ public:
PoolColorArray get_preview_colors(); PoolColorArray get_preview_colors();
void set_preview_colors(const PoolColorArray &val); void set_preview_colors(const PoolColorArray &val);
//deprecated
Ref<PaintCanvasLayer> get_layer();
void set_layer(const Ref<PaintCanvasLayer> &val);
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_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);
void do_action(const Array &data); void do_action(const Array &data);
void commit_action(); void commit_action();
@ -105,10 +93,8 @@ public:
PoolVector2iArray get_y_sym_points(const int canvas_height, const Vector2i &pixel); PoolVector2iArray get_y_sym_points(const int canvas_height, const Vector2i &pixel);
PoolVector2iArray get_xy_sym_points(const int canvas_width, const int canvas_height, const Vector2i &pixel); PoolVector2iArray get_xy_sym_points(const int canvas_width, const int canvas_height, const Vector2i &pixel);
PoolVector2iArray get_points(const Vector2i &pixel); PoolVector2iArray get_points(const Vector2i &pixel);
PoolVector2iArray get_points_old(PaintCanvasOld *canvas, const Vector2i &pixel);
void draw_points(const PoolVector2iArray &point_arr, const PoolColorArray &color_arr); void draw_points(const PoolVector2iArray &point_arr, const PoolColorArray &color_arr);
void draw_points_old(PaintCanvasOld *canvas, const PoolVector2iArray &point_arr, const PoolColorArray &color_arr);
PaintAction(); PaintAction();
~PaintAction(); ~PaintAction();
@ -126,8 +112,6 @@ public:
PoolVector2iArray preview_cells; PoolVector2iArray preview_cells;
PoolColorArray preview_colors; PoolColorArray preview_colors;
Ref<PaintCanvasLayer> layer;
Dictionary action_data; Dictionary action_data;
protected: protected:

View File

@ -24,67 +24,10 @@ SOFTWARE.
#include "paste_cut_action.h" #include "paste_cut_action.h"
#include "../deprecated/paint_canvas.h"
#include "../deprecated/paint_canvas_layer.h"
#include "../paint_utilities.h" #include "../paint_utilities.h"
#include "../nodes/paint_canvas.h" #include "../nodes/paint_canvas.h"
//arr.append(cell_mouse_position);
//arr.append(last_cell_mouse_position);
//arr.append(_selection_cells);
//arr.append(_selection_colors);
//arr.append(_cut_pos);
//arr.append(_cut_size);
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];
Vector2i cut_size = data[5];
for (int i = 0; i < pixels.size(); ++i) {
Vector2i pixel_pos = pixels[i];
PoolVector2iArray cells = data[2];
PoolColorArray colors = data[3];
for (int idx = 0; idx < cells.size(); ++idx) {
Vector2i pixel = cells[idx];
Color color = colors[idx];
pixel -= cut_pos + cut_size / 2;
pixel += pixel_pos;
if (!canvas->validate_pixel_v(pixel)) {
continue;
}
Color col = canvas->get_pixel_v(pixel);
if (canvas->is_alpha_locked() && col.a < 0.0001) {
continue;
}
int found = redo_cells.find(pixel);
if (found == -1) {
redo_cells.push_back(pixel);
redo_colors.push_back(color);
} else {
redo_colors[found] = color;
}
found = undo_cells.find(pixel);
if (found == -1) {
undo_colors.append(col);
undo_cells.append(pixel);
}
canvas->set_pixel_v(pixel, color);
}
}
}
void PasteCutAction::_do_action(const Array &data) { void PasteCutAction::_do_action(const Array &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

@ -27,14 +27,10 @@ SOFTWARE.
#include "paint_action.h" #include "paint_action.h"
class PaintCanvasOld;
class PasteCutAction : public PaintAction { class PasteCutAction : public PaintAction {
GDCLASS(PasteCutAction, PaintAction); GDCLASS(PasteCutAction, PaintAction);
public: public:
void do_action_old(PaintCanvasOld *canvas, const Array &data);
void _do_action(const Array &data); void _do_action(const Array &data);
PasteCutAction(); PasteCutAction();

View File

@ -24,43 +24,11 @@ SOFTWARE.
#include "pencil_action.h" #include "pencil_action.h"
#include "../deprecated/paint_canvas.h"
#include "../deprecated/paint_canvas_layer.h"
#include "../paint_utilities.h" #include "../paint_utilities.h"
#include "core/string/print_string.h" #include "core/string/print_string.h"
#include "../nodes/paint_canvas.h" #include "../nodes/paint_canvas.h"
void PencilAction::do_action_old(PaintCanvasOld *canvas, const Array &data) {
PaintAction::do_action_old(canvas, data);
Color c = data[2];
PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]);
for (int i = 0; i < pixels.size(); ++i) {
Vector2i pixel = pixels[i];
PoolVector2iArray points = get_points_old(canvas, pixel);
for (int j = 0; j < points.size(); ++j) {
Vector2i p = points[j];
_set_pixel_old(canvas, p, c);
}
}
}
void PencilAction::_set_pixel_old(PaintCanvasOld *canvas, Vector2i pixel, Color color) {
undo_colors.append(canvas->get_pixel_v(pixel));
undo_cells.append(pixel);
canvas->set_pixel_v(pixel, color);
redo_cells.append(pixel);
redo_colors.append(color);
}
void PencilAction::_do_action(const Array &data) { void PencilAction::_do_action(const Array &data) {
Color c = data[2]; Color c = data[2];

View File

@ -27,15 +27,10 @@ SOFTWARE.
#include "paint_action.h" #include "paint_action.h"
class PaintCanvasOld;
class PencilAction : public PaintAction { class PencilAction : public PaintAction {
GDCLASS(PencilAction, PaintAction); GDCLASS(PencilAction, PaintAction);
public: public:
void do_action_old(PaintCanvasOld *canvas, const Array &data);
void _set_pixel_old(PaintCanvasOld *canvas, Vector2i pixel, Color color);
void _do_action(const Array &data); void _do_action(const Array &data);
void _set_pixel(Vector2i pixel, Color color); void _set_pixel(Vector2i pixel, Color color);

View File

@ -24,55 +24,10 @@ SOFTWARE.
#include "rainbow_action.h" #include "rainbow_action.h"
#include "../deprecated/paint_canvas.h"
#include "../deprecated/paint_canvas_layer.h"
#include "../paint_utilities.h" #include "../paint_utilities.h"
#include "../nodes/paint_canvas.h" #include "../nodes/paint_canvas.h"
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]);
for (int i = 0; i < pixels.size(); ++i) {
Vector2i pixel = pixels[i];
if (!canvas->validate_pixel_v(pixel)) {
continue;
}
Color col = canvas->get_pixel_v(pixel);
if (canvas->is_alpha_locked() && col.a < 0.0001) {
continue;
}
if (undo_cells.contains(pixel)) {
Color color = PaintUtilities::random_color();
canvas->set_pixel_v(pixel, color);
int idx = redo_cells.find(pixel);
redo_cells.remove(idx);
redo_colors.remove(idx);
redo_cells.append(pixel);
redo_colors.append(color);
continue;
}
undo_colors.append(col);
undo_cells.append(pixel);
Color color = PaintUtilities::random_color();
canvas->set_pixel_v(pixel, color);
redo_cells.append(pixel);
redo_colors.append(color);
}
}
void RainbowAction::_do_action(const Array &data) { void RainbowAction::_do_action(const Array &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

@ -27,14 +27,10 @@ SOFTWARE.
#include "paint_action.h" #include "paint_action.h"
class PaintCanvasOld;
class RainbowAction : public PaintAction { class RainbowAction : public PaintAction {
GDCLASS(RainbowAction, PaintAction); GDCLASS(RainbowAction, PaintAction);
public: public:
void do_action_old(PaintCanvasOld *canvas, const Array &data);
void _do_action(const Array &data); void _do_action(const Array &data);
RainbowAction(); RainbowAction();

View File

@ -24,8 +24,6 @@ SOFTWARE.
#include "rect_action.h" #include "rect_action.h"
#include "../deprecated/paint_canvas.h"
#include "../deprecated/paint_canvas_layer.h"
#include "../paint_utilities.h" #include "../paint_utilities.h"
#include "../nodes/paint_canvas.h" #include "../nodes/paint_canvas.h"
@ -44,69 +42,6 @@ void RectAction::set_mouse_start_pos_set(const bool val) {
mouse_start_pos_set = val; mouse_start_pos_set = val;
} }
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];
//print("init:", mouse_start_pos)
mouse_start_pos_set = true;
}
undo_cells.clear();
undo_colors.clear();
preview_cells.clear();
preview_colors.clear();
canvas->clear_preview_layer();
Vector2i p = mouse_start_pos;
Vector2i current_mouse_pos = data[0];
Vector2i s = current_mouse_pos - mouse_start_pos;
PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(p, p + Vector2i(s.x, 0));
pixels.append_array(PaintUtilities::get_pixels_in_line(p, p + Vector2(0, s.y)));
pixels.append_array(PaintUtilities::get_pixels_in_line(p + s, p + s + Vector2(0, -s.y)));
pixels.append_array(PaintUtilities::get_pixels_in_line(p + s, p + s + Vector2(-s.x, 0)));
for (int i = 0; i < pixels.size(); ++i) {
Vector2i pixel = pixels[i];
if (!canvas->validate_pixel_v(pixel)) {
continue;
}
Color col = canvas->get_pixel_v(pixel);
if (canvas->is_alpha_locked() && col.a < 0.00001) {
continue;
}
Color tc = data[2];
canvas->set_preview_pixel_v(pixel, tc);
undo_cells.append(pixel);
undo_colors.append(col);
preview_cells.append(pixel);
preview_colors.append(tc);
}
}
void RectAction::commit_action_old(PaintCanvasOld *canvas) {
canvas->clear_preview_layer();
for (int idx = 0; idx < preview_cells.size(); ++idx) {
Vector2i pcell = preview_cells[idx];
Color pcolor = preview_colors[idx];
canvas->set_pixel_v(pcell, pcolor);
redo_cells.append(pcell);
redo_colors.append(pcolor);
}
mouse_start_pos_set = false;
}
void RectAction::_do_action(const Array &data) { void RectAction::_do_action(const Array &data) {
if (!mouse_start_pos_set) { if (!mouse_start_pos_set) {
mouse_start_pos = data[0]; mouse_start_pos = data[0];

View File

@ -27,8 +27,6 @@ SOFTWARE.
#include "paint_action.h" #include "paint_action.h"
class PaintCanvasOld;
class RectAction : public PaintAction { class RectAction : public PaintAction {
GDCLASS(RectAction, PaintAction); GDCLASS(RectAction, PaintAction);
@ -39,9 +37,6 @@ 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_old(PaintCanvasOld *canvas, const Array &data);
void commit_action_old(PaintCanvasOld *canvas);
void _do_action(const Array &data); void _do_action(const Array &data);
void _commit_action(); void _commit_action();
bool _can_commit(); bool _can_commit();

View File

@ -1,133 +0,0 @@
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "paint_canvas_dialog.h"
#include "scene/gui/box_container.h"
#include "scene/gui/label.h"
#include "scene/gui/spin_box.h"
int PaintCanvasDialog::get_size_x() const {
return static_cast<int>(size_x_spin_box->get_value());
}
void PaintCanvasDialog::set_size_x(const int val) {
size_x_spin_box->set_value(val);
_x_prev_val = val;
}
int PaintCanvasDialog::get_size_y() const {
return static_cast<int>(size_y_spin_box->get_value());
}
void PaintCanvasDialog::set_size_y(const int val) {
size_y_spin_box->set_value(val);
_y_prev_val = val;
}
void PaintCanvasDialog::_on_confirmed() {
_x_prev_val = get_size_x();
_y_prev_val = get_size_y();
}
void PaintCanvasDialog::_on_about_to_show() {
set_size_x(_x_prev_val);
set_size_y(_y_prev_val);
}
PaintCanvasDialog::PaintCanvasDialog() {
_x_prev_val = 0;
_y_prev_val = 0;
is_new = false;
set_resizable(true);
set_title("Please Confirm...");
VBoxContainer *main_box_container = memnew(VBoxContainer);
add_child(main_box_container);
Label *main_label = memnew(Label);
main_label->set_text("Change canvas size?");
main_label->set_align(Label::ALIGN_CENTER);
main_label->set_v_size_flags(Control::SIZE_EXPAND_FILL);
main_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
main_box_container->add_child(main_label);
HBoxContainer *grid_spin_container = memnew(HBoxContainer);
grid_spin_container->set_v_size_flags(Control::SIZE_EXPAND_FILL);
grid_spin_container->set_h_size_flags(Control::SIZE_EXPAND_FILL);
main_box_container->add_child(grid_spin_container);
Label *grid_label = memnew(Label);
grid_label->set_text("Width (X)");
grid_label->set_align(Label::ALIGN_CENTER);
grid_label->set_v_size_flags(Control::SIZE_EXPAND_FILL);
grid_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
grid_spin_container->add_child(grid_label);
size_x_spin_box = memnew(SpinBox);
size_x_spin_box->set_value(64);
size_x_spin_box->set_min(1);
size_x_spin_box->set_max(2500);
size_x_spin_box->set_v_size_flags(Control::SIZE_EXPAND_FILL);
size_x_spin_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
grid_spin_container->add_child(size_x_spin_box);
HBoxContainer *big_grid_spin_container = memnew(HBoxContainer);
big_grid_spin_container->set_v_size_flags(Control::SIZE_EXPAND_FILL);
big_grid_spin_container->set_h_size_flags(Control::SIZE_EXPAND_FILL);
main_box_container->add_child(big_grid_spin_container);
grid_label = memnew(Label);
grid_label->set_text("Height (Y)");
grid_label->set_align(Label::ALIGN_CENTER);
grid_label->set_v_size_flags(Control::SIZE_EXPAND_FILL);
grid_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
big_grid_spin_container->add_child(grid_label);
size_y_spin_box = memnew(SpinBox);
size_y_spin_box->set_value(64);
size_y_spin_box->set_min(1);
size_y_spin_box->set_max(2500);
size_y_spin_box->set_v_size_flags(Control::SIZE_EXPAND_FILL);
size_y_spin_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
big_grid_spin_container->add_child(size_y_spin_box);
}
PaintCanvasDialog::~PaintCanvasDialog() {
}
void PaintCanvasDialog::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_POSTINITIALIZE: {
connect("confirmed", this, "_on_confirmed");
connect("about_to_show", this, "_on_about_to_show");
} break;
default: {
} break;
}
}
void PaintCanvasDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("_on_confirmed"), &PaintCanvasDialog::_on_confirmed);
ClassDB::bind_method(D_METHOD("_on_about_to_show"), &PaintCanvasDialog::_on_about_to_show);
}

View File

@ -1,61 +0,0 @@
#ifndef PAINT_CANVAS_DIALOG_H
#define PAINT_CANVAS_DIALOG_H
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "scene/gui/dialogs.h"
class SpinBox;
class PaintCanvasDialog : public ConfirmationDialog {
GDCLASS(PaintCanvasDialog, ConfirmationDialog);
public:
int get_size_x() const;
void set_size_x(const int val);
int get_size_y() const;
void set_size_y(const int val);
SpinBox *size_x_spin_box;
SpinBox *size_y_spin_box;
PaintCanvasDialog();
~PaintCanvasDialog();
bool is_new;
protected:
void _on_confirmed();
void _on_about_to_show();
int _x_prev_val;
int _y_prev_val;
void _notification(int p_what);
static void _bind_methods();
};
#endif

View File

@ -1,102 +0,0 @@
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "paint_change_grid_size_dialog.h"
#include "scene/gui/box_container.h"
#include "scene/gui/label.h"
#include "scene/gui/spin_box.h"
int PaintChangeGridSizeDialog::get_grid_value() const {
return static_cast<int>(grid_spin_box->get_value());
}
void PaintChangeGridSizeDialog::set_grid_value(const int val) {
grid_spin_box->set_value(val);
}
int PaintChangeGridSizeDialog::get_big_grid_value() const {
return static_cast<int>(big_grid_spin_box->get_value());
}
void PaintChangeGridSizeDialog::set_big_grid_value(const int val) {
big_grid_spin_box->set_value(val);
}
PaintChangeGridSizeDialog::PaintChangeGridSizeDialog() {
set_resizable(true);
set_title("Change Grid Size");
VBoxContainer *main_box_container = memnew(VBoxContainer);
add_child(main_box_container);
Label *main_label = memnew(Label);
main_label->set_text("Change Grid Size");
main_label->set_align(Label::ALIGN_CENTER);
main_label->set_v_size_flags(Control::SIZE_EXPAND_FILL);
main_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
main_box_container->add_child(main_label);
HBoxContainer *grid_spin_container = memnew(HBoxContainer);
grid_spin_container->set_v_size_flags(Control::SIZE_EXPAND_FILL);
grid_spin_container->set_h_size_flags(Control::SIZE_EXPAND_FILL);
main_box_container->add_child(grid_spin_container);
Label *grid_label = memnew(Label);
grid_label->set_text("Grid 1");
grid_label->set_align(Label::ALIGN_CENTER);
grid_label->set_v_size_flags(Control::SIZE_EXPAND_FILL);
grid_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
grid_spin_container->add_child(grid_label);
grid_spin_box = memnew(SpinBox);
grid_spin_box->set_value(1);
grid_spin_box->set_max(2500);
grid_spin_box->set_v_size_flags(Control::SIZE_EXPAND_FILL);
grid_spin_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
grid_spin_container->add_child(grid_spin_box);
HBoxContainer *big_grid_spin_container = memnew(HBoxContainer);
big_grid_spin_container->set_v_size_flags(Control::SIZE_EXPAND_FILL);
big_grid_spin_container->set_h_size_flags(Control::SIZE_EXPAND_FILL);
main_box_container->add_child(big_grid_spin_container);
grid_label = memnew(Label);
grid_label->set_text("Grid 2");
grid_label->set_align(Label::ALIGN_CENTER);
grid_label->set_v_size_flags(Control::SIZE_EXPAND_FILL);
grid_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
big_grid_spin_container->add_child(grid_label);
big_grid_spin_box = memnew(SpinBox);
big_grid_spin_box->set_value(8);
big_grid_spin_box->set_max(2500);
big_grid_spin_box->set_v_size_flags(Control::SIZE_EXPAND_FILL);
big_grid_spin_box->set_h_size_flags(Control::SIZE_EXPAND_FILL);
big_grid_spin_container->add_child(big_grid_spin_box);
}
PaintChangeGridSizeDialog::~PaintChangeGridSizeDialog() {
}
void PaintChangeGridSizeDialog::_bind_methods() {
}

View File

@ -1,52 +0,0 @@
#ifndef PAINT_CHANGE_GRID_SIZE_DIALOG_H
#define PAINT_CHANGE_GRID_SIZE_DIALOG_H
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "scene/gui/dialogs.h"
class SpinBox;
class PaintChangeGridSizeDialog : public AcceptDialog {
GDCLASS(PaintChangeGridSizeDialog, AcceptDialog);
public:
int get_grid_value() const;
void set_grid_value(const int val);
int get_big_grid_value() const;
void set_big_grid_value(const int val);
PaintChangeGridSizeDialog();
~PaintChangeGridSizeDialog();
SpinBox *grid_spin_box;
SpinBox *big_grid_spin_box;
protected:
static void _bind_methods();
};
#endif

View File

@ -1,114 +0,0 @@
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "paint_load_file_dialog.h"
#include "../paint_canvas.h"
#include "../paint_canvas_layer.h"
#include "../paint_window.h"
#include "../../paint_utilities.h"
void PaintLoadFileDialog::load_img() {
Ref<Image> image;
image.instance();
if (image->load(file_path) != OK) {
ERR_FAIL_MSG("couldn't load image!");
}
PoolByteArray image_data = image->get_data();
Ref<PaintCanvasLayer> layer = window->add_new_layer();
int width = image->get_width();
int height = image->get_height();
if (canvas->get_canvas_width() < width) {
canvas->resize(width, canvas->get_canvas_height());
}
if (canvas->get_canvas_height() < height) {
canvas->resize(canvas->get_canvas_width(), height);
}
int iss = image_data.size() / 4;
for (int i = 0; i < iss; ++i) {
Color color = Color(image_data[i*4] / 255.0, image_data[i*4+1] / 255.0, image_data[i*4+2] / 255.0, image_data[i*4+3] / 255.0);
Vector2i pos = PaintUtilities::to_2D(i, image->get_width());
if (pos.x > layer->layer_width) {
continue;
}
layer->set_pixel(pos.x, pos.y, color);
}
layer->update_texture();
}
void PaintLoadFileDialog::_on_LoadFileDialog_file_selected(const String &path) {
file_path = path;
load_img();
}
void PaintLoadFileDialog::_on_LoadFileDialog_confirmed() {
/*
return
#print("ere")
#load_img()
*/
}
void PaintLoadFileDialog::_on_LoadFileDialog_about_to_show() {
invalidate();
}
void PaintLoadFileDialog::_on_LoadFileDialog_visibility_changed() {
invalidate();
}
void PaintLoadFileDialog::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_POSTINITIALIZE: {
connect("file_selected", this, "_on_LoadFileDialog_file_selected");
connect("about_to_show", this, "_on_LoadFileDialog_about_to_show");
connect("confirmed", this, "_on_LoadFileDialog_confirmed");
connect("visibility_changed", this, "_on_LoadFileDialog_visibility_changed");
} break;
}
}
PaintLoadFileDialog::PaintLoadFileDialog() {
add_filter("*.png ; PNG Images");
set_mode(FileDialog::MODE_OPEN_FILE);
set_show_hidden_files(true);
set_resizable(true);
set_size(Size2(600, 400));
set_title("Open a File");
}
PaintLoadFileDialog::~PaintLoadFileDialog() {
}
void PaintLoadFileDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("_on_LoadFileDialog_file_selected", "path"), &PaintLoadFileDialog::_on_LoadFileDialog_file_selected);
ClassDB::bind_method(D_METHOD("_on_LoadFileDialog_confirmed"), &PaintLoadFileDialog::_on_LoadFileDialog_confirmed);
ClassDB::bind_method(D_METHOD("_on_LoadFileDialog_about_to_show"), &PaintLoadFileDialog::_on_LoadFileDialog_about_to_show);
ClassDB::bind_method(D_METHOD("_on_LoadFileDialog_visibility_changed"), &PaintLoadFileDialog::_on_LoadFileDialog_visibility_changed);
}

View File

@ -1,57 +0,0 @@
#ifndef PAINT_LOAD_FILE_DIALOG_H
#define PAINT_LOAD_FILE_DIALOG_H
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "scene/gui/file_dialog.h"
class PaintCanvasOld;
class PaintWindow;
class PaintLoadFileDialog : public FileDialog {
GDCLASS(PaintLoadFileDialog, FileDialog);
public:
void load_img();
void _on_LoadFileDialog_file_selected(const String &path);
void _on_LoadFileDialog_confirmed();
void _on_LoadFileDialog_about_to_show();
void _on_LoadFileDialog_visibility_changed();
PaintLoadFileDialog();
~PaintLoadFileDialog();
String file_path;
PaintCanvasOld *canvas;
PaintWindow *window;
protected:
void _notification(int p_what);
static void _bind_methods();
};
#endif

View File

@ -1,106 +0,0 @@
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "paint_save_file_dialog.h"
#include "../paint_canvas.h"
#include "../paint_canvas_layer.h"
#include "core/io/image.h"
#include "core/os/dir_access.h"
#include "core/os/file_access.h"
void PaintSaveFileDialog::save_file() {
Ref<Image> image;
image.instance();
image->create(canvas->get_canvas_width(), canvas->get_canvas_height(), true, Image::FORMAT_RGBA8);
image->lock();
for (int i = 0; i < canvas->layers.size(); ++i) {
Ref<PaintCanvasLayer> layer = canvas->layers[i];
if (!layer->get_visible()) {
continue;
}
for (int x = 0; x < layer->layer_width; ++x) {
for (int y = 0; y < layer->layer_height; ++y) {
Color color = layer->get_pixel(x, y);
Color image_color = image->get_pixel(x, y);
if (color.a < 0.999998) {
image->set_pixel(x, y, image_color.blend(color));
} else {
image->set_pixel(x, y, color);
}
}
}
}
image->unlock();
if (FileAccess::exists(file_path)) {
DirAccess::remove_file_or_error(file_path);
}
image->save_png(file_path);
}
void PaintSaveFileDialog::_on_SaveFileDialog_file_selected(const String &path) {
file_path = path;
save_file();
}
void PaintSaveFileDialog::_on_SaveFileDialog_about_to_show() {
invalidate();
}
void PaintSaveFileDialog::_on_SaveFileDialog_visibility_changed() {
invalidate();
}
void PaintSaveFileDialog::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_POSTINITIALIZE: {
connect("file_selected", this, "_on_SaveFileDialog_file_selected");
connect("about_to_show", this, "_on_SaveFileDialog_about_to_show");
connect("visibility_changed", this, "_on_SaveFileDialog_visibility_changed");
} break;
}
}
PaintSaveFileDialog::PaintSaveFileDialog() {
add_filter("*.png ; PNG Images");
set_show_hidden_files(true);
set_resizable(true);
set_size(Size2(600, 400));
}
PaintSaveFileDialog::~PaintSaveFileDialog() {
}
void PaintSaveFileDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("_on_SaveFileDialog_file_selected"), &PaintSaveFileDialog::_on_SaveFileDialog_file_selected);
ClassDB::bind_method(D_METHOD("_on_SaveFileDialog_about_to_show"), &PaintSaveFileDialog::_on_SaveFileDialog_about_to_show);
ClassDB::bind_method(D_METHOD("_on_SaveFileDialog_visibility_changed"), &PaintSaveFileDialog::_on_SaveFileDialog_visibility_changed);
}

View File

@ -1,54 +0,0 @@
#ifndef PAINT_SAVE_FILE_DIALOG_H
#define PAINT_SAVE_FILE_DIALOG_H
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "scene/gui/file_dialog.h"
class PaintCanvasOld;
class PaintSaveFileDialog : public FileDialog {
GDCLASS(PaintSaveFileDialog, FileDialog);
public:
void save_file();
void _on_SaveFileDialog_file_selected(const String &path);
void _on_SaveFileDialog_about_to_show();
void _on_SaveFileDialog_visibility_changed();
PaintSaveFileDialog();
~PaintSaveFileDialog();
String file_path;
PaintCanvasOld *canvas;
protected:
void _notification(int p_what);
static void _bind_methods();
};
#endif

View File

@ -1,628 +0,0 @@
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "paint_canvas.h"
#include "../ui/paint_canvas_background.h"
#include "../ui/paint_canvas_outline.h"
#include "../paint_utilities.h"
#include "../ui/paint_visual_grid.h"
#include "scene/gui/control.h"
#include "scene/gui/texture_rect.h"
#include "paint_canvas_layer.h"
#include "../paint_icons/icons.h"
void PaintCanvasOld::_process(float delta) {
if (!is_visible_in_tree()) {
return;
}
Vector2 mouse_position = get_local_mouse_position();
Rect2 rect = Rect2(Vector2(0, 0), get_size());
mouse_in_region = rect.has_point(mouse_position);
}
void PaintCanvasOld::_draw() {
for (int i = 0; i < layers.size(); ++i) {
Ref<PaintCanvasLayer> layer = layers[i];
ERR_CONTINUE(!layer.is_valid());
layer->update_texture();
}
preview_layer->update_texture();
tool_layer->update_texture();
}
int PaintCanvasOld::get_pixel_size() const {
return _pixel_size;
}
void PaintCanvasOld::set_pixel_size(const int size) {
_pixel_size = size;
set_grid_size(_grid_size);
set_big_grid_size(_big_grid_size);
set_canvas_width(_canvas_width);
set_canvas_height(_canvas_height);
}
int PaintCanvasOld::get_grid_size() const {
return _grid_size;
}
void PaintCanvasOld::set_grid_size(const int size) {
_grid_size = size;
if (grid) {
int s = size * _pixel_size;
grid->set_grid_size(s);
}
}
int PaintCanvasOld::get_big_grid_size() const {
return _big_grid_size;
}
void PaintCanvasOld::set_big_grid_size(const int size) {
_big_grid_size = size;
if (big_grid) {
int s = size * _pixel_size;
big_grid->set_size(Size2(s, s));
}
}
int PaintCanvasOld::get_canvas_width() const {
return _canvas_width;
}
void PaintCanvasOld::set_canvas_width(const int val) {
_canvas_width = val;
Size2 s = get_size();
s.x = _canvas_width * _pixel_size;
set_size(s);
}
int PaintCanvasOld::get_canvas_height() const {
return _canvas_height;
}
void PaintCanvasOld::set_canvas_height(const int val) {
_canvas_height = val;
Size2 s = get_size();
s.y = _canvas_height * _pixel_size;
set_size(s);
}
void PaintCanvasOld::toggle_alpha_locked(const String &layer_name) {
Ref<PaintCanvasLayer> layer = find_layer_by_name(layer_name);
if (layer.is_valid()) {
layer->toggle_alpha_locked();
}
}
bool PaintCanvasOld::is_alpha_locked() {
if (!active_layer.is_valid()) {
return false;
}
return active_layer->alpha_locked;
}
Rect2 PaintCanvasOld::get_content_margin() {
Rect2 rect = Rect2(999999, 999999, -999999, -999999);
for (int i = 0; i < layers.size(); ++i) {
Ref<PaintCanvasLayer> l = layers[i];
ERR_CONTINUE(!l.is_valid());
Rect2 r = l->image->get_used_rect();
if (r.position.x < rect.position.x) {
rect.position.x = r.position.x;
}
if (r.position.y < rect.position.y) {
rect.position.y = r.position.y;
}
if (r.size.x > rect.size.x) {
rect.size.x = r.size.x;
}
if (r.size.y > rect.size.y) {
rect.size.y = r.size.y;
}
}
return rect;
}
void PaintCanvasOld::crop_to_content() {
/*
var rect = get_content_margin()
#print(rect)
for layer in layers:
layer.image
# set_canvas_width(rect.size.x)
# set_canvas_height(rect.size.x)
# preview_layer.resize(width, height)
# tool_layer.resize(width, height)
# for layer in layers:
# layer.resize(width, height)
*/
}
Ref<PaintCanvasLayer> PaintCanvasOld::get_active_layer() {
return active_layer;
}
Ref<PaintCanvasLayer> PaintCanvasOld::get_preview_layer() {
return preview_layer;
}
void PaintCanvasOld::clear_active_layer() {
if (active_layer.is_valid()) {
active_layer->clear();
}
}
void PaintCanvasOld::clear_preview_layer() {
preview_layer->clear();
}
void PaintCanvasOld::clear_layer(const String &layer_name) {
for (int i = 0; i < layers.size(); ++i) {
Ref<PaintCanvasLayer> l = layers[i];
ERR_CONTINUE(!l.is_valid());
if (l->name == layer_name) {
l->clear();
return;
}
}
}
Ref<PaintCanvasLayer> PaintCanvasOld::remove_layer(const String &layer_name) {
// change current layer if the active layer is removed
Ref<PaintCanvasLayer> del_layer = find_layer_by_name(layer_name);
del_layer->clear();
if (del_layer == active_layer) {
if (layers.size() > 1) {
for (int i = 0; i < layers.size(); ++i) {
Ref<PaintCanvasLayer> layer = layers[i];
ERR_CONTINUE(!layer.is_valid());
if (layer == active_layer) {
continue;
}
active_layer = layer;
break;
}
} else {
active_layer.unref();
}
}
layers.erase(del_layer);
return active_layer;
}
Ref<PaintCanvasLayer> PaintCanvasOld::add_new_layer(const String &layer_name) {
for (int i = 0; i < layers.size(); ++i) {
Ref<PaintCanvasLayer> layer = layers[i];
ERR_CONTINUE(!layer.is_valid());
if (layer->name == layer_name) {
return layer;
}
}
Ref<PaintCanvasLayer> layer;
layer.instance();
layer->name = layer_name;
TextureRect *texture_rect = memnew(TextureRect);
texture_rect->set_name(layer_name);
canvas_layers->add_child(texture_rect, true);
texture_rect->set_expand(true);
texture_rect->set_anchors_and_margins_preset(Control::PRESET_WIDE);
//texture_rect->set_margin(Margin::MARGIN_RIGHT, 0);
//texture_rect->set_margin(Margin::MARGIN_BOTTOM, 0);
texture_rect->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
layer->create(texture_rect, _canvas_width, _canvas_height);
layers.push_back(layer);
if (!active_layer.is_valid()) {
active_layer = layer;
}
return layer;
}
Ref<PaintCanvasLayer> PaintCanvasOld::duplicate_layer(const String &layer_name, const String &new_layer_name) {
for (int i = 0; i < layers.size(); ++i) {
Ref<PaintCanvasLayer> layer = layers[i];
ERR_CONTINUE(!layer.is_valid());
if (layer->name == new_layer_name) {
return layer;
}
}
Ref<PaintCanvasLayer> dup_layer = find_layer_by_name(layer_name);
Ref<PaintCanvasLayer> layer = add_new_layer(new_layer_name);
layer->image->copy_internals_from(dup_layer->image);
return layer;
}
void PaintCanvasOld::toggle_layer_visibility(const String &layer_name) {
for (int i = 0; i < layers.size(); ++i) {
Ref<PaintCanvasLayer> layer = layers[i];
ERR_CONTINUE(!layer.is_valid());
if (layer->name == layer_name) {
layer->set_visible(!layer->get_visible());
return;
}
}
}
Ref<PaintCanvasLayer> PaintCanvasOld::find_layer_by_name(const String &layer_name) {
for (int i = 0; i < layers.size(); ++i) {
Ref<PaintCanvasLayer> layer = layers[i];
ERR_CONTINUE(!layer.is_valid());
if (layer->name == layer_name) {
return layer;
}
}
return Ref<PaintCanvasLayer>();
}
void PaintCanvasOld::toggle_lock_layer(const String &layer_name) {
find_layer_by_name(layer_name)->toggle_lock();
}
bool PaintCanvasOld::is_active_layer_locked() {
return active_layer->locked;
}
void PaintCanvasOld::move_layer_forward(const String &layer_name) {
TextureRect *layer = find_layer_by_name(layer_name)->texture_rect_ref;
int new_idx = MAX(layer->get_index() - 1, 0);
canvas_layers->move_child(layer, new_idx);
}
void PaintCanvasOld::move_layer_back(const String &layer_name) {
TextureRect *layer = find_layer_by_name(layer_name)->texture_rect_ref;
canvas_layers->move_child(layer, layer->get_index() + 1);
}
void PaintCanvasOld::select_layer(const String &layer_name) {
active_layer = find_layer_by_name(layer_name);
}
void PaintCanvasOld::_on_mouse_entered() {
mouse_on_top = true;
}
void PaintCanvasOld::_on_mouse_exited() {
mouse_on_top = false;
}
bool PaintCanvasOld::is_inside_canvas(const int x, const int y) {
if (x < 0 || y < 0) {
return false;
}
if (x >= _canvas_width || y >= _canvas_height) {
return false;
}
return true;
}
//Note: Arrays are always passed by reference. To get a copy of an array which
// can be modified independently of the original array, use duplicate.
// (https://docs.godotengine.org/en/stable/classes/class_array.html)
void PaintCanvasOld::set_pixel_arr(const PoolVector2iArray &pixels, const Color &color) {
PoolVector2iArray::Read r = pixels.read();
for (int i = 0; i < pixels.size(); ++i) {
const Vector2i &pixel = r[i];
_set_pixel(active_layer, pixel.x, pixel.y, color);
}
}
void PaintCanvasOld::set_pixel_v(const Vector2i &pos, const Color &color) {
set_pixel(pos.x, pos.y, color);
}
void PaintCanvasOld::set_pixel(const int x, const int y, const Color &color) {
_set_pixel(active_layer, x, y, color);
}
void PaintCanvasOld::_set_pixel_v(Ref<PaintCanvasLayer> layer, const Vector2i &v, const Color &color) {
_set_pixel(layer, v.x, v.y, color);
}
void PaintCanvasOld::_set_pixel(Ref<PaintCanvasLayer> layer, const int x, const int y, const Color &color) {
if (!is_inside_canvas(x, y)) {
return;
}
layer->set_pixel(x, y, color);
}
Color PaintCanvasOld::get_pixel_v(const Vector2i &pos) {
return get_pixel(pos.x, pos.y);
}
Color PaintCanvasOld::get_pixel(const int x, const int y) {
if (active_layer.is_valid()) {
return active_layer->get_pixel(x, y);
}
return Color();
}
void PaintCanvasOld::set_preview_pixel_v(const Vector2i &pos, const Color &color) {
set_preview_pixel(pos.x, pos.y, color);
}
void PaintCanvasOld::set_preview_pixel(const int x, const int y, const Color &color) {
if (!is_inside_canvas(x, y)) {
return;
}
preview_layer->set_pixel(x, y, color);
}
Color PaintCanvasOld::get_preview_pixel_v(const Vector2i &pos) {
return get_preview_pixel(pos.x, pos.y);
}
Color PaintCanvasOld::get_preview_pixel(const int x, const int y) {
return preview_layer->get_pixel(x, y);
}
bool PaintCanvasOld::validate_pixel_v(const Vector2i &pos) const {
if (active_layer.is_valid()) {
return active_layer->validate_pixel_v(pos);
}
return false;
}
void PaintCanvasOld::toggle_grid() {
grid->set_visible(!grid->is_visible());
}
void PaintCanvasOld::show_grid() {
grid->show();
}
void PaintCanvasOld::hide_grid() {
grid->hide();
}
PoolVector2iArray PaintCanvasOld::select_color(const int p_x, const int p_y) {
PoolVector2iArray same_color_pixels;
Color color = get_pixel(p_x, p_y);
for (int x = 0; x < active_layer->layer_width; ++x) {
for (int y = 0; y < active_layer->layer_height; ++y) {
Color pixel_color = active_layer->get_pixel(x, y);
if (pixel_color == color) {
same_color_pixels.append(Vector2i(x, y));
}
}
}
return same_color_pixels;
}
PoolVector2iArray PaintCanvasOld::select_same_color(const int p_x, const int p_y) {
return get_neighbouring_pixels(p_x, p_y);
}
// returns array of Vector2
// yoinked from
// https://www.geeksforgeeks.org/flood-fill-algorithm-implement-fill-paint/
PoolVector2iArray PaintCanvasOld::get_neighbouring_pixels(const int pos_x, const int pos_y) {
PoolVector2iArray pixels;
PoolIntArray to_check_queue;
PoolIntArray checked_queue;
to_check_queue.append(PaintUtilities::to_1D(pos_x, pos_y, _canvas_width));
Color color = get_pixel(pos_x, pos_y);
while (!to_check_queue.empty()) {
int idx = to_check_queue[0];
to_check_queue.remove(0);
Vector2i p = PaintUtilities::to_2D(idx, _canvas_width);
if (checked_queue.contains(idx)) {
continue;
}
checked_queue.append(idx);
if (get_pixel(p.x, p.y) != color) {
continue;
}
// add to result
pixels.append(p);
// check neighbours
int x = p.x - 1;
int y = p.y;
if (is_inside_canvas(x, y)) {
idx = PaintUtilities::to_1D(x, y, _canvas_width);
to_check_queue.append(idx);
}
x = p.x + 1;
if (is_inside_canvas(x, y)) {
idx = PaintUtilities::to_1D(x, y, _canvas_width);
to_check_queue.append(idx);
}
x = p.x;
y = p.y - 1;
if (is_inside_canvas(x, y)) {
idx = PaintUtilities::to_1D(x, y, _canvas_width);
to_check_queue.append(idx);
}
y = p.y + 1;
if (is_inside_canvas(x, y)) {
idx = PaintUtilities::to_1D(x, y, _canvas_width);
to_check_queue.append(idx);
}
}
return pixels;
}
void PaintCanvasOld::resize(int width, int height) {
//if (get_canvas_width() == width && get_canvas_height() == height) {
// return;
// }
if (width < 0) {
width = 1;
}
if (height < 0) {
height = 1;
}
_canvas_width = width;
_canvas_height = height;
Size2 s;
s.x = _canvas_width * _pixel_size;
s.y = _canvas_height * _pixel_size;
set_size(s);
preview_layer->resize(width, height);
tool_layer->resize(width, height);
for (int i = 0; i < layers.size(); ++i) {
Ref<PaintCanvasLayer> layer = layers[i];
ERR_CONTINUE(!layer.is_valid());
layer->resize(width, height);
}
update();
}
void PaintCanvasOld::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_POSTINITIALIZE: {
connect("mouse_entered", this, "_on_mouse_entered");
connect("mouse_exited", this, "_on_mouse_exited");
//canvas_size = Vector2(int(rect_size.x / grid_size), int(rect_size.y / grid_size));
//pixel_size = canvas_size;
active_layer = add_new_layer("Layer1");
////hack
//_canvas_width = 0;
//_canvas_height = 0;
set_process(true);
} break;
case NOTIFICATION_ENTER_TREE: {
resize(64, 64);
} break;
case NOTIFICATION_PROCESS: {
_process(get_process_delta_time());
} break;
case NOTIFICATION_DRAW: {
_draw();
} break;
}
}
PaintCanvasOld::PaintCanvasOld() {
big_grid = nullptr;
_pixel_size = 16;
_canvas_width = 64;
_canvas_height = 64;
_grid_size = 16;
_big_grid_size = 10;
_can_draw = true;
symmetry_x = false;
symmetry_y = false;
mouse_in_region = false;
mouse_on_top = false;
canvas_background = memnew(PaintCanvasBackground);
canvas_background->set_grid_size(32);
add_child(canvas_background);
canvas_layers = memnew(Control);
canvas_layers->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
canvas_layers->set_anchors_and_margins_preset(Control::PRESET_WIDE);
add_child(canvas_layers);
preview_layer_rect = memnew(TextureRect);
preview_layer_rect->set_expand(true);
preview_layer_rect->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
preview_layer_rect->set_anchors_and_margins_preset(Control::PRESET_WIDE);
add_child(preview_layer_rect);
tool_preview_layer_rect = memnew(TextureRect);
tool_preview_layer_rect->set_expand(true);
tool_preview_layer_rect->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
tool_preview_layer_rect->set_anchors_and_margins_preset(Control::PRESET_WIDE);
add_child(tool_preview_layer_rect);
grid = memnew(PaintVisualGrid);
grid->set_grid_size(4);
grid->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
add_child(grid);
canvas_outline = memnew(PaintCanvasOutline);
canvas_outline->color = Color(0, 1, 0, 1);
canvas_outline->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
add_child(canvas_outline);
preview_layer.instance();
tool_layer.instance();
preview_layer->name = "Preview";
tool_layer->name = "Tool";
preview_layer->create(preview_layer_rect, _canvas_width, _canvas_height);
tool_layer->create(tool_preview_layer_rect, _canvas_width, _canvas_height);
}
PaintCanvasOld::~PaintCanvasOld() {
}
void PaintCanvasOld::_bind_methods() {
ClassDB::bind_method(D_METHOD("_on_mouse_entered"), &PaintCanvasOld::_on_mouse_entered);
ClassDB::bind_method(D_METHOD("_on_mouse_exited"), &PaintCanvasOld::_on_mouse_exited);
}

View File

@ -1,152 +0,0 @@
#ifndef PAINT_CANVAS_OLD_H
#define PAINT_CANVAS_OLD_H
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "core/object/reference.h"
#include "scene/gui/margin_container.h"
#include "core/containers/vector.h"
class PaintCanvasLayer;
class TextureRect;
class Control;
class PaintCanvasOutline;
class PaintVisualGrid;
class PaintCanvasLayer;
class PaintCanvasBackground;
//class_name GECanvas
class PaintCanvasOld : public MarginContainer {
GDCLASS(PaintCanvasOld, MarginContainer);
public:
void _process(float delta);
void _draw();
int get_pixel_size() const;
void set_pixel_size(const int size);
int get_grid_size() const;
void set_grid_size(const int size);
int get_big_grid_size() const;
void set_big_grid_size(const int size);
int get_canvas_width() const;
void set_canvas_width(const int val);
int get_canvas_height() const;
void set_canvas_height(const int val);
void toggle_alpha_locked(const String &layer_name);
bool is_alpha_locked();
Rect2 get_content_margin();
void crop_to_content();
Ref<PaintCanvasLayer> get_active_layer();
Ref<PaintCanvasLayer> get_preview_layer();
void clear_active_layer();
void clear_preview_layer();
void clear_layer(const String &layer_name);
Ref<PaintCanvasLayer> remove_layer(const String &layer_name);
Ref<PaintCanvasLayer> add_new_layer(const String &layer_name);
Ref<PaintCanvasLayer> duplicate_layer(const String &layer_name, const String &new_layer_name);
void toggle_layer_visibility(const String &layer_name);
Ref<PaintCanvasLayer> find_layer_by_name(const String &layer_name);
void toggle_lock_layer(const String &layer_name);
bool is_active_layer_locked();
void move_layer_forward(const String &layer_name);
void move_layer_back(const String &layer_name);
void select_layer(const String &layer_name);
void _on_mouse_entered();
void _on_mouse_exited();
bool is_inside_canvas(const int x, const int y);
void set_pixel_arr(const PoolVector2iArray &pixels, const Color &color);
void set_pixel_v(const Vector2i &pos, const Color &color);
void set_pixel(const int x, const int y, const Color &color);
void _set_pixel_v(Ref<PaintCanvasLayer> layer, const Vector2i &v, const Color &color);
void _set_pixel(Ref<PaintCanvasLayer> layer, const int x, const int y, const Color &color);
Color get_pixel_v(const Vector2i &pos);
Color get_pixel(const int x, const int y);
void set_preview_pixel_v(const Vector2i &pos, const Color &color);
void set_preview_pixel(const int x, const int y, const Color &color);
Color get_preview_pixel_v(const Vector2i &pos);
Color get_preview_pixel(const int x, const int y);
bool validate_pixel_v(const Vector2i &pos) const;
void toggle_grid();
void show_grid();
void hide_grid();
PoolVector2iArray select_color(const int p_x, const int p_y);
PoolVector2iArray select_same_color(const int p_x, const int p_y);
PoolVector2iArray get_neighbouring_pixels(const int pos_x, const int pos_y);
void resize(int width, int height);
PaintCanvasOld();
~PaintCanvasOld();
Vector<Ref<PaintCanvasLayer>> layers;
Ref<PaintCanvasLayer> active_layer;
Ref<PaintCanvasLayer> preview_layer;
Ref<PaintCanvasLayer> tool_layer;
PaintCanvasBackground *canvas_background;
Control *canvas_layers;
TextureRect *preview_layer_rect;
TextureRect *tool_preview_layer_rect;
PaintVisualGrid *grid;
PaintCanvasOutline *canvas_outline;
//not used
PaintVisualGrid *big_grid;
bool symmetry_x;
bool symmetry_y;
bool mouse_in_region;
bool mouse_on_top;
Array selected_pixels;
protected:
void _notification(int p_what);
static void _bind_methods();
int _pixel_size;
int _canvas_width;
int _canvas_height;
int _grid_size;
int _big_grid_size;
bool _can_draw;
};
#endif

View File

@ -1,145 +0,0 @@
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "paint_canvas_layer.h"
#include "../paint_utilities.h"
#include "scene/gui/texture_rect.h"
bool PaintCanvasLayer::get_visible() {
return _visible;
}
void PaintCanvasLayer::set_visible(const bool vis) {
_visible = vis;
texture_rect_ref->set_visible(_visible);
}
void PaintCanvasLayer::create(TextureRect *p_texture_rect_ref, const int width, const int height) {
texture_rect_ref = p_texture_rect_ref;
layer_width = width;
layer_height = height;
image.instance();
image->create(width, height, false, Image::FORMAT_RGBA8);
//Color.transparent
image->fill(Color(1.00, 1.00, 1.00, 0.00));
update_texture();
}
void PaintCanvasLayer::resize(const int width, const int height) {
PoolColorArray pixel_colors;
int prev_width = layer_width;
int prev_height = layer_height;
image->lock();
for (int y = 0; y < prev_height; ++y) {
for (int x = 0; x < prev_width; ++x) {
pixel_colors.append(image->get_pixel(x, y));
}
}
image->unlock();
layer_width = width;
layer_height = height;
image->create(width, height, false, Image::FORMAT_RGBA8);
image->lock();
for (int x = 0; x < prev_width; ++x) {
for (int y = 0; y < prev_height; ++y) {
if (x >= width || y >= height) {
continue;
}
image->set_pixel(x, y, pixel_colors[PaintUtilities::to_1D(x, y, prev_width)]);
}
}
image->unlock();
update_texture();
}
void PaintCanvasLayer::set_pixel(const int x, const int y, const Color &color) {
image->lock();
image->set_pixel(x, y, color);
image->unlock();
}
Color PaintCanvasLayer::get_pixel(const int x, const int y) {
if (x < 0 || y < 0 || x >= image->get_width() || y >= image->get_height()) {
return Color();
}
image->lock();
Color pixel = image->get_pixel(x, y);
image->unlock();
return pixel;
}
bool PaintCanvasLayer::validate_pixel_v(const Vector2i &pos) const {
if (pos.x < 0 || pos.y < 0 || pos.x >= image->get_width() || pos.y >= image->get_height()) {
return false;
}
return true;
}
void PaintCanvasLayer::clear() {
//Color.transparent
image->fill(Color(1.00, 1.00, 1.00, 0.00));
update_texture();
}
void PaintCanvasLayer::update_texture() {
texture->create_from_image(image, 0);
texture_rect_ref->set_texture(texture);
}
void PaintCanvasLayer::toggle_lock() {
locked = !locked;
}
void PaintCanvasLayer::toggle_alpha_locked() {
alpha_locked = !alpha_locked;
}
PaintCanvasLayer::PaintCanvasLayer() {
layer_width = 0;
layer_height = 0;
_visible = true;
locked = false;
alpha_locked = false;
texture_rect_ref = nullptr;
texture.instance();
}
PaintCanvasLayer::~PaintCanvasLayer() {
}
void PaintCanvasLayer::_bind_methods() {
}

View File

@ -1,75 +0,0 @@
#ifndef PAINT_CANVAS_LAYER_H
#define PAINT_CANVAS_LAYER_H
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "core/object/reference.h"
#include "core/io/image.h"
#include "scene/resources/texture.h"
class TextureRect;
//class_name GELayer
class PaintCanvasLayer : public Reference {
GDCLASS(PaintCanvasLayer, Reference);
public:
String name;
int layer_width;
int layer_height;
bool locked = false;
bool alpha_locked = false;
Ref<ImageTexture> texture;
Ref<Image> image;
TextureRect *texture_rect_ref;
bool get_visible();
void set_visible(const bool vis);
void create(TextureRect *p_texture_rect_ref, const int width, const int height);
void resize(const int width, const int height);
void set_pixel(const int x, const int y, const Color &color);
Color get_pixel(const int x, const int y);
bool validate_pixel_v(const Vector2i &pos) const;
void clear();
void update_texture();
void toggle_lock();
void toggle_alpha_locked();
PaintCanvasLayer();
~PaintCanvasLayer();
protected:
static void _bind_methods();
bool _visible;
};
#endif

View File

@ -1,137 +0,0 @@
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "paint_layer_button.h"
#include "core/io/image.h"
#include "scene/resources/style_box.h"
#include "scene/resources/texture.h"
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
#include "scene/gui/check_button.h"
#include "scene/gui/margin_container.h"
#include "scene/gui/texture_button.h"
#include "../paint_icons/icons.h"
PaintLayerButton::PaintLayerButton() {
set_custom_minimum_size(Size2(0, 32));
set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
Ref<StyleBoxFlat> style_box;
style_box.instance();
style_box->set("bg_color", Color(0.35, 0.5, 0.77));
set("custom_styles/panel", style_box);
HBoxContainer *main_box_container = memnew(HBoxContainer);
add_child(main_box_container);
MarginContainer *left_main_container = memnew(MarginContainer);
left_main_container->set("custom_constants/margin_right", 2);
left_main_container->set("custom_constants/margin_top", 2);
left_main_container->set("custom_constants/margin_left", 2);
left_main_container->set("custom_constants/margin_bottom", 2);
left_main_container->set_h_size_flags(SIZE_EXPAND_FILL);
left_main_container->set_v_size_flags(SIZE_EXPAND_FILL);
main_box_container->add_child(left_main_container);
// Layer Button
layer_button = memnew(Button);
layer_button->set_text("Layer 1");
layer_button->set_text_align(Button::ALIGN_RIGHT);
layer_button->set_h_size_flags(SIZE_EXPAND_FILL);
layer_button->set_v_size_flags(SIZE_EXPAND_FILL);
style_box.instance();
style_box->set("bg_color", Color(0.25, 0.25, 0.25));
layer_button->set("custom_styles/hover", style_box);
style_box.instance();
style_box->set("bg_color", Color(0.25, 0.25, 0.25));
layer_button->set("custom_styles/pressed", style_box);
style_box.instance();
style_box->set("bg_color", Color(0.25, 0.25, 0.25));
layer_button->set("custom_styles/focus", style_box);
style_box.instance();
style_box->set("bg_color", Color(0.25, 0.25, 0.25));
layer_button->set("custom_styles/disabled", style_box);
style_box.instance();
style_box->set("bg_color", Color(0.25, 0.25, 0.25));
layer_button->set("custom_styles/normal", style_box);
left_main_container->add_child(layer_button);
HBoxContainer *check_container = memnew(HBoxContainer);
check_container->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
left_main_container->add_child(check_container);
// Visible Button
visible_button = memnew(CheckButton);
visible_button->set_pressed(true);
visible_button->set("custom_icons/off", PaintIcons::make_icon_minidotta_invis_png());
visible_button->set("custom_icons/on", PaintIcons::make_icon_minidotta_png());
style_box.instance();
style_box->set("bg_color", Color(0.6, 0.6, 0.6));
layer_button->set("custom_styles/normal", style_box);
check_container->add_child(visible_button);
// Lock Button
lock_button = memnew(CheckButton);
lock_button->set_pressed(false);
lock_button->set("custom_icons/off", PaintIcons::make_icon_unlock_layer_png());
lock_button->set("custom_icons/on", PaintIcons::make_icon_lock_layer_1_png());
style_box.instance();
style_box->set("bg_color", Color(0.6, 0.6, 0.6));
layer_button->set("custom_styles/normal", style_box);
check_container->add_child(lock_button);
// Right side
VBoxContainer *right_main_container = memnew(VBoxContainer);
main_box_container->add_child(right_main_container);
up_button = memnew(TextureButton);
up_button->set_expand(true);
up_button->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED);
up_button->set_h_size_flags(SIZE_EXPAND_FILL);
up_button->set_v_size_flags(SIZE_EXPAND_FILL);
up_button->set_normal_texture(PaintIcons::make_icon_arrow_up_png());
up_button->set_pressed_texture(PaintIcons::make_icon_minidotta_png());
up_button->set_custom_minimum_size(Vector2(15, 15));
right_main_container->add_child(up_button);
down_button = memnew(TextureButton);
down_button->set_expand(true);
down_button->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED);
down_button->set_h_size_flags(SIZE_EXPAND_FILL);
down_button->set_v_size_flags(SIZE_EXPAND_FILL);
down_button->set_normal_texture(PaintIcons::make_icon_arrow_down_png());
down_button->set_pressed_texture(PaintIcons::make_icon_minidotta_png());
down_button->set_custom_minimum_size(Vector2(15, 15));
right_main_container->add_child(down_button);
}
PaintLayerButton::~PaintLayerButton() {
}
void PaintLayerButton::_bind_methods() {
}

View File

@ -1,51 +0,0 @@
#ifndef PAINT_LAYER_BUTTON_H
#define PAINT_LAYER_BUTTON_H
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "scene/gui/panel_container.h"
class Button;
class CheckButton;
class TextureButton;
class PaintLayerButton : public PanelContainer {
GDCLASS(PaintLayerButton, PanelContainer);
public:
PaintLayerButton();
~PaintLayerButton();
Button *layer_button;
CheckButton *visible_button;
CheckButton *lock_button;
TextureButton *up_button;
TextureButton *down_button;
protected:
static void _bind_methods();
};
#endif

View File

@ -1,248 +0,0 @@
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "paint_navbar.h"
#include "paint_canvas.h"
#include "paint_window.h"
#include "scene/gui/label.h"
#include "scene/gui/menu_button.h"
#include "scene/gui/popup_menu.h"
#include "dialogs/paint_canvas_dialog.h"
#include "dialogs/paint_change_grid_size_dialog.h"
#include "dialogs/paint_load_file_dialog.h"
#include "dialogs/paint_save_file_dialog.h"
#include "paint_canvas_layer.h"
#include "paint_settings.h"
void PaintNavbar::handle_menu_item_pressed(const int id) {
switch (id) {
case MENU_FILE_NEW:
paint_window->paint_canvas_dialog->is_new = true;
paint_window->paint_canvas_dialog->popup_centered();
break;
case MENU_FILE_SAVE:
paint_window->paint_save_file_dialog->popup_centered();
break;
case MENU_FILE_LOAD:
paint_window->paint_load_file_dialog->popup_centered();
break;
case MENU_EDIT_UNDO:
break;
case MENU_EDIT_REDO:
break;
case MENU_EDIT_CUT:
break;
case MENU_EDIT_COPY:
break;
case MENU_EDIT_PASTE:
break;
case MENU_CANVAS_CHANGE_SIZE:
paint_window->paint_canvas_dialog->is_new = false;
paint_window->paint_canvas_dialog->popup_centered();
break;
case MENU_CANVAS_CROP_TO_CONTENT:
canvas->crop_to_content();
break;
case MENU_LAYER_ADD:
paint_window->add_new_layer();
break;
case MENU_LAYER_DELETE:
paint_window->remove_active_layer();
break;
case MENU_LAYER_DUPLICATE:
paint_window->duplicate_active_layer();
break;
case MENU_LAYER_CLEAR:
canvas->clear_active_layer();
break;
case MENU_LAYER_TOGGLE_ALPHA_LOCKED:
//owner.paint_canvas.active_layer.toggle_alpha_locked()
//$Buttons/Layer.get_popup().set_item_checked(id, not $Buttons/Layer.get_popup().is_item_checked(id))
//owner.find_node("LockAlpha").pressed = $Buttons/Layer.get_popup().is_item_checked(id)
break;
case MENU_GRID_TOGGLE:
canvas->toggle_grid();
break;
case MENU_GRID_CHANGE_SIZE:
paint_window->paint_change_grid_size_dialog->popup_centered();
break;
case MENU_MAGIC_CHANGE_SINGLE_COLOR:
break;
case MENU_MAGIC_CHANGE_COLOR_RANGE:
break;
case MENU_MAGIC_HSV_NOISE:
break;
case MENU_MAGIC_HSV_COLOR_MODULATION:
break;
case MENU_EDITOR_SETTINGS:
paint_window->paint_settings_dialog->popup_centered();
break;
default:
break;
}
}
bool PaintNavbar::is_any_menu_open() {
if (file_menu_button->get_popup()->is_visible() || edit_menu_button->get_popup()->is_visible() ||
canvas_menu_button->get_popup()->is_visible() || layer_menu_button->get_popup()->is_visible() ||
grid_menu_button->get_popup()->is_visible() || magic_menu_button->get_popup()->is_visible() ||
editor_menu_button->get_popup()->is_visible()) {
return true;
}
return false;
}
PaintNavbar::PaintNavbar() {
paint_window = nullptr;
canvas = nullptr;
HBoxContainer *button_hbox_container = memnew(HBoxContainer);
add_child(button_hbox_container);
file_menu_button = memnew(MenuButton);
file_menu_button->set_switch_on_hover(true);
file_menu_button->set_text("File");
file_menu_button->set_flat(false);
file_menu_button->set_h_size_flags(Control::SIZE_EXPAND_FILL);
file_menu_button->set_v_size_flags(Control::SIZE_EXPAND_FILL);
button_hbox_container->add_child(file_menu_button);
PopupMenu *menu = file_menu_button->get_popup();
menu->add_item("New", MENU_FILE_NEW);
menu->add_item("Save", MENU_FILE_SAVE);
menu->add_item("Load", MENU_FILE_LOAD);
menu->connect("id_pressed", this, "handle_menu_item_pressed");
edit_menu_button = memnew(MenuButton);
edit_menu_button->set_switch_on_hover(true);
edit_menu_button->set_text("Edit");
edit_menu_button->set_disabled(true);
edit_menu_button->set_flat(false);
edit_menu_button->set_h_size_flags(Control::SIZE_EXPAND_FILL);
edit_menu_button->set_v_size_flags(Control::SIZE_EXPAND_FILL);
button_hbox_container->add_child(edit_menu_button);
menu = edit_menu_button->get_popup();
menu->add_item("Undo", MENU_EDIT_UNDO);
menu->add_item("Redo", MENU_EDIT_REDO);
menu->add_item("Cut", MENU_EDIT_CUT);
menu->add_item("Copy", MENU_EDIT_COPY);
menu->add_item("Paste", MENU_EDIT_PASTE);
menu->connect("id_pressed", this, "handle_menu_item_pressed");
canvas_menu_button = memnew(MenuButton);
canvas_menu_button->set_switch_on_hover(true);
canvas_menu_button->set_text("Canvas");
canvas_menu_button->set_flat(false);
canvas_menu_button->set_h_size_flags(Control::SIZE_EXPAND_FILL);
canvas_menu_button->set_v_size_flags(Control::SIZE_EXPAND_FILL);
button_hbox_container->add_child(canvas_menu_button);
menu = canvas_menu_button->get_popup();
menu->add_item("Change Size", MENU_CANVAS_CHANGE_SIZE);
//menu->add_item("Crop To Content", MENU_CANVAS_CROP_TO_CONTENT);
menu->connect("id_pressed", this, "handle_menu_item_pressed");
layer_menu_button = memnew(MenuButton);
layer_menu_button->set_switch_on_hover(true);
layer_menu_button->set_text("Layer");
layer_menu_button->set_flat(false);
layer_menu_button->set_h_size_flags(Control::SIZE_EXPAND_FILL);
layer_menu_button->set_v_size_flags(Control::SIZE_EXPAND_FILL);
button_hbox_container->add_child(layer_menu_button);
menu = layer_menu_button->get_popup();
menu->add_item("Add Layer", MENU_LAYER_ADD);
menu->add_item("Delete Layer", MENU_LAYER_DELETE);
menu->add_item("Duplicate Layer", MENU_LAYER_DUPLICATE);
menu->add_item("Clear Layer", MENU_LAYER_CLEAR);
menu->add_separator();
menu->add_check_item("Toggle Alpha Locked", MENU_LAYER_TOGGLE_ALPHA_LOCKED);
menu->connect("id_pressed", this, "handle_menu_item_pressed");
grid_menu_button = memnew(MenuButton);
grid_menu_button->set_switch_on_hover(true);
grid_menu_button->set_text("Grid");
grid_menu_button->set_flat(false);
grid_menu_button->set_h_size_flags(Control::SIZE_EXPAND_FILL);
grid_menu_button->set_v_size_flags(Control::SIZE_EXPAND_FILL);
button_hbox_container->add_child(grid_menu_button);
menu = grid_menu_button->get_popup();
menu->add_item("Toggle Grid", MENU_GRID_TOGGLE);
menu->add_item("Change Grid Size", MENU_GRID_CHANGE_SIZE);
menu->connect("id_pressed", this, "handle_menu_item_pressed");
magic_menu_button = memnew(MenuButton);
magic_menu_button->set_switch_on_hover(true);
magic_menu_button->set_text("Magic");
magic_menu_button->set_flat(false);
magic_menu_button->set_h_size_flags(Control::SIZE_EXPAND_FILL);
magic_menu_button->set_v_size_flags(Control::SIZE_EXPAND_FILL);
button_hbox_container->add_child(magic_menu_button);
menu = magic_menu_button->get_popup();
menu->add_item("Change Single Color", MENU_MAGIC_CHANGE_SINGLE_COLOR);
menu->add_item("Change Color Range", MENU_MAGIC_CHANGE_COLOR_RANGE);
menu->add_item("HSV Noise", MENU_MAGIC_HSV_NOISE);
menu->add_item("HSV Color Modulation", MENU_MAGIC_HSV_COLOR_MODULATION);
menu->connect("id_pressed", this, "handle_menu_item_pressed");
magic_menu_button->hide();
editor_menu_button = memnew(MenuButton);
editor_menu_button->set_switch_on_hover(true);
editor_menu_button->set_text("Editor");
editor_menu_button->set_flat(false);
editor_menu_button->set_h_size_flags(Control::SIZE_EXPAND_FILL);
editor_menu_button->set_v_size_flags(Control::SIZE_EXPAND_FILL);
button_hbox_container->add_child(editor_menu_button);
menu = editor_menu_button->get_popup();
menu->add_item("Settings", MENU_EDITOR_SETTINGS);
menu->connect("id_pressed", this, "handle_menu_item_pressed");
Control *spacer = memnew(Control);
spacer->set_h_size_flags(Control::SIZE_EXPAND_FILL);
add_child(spacer);
Label *urlabel = memnew(Label);
urlabel->set_text("Undo (Z) Redo (Y)");
urlabel->set_align(Label::ALIGN_CENTER);
urlabel->set_valign(Label::VALIGN_CENTER);
add_child(urlabel);
}
PaintNavbar::~PaintNavbar() {
}
void PaintNavbar::_bind_methods() {
ClassDB::bind_method(D_METHOD("handle_menu_item_pressed"), &PaintNavbar::handle_menu_item_pressed);
}

View File

@ -1,91 +0,0 @@
#ifndef PAINT_NAVBAR_H
#define PAINT_NAVBAR_H
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "scene/gui/box_container.h"
class PaintWindow;
class PaintCanvasOld;
class MenuButton;
class PaintNavbar : public BoxContainer {
GDCLASS(PaintNavbar, BoxContainer);
public:
enum {
MENU_FILE_NEW = 0,
MENU_FILE_SAVE,
MENU_FILE_LOAD,
MENU_EDIT_UNDO,
MENU_EDIT_REDO,
MENU_EDIT_CUT,
MENU_EDIT_COPY,
MENU_EDIT_PASTE,
MENU_CANVAS_CHANGE_SIZE,
MENU_CANVAS_CROP_TO_CONTENT,
MENU_LAYER_ADD,
MENU_LAYER_DELETE,
MENU_LAYER_DUPLICATE,
MENU_LAYER_CLEAR,
MENU_LAYER_TOGGLE_ALPHA_LOCKED,
MENU_GRID_TOGGLE,
MENU_GRID_CHANGE_SIZE,
MENU_MAGIC_CHANGE_SINGLE_COLOR,
MENU_MAGIC_CHANGE_COLOR_RANGE,
MENU_MAGIC_HSV_NOISE,
MENU_MAGIC_HSV_COLOR_MODULATION,
MENU_EDITOR_SETTINGS,
};
void handle_menu_item_pressed(const int id);
bool is_any_menu_open();
PaintNavbar();
~PaintNavbar();
PaintWindow *paint_window;
PaintCanvasOld *canvas;
MenuButton *file_menu_button;
MenuButton *edit_menu_button;
MenuButton *canvas_menu_button;
MenuButton *layer_menu_button;
MenuButton *grid_menu_button;
MenuButton *magic_menu_button;
MenuButton *editor_menu_button;
protected:
static void _bind_methods();
};
#endif

View File

@ -1,95 +0,0 @@
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "paint_settings.h"
#include "../ui/paint_canvas_outline.h"
#include "scene/gui/box_container.h"
#include "scene/gui/check_button.h"
#include "scene/gui/color_picker.h"
#include "scene/gui/label.h"
#include "scene/gui/spin_box.h"
void PaintSettings::_on_ColorPickerButton_color_changed(const Color &color) {
canvas_outline->color = color;
canvas_outline->update();
}
void PaintSettings::_on_CheckButton_toggled(const bool button_pressed) {
canvas_outline->set_visible(button_pressed);
}
PaintSettings::PaintSettings() {
set_resizable(true);
set_title("Settings");
VBoxContainer *main_box_container = memnew(VBoxContainer);
add_child(main_box_container);
HBoxContainer *outline_container = memnew(HBoxContainer);
outline_container->set_v_size_flags(Control::SIZE_EXPAND_FILL);
outline_container->set_h_size_flags(Control::SIZE_EXPAND_FILL);
main_box_container->add_child(outline_container);
Label *outline_label = memnew(Label);
outline_label->set_text("Canvas Outline:");
outline_label->set_valign(Label::VALIGN_CENTER);
outline_label->set_v_size_flags(Control::SIZE_EXPAND_FILL);
outline_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
outline_container->add_child(outline_label);
_check_button = memnew(CheckButton);
_check_button->set_pressed(true);
_check_button->set_v_size_flags(Control::SIZE_EXPAND_FILL);
_check_button->set_h_size_flags(Control::SIZE_EXPAND_FILL);
_check_button->connect("toggled", this, "_on_CheckButton_toggled");
outline_container->add_child(_check_button);
HBoxContainer *color_picker_container = memnew(HBoxContainer);
color_picker_container->set_v_size_flags(Control::SIZE_EXPAND_FILL);
color_picker_container->set_h_size_flags(Control::SIZE_EXPAND_FILL);
main_box_container->add_child(color_picker_container);
Label *grid_label = memnew(Label);
grid_label->set_text("Canvas Outline Color:");
grid_label->set_valign(Label::VALIGN_CENTER);
grid_label->set_v_size_flags(Control::SIZE_EXPAND_FILL);
grid_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
color_picker_container->add_child(grid_label);
_color_picker_button = memnew(ColorPickerButton);
_color_picker_button->set_v_size_flags(Control::SIZE_EXPAND_FILL);
_color_picker_button->set_h_size_flags(Control::SIZE_EXPAND_FILL);
_color_picker_button->set_custom_minimum_size(Size2(100, 0));
_color_picker_button->connect("color_changed", this, "_on_ColorPickerButton_color_changed");
color_picker_container->add_child(_color_picker_button);
}
PaintSettings::~PaintSettings() {
}
void PaintSettings::_bind_methods() {
ClassDB::bind_method(D_METHOD("_on_ColorPickerButton_color_changed"), &PaintSettings::_on_ColorPickerButton_color_changed);
ClassDB::bind_method(D_METHOD("_on_CheckButton_toggled"), &PaintSettings::_on_CheckButton_toggled);
}

View File

@ -1,53 +0,0 @@
#ifndef PAINT_SETTINGS_H
#define PAINT_SETTINGS_H
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "scene/gui/dialogs.h"
class CheckButton;
class ColorPickerButton;
class PaintCanvasOutline;
class PaintSettings : public AcceptDialog {
GDCLASS(PaintSettings, AcceptDialog);
public:
PaintSettings();
~PaintSettings();
PaintCanvasOutline *canvas_outline;
protected:
void _on_ColorPickerButton_color_changed(const Color &color);
void _on_CheckButton_toggled(const bool button_pressed);
static void _bind_methods();
CheckButton *_check_button;
ColorPickerButton *_color_picker_button;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,312 +0,0 @@
#ifndef PAINT_WINDOW_H
#define PAINT_WINDOW_H
/*
Copyright (c) 2019 Flairieve
Copyright (c) 2020-2022 cobrapitz
Copyright (c) 2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "scene/gui/control.h"
#include "../bush_prefabs.h"
#include "core/containers/hash_map.h"
#include "core/object/reference.h"
#include "core/os/keyboard.h"
class PaintAction;
class PaintCanvasLayer;
class PaintCanvasOld;
class InputEvent;
class PaintCanvasDialog;
class PaintChangeGridSizeDialog;
class PaintLoadFileDialog;
class PaintSaveFileDialog;
class PaintSettings;
class RichTextLabel;
class PaintNavbar;
class PaintColorGrid;
class CheckButton;
class Label;
class HSlider;
class Control;
class Button;
class ColorPickerButton;
class VBoxContainer;
class PaintLayerButton;
class PanelContainer;
class PaintWindow : public Control {
GDCLASS(PaintWindow, Control);
public:
enum Tools {
PAINT = 0,
BRUSH,
BUCKET,
RAINBOW,
LINE,
RECT,
DARKEN,
BRIGHTEN,
COLORPICKER,
CUT,
PASTECUT,
};
enum KeyboardShortcuts {
K_UNDO = KEY_Z,
K_REDO = KEY_Y,
K_PENCIL = KEY_Q,
K_BRUSH = KEY_W,
K_BUCKET = KEY_F,
K_RAINBOW = KEY_R,
K_LINE = KEY_L,
K_DARK = KEY_D,
K_BRIGHT = KEY_B,
K_CUT = KEY_C,
K_PICK = KEY_P,
};
enum {
max_zoom_out = 1,
max_zoom_in = 50,
};
Control *get_navbar();
Control *get_left_content_panel();
Control *get_paint_canvas();
Control *get_right_panel_container();
Control *get_bottom_content_panel();
Control *get_text_info_control();
bool get_allow_canvas_zoom();
void set_allow_canvas_zoom(const bool val);
bool get_allow_canvas_move();
void set_allow_canvas_move(const bool val);
Color get_selected_color();
void set_selected_color(const Color &color);
int get_tool();
void set_tool(const int val);
int get_brush_type();
void set_brush_type(const int val);
int get_brush_size();
void set_brush_size(const int val);
Ref<Image> get_image();
void new_image(const int x, const int y);
void clear_image();
void center_paint_canvas();
void window_fit_paint_canvas(const float ratio = 0.8);
void _input(const Ref<InputEvent> &event);
void _process(float delta);
void _handle_shortcuts(const int scancode);
void _draw_tool_brush();
void _handle_scroll();
void _handle_zoom(const Ref<InputEvent> &event);
void _handle_cut();
void brush_process();
void update_text_info();
void _on_Save_pressed();
void do_action_old(const Array &data);
void commit_action_old();
void redo_action_old();
void undo_action_old();
Ref<PaintAction> get_action();
void set_brush(const Tools new_mode);
void change_color(const Color &new_color);
void _on_ColorPicker_color_changed(const Color &color);
void _on_PaintTool_pressed();
void _on_BucketTool_pressed();
void _on_RainbowTool_pressed();
void _on_BrushTool_pressed();
void _on_LineTool_pressed();
void _on_RectTool_pressed();
void _on_DarkenTool_pressed();
void _on_BrightenTool_pressed();
void _on_ColorPickerTool_pressed();
void _on_CutTool_pressed();
void _on_Editor_visibility_changed();
void _on_ChangeGridSizeDialog_confirmed();
void _on_ChangeCanvasSizeDialog_confirmed();
void highlight_layer(const String &layer_name);
void toggle_layer_visibility(Node *button, const String &layer_name);
void select_layer(const String &layer_name);
void lock_layer(Node *button, const String &layer_name);
Ref<PaintCanvasLayer> add_new_layer();
void remove_active_layer();
void duplicate_active_layer();
void delete_all_layers();
void move_up(Node *layer_btn);
void move_down(Node *layer_btn);
void _connect_layer_buttons();
void _on_Button_pressed();
void _on_PaintCanvasContainer_mouse_entered();
void _on_PaintCanvasContainer_mouse_exited();
void _on_ColorPicker_popup_closed();
bool is_position_in_canvas(const Vector2 &pos);
bool is_mouse_in_canvas();
bool is_any_menu_open();
void _on_LockAlpha_pressed();
void _on_BrushRect_pressed();
void _on_BrushCircle_pressed();
void _on_BrushVLine_pressed();
void _on_BrushHLine_pressed();
void _on_BrushSize_value_changed(float value);
void _on_XSymmetry_pressed();
void _on_YSymmetry_pressed();
PaintWindow();
~PaintWindow();
PaintCanvasDialog *paint_canvas_dialog;
PaintChangeGridSizeDialog *paint_change_grid_size_dialog;
PaintLoadFileDialog *paint_load_file_dialog;
PaintSaveFileDialog *paint_save_file_dialog;
PaintSettings *paint_settings_dialog;
RichTextLabel *text_info;
PaintNavbar *navbar;
PaintColorGrid *color_grid;
CheckButton *lock_alpha_button;
Label *brush_size_label;
HSlider *brush_size_slider;
CheckButton *x_symmetry_button;
CheckButton *y_symmetry_button;
PanelContainer *left_content_panel;
PanelContainer *mid_right_panel_container;
PanelContainer *bottom_content_panel;
Control *paint_canvas_container;
PaintCanvasOld *paint_canvas;
Button *paint_tool_button;
Button *brush_tool_button;
Button *multi_tool_button;
Button *bucket_tool_button;
Button *rainbow_tool_button;
Button *line_tool_button;
Button *rect_tool_button;
Button *darken_tool_button;
Button *brighten_tool_button;
Button *color_picker_tool_button;
Button *cut_tool_button;
ColorPickerButton *color_picker_button;
VBoxContainer *layers_box_container;
Button *add_layer_button;
bool allow_drawing;
bool mouse_in_region;
bool mouse_on_top;
bool mouse_from_touch;
Vector2 _middle_mouse_pressed_pos;
Vector2 _middle_mouse_pressed_start_pos;
bool _middle_mouse_pressed;
Vector2 _left_mouse_pressed_start_pos;
PaintWindow::Tools _previous_tool;
PaintWindow::Tools brush_mode;
HashMap<String, PaintLayerButton *> _layer_button_ref;
int _total_added_layers;
BrushPrefabs::Type selected_brush_prefab;
Vector2 _last_drawn_pixel;
Vector2 _last_preview_draw_cell_pos;
PoolVector2iArray _selection_cells;
PoolColorArray _selection_colors;
Vector2i _cut_pos;
Vector2i _cut_size;
Vector<Ref<PaintAction>> _actions_history;
Vector<Ref<PaintAction>> _redo_history;
Ref<PaintAction> _current_action;
Vector2 _last_mouse_pos_canvas_area;
bool _picked_color;
Vector2 mouse_position;
Vector2 canvas_position;
Vector2 canvas_mouse_position;
Vector2 cell_mouse_position;
Color cell_color;
Vector2 last_mouse_position;
Vector2 last_canvas_position;
Vector2 last_canvas_mouse_position;
Vector2 last_cell_mouse_position;
Color last_cell_color;
Color current_layer_highlight;
Color other_layer_highlight;
Color locked_layer_highlight;
int big_grid_pixels;
bool _allow_canvas_zoom;
bool _allow_canvas_move;
protected:
void _notification(int p_what);
static void _bind_methods();
Color _selected_color;
};
VARIANT_ENUM_CAST(PaintWindow::Tools);
#endif

View File

@ -1,57 +0,0 @@
/*
Copyright (c) 2019-2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "paint_editor_plugin_old.h"
#include "deprecated/paint_window.h"
void PaintEditorPluginOld::make_visible(const bool visible) {
window->set_visible(visible);
}
String PaintEditorPluginOld::get_name() const {
return "Paint";
}
const Ref<Texture> PaintEditorPluginOld::get_icon() const {
return _icon;
}
bool PaintEditorPluginOld::has_main_screen() const {
return true;
}
PaintEditorPluginOld::PaintEditorPluginOld(EditorNode *p_node) {
editor = p_node;
window = memnew(PaintWindow);
get_editor_interface()->get_editor_viewport()->add_child(window);
window->set_owner(get_editor_interface()->get_editor_viewport());
make_visible(false);
_icon = get_editor_interface()->get_base_control()->get_theme_icon("CanvasModulate", "EditorIcons");
}
PaintEditorPluginOld::~PaintEditorPluginOld() {
}
void PaintEditorPluginOld::_bind_methods() {
}

View File

@ -1,54 +0,0 @@
#ifndef PAINT_EDITOR_PLUGIN_OLD_H
#define PAINT_EDITOR_PLUGIN_OLD_H
/*
Copyright (c) 2019-2022 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "editor/editor_plugin.h"
#include "core/object/reference.h"
class PaintWindow;
class Texture;
class PaintEditorPluginOld : public EditorPlugin {
GDCLASS(PaintEditorPluginOld, EditorPlugin);
public:
void make_visible(const bool visible);
const Ref<Texture> get_icon() const;
bool has_main_screen() const;
String get_name() const;
PaintEditorPluginOld(EditorNode *p_node);
~PaintEditorPluginOld();
EditorNode *editor;
PaintWindow *window;
protected:
static void _bind_methods();
Ref<Texture> _icon;
};
#endif

View File

@ -36,8 +36,6 @@ SOFTWARE.
#include "actions/rainbow_action.h" #include "actions/rainbow_action.h"
#include "actions/rect_action.h" #include "actions/rect_action.h"
#include "deprecated/paint_window.h"
#include "ui/paint_canvas_background.h" #include "ui/paint_canvas_background.h"
#include "ui/paint_canvas_outline.h" #include "ui/paint_canvas_outline.h"
#include "ui/paint_selection_box.h" #include "ui/paint_selection_box.h"
@ -55,12 +53,9 @@ SOFTWARE.
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
#include "paint_editor_plugin.h" #include "paint_editor_plugin.h"
#include "paint_editor_plugin_old.h"
#endif #endif
void register_paint_types() { void register_paint_types() {
ClassDB::register_class<PaintWindow>();
ClassDB::register_class<PaintAction>(); ClassDB::register_class<PaintAction>();
ClassDB::register_class<BrightenAction>(); ClassDB::register_class<BrightenAction>();
@ -92,7 +87,6 @@ void register_paint_types() {
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
EditorPlugins::add_by_type<PaintEditorPlugin>(); EditorPlugins::add_by_type<PaintEditorPlugin>();
EditorPlugins::add_by_type<PaintEditorPluginOld>();
#endif #endif
} }