diff --git a/modules/paint/paint_canvas.cpp b/modules/paint/paint_canvas.cpp index 81421b4c0..d08ed7e12 100644 --- a/modules/paint/paint_canvas.cpp +++ b/modules/paint/paint_canvas.cpp @@ -24,6 +24,13 @@ SOFTWARE. #include "paint_canvas.h" +#include "paint_canvas_outline.h" +#include "paint_visual_grid.h" +#include "scene/gui/control.h" +#include "scene/gui/texture_rect.h" + +#include "paint_canvas_layer.h" + void PaintCanvas::_enter_tree() { /* #------------------------------- @@ -72,22 +79,10 @@ void PaintCanvas::_draw() { */ } -void PaintCanvas::resize(const int width, const int height) { - /* - if width < 0: - width = 1 - if height < 0: - height = 1 - - set_canvas_width(width) - set_canvas_height(height) - - preview_layer.resize(width, height) - tool_layer.resize(width, height) - for layer in layers: - layer.resize(width, height) - */ +int PaintCanvas::get_pixel_size() const { + return _pixel_size; } + void PaintCanvas::set_pixel_size(const int size) { /* pixel_size = size @@ -97,6 +92,10 @@ void PaintCanvas::set_pixel_size(const int size) { set_canvas_height(canvas_height) */ } + +int PaintCanvas::get_grid_size() const { + return _grid_size; +} void PaintCanvas::set_grid_size(const int size) { /* grid_size = size @@ -105,6 +104,10 @@ void PaintCanvas::set_grid_size(const int size) { find_node("Grid").size = size * pixel_size */ } + +int PaintCanvas::get_big_grid_size() const { + return _big_grid_size; +} void PaintCanvas::set_big_grid_size(const int size) { /* big_grid_size = size @@ -113,12 +116,20 @@ void PaintCanvas::set_big_grid_size(const int size) { find_node("BigGrid").size = size * pixel_size */ } + +int PaintCanvas::get_canvas_width() const { + return _canvas_width; +} void PaintCanvas::set_canvas_width(const int val) { /* canvas_width = val rect_size.x = canvas_width * pixel_size */ } + +int PaintCanvas::get_canvas_height() const { + return _canvas_height; +} void PaintCanvas::set_canvas_height(const int val) { /* canvas_height = val @@ -504,37 +515,71 @@ Array PaintCanvas::get_neighbouring_pixels(const int pos_x, const int pos_y) { return Array(); } -PaintCanvas::PaintCanvas() { +void PaintCanvas::resize(const int width, const int height) { /* + if width < 0: + width = 1 + if height < 0: + height = 1 -export var pixel_size: int = 16 setget set_pixel_size -export(int, 1, 2500) var canvas_width = 48 setget set_canvas_width # == pixels -export(int, 1, 2500) var canvas_height = 28 setget set_canvas_height # == pixels -export var grid_size = 16 setget set_grid_size -export var big_grid_size = 10 setget set_big_grid_size -export var can_draw = true - -var mouse_in_region -var mouse_on_top - -var layers : Array = [] # Key: layer_name, val: GELayer -var active_layer: GELayer -var preview_layer: GELayer -var tool_layer: GELayer -var canvas_layers: Control - -var canvas -var grid -var big_grid -var selected_pixels = [] - -var symmetry_x = false -var symmetry_y = false - + set_canvas_width(width) + set_canvas_height(height) + preview_layer.resize(width, height) + tool_layer.resize(width, height) + for layer in layers: + layer.resize(width, height) */ } +PaintCanvas::PaintCanvas() { + big_grid = nullptr; + + _pixel_size = 16; + _canvas_width = 48; + _canvas_height = 28; + _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_rect = memnew(TextureRect); + //canvas_background_rect->set_texture();//res://addons/Godoxel/assets/grid.png + canvas_background_rect->set_expand(true); + canvas_background_rect->set_stretch_mode(TextureRect::STRETCH_TILE); + add_child(canvas_background_rect); + + canvas_layers = memnew(Control); + canvas_layers->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); + 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); + 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); + add_child(tool_preview_layer_rect); + + grid = memnew(PaintVisualGrid); + grid->color = Color(1, 1, 1, 1); + 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); +} + PaintCanvas::~PaintCanvas() { } diff --git a/modules/paint/paint_canvas.h b/modules/paint/paint_canvas.h index 538f9368a..180ad96f4 100644 --- a/modules/paint/paint_canvas.h +++ b/modules/paint/paint_canvas.h @@ -25,25 +25,40 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "scene/gui/control.h" +#include "core/reference.h" +#include "scene/gui/margin_container.h" +#include "core/vector.h" + +class PaintCanvasLayer; +class TextureRect; +class Control; +class PaintCanvasOutline; +class PaintVisualGrid; class PaintCanvasLayer; //class_name GECanvas -class PaintCanvas : public Control { - GDCLASS(PaintCanvas, Control); +class PaintCanvas : public MarginContainer { + GDCLASS(PaintCanvas, MarginContainer); public: void _enter_tree(); void _process(float delta); void _draw(); - void resize(const int width, const int height); - + 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); @@ -92,37 +107,43 @@ public: Array select_same_color(const int x, const int y); Array get_neighbouring_pixels(const int pos_x, const int pos_y); + void resize(const int width, const int height); + PaintCanvas(); ~PaintCanvas(); + Vector> layers; + Ref active_layer; + Ref preview_layer; + Ref tool_layer; + + TextureRect *canvas_background_rect; + 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: static void _bind_methods(); - /* - export var pixel_size: int = 16 setget set_pixel_size - export(int, 1, 2500) var canvas_width = 48 setget set_canvas_width # == pixels - export(int, 1, 2500) var canvas_height = 28 setget set_canvas_height # == pixels - export var grid_size = 16 setget set_grid_size - export var big_grid_size = 10 setget set_big_grid_size - export var can_draw = true - - var mouse_in_region - var mouse_on_top - - var layers : Array = [] # Key: layer_name, val: GELayer - var active_layer: GELayer - var preview_layer: GELayer - var tool_layer: GELayer - var canvas_layers: Control - - var canvas - var grid - var big_grid - var selected_pixels = [] - - var symmetry_x = false - var symmetry_y = false - */ + 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/paint_canvas_outline.h b/modules/paint/paint_canvas_outline.h index c37d77fb7..1fed1bef5 100644 --- a/modules/paint/paint_canvas_outline.h +++ b/modules/paint/paint_canvas_outline.h @@ -36,11 +36,13 @@ public: PaintCanvasOutline(); ~PaintCanvasOutline(); + Color color; + protected: void _notification(int p_what); static void _bind_methods(); - Color color; + }; #endif diff --git a/modules/paint/paint_visual_grid.h b/modules/paint/paint_visual_grid.h index 24001514a..926f3f2e6 100644 --- a/modules/paint/paint_visual_grid.h +++ b/modules/paint/paint_visual_grid.h @@ -42,6 +42,11 @@ public: PaintVisualGrid(); ~PaintVisualGrid(); + Color color; + int size; + float zoom; + Vector2 offset; + protected: void _notification(int p_what); static void _bind_methods(); diff --git a/modules/paint/paint_window.cpp b/modules/paint/paint_window.cpp index 2b0628e08..ea1811a79 100644 --- a/modules/paint/paint_window.cpp +++ b/modules/paint/paint_window.cpp @@ -1055,6 +1055,7 @@ PaintWindow::PaintWindow() { 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_position(Point2()); paint_canvas->set_anchors_and_margins_preset(Control::PRESET_CENTER); paint_canvas_container->add_child(paint_canvas); navbar->canvas = paint_canvas;