Store the previous tool in Paintcanvas.

This commit is contained in:
Relintai 2022-11-16 17:23:17 +01:00
parent f439b421c5
commit 761e381d0e
2 changed files with 11 additions and 0 deletions

View File

@ -59,11 +59,16 @@ void PaintCanvas::set_current_tool(const int val) {
return;
}
_previous_tool = _current_tool;
_current_tool = val;
emit_signal("current_tool_changed");
}
int PaintCanvas::get_previous_tool() const {
return _previous_tool;
}
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;
@ -324,6 +329,7 @@ PaintCanvas::PaintCanvas() {
_brush_prefab = 0;
_brush_size = 1;
_current_tool = 0;
_previous_tool = 0;
_image.instance();
_preview_image.instance();
@ -373,6 +379,8 @@ void PaintCanvas::_bind_methods() {
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("get_previous_tool"), &PaintCanvas::get_previous_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

@ -44,6 +44,8 @@ public:
int get_current_tool() const;
void set_current_tool(const int val);
int get_previous_tool() const;
bool is_inside_canvas(const int x, const int y);
void set_pixel_arr(const PoolVector2iArray &pixels, const Color &color);
@ -93,6 +95,7 @@ protected:
int _brush_prefab;
int _brush_size;
int _current_tool;
int _previous_tool;
Ref<Image> _image;
Ref<Image> _preview_image;