mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-29 07:07:14 +01:00
Node hierarchy port / implementation for PaintCanvas.
This commit is contained in:
parent
bbc671693a
commit
3461d692d4
@ -24,6 +24,13 @@ SOFTWARE.
|
|||||||
|
|
||||||
#include "paint_canvas.h"
|
#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() {
|
void PaintCanvas::_enter_tree() {
|
||||||
/*
|
/*
|
||||||
#-------------------------------
|
#-------------------------------
|
||||||
@ -72,22 +79,10 @@ void PaintCanvas::_draw() {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaintCanvas::resize(const int width, const int height) {
|
int PaintCanvas::get_pixel_size() const {
|
||||||
/*
|
return _pixel_size;
|
||||||
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)
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaintCanvas::set_pixel_size(const int size) {
|
void PaintCanvas::set_pixel_size(const int size) {
|
||||||
/*
|
/*
|
||||||
pixel_size = size
|
pixel_size = size
|
||||||
@ -97,6 +92,10 @@ void PaintCanvas::set_pixel_size(const int size) {
|
|||||||
set_canvas_height(canvas_height)
|
set_canvas_height(canvas_height)
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int PaintCanvas::get_grid_size() const {
|
||||||
|
return _grid_size;
|
||||||
|
}
|
||||||
void PaintCanvas::set_grid_size(const int size) {
|
void PaintCanvas::set_grid_size(const int size) {
|
||||||
/*
|
/*
|
||||||
grid_size = size
|
grid_size = size
|
||||||
@ -105,6 +104,10 @@ void PaintCanvas::set_grid_size(const int size) {
|
|||||||
find_node("Grid").size = size * pixel_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) {
|
void PaintCanvas::set_big_grid_size(const int size) {
|
||||||
/*
|
/*
|
||||||
big_grid_size = 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
|
find_node("BigGrid").size = size * pixel_size
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int PaintCanvas::get_canvas_width() const {
|
||||||
|
return _canvas_width;
|
||||||
|
}
|
||||||
void PaintCanvas::set_canvas_width(const int val) {
|
void PaintCanvas::set_canvas_width(const int val) {
|
||||||
/*
|
/*
|
||||||
canvas_width = val
|
canvas_width = val
|
||||||
rect_size.x = canvas_width * pixel_size
|
rect_size.x = canvas_width * pixel_size
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int PaintCanvas::get_canvas_height() const {
|
||||||
|
return _canvas_height;
|
||||||
|
}
|
||||||
void PaintCanvas::set_canvas_height(const int val) {
|
void PaintCanvas::set_canvas_height(const int val) {
|
||||||
/*
|
/*
|
||||||
canvas_height = val
|
canvas_height = val
|
||||||
@ -504,37 +515,71 @@ Array PaintCanvas::get_neighbouring_pixels(const int pos_x, const int pos_y) {
|
|||||||
return Array();
|
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
|
set_canvas_width(width)
|
||||||
export(int, 1, 2500) var canvas_width = 48 setget set_canvas_width # == pixels
|
set_canvas_height(height)
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
|
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() {
|
PaintCanvas::~PaintCanvas() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,25 +25,40 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
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 PaintCanvasLayer;
|
||||||
|
|
||||||
//class_name GECanvas
|
//class_name GECanvas
|
||||||
class PaintCanvas : public Control {
|
class PaintCanvas : public MarginContainer {
|
||||||
GDCLASS(PaintCanvas, Control);
|
GDCLASS(PaintCanvas, MarginContainer);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void _enter_tree();
|
void _enter_tree();
|
||||||
void _process(float delta);
|
void _process(float delta);
|
||||||
void _draw();
|
void _draw();
|
||||||
|
|
||||||
void resize(const int width, const int height);
|
int get_pixel_size() const;
|
||||||
|
|
||||||
void set_pixel_size(const int size);
|
void set_pixel_size(const int size);
|
||||||
|
|
||||||
|
int get_grid_size() const;
|
||||||
void set_grid_size(const int size);
|
void set_grid_size(const int size);
|
||||||
|
|
||||||
|
int get_big_grid_size() const;
|
||||||
void set_big_grid_size(const int size);
|
void set_big_grid_size(const int size);
|
||||||
|
|
||||||
|
int get_canvas_width() const;
|
||||||
void set_canvas_width(const int val);
|
void set_canvas_width(const int val);
|
||||||
|
|
||||||
|
int get_canvas_height() const;
|
||||||
void set_canvas_height(const int val);
|
void set_canvas_height(const int val);
|
||||||
|
|
||||||
void toggle_alpha_locked(const String &layer_name);
|
void toggle_alpha_locked(const String &layer_name);
|
||||||
@ -92,37 +107,43 @@ public:
|
|||||||
Array select_same_color(const int x, const int y);
|
Array select_same_color(const int x, const int y);
|
||||||
Array get_neighbouring_pixels(const int pos_x, const int pos_y);
|
Array get_neighbouring_pixels(const int pos_x, const int pos_y);
|
||||||
|
|
||||||
|
void resize(const int width, const int height);
|
||||||
|
|
||||||
PaintCanvas();
|
PaintCanvas();
|
||||||
~PaintCanvas();
|
~PaintCanvas();
|
||||||
|
|
||||||
|
Vector<Ref<PaintCanvasLayer>> layers;
|
||||||
|
Ref<PaintCanvasLayer> active_layer;
|
||||||
|
Ref<PaintCanvasLayer> preview_layer;
|
||||||
|
Ref<PaintCanvasLayer> 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:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
/*
|
int _pixel_size;
|
||||||
export var pixel_size: int = 16 setget set_pixel_size
|
int _canvas_width;
|
||||||
export(int, 1, 2500) var canvas_width = 48 setget set_canvas_width # == pixels
|
int _canvas_height;
|
||||||
export(int, 1, 2500) var canvas_height = 28 setget set_canvas_height # == pixels
|
int _grid_size;
|
||||||
export var grid_size = 16 setget set_grid_size
|
int _big_grid_size;
|
||||||
export var big_grid_size = 10 setget set_big_grid_size
|
bool _can_draw;
|
||||||
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
|
|
||||||
*/
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -36,11 +36,13 @@ public:
|
|||||||
PaintCanvasOutline();
|
PaintCanvasOutline();
|
||||||
~PaintCanvasOutline();
|
~PaintCanvasOutline();
|
||||||
|
|
||||||
|
Color color;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
Color color;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -42,6 +42,11 @@ public:
|
|||||||
PaintVisualGrid();
|
PaintVisualGrid();
|
||||||
~PaintVisualGrid();
|
~PaintVisualGrid();
|
||||||
|
|
||||||
|
Color color;
|
||||||
|
int size;
|
||||||
|
float zoom;
|
||||||
|
Vector2 offset;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
@ -1055,6 +1055,7 @@ PaintWindow::PaintWindow() {
|
|||||||
paint_canvas->set_h_size_flags(SIZE_EXPAND_FILL);
|
paint_canvas->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||||
paint_canvas->set_v_size_flags(SIZE_EXPAND_FILL);
|
paint_canvas->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||||
paint_canvas->set_size(Size2(256, 256));
|
paint_canvas->set_size(Size2(256, 256));
|
||||||
|
paint_canvas->set_position(Point2());
|
||||||
paint_canvas->set_anchors_and_margins_preset(Control::PRESET_CENTER);
|
paint_canvas->set_anchors_and_margins_preset(Control::PRESET_CENTER);
|
||||||
paint_canvas_container->add_child(paint_canvas);
|
paint_canvas_container->add_child(paint_canvas);
|
||||||
navbar->canvas = paint_canvas;
|
navbar->canvas = paint_canvas;
|
||||||
|
Loading…
Reference in New Issue
Block a user