From 5c9aa754d701c202ae808ac7d5bb2e5674859dcf Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 20 Nov 2022 21:11:40 +0100 Subject: [PATCH] Removed most of the deprecated classes from the paint module. --- modules/paint/SCsub | 13 - modules/paint/actions/brighten_action.cpp | 36 - modules/paint/actions/brighten_action.h | 4 - modules/paint/actions/brush_action.cpp | 39 - modules/paint/actions/brush_action.h | 4 - modules/paint/actions/bucket_action.cpp | 37 - modules/paint/actions/bucket_action.h | 4 - modules/paint/actions/cut_action.cpp | 77 - modules/paint/actions/cut_action.h | 5 - modules/paint/actions/darken_action.cpp | 36 - modules/paint/actions/darken_action.h | 1 - modules/paint/actions/line_action.cpp | 58 - modules/paint/actions/line_action.h | 5 - modules/paint/actions/multiline_action.cpp | 28 - modules/paint/actions/multiline_action.h | 3 - modules/paint/actions/paint_action.cpp | 114 -- modules/paint/actions/paint_action.h | 20 +- modules/paint/actions/paste_cut_action.cpp | 57 - modules/paint/actions/paste_cut_action.h | 4 - modules/paint/actions/pencil_action.cpp | 32 - modules/paint/actions/pencil_action.h | 5 - modules/paint/actions/rainbow_action.cpp | 45 - modules/paint/actions/rainbow_action.h | 4 - modules/paint/actions/rect_action.cpp | 65 - modules/paint/actions/rect_action.h | 5 - .../dialogs/paint_canvas_dialog.cpp | 133 -- .../deprecated/dialogs/paint_canvas_dialog.h | 61 - .../dialogs/paint_change_grid_size_dialog.cpp | 102 - .../dialogs/paint_change_grid_size_dialog.h | 52 - .../dialogs/paint_load_file_dialog.cpp | 114 -- .../dialogs/paint_load_file_dialog.h | 57 - .../dialogs/paint_save_file_dialog.cpp | 106 - .../dialogs/paint_save_file_dialog.h | 54 - modules/paint/deprecated/paint_canvas.cpp | 628 ------ modules/paint/deprecated/paint_canvas.h | 152 -- .../paint/deprecated/paint_canvas_layer.cpp | 145 -- modules/paint/deprecated/paint_canvas_layer.h | 75 - .../paint/deprecated/paint_layer_button.cpp | 137 -- modules/paint/deprecated/paint_layer_button.h | 51 - modules/paint/deprecated/paint_navbar.cpp | 248 --- modules/paint/deprecated/paint_navbar.h | 91 - modules/paint/deprecated/paint_settings.cpp | 95 - modules/paint/deprecated/paint_settings.h | 53 - modules/paint/deprecated/paint_window.cpp | 1716 ----------------- modules/paint/deprecated/paint_window.h | 312 --- modules/paint/paint_editor_plugin_old.cpp | 57 - modules/paint/paint_editor_plugin_old.h | 54 - modules/paint/register_types.cpp | 6 - 48 files changed, 2 insertions(+), 5198 deletions(-) delete mode 100644 modules/paint/deprecated/dialogs/paint_canvas_dialog.cpp delete mode 100644 modules/paint/deprecated/dialogs/paint_canvas_dialog.h delete mode 100644 modules/paint/deprecated/dialogs/paint_change_grid_size_dialog.cpp delete mode 100644 modules/paint/deprecated/dialogs/paint_change_grid_size_dialog.h delete mode 100644 modules/paint/deprecated/dialogs/paint_load_file_dialog.cpp delete mode 100644 modules/paint/deprecated/dialogs/paint_load_file_dialog.h delete mode 100644 modules/paint/deprecated/dialogs/paint_save_file_dialog.cpp delete mode 100644 modules/paint/deprecated/dialogs/paint_save_file_dialog.h delete mode 100644 modules/paint/deprecated/paint_canvas.cpp delete mode 100644 modules/paint/deprecated/paint_canvas.h delete mode 100644 modules/paint/deprecated/paint_canvas_layer.cpp delete mode 100644 modules/paint/deprecated/paint_canvas_layer.h delete mode 100644 modules/paint/deprecated/paint_layer_button.cpp delete mode 100644 modules/paint/deprecated/paint_layer_button.h delete mode 100644 modules/paint/deprecated/paint_navbar.cpp delete mode 100644 modules/paint/deprecated/paint_navbar.h delete mode 100644 modules/paint/deprecated/paint_settings.cpp delete mode 100644 modules/paint/deprecated/paint_settings.h delete mode 100644 modules/paint/deprecated/paint_window.cpp delete mode 100644 modules/paint/deprecated/paint_window.h delete mode 100644 modules/paint/paint_editor_plugin_old.cpp delete mode 100644 modules/paint/paint_editor_plugin_old.h diff --git a/modules/paint/SCsub b/modules/paint/SCsub index feab29afd..1f00b888b 100644 --- a/modules/paint/SCsub +++ b/modules/paint/SCsub @@ -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/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_background.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_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"]: 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") diff --git a/modules/paint/actions/brighten_action.cpp b/modules/paint/actions/brighten_action.cpp index 29172248f..022bac0d2 100644 --- a/modules/paint/actions/brighten_action.cpp +++ b/modules/paint/actions/brighten_action.cpp @@ -24,8 +24,6 @@ SOFTWARE. #include "brighten_action.h" -#include "../deprecated/paint_canvas.h" -#include "../deprecated/paint_canvas_layer.h" #include "../paint_utilities.h" #include "../nodes/paint_canvas.h" @@ -37,40 +35,6 @@ void BrightenAction::set_brighten_color(const float 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) { PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]); diff --git a/modules/paint/actions/brighten_action.h b/modules/paint/actions/brighten_action.h index b5e890d87..2ded9f917 100644 --- a/modules/paint/actions/brighten_action.h +++ b/modules/paint/actions/brighten_action.h @@ -27,8 +27,6 @@ SOFTWARE. #include "paint_action.h" -class PaintCanvasOld; - class BrightenAction : public PaintAction { GDCLASS(BrightenAction, PaintAction); @@ -36,8 +34,6 @@ public: float get_brighten_color(); void set_brighten_color(const float val); - void do_action_old(PaintCanvasOld *canvas, const Array &data); - void _do_action(const Array &data); BrightenAction(); diff --git a/modules/paint/actions/brush_action.cpp b/modules/paint/actions/brush_action.cpp index cacc3a138..8904339ff 100644 --- a/modules/paint/actions/brush_action.cpp +++ b/modules/paint/actions/brush_action.cpp @@ -25,49 +25,10 @@ SOFTWARE. #include "brush_action.h" #include "../bush_prefabs.h" -#include "../deprecated/paint_canvas.h" -#include "../deprecated/paint_canvas_layer.h" #include "../paint_utilities.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(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) { PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]); int brush_type = data[3]; diff --git a/modules/paint/actions/brush_action.h b/modules/paint/actions/brush_action.h index 9afe80979..28cea7dcc 100644 --- a/modules/paint/actions/brush_action.h +++ b/modules/paint/actions/brush_action.h @@ -27,14 +27,10 @@ SOFTWARE. #include "paint_action.h" -class PaintCanvasOld; - class BrushAction : public PaintAction { GDCLASS(BrushAction, PaintAction); public: - void do_action_old(PaintCanvasOld *canvas, const Array &data); - void _do_action(const Array &data); BrushAction(); diff --git a/modules/paint/actions/bucket_action.cpp b/modules/paint/actions/bucket_action.cpp index 950e5468c..27b3d6ef3 100644 --- a/modules/paint/actions/bucket_action.cpp +++ b/modules/paint/actions/bucket_action.cpp @@ -24,47 +24,10 @@ SOFTWARE. #include "bucket_action.h" -#include "../deprecated/paint_canvas.h" -#include "../deprecated/paint_canvas_layer.h" #include "../paint_utilities.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) { Vector2i pos = data[0]; diff --git a/modules/paint/actions/bucket_action.h b/modules/paint/actions/bucket_action.h index 948a78fb4..cfc2e972a 100644 --- a/modules/paint/actions/bucket_action.h +++ b/modules/paint/actions/bucket_action.h @@ -27,14 +27,10 @@ SOFTWARE. #include "paint_action.h" -class PaintCanvasOld; - class BucketAction : public PaintAction { GDCLASS(BucketAction, PaintAction); public: - void do_action_old(PaintCanvasOld *canvas, const Array &data); - void _do_action(const Array &data); BucketAction(); diff --git a/modules/paint/actions/cut_action.cpp b/modules/paint/actions/cut_action.cpp index a5f1b7191..2d0763e52 100644 --- a/modules/paint/actions/cut_action.cpp +++ b/modules/paint/actions/cut_action.cpp @@ -24,8 +24,6 @@ SOFTWARE. #include "cut_action.h" -#include "../deprecated/paint_canvas.h" -#include "../deprecated/paint_canvas_layer.h" #include "../paint_utilities.h" #include "../nodes/paint_canvas.h" @@ -62,81 +60,6 @@ bool CutAction::_can_commit() { 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) { if (!mouse_start_pos_set) { mouse_start_pos = data[0]; diff --git a/modules/paint/actions/cut_action.h b/modules/paint/actions/cut_action.h index c9862e6df..c9ee7ecdf 100644 --- a/modules/paint/actions/cut_action.h +++ b/modules/paint/actions/cut_action.h @@ -27,8 +27,6 @@ SOFTWARE. #include "paint_action.h" -class PaintCanvasOld; - class CutAction : public PaintAction { GDCLASS(CutAction, PaintAction); @@ -47,9 +45,6 @@ public: 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 _commit_action(); diff --git a/modules/paint/actions/darken_action.cpp b/modules/paint/actions/darken_action.cpp index a62be27f6..06c98ec7d 100644 --- a/modules/paint/actions/darken_action.cpp +++ b/modules/paint/actions/darken_action.cpp @@ -24,8 +24,6 @@ SOFTWARE. #include "darken_action.h" -#include "../deprecated/paint_canvas.h" -#include "../deprecated/paint_canvas_layer.h" #include "../paint_utilities.h" #include "../nodes/paint_canvas.h" @@ -37,40 +35,6 @@ void DarkenAction::set_dark_factor(const float 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) { PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]); diff --git a/modules/paint/actions/darken_action.h b/modules/paint/actions/darken_action.h index 793243187..3fb8bc94f 100644 --- a/modules/paint/actions/darken_action.h +++ b/modules/paint/actions/darken_action.h @@ -36,7 +36,6 @@ public: float get_dark_factor(); void set_dark_factor(const float val); - void do_action_old(PaintCanvasOld *canvas, const Array &data); void _do_action(const Array &data); DarkenAction(); diff --git a/modules/paint/actions/line_action.cpp b/modules/paint/actions/line_action.cpp index 11eb05302..6223838d1 100644 --- a/modules/paint/actions/line_action.cpp +++ b/modules/paint/actions/line_action.cpp @@ -24,8 +24,6 @@ SOFTWARE. #include "line_action.h" -#include "../deprecated/paint_canvas.h" -#include "../deprecated/paint_canvas_layer.h" #include "../paint_utilities.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; } -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) { if (!mouse_start_pos_set) { mouse_start_pos = data[0]; diff --git a/modules/paint/actions/line_action.h b/modules/paint/actions/line_action.h index 1124b16c7..56b754796 100644 --- a/modules/paint/actions/line_action.h +++ b/modules/paint/actions/line_action.h @@ -27,8 +27,6 @@ SOFTWARE. #include "paint_action.h" -class PaintCanvasOld; - class LineAction : public PaintAction { GDCLASS(LineAction, PaintAction); @@ -39,9 +37,6 @@ public: bool get_mouse_start_pos_set(); 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 _commit_action(); bool _can_commit(); diff --git a/modules/paint/actions/multiline_action.cpp b/modules/paint/actions/multiline_action.cpp index 2554885f0..fd6ec9669 100644 --- a/modules/paint/actions/multiline_action.cpp +++ b/modules/paint/actions/multiline_action.cpp @@ -24,8 +24,6 @@ SOFTWARE. #include "multiline_action.h" -#include "../deprecated/paint_canvas.h" -#include "../deprecated/paint_canvas_layer.h" #include "../paint_utilities.h" #include "../nodes/paint_canvas.h" @@ -34,32 +32,6 @@ bool MultiLineAction::_can_commit() { 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) { PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]); diff --git a/modules/paint/actions/multiline_action.h b/modules/paint/actions/multiline_action.h index 98f127c60..bc8912227 100644 --- a/modules/paint/actions/multiline_action.h +++ b/modules/paint/actions/multiline_action.h @@ -27,15 +27,12 @@ SOFTWARE. #include "paint_action.h" -class PaintCanvasOld; - class MultiLineAction : public PaintAction { GDCLASS(MultiLineAction, PaintAction); public: bool _can_commit(); - void do_action_old(PaintCanvasOld *canvas, const Array &data); void _do_action(const Array &data); MultiLineAction(); diff --git a/modules/paint/actions/paint_action.cpp b/modules/paint/actions/paint_action.cpp index 8a8df62e5..5211691e4 100644 --- a/modules/paint/actions/paint_action.cpp +++ b/modules/paint/actions/paint_action.cpp @@ -24,8 +24,6 @@ SOFTWARE. #include "paint_action.h" -#include "../deprecated/paint_canvas.h" -#include "../deprecated/paint_canvas_layer.h" #include "core/object/object.h" #include "../nodes/paint_canvas.h" @@ -103,13 +101,6 @@ void PaintAction::set_preview_colors(const PoolColorArray &val) { preview_colors = val; } -Ref PaintAction::get_layer() { - return layer; -} -void PaintAction::set_layer(const Ref &val) { - layer = val; -} - Dictionary PaintAction::get_action_data() { return action_data; } @@ -117,23 +108,6 @@ void PaintAction::set_action_data(const Dictionary &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) { int p = canvas_width - pixel.x; @@ -246,74 +220,6 @@ PoolVector2iArray PaintAction::get_points(const Vector2i &pixel) { 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) { for (int i = 0; i < point_arr.size(); ++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) { call("_do_action", data); } diff --git a/modules/paint/actions/paint_action.h b/modules/paint/actions/paint_action.h index bb9ef3b95..594b60f22 100644 --- a/modules/paint/actions/paint_action.h +++ b/modules/paint/actions/paint_action.h @@ -27,15 +27,13 @@ SOFTWARE. #include "core/object/resource.h" +#include "core/containers/pool_vector.h" +#include "core/math/vector2i.h" #include "core/variant/array.h" #include "core/variant/dictionary.h" -#include "core/math/vector2i.h" -#include "core/containers/pool_vector.h" #include "core/variant/variant.h" -class PaintCanvasOld; class PaintCanvas; -class PaintCanvasLayer; class Node; class PaintAction : public Resource { @@ -73,19 +71,9 @@ public: PoolColorArray get_preview_colors(); void set_preview_colors(const PoolColorArray &val); - //deprecated - Ref get_layer(); - void set_layer(const Ref &val); - Dictionary get_action_data(); 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 commit_action(); @@ -105,10 +93,8 @@ public: 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_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_old(PaintCanvasOld *canvas, const PoolVector2iArray &point_arr, const PoolColorArray &color_arr); PaintAction(); ~PaintAction(); @@ -126,8 +112,6 @@ public: PoolVector2iArray preview_cells; PoolColorArray preview_colors; - Ref layer; - Dictionary action_data; protected: diff --git a/modules/paint/actions/paste_cut_action.cpp b/modules/paint/actions/paste_cut_action.cpp index 173432040..b137e959b 100644 --- a/modules/paint/actions/paste_cut_action.cpp +++ b/modules/paint/actions/paste_cut_action.cpp @@ -24,67 +24,10 @@ SOFTWARE. #include "paste_cut_action.h" -#include "../deprecated/paint_canvas.h" -#include "../deprecated/paint_canvas_layer.h" #include "../paint_utilities.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) { PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]); Vector2i cut_pos = data[4]; diff --git a/modules/paint/actions/paste_cut_action.h b/modules/paint/actions/paste_cut_action.h index a1137db10..eb38bfdf7 100644 --- a/modules/paint/actions/paste_cut_action.h +++ b/modules/paint/actions/paste_cut_action.h @@ -27,14 +27,10 @@ SOFTWARE. #include "paint_action.h" -class PaintCanvasOld; - class PasteCutAction : public PaintAction { GDCLASS(PasteCutAction, PaintAction); public: - void do_action_old(PaintCanvasOld *canvas, const Array &data); - void _do_action(const Array &data); PasteCutAction(); diff --git a/modules/paint/actions/pencil_action.cpp b/modules/paint/actions/pencil_action.cpp index d3876e1c5..5939e7aca 100644 --- a/modules/paint/actions/pencil_action.cpp +++ b/modules/paint/actions/pencil_action.cpp @@ -24,43 +24,11 @@ SOFTWARE. #include "pencil_action.h" -#include "../deprecated/paint_canvas.h" -#include "../deprecated/paint_canvas_layer.h" #include "../paint_utilities.h" #include "core/string/print_string.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) { Color c = data[2]; diff --git a/modules/paint/actions/pencil_action.h b/modules/paint/actions/pencil_action.h index 29e5abbe9..2de8ea603 100644 --- a/modules/paint/actions/pencil_action.h +++ b/modules/paint/actions/pencil_action.h @@ -27,15 +27,10 @@ SOFTWARE. #include "paint_action.h" -class PaintCanvasOld; - class PencilAction : public PaintAction { GDCLASS(PencilAction, PaintAction); 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 _set_pixel(Vector2i pixel, Color color); diff --git a/modules/paint/actions/rainbow_action.cpp b/modules/paint/actions/rainbow_action.cpp index 775493e11..b5826822f 100644 --- a/modules/paint/actions/rainbow_action.cpp +++ b/modules/paint/actions/rainbow_action.cpp @@ -24,55 +24,10 @@ SOFTWARE. #include "rainbow_action.h" -#include "../deprecated/paint_canvas.h" -#include "../deprecated/paint_canvas_layer.h" #include "../paint_utilities.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) { PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(data[0], data[1]); diff --git a/modules/paint/actions/rainbow_action.h b/modules/paint/actions/rainbow_action.h index a3c66b58c..1d9e8646d 100644 --- a/modules/paint/actions/rainbow_action.h +++ b/modules/paint/actions/rainbow_action.h @@ -27,14 +27,10 @@ SOFTWARE. #include "paint_action.h" -class PaintCanvasOld; - class RainbowAction : public PaintAction { GDCLASS(RainbowAction, PaintAction); public: - void do_action_old(PaintCanvasOld *canvas, const Array &data); - void _do_action(const Array &data); RainbowAction(); diff --git a/modules/paint/actions/rect_action.cpp b/modules/paint/actions/rect_action.cpp index 12ad62ff8..7da0ed0d6 100644 --- a/modules/paint/actions/rect_action.cpp +++ b/modules/paint/actions/rect_action.cpp @@ -24,8 +24,6 @@ SOFTWARE. #include "rect_action.h" -#include "../deprecated/paint_canvas.h" -#include "../deprecated/paint_canvas_layer.h" #include "../paint_utilities.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; } -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) { if (!mouse_start_pos_set) { mouse_start_pos = data[0]; diff --git a/modules/paint/actions/rect_action.h b/modules/paint/actions/rect_action.h index fd6683417..66ba9d386 100644 --- a/modules/paint/actions/rect_action.h +++ b/modules/paint/actions/rect_action.h @@ -27,8 +27,6 @@ SOFTWARE. #include "paint_action.h" -class PaintCanvasOld; - class RectAction : public PaintAction { GDCLASS(RectAction, PaintAction); @@ -39,9 +37,6 @@ public: bool get_mouse_start_pos_set(); 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 _commit_action(); bool _can_commit(); diff --git a/modules/paint/deprecated/dialogs/paint_canvas_dialog.cpp b/modules/paint/deprecated/dialogs/paint_canvas_dialog.cpp deleted file mode 100644 index 18f59f8be..000000000 --- a/modules/paint/deprecated/dialogs/paint_canvas_dialog.cpp +++ /dev/null @@ -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(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(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); -} diff --git a/modules/paint/deprecated/dialogs/paint_canvas_dialog.h b/modules/paint/deprecated/dialogs/paint_canvas_dialog.h deleted file mode 100644 index 0e1ff670e..000000000 --- a/modules/paint/deprecated/dialogs/paint_canvas_dialog.h +++ /dev/null @@ -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 diff --git a/modules/paint/deprecated/dialogs/paint_change_grid_size_dialog.cpp b/modules/paint/deprecated/dialogs/paint_change_grid_size_dialog.cpp deleted file mode 100644 index 9aabb764c..000000000 --- a/modules/paint/deprecated/dialogs/paint_change_grid_size_dialog.cpp +++ /dev/null @@ -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(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(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() { -} diff --git a/modules/paint/deprecated/dialogs/paint_change_grid_size_dialog.h b/modules/paint/deprecated/dialogs/paint_change_grid_size_dialog.h deleted file mode 100644 index 7e4f32e6e..000000000 --- a/modules/paint/deprecated/dialogs/paint_change_grid_size_dialog.h +++ /dev/null @@ -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 diff --git a/modules/paint/deprecated/dialogs/paint_load_file_dialog.cpp b/modules/paint/deprecated/dialogs/paint_load_file_dialog.cpp deleted file mode 100644 index 130421dfb..000000000 --- a/modules/paint/deprecated/dialogs/paint_load_file_dialog.cpp +++ /dev/null @@ -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.instance(); - - if (image->load(file_path) != OK) { - ERR_FAIL_MSG("couldn't load image!"); - } - - PoolByteArray image_data = image->get_data(); - Ref 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); -} diff --git a/modules/paint/deprecated/dialogs/paint_load_file_dialog.h b/modules/paint/deprecated/dialogs/paint_load_file_dialog.h deleted file mode 100644 index 561298c10..000000000 --- a/modules/paint/deprecated/dialogs/paint_load_file_dialog.h +++ /dev/null @@ -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 diff --git a/modules/paint/deprecated/dialogs/paint_save_file_dialog.cpp b/modules/paint/deprecated/dialogs/paint_save_file_dialog.cpp deleted file mode 100644 index b71104e4a..000000000 --- a/modules/paint/deprecated/dialogs/paint_save_file_dialog.cpp +++ /dev/null @@ -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.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 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); -} diff --git a/modules/paint/deprecated/dialogs/paint_save_file_dialog.h b/modules/paint/deprecated/dialogs/paint_save_file_dialog.h deleted file mode 100644 index 938130fd3..000000000 --- a/modules/paint/deprecated/dialogs/paint_save_file_dialog.h +++ /dev/null @@ -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 diff --git a/modules/paint/deprecated/paint_canvas.cpp b/modules/paint/deprecated/paint_canvas.cpp deleted file mode 100644 index 578dd09f9..000000000 --- a/modules/paint/deprecated/paint_canvas.cpp +++ /dev/null @@ -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 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 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 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 PaintCanvasOld::get_active_layer() { - return active_layer; -} -Ref 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 l = layers[i]; - - ERR_CONTINUE(!l.is_valid()); - - if (l->name == layer_name) { - l->clear(); - return; - } - } -} -Ref PaintCanvasOld::remove_layer(const String &layer_name) { - // change current layer if the active layer is removed - Ref 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 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 PaintCanvasOld::add_new_layer(const String &layer_name) { - for (int i = 0; i < layers.size(); ++i) { - Ref layer = layers[i]; - - ERR_CONTINUE(!layer.is_valid()); - - if (layer->name == layer_name) { - return layer; - } - } - - Ref 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 PaintCanvasOld::duplicate_layer(const String &layer_name, const String &new_layer_name) { - for (int i = 0; i < layers.size(); ++i) { - Ref layer = layers[i]; - - ERR_CONTINUE(!layer.is_valid()); - - if (layer->name == new_layer_name) { - return layer; - } - } - - Ref dup_layer = find_layer_by_name(layer_name); - Ref 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 layer = layers[i]; - - ERR_CONTINUE(!layer.is_valid()); - - if (layer->name == layer_name) { - layer->set_visible(!layer->get_visible()); - return; - } - } -} -Ref PaintCanvasOld::find_layer_by_name(const String &layer_name) { - for (int i = 0; i < layers.size(); ++i) { - Ref layer = layers[i]; - - ERR_CONTINUE(!layer.is_valid()); - - if (layer->name == layer_name) { - return layer; - } - } - - return Ref(); -} -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 layer, const Vector2i &v, const Color &color) { - _set_pixel(layer, v.x, v.y, color); -} -void PaintCanvasOld::_set_pixel(Ref 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 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); -} diff --git a/modules/paint/deprecated/paint_canvas.h b/modules/paint/deprecated/paint_canvas.h deleted file mode 100644 index c773c765d..000000000 --- a/modules/paint/deprecated/paint_canvas.h +++ /dev/null @@ -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 get_active_layer(); - Ref get_preview_layer(); - void clear_active_layer(); - void clear_preview_layer(); - void clear_layer(const String &layer_name); - Ref remove_layer(const String &layer_name); - Ref add_new_layer(const String &layer_name); - Ref duplicate_layer(const String &layer_name, const String &new_layer_name); - void toggle_layer_visibility(const String &layer_name); - Ref 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 layer, const Vector2i &v, const Color &color); - void _set_pixel(Ref 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> layers; - Ref active_layer; - Ref preview_layer; - Ref 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 diff --git a/modules/paint/deprecated/paint_canvas_layer.cpp b/modules/paint/deprecated/paint_canvas_layer.cpp deleted file mode 100644 index e7a217b68..000000000 --- a/modules/paint/deprecated/paint_canvas_layer.cpp +++ /dev/null @@ -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() { -} diff --git a/modules/paint/deprecated/paint_canvas_layer.h b/modules/paint/deprecated/paint_canvas_layer.h deleted file mode 100644 index 8cd68ce72..000000000 --- a/modules/paint/deprecated/paint_canvas_layer.h +++ /dev/null @@ -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 texture; - Ref 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 diff --git a/modules/paint/deprecated/paint_layer_button.cpp b/modules/paint/deprecated/paint_layer_button.cpp deleted file mode 100644 index 5ea0e7c1f..000000000 --- a/modules/paint/deprecated/paint_layer_button.cpp +++ /dev/null @@ -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 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() { -} diff --git a/modules/paint/deprecated/paint_layer_button.h b/modules/paint/deprecated/paint_layer_button.h deleted file mode 100644 index 9cf5611ca..000000000 --- a/modules/paint/deprecated/paint_layer_button.h +++ /dev/null @@ -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 diff --git a/modules/paint/deprecated/paint_navbar.cpp b/modules/paint/deprecated/paint_navbar.cpp deleted file mode 100644 index 78d93a8ba..000000000 --- a/modules/paint/deprecated/paint_navbar.cpp +++ /dev/null @@ -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); -} diff --git a/modules/paint/deprecated/paint_navbar.h b/modules/paint/deprecated/paint_navbar.h deleted file mode 100644 index e3e06ac20..000000000 --- a/modules/paint/deprecated/paint_navbar.h +++ /dev/null @@ -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 diff --git a/modules/paint/deprecated/paint_settings.cpp b/modules/paint/deprecated/paint_settings.cpp deleted file mode 100644 index 8737c1f81..000000000 --- a/modules/paint/deprecated/paint_settings.cpp +++ /dev/null @@ -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); -} diff --git a/modules/paint/deprecated/paint_settings.h b/modules/paint/deprecated/paint_settings.h deleted file mode 100644 index baaaea5d9..000000000 --- a/modules/paint/deprecated/paint_settings.h +++ /dev/null @@ -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 diff --git a/modules/paint/deprecated/paint_window.cpp b/modules/paint/deprecated/paint_window.cpp deleted file mode 100644 index 0ec8c6478..000000000 --- a/modules/paint/deprecated/paint_window.cpp +++ /dev/null @@ -1,1716 +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_window.h" - -#include "core/input/input.h" -#include "core/io/image.h" -#include "scene/resources/texture.h" - -#include "../actions/brighten_action.h" -#include "../actions/brush_action.h" -#include "../actions/bucket_action.h" -#include "../actions/cut_action.h" -#include "../actions/darken_action.h" -#include "../actions/line_action.h" -#include "../actions/multiline_action.h" -#include "../actions/paste_cut_action.h" -#include "../actions/pencil_action.h" -#include "../actions/rainbow_action.h" -#include "../actions/rect_action.h" - -#include "paint_canvas.h" -#include "../ui/paint_canvas_background.h" -#include "paint_canvas_layer.h" -#include "../ui/property_inspectors/paint_color_grid.h" -#include "paint_layer_button.h" -#include "paint_navbar.h" -#include "../paint_utilities.h" -#include "scene/resources/style_box.h" - -#include "scene/gui/button.h" -#include "scene/gui/check_button.h" -#include "scene/gui/color_picker.h" -#include "scene/gui/label.h" -#include "scene/gui/margin_container.h" -#include "scene/gui/panel_container.h" -#include "scene/gui/rich_text_label.h" -#include "scene/gui/scroll_container.h" -#include "scene/gui/slider.h" -#include "scene/gui/texture_button.h" -#include "scene/gui/texture_rect.h" -#include "scene/gui/grid_container.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_settings.h" - -#include "../paint_icons/icons.h" - -Control *PaintWindow::get_navbar() { - return navbar; -} -Control *PaintWindow::get_left_content_panel() { - return left_content_panel; -} -Control *PaintWindow::get_paint_canvas() { - return paint_canvas; -} -Control *PaintWindow::get_right_panel_container() { - return mid_right_panel_container; -} -Control *PaintWindow::get_bottom_content_panel() { - return bottom_content_panel; -} -Control *PaintWindow::get_text_info_control() { - return text_info; -} - -bool PaintWindow::get_allow_canvas_zoom() { - return _allow_canvas_zoom; -} -void PaintWindow::set_allow_canvas_zoom(const bool val) { - _allow_canvas_zoom = val; -} - -bool PaintWindow::get_allow_canvas_move() { - return _allow_canvas_move; -} -void PaintWindow::set_allow_canvas_move(const bool val) { - _allow_canvas_move = val; -} - -Color PaintWindow::get_selected_color() { - return _selected_color; -} -void PaintWindow::set_selected_color(const Color &color) { - if (color.a == 0) { - return; - } - - _selected_color = color; - - color_picker_button->set_pick_color(_selected_color); -} - -int PaintWindow::get_tool() { - return static_cast(brush_mode); -} -void PaintWindow::set_tool(const int val) { - set_brush(static_cast(val)); -} - -int PaintWindow::get_brush_type() { - return static_cast(selected_brush_prefab); -} -void PaintWindow::set_brush_type(const int val) { - selected_brush_prefab = static_cast(val); -} - -int PaintWindow::get_brush_size() { - return brush_size_slider->get_value(); -} -void PaintWindow::set_brush_size(const int val) { - brush_size_slider->set_value(val); - brush_size_label->set_text(rtos(val)); -} - -Ref PaintWindow::get_image() { - Ref image; - image.instance(); - - image->create(paint_canvas->get_canvas_width(), paint_canvas->get_canvas_height(), true, Image::FORMAT_RGBA8); - image->lock(); - - for (int i = 0; i < paint_canvas->layers.size(); ++i) { - Ref layer = paint_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(); - - return image; -} - -void PaintWindow::new_image(const int x, const int y) { - delete_all_layers(); - add_new_layer(); - paint_canvas->resize(x, y); -} -void PaintWindow::clear_image() { - delete_all_layers(); - add_new_layer(); -} - -void PaintWindow::center_paint_canvas() { - Vector2 csize = paint_canvas_container->get_rect().size; - Vector2 psize = paint_canvas->get_rect().size; - - Vector2 pos; - - pos.x = (csize.x - psize.x) / 2.0; - pos.y = (csize.y - psize.y) / 2.0; - - paint_canvas->set_position(pos); -} -void PaintWindow::window_fit_paint_canvas(const float ratio) { - Vector2 csize = paint_canvas_container->get_rect().size; - Vector2 psize = csize; - psize *= Vector2(ratio, ratio); - - paint_canvas->set_size(psize); -} - -void PaintWindow::_input(const Ref &event) { - if (!is_visible_in_tree()) { - return; - } - - if (is_any_menu_open()) { - return; - } - - Ref iek = event; - - if (iek.is_valid() && iek->is_pressed() && !iek->is_echo()) { - _handle_shortcuts(iek->get_scancode()); - return; - } - - if (_allow_canvas_zoom && is_mouse_in_canvas() && paint_canvas->mouse_on_top) { - _handle_zoom(event); - } - - if (paint_canvas->is_active_layer_locked()) { - return; - } - - Ref iemb = event; - - if (iemb.is_valid()) { - if (iemb->get_device() == InputEvent::DEVICE_ID_TOUCH_MOUSE) { - Vector2 mouse_position = paint_canvas->get_local_mouse_position(); - Rect2 rect = Rect2(Vector2(0, 0), paint_canvas->get_size()); - bool has_point = rect.has_point(mouse_position); - - if ((has_point && !paint_canvas->mouse_in_region) || iemb->is_pressed()) { - paint_canvas->mouse_in_region = true; - _on_PaintCanvasContainer_mouse_entered(); - paint_canvas->_on_mouse_entered(); - //_process(0.0000001); - - int grid_size = paint_canvas->get_pixel_size(); - mouse_position = get_global_mouse_position(); - canvas_position = paint_canvas->get_global_position(); - canvas_mouse_position = Vector2(mouse_position.x - canvas_position.x, mouse_position.y - canvas_position.y); - cell_mouse_position = Vector2(floor(canvas_mouse_position.x / grid_size), floor(canvas_mouse_position.y / grid_size)); - cell_color = paint_canvas->get_pixel(cell_mouse_position.x, cell_mouse_position.y); - last_mouse_position = mouse_position; - last_canvas_position = canvas_position; - last_canvas_mouse_position = canvas_mouse_position; - last_cell_mouse_position = cell_mouse_position; - last_cell_color = cell_color; - - _last_mouse_pos_canvas_area = get_global_mouse_position(); //paint_canvas_container_node.get_local_mouse_position() - paint_canvas->clear_preview_layer(); - } - } - - if (brush_mode == Tools::CUT) { - if (iemb->get_button_index() == BUTTON_LEFT && !iemb->is_pressed()) { - commit_action_old(); - } - } - - if (paint_canvas->mouse_in_region && paint_canvas->mouse_on_top) { - switch (brush_mode) { - case Tools::BUCKET: { - if (iemb->get_button_index() == BUTTON_LEFT && iemb->is_pressed()) { - if (!_current_action.is_valid()) { - _current_action = get_action(); - } - - Array arr; - arr.append(cell_mouse_position); - arr.append(last_cell_mouse_position); - arr.append(_selected_color); - - do_action_old(arr); - } - } break; - case Tools::COLORPICKER: { - if (iemb->get_button_index() == BUTTON_LEFT) { - if (iemb->is_pressed()) { - Color c = paint_canvas->get_pixel(cell_mouse_position.x, cell_mouse_position.y); - - if (c.a < 0.00001) { - return; - } - - _selected_color = c; - _picked_color = true; - - color_grid->add_color_prefab(_selected_color); - } else { - if (_picked_color) { - set_brush(_previous_tool); - } - } - } else { - if (iemb->get_button_index() == BUTTON_RIGHT && iemb->is_pressed()) { - set_brush(_previous_tool); - } - } - } break; - case Tools::PASTECUT: { - if (iemb->get_button_index() == BUTTON_RIGHT && iemb->is_pressed()) { - commit_action_old(); - set_brush(Tools::PAINT); - } - } break; - default: - break; - } - } - - if (iemb->get_device() == InputEvent::DEVICE_ID_TOUCH_MOUSE) { - Vector2 mouse_position = paint_canvas->get_local_mouse_position(); - Rect2 rect = Rect2(Vector2(0, 0), paint_canvas->get_size()); - bool has_point = rect.has_point(mouse_position); - - if ((!has_point && paint_canvas->mouse_in_region) || !iemb->is_pressed()) { - paint_canvas->mouse_in_region = false; - _on_PaintCanvasContainer_mouse_exited(); - paint_canvas->_on_mouse_exited(); - //_process(0.0000001); - } - } - } -} -void PaintWindow::_process(float delta) { - if (!is_visible_in_tree()) { - return; - } - - if (is_any_menu_open()) { - return; - } - - if (_allow_canvas_move && is_mouse_in_canvas()) { - _handle_scroll(); - } - - //Update commonly used variables - int grid_size = paint_canvas->get_pixel_size(); - mouse_position = get_global_mouse_position(); //paint_canvas.get_local_mouse_position() - canvas_position = paint_canvas->get_global_position(); - canvas_mouse_position = Vector2(mouse_position.x - canvas_position.x, mouse_position.y - canvas_position.y); - - if (is_mouse_in_canvas() && paint_canvas->mouse_on_top) { - cell_mouse_position = Vector2(floor(canvas_mouse_position.x / grid_size), floor(canvas_mouse_position.y / grid_size)); - cell_color = paint_canvas->get_pixel(cell_mouse_position.x, cell_mouse_position.y); - } - - update_text_info(); - - // if not is_mouse_in_canvas(): - // paint_canvas.tool_layer.clear() - // paint_canvas.update() - // paint_canvas.tool_layer.update_texture() - // else: - - if (is_mouse_in_canvas() && paint_canvas->mouse_on_top) { - if (!paint_canvas->is_active_layer_locked()) { - if (is_position_in_canvas(get_global_mouse_position()) || is_position_in_canvas(_last_mouse_pos_canvas_area)) { - brush_process(); - } - //else { - //print(cell_mouse_position, " not in ", paint_canvas_container_node.rect_size); - //print("not in canvas"); - //} - } - - _draw_tool_brush(); - } - - //Update last variables with the current variables - - last_mouse_position = mouse_position; - last_canvas_position = canvas_position; - last_canvas_mouse_position = canvas_mouse_position; - last_cell_mouse_position = cell_mouse_position; - last_cell_color = cell_color; - - _last_mouse_pos_canvas_area = get_global_mouse_position(); //paint_canvas_container_node.get_local_mouse_position() -} - -void PaintWindow::_handle_shortcuts(const int scancode) { - switch (scancode) { - case K_UNDO: - undo_action_old(); - break; - case K_REDO: - redo_action_old(); - break; - case K_PENCIL: - set_brush(Tools::PAINT); - break; - case K_BRUSH: - set_brush(Tools::BRUSH); - break; - case K_BUCKET: - set_brush(Tools::BUCKET); - break; - case K_RAINBOW: - set_brush(Tools::RAINBOW); - break; - case K_LINE: - set_brush(Tools::LINE); - break; - case K_DARK: - set_brush(Tools::DARKEN); - break; - case K_BRIGHT: - set_brush(Tools::BRIGHTEN); - break; - case K_CUT: - set_brush(Tools::CUT); - break; - case K_PICK: - set_brush(Tools::COLORPICKER); - break; - } -} - -void PaintWindow::_draw_tool_brush() { - paint_canvas->tool_layer->clear(); - - switch (brush_mode) { - case Tools::PASTECUT: { - for (int idx = 0; idx < _selection_cells.size(); ++idx) { - Vector2i pixel = _selection_cells[idx]; - //if pixel.x < 0 || pixel.y < 0: - // print(pixel); - Color color = _selection_colors[idx]; - pixel -= _cut_pos + _cut_size / 2; - pixel += cell_mouse_position; - paint_canvas->_set_pixel_v(paint_canvas->tool_layer, pixel, color); - } - } break; - case Tools::BRUSH: { - PoolVector2iArray pixels = BrushPrefabs::get_brush(selected_brush_prefab, brush_size_slider->get_value()); - - PoolVector2iArray::Read r = pixels.read(); - - for (int i = 0; i < pixels.size(); ++i) { - Vector2i pixel = r[i]; - paint_canvas->_set_pixel(paint_canvas->tool_layer, cell_mouse_position.x + pixel.x, cell_mouse_position.y + pixel.y, _selected_color); - //print_error("ad " + String::num(cell_mouse_position.x + pixel.x) + " " + String::num(cell_mouse_position.y + pixel.y)); - } - - r.release(); - } break; - case Tools::RAINBOW: { - paint_canvas->_set_pixel(paint_canvas->tool_layer, cell_mouse_position.x, cell_mouse_position.y, Color(0.46875, 0.446777, 0.446777, 0.196078)); - } break; - case Tools::COLORPICKER: { - paint_canvas->_set_pixel(paint_canvas->tool_layer, cell_mouse_position.x, cell_mouse_position.y, Color(0.866667, 0.847059, 0.847059, 0.196078)); - } break; - default: { - paint_canvas->_set_pixel(paint_canvas->tool_layer, cell_mouse_position.x, cell_mouse_position.y, _selected_color); - } break; - } - - paint_canvas->update(); - //TODO add here brush prefab drawing - // paint_canvas->tool_layer->update_texture(); -} - -void PaintWindow::_handle_scroll() { - if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_MIDDLE)) { - if (!_middle_mouse_pressed) { - _middle_mouse_pressed_start_pos = paint_canvas->get_position(); - _middle_mouse_pressed_pos = get_global_mouse_position(); - - _middle_mouse_pressed = true; - } - - paint_canvas->set_position(_middle_mouse_pressed_start_pos + (get_global_mouse_position() - _middle_mouse_pressed_pos)); - - } else if (!_middle_mouse_pressed) { - _middle_mouse_pressed = false; - } -} - -void PaintWindow::_handle_zoom(const Ref &event) { - Ref iemb = event; - - if (!iemb.is_valid()) { - return; - } - - if (iemb->is_pressed()) { - if (iemb->get_button_index() == BUTTON_WHEEL_UP) { - int pixel_size = paint_canvas->get_pixel_size(); - int px = MIN(pixel_size * 2, max_zoom_in); - - if (px == pixel_size) { - return; - } - - paint_canvas->set_pixel_size(px); - - //paint_canvas->canvas_background->set_pixel_size(8 * pow(0.5, big_grid_pixels) / paint_canvas->get_pixel_size()); - - Point2 pos = paint_canvas->get_position(); - Size2 size = paint_canvas->get_size(); - Size2 tsize = get_size(); - - pos -= paint_canvas->get_local_mouse_position(); - pos.x = CLAMP(pos.x, -size.x * 0.8, tsize.x); - pos.y = CLAMP(pos.y, -size.y * 0.8, tsize.y); - - paint_canvas->set_position(pos); - - } else if (iemb->get_button_index() == BUTTON_WHEEL_DOWN) { - int pixel_size = paint_canvas->get_pixel_size(); - int px = MAX(pixel_size / 2.0, max_zoom_out); - - if (px == pixel_size) { - return; - } - - paint_canvas->set_pixel_size(px); - - //paint_canvas->canvas_background->set_pixel_size(8 * pow(0.5, big_grid_pixels) / paint_canvas->get_pixel_size()); - - Point2 pos = paint_canvas->get_position(); - Size2 size = paint_canvas->get_size(); - Size2 tsize = get_size(); - - pos += paint_canvas->get_local_mouse_position() / 2; - pos.x = CLAMP(pos.x, -size.x * 0.8, tsize.x); - pos.y = CLAMP(pos.y, -size.y * 0.8, tsize.y); - - paint_canvas->set_position(pos); - } - } -} - -void PaintWindow::_handle_cut() { - if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_RIGHT)) { - paint_canvas->clear_preview_layer(); - set_brush(_previous_tool); - return; - } - - if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { - PoolVector2iArray pixels = PaintUtilities::get_pixels_in_line(cell_mouse_position, last_cell_mouse_position); - - PoolVector2iArray::Read r = pixels.read(); - for (int i = 0; i < pixels.size(); ++i) { - Vector2i pixel_pos = r[i]; - - for (int idx = 0; idx < _selection_cells.size(); ++idx) { - Vector2i pixel = _selection_cells[idx]; - Color color = _selection_colors[idx]; - pixel -= _cut_pos + _cut_size / 2; - pixel += pixel_pos; - paint_canvas->set_pixel_v(pixel, color); - } - } - - r.release(); - } else { - if (_last_preview_draw_cell_pos == cell_mouse_position) { - return; - } - - paint_canvas->clear_preview_layer(); - - for (int idx = 0; idx < _selection_cells.size(); ++idx) { - Vector2i pixel = _selection_cells[idx]; - Color color = _selection_colors[idx]; - pixel -= _cut_pos + _cut_size / 2; - pixel += cell_mouse_position; - paint_canvas->set_preview_pixel_v(pixel, color); - } - - _last_preview_draw_cell_pos = cell_mouse_position; - } -} -void PaintWindow::brush_process() { - if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { - if (_current_action.is_null()) { - _current_action = get_action(); - } - - if (brush_mode == Tools::COLORPICKER) { - _current_action.unref(); - } - - switch (brush_mode) { - case Tools::PAINT: { - Array arr; - - arr.append(cell_mouse_position); - arr.append(last_cell_mouse_position); - arr.append(_selected_color); - - do_action_old(arr); - } break; - case Tools::BRUSH: { - Array arr; - - arr.append(cell_mouse_position); - arr.append(last_cell_mouse_position); - arr.append(_selected_color); - arr.append(selected_brush_prefab); - arr.append(brush_size_slider->get_value()); - - do_action_old(arr); - } break; - case Tools::LINE: { - Array arr; - - arr.append(cell_mouse_position); - arr.append(last_cell_mouse_position); - arr.append(_selected_color); - - do_action_old(arr); - } break; - case Tools::RECT: { - Array arr; - - arr.append(cell_mouse_position); - arr.append(last_cell_mouse_position); - arr.append(_selected_color); - - do_action_old(arr); - } break; - case Tools::DARKEN: { - Array arr; - - arr.append(cell_mouse_position); - arr.append(last_cell_mouse_position); - arr.append(_selected_color); - - do_action_old(arr); - } break; - case Tools::BRIGHTEN: { - Array arr; - - arr.append(cell_mouse_position); - arr.append(last_cell_mouse_position); - arr.append(_selected_color); - - do_action_old(arr); - } break; - case Tools::COLORPICKER: { - } break; - case Tools::CUT: { - Array arr; - - arr.append(cell_mouse_position); - arr.append(last_cell_mouse_position); - arr.append(_selected_color); - - do_action_old(arr); - } break; - case Tools::PASTECUT: { - Array arr; - - 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); - - do_action_old(arr); - } break; - case Tools::RAINBOW: { - Array arr; - - arr.append(cell_mouse_position); - arr.append(last_cell_mouse_position); - - do_action_old(arr); - } break; - default: { - } break; - } - - paint_canvas->update(); - - } else if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_RIGHT)) { - paint_canvas->update(); - - if (_current_action.is_null()) { - _current_action = get_action(); - } - - switch (brush_mode) { - case Tools::PAINT: { - Array arr; - - arr.append(cell_mouse_position); - arr.append(last_cell_mouse_position); - arr.append(Color(1, 1, 1, 0)); - - do_action_old(arr); - } break; - case Tools::BRUSH: { - Array arr; - - arr.append(cell_mouse_position); - arr.append(last_cell_mouse_position); - arr.append(Color(1, 1, 1, 0)); - arr.append(selected_brush_prefab); - arr.append(brush_size_slider->get_value()); - - do_action_old(arr); - } break; - default: { - } break; - } - } else { - if (_current_action.is_valid() && _current_action->can_commit()) { - commit_action_old(); - paint_canvas->update(); - } - } -} -void PaintWindow::update_text_info() { - String text; - - text = vformat("Mouse Position %s\tCanvas Mouse Position %s \tCanvas Position %s\t\nCell Position %s \tCell Color %s\t", - mouse_position, canvas_mouse_position, canvas_position, cell_mouse_position, cell_color); - - text_info->set_text(text); -} - -void PaintWindow::_on_Save_pressed() { - paint_save_file_dialog->popup_centered(); -} - -void PaintWindow::do_action_old(const Array &data) { - if (_current_action.is_null()) { - //print("clear redo"); - _redo_history.clear(); - } - - _current_action->do_action_old(paint_canvas, data); -} -void PaintWindow::commit_action_old() { - if (!_current_action.is_valid()) { - return; - } - - //print("commit action") - _current_action->commit_action_old(paint_canvas); - //Ref action = _current_action->duplicate(true); - //action->layer = _current_action->layer; - - _actions_history.push_back(_current_action); - _redo_history.clear(); - - switch (brush_mode) { - case Tools::CUT: { - Ref ca = _current_action; - - _cut_pos = ca->mouse_start_pos; - _cut_size = ca->mouse_end_pos - ca->mouse_start_pos; - - _selection_cells.clear(); - _selection_colors.clear(); - - _selection_cells.append_array(ca->redo_cells); - _selection_colors.append_array(ca->redo_colors); - - set_brush(Tools::PASTECUT); - } break; - default: { - _current_action.unref(); - } break; - } -} -void PaintWindow::redo_action_old() { - if (_redo_history.empty()) { - //print("nothing to redo"); - return; - } - - Ref action = _redo_history[_redo_history.size() - 1]; - _redo_history.remove(_redo_history.size() - 1); - - if (!action.is_valid()) { - return; - } - - _actions_history.push_back(action); - action->redo_action_old(paint_canvas); - paint_canvas->update(); - - //print("redo action"); -} -void PaintWindow::undo_action_old() { - if (_actions_history.empty()) { - return; - } - - Ref action = _actions_history[_actions_history.size() - 1]; - _actions_history.remove(_actions_history.size() - 1); - - if (!action.is_valid()) { - return; - } - - _redo_history.push_back(action); - action->undo_action_old(paint_canvas); - update(); - paint_canvas->update(); - - //print("undo action") -} - -Ref PaintWindow::get_action() { - switch (brush_mode) { - case Tools::PAINT: - return Ref(memnew(PencilAction)); - case Tools::BRUSH: - return Ref(memnew(BrushAction)); - case Tools::LINE: - return Ref(memnew(LineAction)); - case Tools::RAINBOW: - return Ref(memnew(RainbowAction)); - case Tools::BUCKET: - return Ref(memnew(BucketAction)); - case Tools::RECT: - return Ref(memnew(RectAction)); - case Tools::DARKEN: - return Ref(memnew(DarkenAction)); - case Tools::BRIGHTEN: - return Ref(memnew(BrightenAction)); - case Tools::CUT: - return Ref(memnew(CutAction)); - case Tools::PASTECUT: - return Ref(memnew(PasteCutAction)); - default: - //print("no tool!") - break; - } - - return Ref(); -} - -void PaintWindow::set_brush(const PaintWindow::Tools new_mode) { - if (brush_mode == new_mode) { - return; - } - - _previous_tool = brush_mode; - brush_mode = new_mode; - - _current_action = get_action(); - - switch (_previous_tool) { - case Tools::CUT: - paint_canvas->clear_preview_layer(); - break; - case Tools::PASTECUT: - _selection_cells.resize(0); - _selection_colors.resize(0); - break; - case Tools::BUCKET: - _current_action.unref(); - break; - default: - break; - } - - //print("Selected: ", Tools::keys()[brush_mode]); -} - -void PaintWindow::change_color(const Color &new_color) { - set_selected_color(new_color); -} - -void PaintWindow::_on_ColorPicker_color_changed(const Color &color) { - _selected_color = color; -} -void PaintWindow::_on_PaintTool_pressed() { - set_brush(Tools::PAINT); -} -void PaintWindow::_on_BucketTool_pressed() { - set_brush(Tools::BUCKET); -} -void PaintWindow::_on_RainbowTool_pressed() { - set_brush(Tools::RAINBOW); -} -void PaintWindow::_on_BrushTool_pressed() { - set_brush(Tools::BRUSH); -} -void PaintWindow::_on_LineTool_pressed() { - set_brush(Tools::LINE); -} -void PaintWindow::_on_RectTool_pressed() { - set_brush(Tools::RECT); -} -void PaintWindow::_on_DarkenTool_pressed() { - set_brush(Tools::DARKEN); -} -void PaintWindow::_on_BrightenTool_pressed() { - set_brush(Tools::BRIGHTEN); -} -void PaintWindow::_on_ColorPickerTool_pressed() { - set_brush(Tools::COLORPICKER); -} -void PaintWindow::_on_CutTool_pressed() { - set_brush(Tools::CUT); -} -void PaintWindow::_on_Editor_visibility_changed() { - set_process(is_visible_in_tree()); -} - -void PaintWindow::_on_ChangeGridSizeDialog_confirmed() { - paint_canvas->set_grid_size(paint_change_grid_size_dialog->get_grid_value()); - paint_canvas->set_big_grid_size(paint_change_grid_size_dialog->get_big_grid_value()); -} - -void PaintWindow::_on_ChangeCanvasSizeDialog_confirmed() { - if (paint_canvas_dialog->is_new) { - delete_all_layers(); - add_new_layer(); - } - - paint_canvas->resize(paint_canvas_dialog->get_size_x(), paint_canvas_dialog->get_size_y()); -} - -void PaintWindow::highlight_layer(const String &layer_name) { - for (int i = 0; i < layers_box_container->get_child_count(); ++i) { - PaintLayerButton *button = Object::cast_to(layers_box_container->get_child(i)); - - if (!button) { - continue; - } - - String name = button->get_name(); - - if (paint_canvas->find_layer_by_name(name)->locked) { - Ref sb = button->get("custom_styles/panel"); - - if (sb.is_valid()) { - sb->set("bg_color", locked_layer_highlight); - } - } else if (name == layer_name) { - Ref sb = button->get("custom_styles/panel"); - - if (sb.is_valid()) { - sb->set("bg_color", current_layer_highlight); - } - } else { - Ref sb = button->get("custom_styles/panel"); - - if (sb.is_valid()) { - sb->set("bg_color", other_layer_highlight); - } - } - } -} - -void PaintWindow::toggle_layer_visibility(Node *button, const String &layer_name) { - //print("toggling: ", layer_name) - paint_canvas->toggle_layer_visibility(layer_name); -} -void PaintWindow::select_layer(const String &layer_name) { - //print("select layer: ", layer_name) - paint_canvas->select_layer(layer_name); - highlight_layer(layer_name); -} -void PaintWindow::lock_layer(Node *button, const String &layer_name) { - paint_canvas->toggle_lock_layer(layer_name); - highlight_layer(paint_canvas->get_active_layer()->name); -} - -Ref PaintWindow::add_new_layer() { - PaintLayerButton *new_layer_button = memnew(PaintLayerButton); - - _total_added_layers += 1; - String name = "Layer" + String::num(_total_added_layers); - new_layer_button->set_name(name); - new_layer_button->layer_button->set_text(name); - - if (layers_box_container->get_child_count() > 0) { - layers_box_container->add_child_below_node(layers_box_container->get_child(layers_box_container->get_child_count() - 1), new_layer_button, true); - } else { - layers_box_container->add_child(new_layer_button, true); - } - - _layer_button_ref[new_layer_button->get_name()] = new_layer_button; - - Vector blb; - blb.push_back(new_layer_button->get_name()); - new_layer_button->layer_button->connect("pressed", this, "select_layer", blb); - - Vector bvis; - bvis.push_back(new_layer_button->visible_button); - bvis.push_back(new_layer_button->get_name()); - new_layer_button->visible_button->connect("pressed", this, "toggle_layer_visibility", bvis); - - Vector bud; - bud.push_back(new_layer_button); - new_layer_button->up_button->connect("pressed", this, "move_down", bud); - new_layer_button->down_button->connect("pressed", this, "move_up", bud); - - Vector blo; - blo.push_back(new_layer_button); - blo.push_back(new_layer_button->get_name()); - new_layer_button->lock_button->connect("pressed", this, "lock_layer", blo); - - Ref layer = paint_canvas->add_new_layer(new_layer_button->get_name()); - - highlight_layer(paint_canvas->get_active_layer()->name); - - //print("added layer: ", layer.name) - - return layer; -} -void PaintWindow::remove_active_layer() { - if (layers_box_container->get_child_count() <= 1) { - return; - } - - String layer_name = paint_canvas->active_layer->name; - paint_canvas->remove_layer(layer_name); - layers_box_container->remove_child(_layer_button_ref[layer_name]); - _layer_button_ref[layer_name]->queue_delete(); - _layer_button_ref.erase(layer_name); - - highlight_layer(paint_canvas->get_active_layer()->name); -} -void PaintWindow::duplicate_active_layer() { - PaintLayerButton *new_layer_button = memnew(PaintLayerButton); - //new_layer_button.set("custom_styles/panel", layers_box_container.get_child(0).get("custom_styles/panel").duplicate()); - layers_box_container->add_child_below_node(layers_box_container->get_child(layers_box_container->get_child_count() - 1), new_layer_button, true); - - _total_added_layers += 1; // for keeping track... - new_layer_button->layer_button->set_text("Layer" + String::num(_total_added_layers)); - - Ref new_layer = paint_canvas->duplicate_layer(paint_canvas->active_layer->name, new_layer_button->get_name()); - new_layer->update_texture(); - _layer_button_ref[new_layer->name] = new_layer_button; - - Vector blb; - blb.push_back(new_layer_button->get_name()); - new_layer_button->layer_button->connect("pressed", this, "select_layer", blb); - - Vector bvis; - bvis.push_back(new_layer_button->visible_button); - bvis.push_back(new_layer_button->get_name()); - new_layer_button->visible_button->connect("pressed", this, "toggle_layer_visibility", bvis); - - Vector bud; - bud.push_back(new_layer_button); - new_layer_button->up_button->connect("pressed", this, "move_down", bud); - new_layer_button->down_button->connect("pressed", this, "move_up", bud); - - Vector blo; - blo.push_back(new_layer_button); - blo.push_back(new_layer_button->get_name()); - new_layer_button->lock_button->connect("pressed", this, "lock_layer", blo); - - // update highlight - highlight_layer(paint_canvas->get_active_layer()->name); - //print("added layer: ", new_layer.name, " (total:", layers_box_container.get_child_count(), ")") -} - -void PaintWindow::delete_all_layers() { - while (paint_canvas->layers.size() > 0) { - String layer_name = paint_canvas->layers[0]->name; - paint_canvas->remove_layer(layer_name); - layers_box_container->remove_child(_layer_button_ref[layer_name]); - _layer_button_ref[layer_name]->queue_delete(); - _layer_button_ref.erase(layer_name); - } - - _total_added_layers = 0; -} - -void PaintWindow::move_up(Node *layer_btn) { - int new_idx = MIN(layer_btn->get_index() + 1, layers_box_container->get_child_count()); - //print("move_up: ", layer_btn.name, " from ", layer_btn.get_index(), " to ", new_idx) - layers_box_container->move_child(layer_btn, new_idx); - paint_canvas->move_layer_back(layer_btn->get_name()); -} -void PaintWindow::move_down(Node *layer_btn) { - int new_idx = MAX(layer_btn->get_index() - 1, 0); - //print("move_down: ", layer_btn.name, " from ", layer_btn.get_index(), " to ", new_idx) - layers_box_container->move_child(layer_btn, new_idx); - paint_canvas->move_layer_forward(layer_btn->get_name()); -} - -void PaintWindow::_connect_layer_buttons() { - for (int i = 0; i < layers_box_container->get_child_count(); ++i) { - PaintLayerButton *layer_btn = Object::cast_to(layers_box_container->get_child(i)); - - if (!layer_btn) { - continue; - } - - if (layer_btn->layer_button->is_connected("pressed", this, "select_layer")) { - continue; - } - - Vector blb; - blb.push_back(layer_btn->get_name()); - layer_btn->layer_button->connect("pressed", this, "select_layer", blb); - - Vector bvis; - bvis.push_back(layer_btn->visible_button); - bvis.push_back(layer_btn->get_name()); - layer_btn->visible_button->connect("pressed", this, "toggle_layer_visibility", bvis); - - Vector bud; - bud.push_back(layer_btn); - layer_btn->up_button->connect("pressed", this, "move_down", bud); - layer_btn->down_button->connect("pressed", this, "move_up", bud); - - Vector blo; - blo.push_back(layer_btn); - blo.push_back(layer_btn->get_name()); - layer_btn->lock_button->connect("pressed", this, "lock_layer", blo); - } -} - -void PaintWindow::_on_Button_pressed() { - add_new_layer(); -} -void PaintWindow::_on_PaintCanvasContainer_mouse_entered() { - if (mouse_on_top) { - return; - } - - mouse_on_top = true; - paint_canvas->tool_layer->clear(); - paint_canvas->update(); - //paint_canvas->tool_layer->update_texture(); -} -void PaintWindow::_on_PaintCanvasContainer_mouse_exited() { - if (!mouse_on_top) { - return; - } - - mouse_on_top = false; - paint_canvas->tool_layer->clear(); - paint_canvas->update(); - //paint_canvas->tool_layer->update_texture(); -} -void PaintWindow::_on_ColorPicker_popup_closed() { - color_grid->add_color_prefab(color_picker_button->get_pick_color()); -} - -bool PaintWindow::is_position_in_canvas(const Vector2 &pos) { - Rect2 r = Rect2(paint_canvas_container->get_global_position(), paint_canvas_container->get_global_position() + paint_canvas_container->get_size()); - - if (r.has_point(pos)) { - return true; - } - - return false; -} - -bool PaintWindow::is_mouse_in_canvas() { - if (is_position_in_canvas(get_global_mouse_position())) { - return true; //mouse_on_top # check if mouse is inside canvas - } else { - return false; - } -} - -bool PaintWindow::is_any_menu_open() { - return paint_canvas_dialog->is_visible() || paint_change_grid_size_dialog->is_visible() || - paint_load_file_dialog->is_visible() || paint_save_file_dialog->is_visible() || - paint_settings_dialog->is_visible() || navbar->is_any_menu_open(); -} - -void PaintWindow::_on_LockAlpha_pressed() { - //bool checked = lock_alpha_button->is_pressed(); - paint_canvas->active_layer->toggle_alpha_locked(); - - /* - for i in range(find_node("Layer").get_popup().get_item_count()): - if find_node("Layer").get_popup().get_item_text(i) == "Toggle Alpha Locked": - find_node("Layer").get_popup().set_item_checked(i, not find_node("Layer").get_popup().is_item_checked(i)); - */ -} -void PaintWindow::_on_BrushRect_pressed() { - if (brush_mode != Tools::BRUSH) { - set_brush(Tools::BRUSH); - } - - selected_brush_prefab = BrushPrefabs::RECT; -} -void PaintWindow::_on_BrushCircle_pressed() { - if (brush_mode != Tools::BRUSH) { - set_brush(Tools::BRUSH); - } - - selected_brush_prefab = BrushPrefabs::CIRCLE; -} -void PaintWindow::_on_BrushVLine_pressed() { - if (brush_mode != Tools::BRUSH) { - set_brush(Tools::BRUSH); - } - - selected_brush_prefab = BrushPrefabs::V_LINE; -} -void PaintWindow::_on_BrushHLine_pressed() { - if (brush_mode != Tools::BRUSH) { - set_brush(Tools::BRUSH); - } - - selected_brush_prefab = BrushPrefabs::H_LINE; -} -void PaintWindow::_on_BrushSize_value_changed(float value) { - brush_size_label->set_text(rtos(value)); -} -void PaintWindow::_on_XSymmetry_pressed() { - paint_canvas->symmetry_x = !paint_canvas->symmetry_x; -} -void PaintWindow::_on_YSymmetry_pressed() { - paint_canvas->symmetry_y = !paint_canvas->symmetry_y; -} - -void PaintWindow::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - set_process_input(is_visible_in_tree()); - } break; - case NOTIFICATION_VISIBILITY_CHANGED: { - if (is_visible_in_tree()) { - set_process_input(true); - } else { - set_process_input(false); - } - } break; - case NOTIFICATION_POSTINITIALIZE: { - connect("visibility_changed", this, "_on_Editor_visibility_changed"); - //paint_canvas->canvas_background->set_pixel_size(8 * pow(0.5, big_grid_pixels) / paint_canvas->get_pixel_size()); - } break; - case NOTIFICATION_PROCESS: { - _process(get_process_delta_time()); - } break; - default: { - } break; - } -} - -PaintWindow::PaintWindow() { - _selected_color = Color(1, 1, 1, 1); - - allow_drawing = true; - - mouse_in_region = false; - mouse_on_top = false; - mouse_from_touch = false; - - _picked_color = false; - - _total_added_layers = 0; - - _middle_mouse_pressed = false; - _previous_tool = PaintWindow::COLORPICKER; - brush_mode = PaintWindow::COLORPICKER; - - selected_brush_prefab = BrushPrefabs::CIRCLE; - - current_layer_highlight = Color(0.354706, 0.497302, 0.769531); - other_layer_highlight = Color(0.180392, 0.176471, 0.176471); - locked_layer_highlight = Color(0.098039, 0.094118, 0.094118); - - big_grid_pixels = 4; - - _allow_canvas_zoom = true; - _allow_canvas_move = true; - - set_clip_contents(true); - set_h_size_flags(SIZE_EXPAND_FILL); - set_v_size_flags(SIZE_EXPAND_FILL); - - //Main content panel - PanelContainer *main_content_panel = memnew(PanelContainer); - add_child(main_content_panel); - main_content_panel->set_anchors_and_margins_preset(Control::PRESET_WIDE); - - VBoxContainer *main_content_container = memnew(VBoxContainer); - main_content_panel->add_child(main_content_container); - - //Main Content Top (Navbar) - navbar = memnew(PaintNavbar); - navbar->paint_window = this; - navbar->set_h_size_flags(SIZE_EXPAND_FILL); - main_content_container->add_child(navbar); - - //Main Content Mid (App) - HBoxContainer *app_mid_container = memnew(HBoxContainer); - app_mid_container->set_h_size_flags(SIZE_EXPAND_FILL); - app_mid_container->set_v_size_flags(SIZE_EXPAND_FILL); - main_content_container->add_child(app_mid_container); - - //Main Content Mid (App) -- Left Panel - left_content_panel = memnew(PanelContainer); - left_content_panel->set_h_size_flags(SIZE_EXPAND_FILL); - left_content_panel->set_v_size_flags(SIZE_EXPAND_FILL); - app_mid_container->add_child(left_content_panel); - - Ref style_box; - style_box.instance(); - style_box->set("bg_color", Color(0.2, 0.2, 0.2)); - left_content_panel->set("custom_styles/panel", style_box); - - //Main Content Mid (App) -- Left Panel -- Margin container - MarginContainer *left_main_margin_container = memnew(MarginContainer); - left_content_panel->add_child(left_main_margin_container); - - //Main Content Mid (App) -- Left Panel -- Margin container -- VBoxContainer - VBoxContainer *left_main_vbox_container = memnew(VBoxContainer); - left_main_vbox_container->set("custom_constants/separation", 12); - left_main_margin_container->add_child(left_main_vbox_container); - - //Main Content Mid (App) -- Left Panel -- Margin container -- VBoxContainer -- Colors - //ScrollContainer *left_color_scroll_container = memnew(ScrollContainer); - //left_color_scroll_container->set_custom_minimum_size(Size2(0, 145)); - //left_main_vbox_container->add_child(left_color_scroll_container); - - color_grid = memnew(PaintColorGrid); - //color_grid->set_columns(4); - color_grid->set_custom_minimum_size(Size2(0, 145)); - //color_grid->set_h_size_flags(SIZE_EXPAND_FILL); - //color_grid->set_v_size_flags(SIZE_EXPAND_FILL); - color_grid->connect("color_change_request", this, "change_color"); - left_main_vbox_container->add_child(color_grid); - - //Main Content Mid (App) -- Left Panel -- Margin container -- VBoxContainer -- Lock Alpha Button - lock_alpha_button = memnew(CheckButton); - lock_alpha_button->set_text("Lock Alpha"); - lock_alpha_button->set_text_align(Button::ALIGN_RIGHT); - lock_alpha_button->connect("pressed", this, "_on_LockAlpha_pressed"); - left_main_vbox_container->add_child(lock_alpha_button); - - //Main Content Mid (App) -- Left Panel -- Margin container -- VBoxContainer -- Brush Selection - GridContainer *brush_container = memnew(GridContainer); - brush_container->set_columns(4); - left_main_vbox_container->add_child(brush_container); - - TextureButton *brush_rect_button = memnew(TextureButton); - brush_rect_button->set_normal_texture(PaintIcons::make_icon_brush_rect_png()); - brush_rect_button->set_hover_texture(PaintIcons::make_icon_brush_rect_hovered_png()); - brush_rect_button->set_custom_minimum_size(Size2(25, 25)); - brush_rect_button->connect("pressed", this, "_on_BrushRect_pressed"); - brush_container->add_child(brush_rect_button); - - TextureButton *brush_circle_button = memnew(TextureButton); - brush_circle_button->set_normal_texture(PaintIcons::make_icon_brush_circle_png()); - brush_circle_button->set_hover_texture(PaintIcons::make_icon_brush_circle_hovered_png()); - brush_circle_button->set_custom_minimum_size(Size2(25, 25)); - brush_circle_button->connect("pressed", this, "_on_BrushCircle_pressed"); - brush_container->add_child(brush_circle_button); - - TextureButton *brush_v_line_button = memnew(TextureButton); - brush_v_line_button->set_normal_texture(PaintIcons::make_icon_brush_v_line_png()); - brush_v_line_button->set_hover_texture(PaintIcons::make_icon_brush_v_line_hovered_png()); - brush_v_line_button->set_custom_minimum_size(Size2(25, 25)); - brush_v_line_button->connect("pressed", this, "_on_BrushVLine_pressed"); - brush_container->add_child(brush_v_line_button); - - TextureButton *brush_h_line_button = memnew(TextureButton); - brush_h_line_button->set_normal_texture(PaintIcons::make_icon_brush_h_line_png()); - brush_h_line_button->set_hover_texture(PaintIcons::make_icon_brush_h_line_hovered_png()); - brush_h_line_button->set_custom_minimum_size(Size2(25, 25)); - brush_h_line_button->connect("pressed", this, "_on_BrushHLine_pressed"); - brush_container->add_child(brush_h_line_button); - - //Main Content Mid (App) -- Left Panel -- Margin container -- VBoxContainer -- Brush Size - Label *brush_size_name_label = memnew(Label); - brush_size_name_label->set_text("Brush Size"); - left_main_vbox_container->add_child(brush_size_name_label); - - HBoxContainer *brush_size_container = memnew(HBoxContainer); - left_main_vbox_container->add_child(brush_size_container); - - brush_size_label = memnew(Label); - brush_size_label->set_text("1"); - brush_size_container->add_child(brush_size_label); - - brush_size_slider = memnew(HSlider); - brush_size_slider->set_min(1); - brush_size_slider->set_value(1); - brush_size_slider->set_h_size_flags(SIZE_EXPAND_FILL); - brush_size_slider->set_v_size_flags(SIZE_EXPAND); - brush_size_container->add_child(brush_size_slider); - - brush_size_label->set_text(String::num(static_cast(brush_size_slider->get_value()))); - brush_size_slider->connect("value_changed", this, "_on_BrushSize_value_changed"); - - //Main Content Mid (App) -- Left Panel -- Margin container -- VBoxContainer -- Symmetries - x_symmetry_button = memnew(CheckButton); - x_symmetry_button->set_text("X Symmetry"); - x_symmetry_button->connect("pressed", this, "_on_XSymmetry_pressed"); - left_main_vbox_container->add_child(x_symmetry_button); - - y_symmetry_button = memnew(CheckButton); - y_symmetry_button->set_text("Y Symmetry"); - y_symmetry_button->connect("pressed", this, "_on_YSymmetry_pressed"); - left_main_vbox_container->add_child(y_symmetry_button); - - //Main Content Mid (App) -- Mid (PaintCanvas) - paint_canvas_container = memnew(Control); - paint_canvas_container->set_clip_contents(true); - paint_canvas_container->set_focus_mode(Control::FOCUS_CLICK); - paint_canvas_container->set_mouse_filter(Control::MOUSE_FILTER_PASS); - paint_canvas_container->set_h_size_flags(SIZE_EXPAND_FILL); - paint_canvas_container->set_v_size_flags(SIZE_EXPAND_FILL); - paint_canvas_container->set_stretch_ratio(6); - paint_canvas_container->connect("mouse_entered", this, "_on_PaintCanvasContainer_mouse_entered"); - paint_canvas_container->connect("mouse_exited", this, "_on_PaintCanvasContainer_mouse_exited"); - app_mid_container->add_child(paint_canvas_container); - - paint_canvas = memnew(PaintCanvasOld); - paint_canvas->set_pixel_size(4); - paint_canvas->set_canvas_width(64); - paint_canvas->set_canvas_height(64); - paint_canvas->set_grid_size(1); - paint_canvas->set_big_grid_size(8); - paint_canvas->set_mouse_filter(Control::MOUSE_FILTER_PASS); - paint_canvas->set_h_size_flags(SIZE_EXPAND_FILL); - paint_canvas->set_v_size_flags(SIZE_EXPAND_FILL); - paint_canvas->set_size(Size2(256, 256)); - paint_canvas->set_anchors_and_margins_preset(Control::PRESET_CENTER); - paint_canvas_container->add_child(paint_canvas); - navbar->canvas = paint_canvas; - - //Main Content Mid (App) -- Right Panel - mid_right_panel_container = memnew(PanelContainer); - mid_right_panel_container->set_h_size_flags(SIZE_EXPAND_FILL); - mid_right_panel_container->set_v_size_flags(SIZE_EXPAND_FILL); - app_mid_container->add_child(mid_right_panel_container); - - style_box.instance(); - style_box->set("bg_color", Color(0.2, 0.2, 0.2)); - mid_right_panel_container->set("custom_styles/panel", style_box); - - ScrollContainer *mid_right_main_scroll_container = memnew(ScrollContainer); - mid_right_main_scroll_container->set_h_size_flags(SIZE_EXPAND_FILL); - mid_right_main_scroll_container->set_v_size_flags(SIZE_EXPAND_FILL); - mid_right_main_scroll_container->set_h_scroll(false); - mid_right_panel_container->add_child(mid_right_main_scroll_container); - - VBoxContainer *main_tool_contianer = memnew(VBoxContainer); - main_tool_contianer->set_h_size_flags(SIZE_EXPAND_FILL); - main_tool_contianer->set_v_size_flags(SIZE_EXPAND_FILL); - mid_right_main_scroll_container->add_child(main_tool_contianer); - - //Main Content Mid (App) -- Right Panel -- Tools - VBoxContainer *tools_contianer = memnew(VBoxContainer); - tools_contianer->set_h_size_flags(SIZE_EXPAND_FILL); - main_tool_contianer->add_child(tools_contianer); - - paint_tool_button = memnew(Button); - paint_tool_button->set_text("Pencil (Q)"); - paint_tool_button->set_h_size_flags(SIZE_EXPAND_FILL); - paint_tool_button->set_v_size_flags(SIZE_EXPAND_FILL); - paint_tool_button->connect("pressed", this, "_on_PaintTool_pressed"); - tools_contianer->add_child(paint_tool_button); - - brush_tool_button = memnew(Button); - brush_tool_button->set_text("Brush"); - brush_tool_button->set_h_size_flags(SIZE_EXPAND_FILL); - brush_tool_button->set_v_size_flags(SIZE_EXPAND_FILL); - brush_tool_button->connect("pressed", this, "_on_BrushTool_pressed"); - tools_contianer->add_child(brush_tool_button); - brush_tool_button->hide(); - - multi_tool_button = memnew(Button); - multi_tool_button->set_text("Polygon"); - multi_tool_button->set_h_size_flags(SIZE_EXPAND_FILL); - multi_tool_button->set_v_size_flags(SIZE_EXPAND_FILL); - //multi_tool_button->connect("pressed", this, "_on_PaintTool_pressed"); - tools_contianer->add_child(multi_tool_button); - multi_tool_button->hide(); - - bucket_tool_button = memnew(Button); - bucket_tool_button->set_text("Bucket Fill (F)"); - bucket_tool_button->set_h_size_flags(SIZE_EXPAND_FILL); - bucket_tool_button->set_v_size_flags(SIZE_EXPAND_FILL); - bucket_tool_button->connect("pressed", this, "_on_BucketTool_pressed"); - tools_contianer->add_child(bucket_tool_button); - - rainbow_tool_button = memnew(Button); - rainbow_tool_button->set_text("Rainbow (R)"); - rainbow_tool_button->set_h_size_flags(SIZE_EXPAND_FILL); - rainbow_tool_button->set_v_size_flags(SIZE_EXPAND_FILL); - rainbow_tool_button->connect("pressed", this, "_on_RainbowTool_pressed"); - tools_contianer->add_child(rainbow_tool_button); - - line_tool_button = memnew(Button); - line_tool_button->set_text("Line (L)"); - line_tool_button->set_h_size_flags(SIZE_EXPAND_FILL); - line_tool_button->set_v_size_flags(SIZE_EXPAND_FILL); - line_tool_button->connect("pressed", this, "_on_LineTool_pressed"); - tools_contianer->add_child(line_tool_button); - - rect_tool_button = memnew(Button); - rect_tool_button->set_text("Rectangle"); - rect_tool_button->set_h_size_flags(SIZE_EXPAND_FILL); - rect_tool_button->set_v_size_flags(SIZE_EXPAND_FILL); - rect_tool_button->connect("pressed", this, "_on_RectTool_pressed"); - tools_contianer->add_child(rect_tool_button); - - darken_tool_button = memnew(Button); - darken_tool_button->set_text("Darken (D)"); - darken_tool_button->set_h_size_flags(SIZE_EXPAND_FILL); - darken_tool_button->set_v_size_flags(SIZE_EXPAND_FILL); - darken_tool_button->connect("pressed", this, "_on_DarkenTool_pressed"); - tools_contianer->add_child(darken_tool_button); - - brighten_tool_button = memnew(Button); - brighten_tool_button->set_text("Brighten (B)"); - brighten_tool_button->set_h_size_flags(SIZE_EXPAND_FILL); - brighten_tool_button->set_v_size_flags(SIZE_EXPAND_FILL); - brighten_tool_button->connect("pressed", this, "_on_BrightenTool_pressed"); - tools_contianer->add_child(brighten_tool_button); - - color_picker_tool_button = memnew(Button); - color_picker_tool_button->set_text("Color Picker (P)"); - color_picker_tool_button->set_h_size_flags(SIZE_EXPAND_FILL); - color_picker_tool_button->set_v_size_flags(SIZE_EXPAND_FILL); - color_picker_tool_button->connect("pressed", this, "_on_ColorPickerTool_pressed"); - tools_contianer->add_child(color_picker_tool_button); - - cut_tool_button = memnew(Button); - cut_tool_button->set_text("Cut Section (C)"); - cut_tool_button->set_h_size_flags(SIZE_EXPAND_FILL); - cut_tool_button->set_v_size_flags(SIZE_EXPAND_FILL); - cut_tool_button->connect("pressed", this, "_on_CutTool_pressed"); - tools_contianer->add_child(cut_tool_button); - - color_picker_button = memnew(ColorPickerButton); - color_picker_button->set_text("Cut Section (C)"); - color_picker_button->set_h_size_flags(SIZE_EXPAND_FILL); - color_picker_button->set_v_size_flags(SIZE_EXPAND_FILL); - color_picker_button->connect("color_changed", this, "_on_ColorPicker_color_changed"); - color_picker_button->connect("popup_closed", this, "_on_ColorPicker_popup_closed"); - tools_contianer->add_child(color_picker_button); - - //Main Content Mid (App) -- Right Panel -- Layers - ScrollContainer *layers_scroll_contianer = memnew(ScrollContainer); - layers_scroll_contianer->set_h_size_flags(SIZE_EXPAND_FILL); - layers_scroll_contianer->set_v_size_flags(SIZE_EXPAND_FILL); - layers_scroll_contianer->set_h_scroll(false); - main_tool_contianer->add_child(layers_scroll_contianer); - - VBoxContainer *main_layers_box_container = memnew(VBoxContainer); - main_layers_box_container->set_h_size_flags(SIZE_EXPAND_FILL); - main_layers_box_container->set_v_size_flags(SIZE_EXPAND_FILL); - layers_scroll_contianer->add_child(main_layers_box_container); - - layers_box_container = memnew(VBoxContainer); - layers_box_container->set_h_size_flags(SIZE_EXPAND_FILL); - layers_box_container->set_v_size_flags(SIZE_EXPAND_FILL); - main_layers_box_container->add_child(layers_box_container); - - add_layer_button = memnew(Button); - add_layer_button->set_text("+"); - add_layer_button->set_custom_minimum_size(Size2(0, 25)); - add_layer_button->set_h_size_flags(SIZE_EXPAND_FILL); - add_layer_button->connect("pressed", this, "_on_Button_pressed"); - main_layers_box_container->add_child(add_layer_button); - - //Main Content Bottom (Text display) - bottom_content_panel = memnew(PanelContainer); - bottom_content_panel->set_h_size_flags(SIZE_EXPAND_FILL); - bottom_content_panel->set_custom_minimum_size(Size2(0, 50)); - main_content_container->add_child(bottom_content_panel); - - text_info = memnew(RichTextLabel); - text_info->set_scroll_active(false); - bottom_content_panel->add_child(text_info); - - //PaintCanvasDialog - paint_canvas_dialog = memnew(PaintCanvasDialog); - paint_canvas_dialog->set_size_x(64); - paint_canvas_dialog->set_size_y(64); - paint_canvas_dialog->connect("confirmed", this, "_on_ChangeCanvasSizeDialog_confirmed"); - add_child(paint_canvas_dialog); - - //PaintChangeGridSizeDialog - paint_change_grid_size_dialog = memnew(PaintChangeGridSizeDialog); - paint_change_grid_size_dialog->set_grid_value(1); - paint_change_grid_size_dialog->set_big_grid_value(8); - paint_change_grid_size_dialog->connect("confirmed", this, "_on_ChangeGridSizeDialog_confirmed"); - add_child(paint_change_grid_size_dialog); - - //PaintLoadFileDialog - paint_load_file_dialog = memnew(PaintLoadFileDialog); - paint_load_file_dialog->canvas = paint_canvas; - paint_load_file_dialog->window = this; - paint_load_file_dialog->set_size(Size2(600, 400)); - add_child(paint_load_file_dialog); - - //PaintSaveFileDialog - paint_save_file_dialog = memnew(PaintSaveFileDialog); - paint_save_file_dialog->canvas = paint_canvas; - paint_load_file_dialog->set_size(Size2(600, 400)); - add_child(paint_save_file_dialog); - - //PaintSettings - paint_settings_dialog = memnew(PaintSettings); - paint_settings_dialog->canvas_outline = paint_canvas->canvas_outline; - add_child(paint_settings_dialog); - - set_brush(Tools::PAINT); - - _on_ChangeCanvasSizeDialog_confirmed(); - _on_ChangeGridSizeDialog_confirmed(); - - //find_node("CanvasBackground").material.set_shader_param("pixel_size", 8 * pow(0.5, big_grid_pixels)/paint_canvas.pixel_size) - - add_new_layer(); - paint_canvas->update(); -} - -PaintWindow::~PaintWindow() { -} - -void PaintWindow::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_navbar"), &PaintWindow::get_navbar); - ClassDB::bind_method(D_METHOD("get_left_content_panel"), &PaintWindow::get_left_content_panel); - ClassDB::bind_method(D_METHOD("get_paint_canvas"), &PaintWindow::get_paint_canvas); - ClassDB::bind_method(D_METHOD("get_right_panel_container"), &PaintWindow::get_right_panel_container); - ClassDB::bind_method(D_METHOD("get_bottom_content_panel"), &PaintWindow::get_bottom_content_panel); - ClassDB::bind_method(D_METHOD("get_text_info_control"), &PaintWindow::get_text_info_control); - - ClassDB::bind_method(D_METHOD("get_allow_canvas_zoom"), &PaintWindow::get_allow_canvas_zoom); - ClassDB::bind_method(D_METHOD("set_allow_canvas_zoom", "value"), &PaintWindow::set_allow_canvas_zoom); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_canvas_zoom"), "set_allow_canvas_zoom", "get_allow_canvas_zoom"); - - ClassDB::bind_method(D_METHOD("get_allow_canvas_move"), &PaintWindow::get_allow_canvas_move); - ClassDB::bind_method(D_METHOD("set_allow_canvas_move", "value"), &PaintWindow::set_allow_canvas_move); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_canvas_move"), "set_allow_canvas_move", "get_allow_canvas_move"); - - ClassDB::bind_method(D_METHOD("get_selected_color"), &PaintWindow::get_selected_color); - ClassDB::bind_method(D_METHOD("set_selected_color", "value"), &PaintWindow::set_selected_color); - ADD_PROPERTY(PropertyInfo(Variant::COLOR, "selected_color"), "set_selected_color", "get_selected_color"); - - ClassDB::bind_method(D_METHOD("get_tool"), &PaintWindow::get_tool); - ClassDB::bind_method(D_METHOD("set_tool", "value"), &PaintWindow::set_tool); - ADD_PROPERTY(PropertyInfo(Variant::INT, "tool"), "set_tool", "get_tool"); - - ClassDB::bind_method(D_METHOD("get_brush_type"), &PaintWindow::get_brush_type); - ClassDB::bind_method(D_METHOD("set_brush_type", "value"), &PaintWindow::set_brush_type); - ADD_PROPERTY(PropertyInfo(Variant::INT, "brush_type"), "set_brush_type", "get_brush_type"); - - ClassDB::bind_method(D_METHOD("get_brush_size"), &PaintWindow::get_brush_size); - ClassDB::bind_method(D_METHOD("set_brush_size", "value"), &PaintWindow::set_brush_size); - ADD_PROPERTY(PropertyInfo(Variant::INT, "brush_size"), "set_brush_size", "get_brush_size"); - - ClassDB::bind_method(D_METHOD("get_image"), &PaintWindow::get_image); - ClassDB::bind_method(D_METHOD("clear_image"), &PaintWindow::clear_image); - ClassDB::bind_method(D_METHOD("new_image", "x", "y"), &PaintWindow::new_image); - - ClassDB::bind_method(D_METHOD("center_paint_canvas"), &PaintWindow::center_paint_canvas); - ClassDB::bind_method(D_METHOD("window_fit_paint_canvas", "ratio"), &PaintWindow::window_fit_paint_canvas, 0.8); - - ClassDB::bind_method(D_METHOD("change_color", "color"), &PaintWindow::change_color); - - ClassDB::bind_method(D_METHOD("_input", "event"), &PaintWindow::_input); - ClassDB::bind_method(D_METHOD("_on_Save_pressed"), &PaintWindow::_on_Save_pressed); - - ClassDB::bind_method(D_METHOD("_on_ColorPicker_color_changed", "color"), &PaintWindow::_on_ColorPicker_color_changed); - - ClassDB::bind_method(D_METHOD("_on_PaintTool_pressed"), &PaintWindow::_on_PaintTool_pressed); - ClassDB::bind_method(D_METHOD("_on_BucketTool_pressed"), &PaintWindow::_on_BucketTool_pressed); - ClassDB::bind_method(D_METHOD("_on_RainbowTool_pressed"), &PaintWindow::_on_RainbowTool_pressed); - ClassDB::bind_method(D_METHOD("_on_BrushTool_pressed"), &PaintWindow::_on_BrushTool_pressed); - ClassDB::bind_method(D_METHOD("_on_LineTool_pressed"), &PaintWindow::_on_LineTool_pressed); - ClassDB::bind_method(D_METHOD("_on_RectTool_pressed"), &PaintWindow::_on_RectTool_pressed); - ClassDB::bind_method(D_METHOD("_on_DarkenTool_pressed"), &PaintWindow::_on_DarkenTool_pressed); - ClassDB::bind_method(D_METHOD("_on_BrightenTool_pressed"), &PaintWindow::_on_BrightenTool_pressed); - ClassDB::bind_method(D_METHOD("_on_ColorPickerTool_pressed"), &PaintWindow::_on_ColorPickerTool_pressed); - ClassDB::bind_method(D_METHOD("_on_CutTool_pressed"), &PaintWindow::_on_CutTool_pressed); - ClassDB::bind_method(D_METHOD("_on_Editor_visibility_changed"), &PaintWindow::_on_Editor_visibility_changed); - ClassDB::bind_method(D_METHOD("_on_ChangeGridSizeDialog_confirmed"), &PaintWindow::_on_ChangeGridSizeDialog_confirmed); - ClassDB::bind_method(D_METHOD("_on_ChangeCanvasSizeDialog_confirmed"), &PaintWindow::_on_ChangeCanvasSizeDialog_confirmed); - - ClassDB::bind_method(D_METHOD("_on_Button_pressed"), &PaintWindow::_on_Button_pressed); - ClassDB::bind_method(D_METHOD("_on_PaintCanvasContainer_mouse_entered"), &PaintWindow::_on_PaintCanvasContainer_mouse_entered); - ClassDB::bind_method(D_METHOD("_on_PaintCanvasContainer_mouse_exited"), &PaintWindow::_on_PaintCanvasContainer_mouse_exited); - ClassDB::bind_method(D_METHOD("_on_ColorPicker_popup_closed"), &PaintWindow::_on_ColorPicker_popup_closed); - - ClassDB::bind_method(D_METHOD("_on_LockAlpha_pressed"), &PaintWindow::_on_LockAlpha_pressed); - ClassDB::bind_method(D_METHOD("_on_BrushRect_pressed"), &PaintWindow::_on_BrushRect_pressed); - ClassDB::bind_method(D_METHOD("_on_BrushCircle_pressed"), &PaintWindow::_on_BrushCircle_pressed); - ClassDB::bind_method(D_METHOD("_on_BrushVLine_pressed"), &PaintWindow::_on_BrushVLine_pressed); - ClassDB::bind_method(D_METHOD("_on_BrushHLine_pressed"), &PaintWindow::_on_BrushHLine_pressed); - ClassDB::bind_method(D_METHOD("_on_BrushSize_value_changed", "value"), &PaintWindow::_on_BrushSize_value_changed); - ClassDB::bind_method(D_METHOD("_on_XSymmetry_pressed"), &PaintWindow::_on_XSymmetry_pressed); - ClassDB::bind_method(D_METHOD("_on_YSymmetry_pressed"), &PaintWindow::_on_YSymmetry_pressed); - - ClassDB::bind_method(D_METHOD("lock_layer"), &PaintWindow::lock_layer); - ClassDB::bind_method(D_METHOD("toggle_layer_visibility"), &PaintWindow::toggle_layer_visibility); - ClassDB::bind_method(D_METHOD("select_layer", "name"), &PaintWindow::select_layer); - ClassDB::bind_method(D_METHOD("move_up", "n"), &PaintWindow::move_up); - ClassDB::bind_method(D_METHOD("move_down", "n"), &PaintWindow::move_down); - - BIND_ENUM_CONSTANT(PAINT); - BIND_ENUM_CONSTANT(BRUSH); - BIND_ENUM_CONSTANT(BUCKET); - BIND_ENUM_CONSTANT(RAINBOW); - BIND_ENUM_CONSTANT(LINE); - BIND_ENUM_CONSTANT(RECT); - BIND_ENUM_CONSTANT(DARKEN); - BIND_ENUM_CONSTANT(BRIGHTEN); - BIND_ENUM_CONSTANT(COLORPICKER); - BIND_ENUM_CONSTANT(CUT); - BIND_ENUM_CONSTANT(PASTECUT); -} diff --git a/modules/paint/deprecated/paint_window.h b/modules/paint/deprecated/paint_window.h deleted file mode 100644 index 721a61781..000000000 --- a/modules/paint/deprecated/paint_window.h +++ /dev/null @@ -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 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 &event); - void _process(float delta); - - void _handle_shortcuts(const int scancode); - void _draw_tool_brush(); - - void _handle_scroll(); - - void _handle_zoom(const Ref &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 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 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 _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> _actions_history; - Vector> _redo_history; - Ref _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 diff --git a/modules/paint/paint_editor_plugin_old.cpp b/modules/paint/paint_editor_plugin_old.cpp deleted file mode 100644 index f68e82b76..000000000 --- a/modules/paint/paint_editor_plugin_old.cpp +++ /dev/null @@ -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 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() { -} diff --git a/modules/paint/paint_editor_plugin_old.h b/modules/paint/paint_editor_plugin_old.h deleted file mode 100644 index da7ae0c99..000000000 --- a/modules/paint/paint_editor_plugin_old.h +++ /dev/null @@ -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 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 _icon; -}; - -#endif diff --git a/modules/paint/register_types.cpp b/modules/paint/register_types.cpp index a77e9545d..41fce5de5 100644 --- a/modules/paint/register_types.cpp +++ b/modules/paint/register_types.cpp @@ -36,8 +36,6 @@ SOFTWARE. #include "actions/rainbow_action.h" #include "actions/rect_action.h" -#include "deprecated/paint_window.h" - #include "ui/paint_canvas_background.h" #include "ui/paint_canvas_outline.h" #include "ui/paint_selection_box.h" @@ -55,12 +53,9 @@ SOFTWARE. #ifdef TOOLS_ENABLED #include "paint_editor_plugin.h" -#include "paint_editor_plugin_old.h" #endif void register_paint_types() { - ClassDB::register_class(); - ClassDB::register_class(); ClassDB::register_class(); @@ -92,7 +87,6 @@ void register_paint_types() { #ifdef TOOLS_ENABLED EditorPlugins::add_by_type(); - EditorPlugins::add_by_type(); #endif }