mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-02-02 22:35:55 +01:00
Structural setup for saving images for PaintProjects.
This commit is contained in:
parent
cebc26f3ce
commit
be9493a25a
@ -337,6 +337,10 @@ Ref<ImageTexture> PaintCanvas::get_preview_image_texture() {
|
||||
return _preview_image_texture;
|
||||
}
|
||||
|
||||
Ref<Image> PaintCanvas::_get_save_image() {
|
||||
return _image;
|
||||
}
|
||||
|
||||
void PaintCanvas::handle_draw(const Vector2 &local_position, const Ref<InputEvent> &event) {
|
||||
PaintProject *proj = get_paint_project();
|
||||
|
||||
|
@ -82,6 +82,8 @@ public:
|
||||
Ref<ImageTexture> get_image_texture();
|
||||
Ref<ImageTexture> get_preview_image_texture();
|
||||
|
||||
Ref<Image> _get_save_image();
|
||||
|
||||
void handle_draw(const Vector2 &local_position, const Ref<InputEvent> &event);
|
||||
Color get_current_color();
|
||||
void update_mouse_position(const Vector2 &local_position, const Ref<InputEvent> &event);
|
||||
|
@ -26,12 +26,19 @@ void PaintNode::set_draw_outline(const bool val) {
|
||||
}
|
||||
}
|
||||
|
||||
void PaintNode::save() {
|
||||
notification(NOTIFICATION_PAINT_PROJECT_PRE_SAVE);
|
||||
call("_save");
|
||||
notification(NOTIFICATION_PAINT_PROJECT_POST_SAVE);
|
||||
void PaintNode::save_image() {
|
||||
_propagate_notification_project_pre_save();
|
||||
call("_save_image");
|
||||
_propagate_notification_project_post_save();
|
||||
}
|
||||
void PaintNode::_save() {
|
||||
void PaintNode::_save_image() {
|
||||
}
|
||||
|
||||
Ref<Image> PaintNode::get_save_image() {
|
||||
return call("_get_save_image");
|
||||
}
|
||||
Ref<Image> PaintNode::_get_save_image() {
|
||||
return Ref<Image>();
|
||||
}
|
||||
|
||||
PoolVector2iArray PaintNode::util_get_pixels_in_line(const Vector2i &from, const Vector2i &to) {
|
||||
@ -109,6 +116,29 @@ void PaintNode::_propagate_notification_resized() {
|
||||
}
|
||||
}
|
||||
|
||||
void PaintNode::_propagate_notification_project_pre_save() {
|
||||
notification(NOTIFICATION_PAINT_PROJECT_PRE_SAVE);
|
||||
|
||||
for (int i = 0; i < get_child_count(); ++i) {
|
||||
PaintNode *pn = Object::cast_to<PaintNode>(get_child(i));
|
||||
|
||||
if (pn) {
|
||||
pn->_propagate_notification_project_pre_save();
|
||||
}
|
||||
}
|
||||
}
|
||||
void PaintNode::_propagate_notification_project_post_save() {
|
||||
notification(NOTIFICATION_PAINT_PROJECT_POST_SAVE);
|
||||
|
||||
for (int i = 0; i < get_child_count(); ++i) {
|
||||
PaintNode *pn = Object::cast_to<PaintNode>(get_child(i));
|
||||
|
||||
if (pn) {
|
||||
pn->_propagate_notification_project_post_save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PaintNode::PaintNode() {
|
||||
_draw_outline = true;
|
||||
}
|
||||
@ -140,9 +170,13 @@ void PaintNode::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_draw_outline", "val"), &PaintNode::set_draw_outline);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_outline"), "set_draw_outline", "get_draw_outline");
|
||||
|
||||
BIND_VMETHOD(MethodInfo("_save"));
|
||||
ClassDB::bind_method(D_METHOD("save"), &PaintNode::save);
|
||||
ClassDB::bind_method(D_METHOD("_save"), &PaintNode::_save);
|
||||
BIND_VMETHOD(MethodInfo("_save_image"));
|
||||
ClassDB::bind_method(D_METHOD("save_image"), &PaintNode::save_image);
|
||||
ClassDB::bind_method(D_METHOD("_save_image"), &PaintNode::_save_image);
|
||||
|
||||
BIND_VMETHOD(MethodInfo("_get_save_image"));
|
||||
ClassDB::bind_method(D_METHOD("get_save_image"), &PaintNode::get_save_image);
|
||||
ClassDB::bind_method(D_METHOD("_get_save_image"), &PaintNode::_get_save_image);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("util_get_pixels_in_line", "from", "to"), &PaintNode::util_get_pixels_in_line);
|
||||
|
||||
|
@ -23,8 +23,11 @@ public:
|
||||
bool get_draw_outline();
|
||||
void set_draw_outline(const bool val);
|
||||
|
||||
void save();
|
||||
virtual void _save();
|
||||
void save_image();
|
||||
virtual void _save_image();
|
||||
|
||||
Ref<Image> get_save_image();
|
||||
virtual Ref<Image> _get_save_image();
|
||||
|
||||
PoolVector2iArray util_get_pixels_in_line(const Vector2i &from, const Vector2i &to);
|
||||
|
||||
@ -44,6 +47,8 @@ public:
|
||||
String get_configuration_warning() const;
|
||||
|
||||
virtual void _propagate_notification_resized();
|
||||
void _propagate_notification_project_pre_save();
|
||||
void _propagate_notification_project_post_save();
|
||||
|
||||
PaintNode();
|
||||
~PaintNode();
|
||||
|
@ -6,6 +6,13 @@
|
||||
|
||||
#include "core/config/engine.h"
|
||||
|
||||
String PaintProject::get_save_file_name() {
|
||||
return _save_file_name;
|
||||
}
|
||||
void PaintProject::set_save_file_name(const String &fn) {
|
||||
_save_file_name = fn;
|
||||
}
|
||||
|
||||
Color PaintProject::get_current_color() {
|
||||
return _current_color;
|
||||
}
|
||||
@ -58,6 +65,14 @@ void PaintProject::set_colors_as_default() {
|
||||
}
|
||||
}
|
||||
|
||||
void PaintProject::_save_image() {
|
||||
ERR_FAIL_COND(_save_file_name.empty());
|
||||
|
||||
//create image
|
||||
//collect and merge in all images returned by _get_save_image() in each PaintNode child
|
||||
//save image
|
||||
}
|
||||
|
||||
void PaintProject::add_paint_canvas_backgorund() {
|
||||
PaintCanvasBackground *bg = memnew(PaintCanvasBackground);
|
||||
add_child(bg);
|
||||
@ -101,6 +116,12 @@ void PaintProject::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("current_color_changed", PropertyInfo(Variant::COLOR, "color")));
|
||||
ADD_SIGNAL(MethodInfo("color_presets_changed"));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_save_file_name"), &PaintProject::get_save_file_name);
|
||||
ClassDB::bind_method(D_METHOD("set_save_file_name", "size"), &PaintProject::set_save_file_name);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "save_file_name"), "set_save_file_name", "get_save_file_name");
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::NIL, "run_save_image", PROPERTY_HINT_BUTTON, "save_image"), "", "");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_current_color"), &PaintProject::get_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");
|
||||
|
@ -9,6 +9,9 @@ class PaintProject : public PaintNode {
|
||||
GDCLASS(PaintProject, PaintNode);
|
||||
|
||||
public:
|
||||
String get_save_file_name();
|
||||
void set_save_file_name(const String &fn);
|
||||
|
||||
Color get_current_color();
|
||||
void set_current_color(const Color &color);
|
||||
|
||||
@ -23,6 +26,8 @@ public:
|
||||
|
||||
void set_colors_as_default();
|
||||
|
||||
void _save_image();
|
||||
|
||||
void add_paint_canvas_backgorund();
|
||||
void add_paint_visual_grid();
|
||||
|
||||
@ -36,6 +41,7 @@ protected:
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
String _save_file_name;
|
||||
Color _current_color;
|
||||
PoolColorArray _color_presets;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user