2022-04-15 02:20:27 +02:00
|
|
|
#ifndef PAINT_CANVAS_H
|
|
|
|
#define PAINT_CANVAS_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.
|
|
|
|
*/
|
|
|
|
|
2022-04-16 22:11:06 +02:00
|
|
|
#include "core/reference.h"
|
|
|
|
#include "scene/gui/margin_container.h"
|
2022-04-15 02:20:27 +02:00
|
|
|
|
2022-04-16 22:11:06 +02:00
|
|
|
#include "core/vector.h"
|
|
|
|
|
|
|
|
class PaintCanvasLayer;
|
|
|
|
class TextureRect;
|
|
|
|
class Control;
|
|
|
|
class PaintCanvasOutline;
|
|
|
|
class PaintVisualGrid;
|
2022-04-15 19:40:12 +02:00
|
|
|
class PaintCanvasLayer;
|
|
|
|
|
|
|
|
//class_name GECanvas
|
2022-04-16 22:11:06 +02:00
|
|
|
class PaintCanvas : public MarginContainer {
|
|
|
|
GDCLASS(PaintCanvas, MarginContainer);
|
2022-04-15 02:20:27 +02:00
|
|
|
|
|
|
|
public:
|
2022-04-15 19:40:12 +02:00
|
|
|
void _process(float delta);
|
|
|
|
void _draw();
|
|
|
|
|
2022-04-16 22:11:06 +02:00
|
|
|
int get_pixel_size() const;
|
2022-04-16 02:35:03 +02:00
|
|
|
void set_pixel_size(const int size);
|
2022-04-16 22:11:06 +02:00
|
|
|
|
|
|
|
int get_grid_size() const;
|
2022-04-16 02:35:03 +02:00
|
|
|
void set_grid_size(const int size);
|
2022-04-16 22:11:06 +02:00
|
|
|
|
|
|
|
int get_big_grid_size() const;
|
2022-04-16 02:35:03 +02:00
|
|
|
void set_big_grid_size(const int size);
|
2022-04-16 22:11:06 +02:00
|
|
|
|
|
|
|
int get_canvas_width() const;
|
2022-04-16 02:35:03 +02:00
|
|
|
void set_canvas_width(const int val);
|
2022-04-16 22:11:06 +02:00
|
|
|
|
|
|
|
int get_canvas_height() const;
|
2022-04-16 02:35:03 +02:00
|
|
|
void set_canvas_height(const int val);
|
2022-04-15 19:40:12 +02:00
|
|
|
|
2022-04-16 02:35:03 +02:00
|
|
|
void toggle_alpha_locked(const String &layer_name);
|
2022-04-15 19:40:12 +02:00
|
|
|
bool is_alpha_locked();
|
|
|
|
|
|
|
|
Rect2 get_content_margin();
|
|
|
|
void crop_to_content();
|
|
|
|
|
2022-04-17 00:17:05 +02:00
|
|
|
Ref<PaintCanvasLayer> get_active_layer();
|
|
|
|
Ref<PaintCanvasLayer> get_preview_layer();
|
2022-04-15 19:40:12 +02:00
|
|
|
void clear_active_layer();
|
|
|
|
void clear_preview_layer();
|
2022-04-16 02:35:03 +02:00
|
|
|
void clear_layer(const String &layer_name);
|
2022-04-17 00:17:05 +02:00
|
|
|
Ref<PaintCanvasLayer> remove_layer(const String &layer_name);
|
|
|
|
Ref<PaintCanvasLayer> add_new_layer(const String &layer_name);
|
|
|
|
Ref<PaintCanvasLayer> duplicate_layer(const String &layer_name, const String &new_layer_name);
|
2022-04-16 02:35:03 +02:00
|
|
|
void toggle_layer_visibility(const String &layer_name);
|
2022-04-17 00:17:05 +02:00
|
|
|
Ref<PaintCanvasLayer> find_layer_by_name(const String &layer_name);
|
2022-04-16 02:35:03 +02:00
|
|
|
void toggle_lock_layer(const String &layer_name);
|
2022-04-15 19:40:12 +02:00
|
|
|
bool is_active_layer_locked();
|
2022-04-16 02:35:03 +02:00
|
|
|
void move_layer_forward(const String &layer_name);
|
|
|
|
void move_layer_back(const String &layer_name);
|
|
|
|
void select_layer(const String &layer_name);
|
2022-04-15 19:40:12 +02:00
|
|
|
|
|
|
|
void _on_mouse_entered();
|
|
|
|
void _on_mouse_exited();
|
|
|
|
|
2022-04-16 02:35:03 +02:00
|
|
|
bool is_inside_canvas(const int x, const int y);
|
2022-04-17 00:17:05 +02:00
|
|
|
void set_pixel_arr(const PoolVector2iArray &pixels, const Color &color);
|
|
|
|
void set_pixel_v(const Vector2i &pos, const Color &color);
|
2022-04-16 02:35:03 +02:00
|
|
|
void set_pixel(const int x, const int y, const Color &color);
|
2022-04-17 00:17:05 +02:00
|
|
|
void _set_pixel_v(Ref<PaintCanvasLayer> layer, const Vector2i &v, const Color &color);
|
|
|
|
void _set_pixel(Ref<PaintCanvasLayer> layer, const int x, const int y, const Color &color);
|
|
|
|
Color get_pixel_v(const Vector2i &pos);
|
2022-04-16 02:35:03 +02:00
|
|
|
Color get_pixel(const int x, const int y);
|
2022-04-17 00:17:05 +02:00
|
|
|
void set_preview_pixel_v(const Vector2i &pos, const Color &color);
|
2022-04-16 02:35:03 +02:00
|
|
|
void set_preview_pixel(const int x, const int y, const Color &color);
|
2022-04-17 00:17:05 +02:00
|
|
|
Color get_preview_pixel_v(const Vector2i &pos);
|
2022-04-16 02:35:03 +02:00
|
|
|
Color get_preview_pixel(const int x, const int y);
|
2022-04-15 19:40:12 +02:00
|
|
|
|
|
|
|
void toggle_grid();
|
|
|
|
void show_grid();
|
|
|
|
void hide_grid();
|
|
|
|
|
2022-04-17 03:20:34 +02:00
|
|
|
PoolVector2iArray select_color(const int p_x, const int p_y);
|
|
|
|
PoolVector2iArray select_same_color(const int p_x, const int p_y);
|
2022-04-17 00:17:05 +02:00
|
|
|
PoolVector2iArray get_neighbouring_pixels(const int pos_x, const int pos_y);
|
2022-04-15 19:40:12 +02:00
|
|
|
|
2022-04-17 00:17:05 +02:00
|
|
|
void resize(int width, int height);
|
2022-04-16 22:11:06 +02:00
|
|
|
|
2022-04-15 02:20:27 +02:00
|
|
|
PaintCanvas();
|
|
|
|
~PaintCanvas();
|
|
|
|
|
2022-04-16 22:11:06 +02:00
|
|
|
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;
|
|
|
|
|
2022-04-15 02:20:27 +02:00
|
|
|
protected:
|
2022-04-17 00:17:05 +02:00
|
|
|
void _notification(int p_what);
|
2022-04-15 02:20:27 +02:00
|
|
|
static void _bind_methods();
|
2022-04-15 19:40:12 +02:00
|
|
|
|
2022-04-16 22:11:06 +02:00
|
|
|
int _pixel_size;
|
|
|
|
int _canvas_width;
|
|
|
|
int _canvas_height;
|
|
|
|
int _grid_size;
|
|
|
|
int _big_grid_size;
|
|
|
|
bool _can_draw;
|
2022-04-15 02:20:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|