Added a current_tool property for PaintCanvas.

This commit is contained in:
Relintai 2022-11-16 15:52:29 +01:00
parent 338fc04a75
commit a2f02d669c
2 changed files with 16 additions and 0 deletions

View File

@ -39,6 +39,13 @@ void PaintCanvas::set_brush_size(const int val) {
_brush_size = val;
}
int PaintCanvas::get_current_tool() const {
return _current_tool;
}
void PaintCanvas::set_current_tool(const int val) {
_current_tool = val;
}
bool PaintCanvas::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;
@ -298,6 +305,7 @@ PaintCanvas::PaintCanvas() {
_alpha_locked = false;
_brush_prefab = 0;
_brush_size = 1;
_current_tool = 0;
_image.instance();
_preview_image.instance();
@ -339,6 +347,10 @@ void PaintCanvas::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_brush_size", "val"), &PaintCanvas::set_brush_size);
ADD_PROPERTY(PropertyInfo(Variant::INT, "brush_size"), "set_brush_size", "get_brush_size");
ClassDB::bind_method(D_METHOD("get_current_tool"), &PaintCanvas::get_current_tool);
ClassDB::bind_method(D_METHOD("set_current_tool", "val"), &PaintCanvas::set_current_tool);
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tool"), "set_current_tool", "get_current_tool");
ClassDB::bind_method(D_METHOD("is_inside_canvas", "x", "y"), &PaintCanvas::is_inside_canvas);
ClassDB::bind_method(D_METHOD("set_pixel_arr", "pixels", "color"), &PaintCanvas::set_pixel_arr);

View File

@ -41,6 +41,9 @@ public:
int get_brush_size() const;
void set_brush_size(const int val);
int get_current_tool() const;
void set_current_tool(const int val);
bool is_inside_canvas(const int x, const int y);
void set_pixel_arr(const PoolVector2iArray &pixels, const Color &color);
@ -89,6 +92,7 @@ protected:
bool _alpha_locked;
int _brush_prefab;
int _brush_size;
int _current_tool;
Ref<Image> _image;
Ref<Image> _preview_image;