Added more helper methods to PaintProject.

This commit is contained in:
Relintai 2022-11-17 23:55:36 +01:00
parent a3bedba43a
commit 2485665f89
2 changed files with 40 additions and 0 deletions

View File

@ -11,6 +11,34 @@ void PaintProject::set_current_color(const Color &color) {
emit_signal("current_color_changed", _current_color); emit_signal("current_color_changed", _current_color);
} }
void PaintProject::add_preset_color(const Color &color) {
_color_presets.push_back(color);
emit_signal("color_presets_changed");
}
void PaintProject::remove_preset_color(const int index) {
ERR_FAIL_INDEX(index, _color_presets.size());
_color_presets.remove(index);
emit_signal("color_presets_changed");
}
Color PaintProject::get_preset_color(const int index) {
ERR_FAIL_INDEX_V(index, _color_presets.size(), Color());
return _color_presets.get(index);
}
void PaintProject::set_preset_color(const int index, const Color &color) {
ERR_FAIL_INDEX(index, _color_presets.size());
_color_presets.set(index, color);
emit_signal("color_presets_changed");
}
int PaintProject::get_preset_color_count() {
return _color_presets.size();
}
PoolColorArray PaintProject::get_color_presets() { PoolColorArray PaintProject::get_color_presets() {
return _color_presets; return _color_presets;
} }
@ -51,6 +79,12 @@ void PaintProject::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_current_color", "size"), &PaintProject::set_current_color); ClassDB::bind_method(D_METHOD("set_current_color", "size"), &PaintProject::set_current_color);
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "current_color"), "set_current_color", "get_current_color"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "current_color"), "set_current_color", "get_current_color");
ClassDB::bind_method(D_METHOD("add_preset_color", "color"), &PaintProject::add_preset_color);
ClassDB::bind_method(D_METHOD("remove_preset_color", "index"), &PaintProject::remove_preset_color);
ClassDB::bind_method(D_METHOD("get_preset_color", "index"), &PaintProject::get_preset_color);
ClassDB::bind_method(D_METHOD("set_preset_color", "index", "color"), &PaintProject::set_preset_color);
ClassDB::bind_method(D_METHOD("get_preset_color_count"), &PaintProject::get_preset_color_count);
ClassDB::bind_method(D_METHOD("get_color_presets"), &PaintProject::get_color_presets); ClassDB::bind_method(D_METHOD("get_color_presets"), &PaintProject::get_color_presets);
ClassDB::bind_method(D_METHOD("set_color_presets", "colors"), &PaintProject::set_color_presets); ClassDB::bind_method(D_METHOD("set_color_presets", "colors"), &PaintProject::set_color_presets);
ADD_PROPERTY(PropertyInfo(Variant::POOL_COLOR_ARRAY, "color_presets"), "set_color_presets", "get_color_presets"); ADD_PROPERTY(PropertyInfo(Variant::POOL_COLOR_ARRAY, "color_presets"), "set_color_presets", "get_color_presets");

View File

@ -12,6 +12,12 @@ public:
Color get_current_color(); Color get_current_color();
void set_current_color(const Color &color); void set_current_color(const Color &color);
void add_preset_color(const Color &color);
void remove_preset_color(const int index);
Color get_preset_color(const int index);
void set_preset_color(const int index, const Color &color);
int get_preset_color_count();
PoolColorArray get_color_presets(); PoolColorArray get_color_presets();
void set_color_presets(const PoolColorArray &colors); void set_color_presets(const PoolColorArray &colors);