Added undo and redo buttons to the PaintToolsPropertyInspector. It won't work for now.

This commit is contained in:
Relintai 2022-11-18 22:25:24 +01:00
parent 65cf1c60d9
commit 8e766ee8ab
2 changed files with 57 additions and 13 deletions

View File

@ -43,7 +43,7 @@ SOFTWARE.
#include "editor/editor_node.h" #include "editor/editor_node.h"
#endif #endif
void PaintToolsPropertyInspector::add_button(int id, const String &hint, const String &icon, const String &theme_type) { void PaintToolsPropertyInspector::add_tool_button(int id, const String &hint, const String &icon, const String &theme_type) {
Button *button = memnew(Button); Button *button = memnew(Button);
Ref<Texture> icon_tex; Ref<Texture> icon_tex;
@ -67,6 +67,27 @@ void PaintToolsPropertyInspector::add_button(int id, const String &hint, const S
_grid->add_child(button); _grid->add_child(button);
} }
void PaintToolsPropertyInspector::add_action_button(const String &callback, const String &hint, const String &icon, const String &theme_type) {
Button *button = memnew(Button);
Ref<Texture> icon_tex;
#ifdef TOOLS_ENABLED
if (EditorNode::get_singleton() && Engine::get_singleton()->is_editor_hint()) {
icon_tex = EditorNode::get_singleton()->get_gui_base()->get_theme_icon(icon, theme_type);
} else
#endif
{
icon_tex = get_theme_icon(icon, theme_type);
}
button->set_icon(icon_tex);
button->set_tooltip(hint);
button->connect("pressed", this, callback);
_grid->add_child(button);
}
void PaintToolsPropertyInspector::add_brush_prefab(int id, const Ref<Texture> &normal_texture, const Ref<Texture> &hover_texture) { void PaintToolsPropertyInspector::add_brush_prefab(int id, const Ref<Texture> &normal_texture, const Ref<Texture> &hover_texture) {
TextureButton *brush_button = memnew(TextureButton); TextureButton *brush_button = memnew(TextureButton);
brush_button->set_normal_texture(normal_texture); brush_button->set_normal_texture(normal_texture);
@ -106,17 +127,19 @@ PaintToolsPropertyInspector::PaintToolsPropertyInspector() {
_grid->set_h_size_flags(SIZE_EXPAND_FILL); _grid->set_h_size_flags(SIZE_EXPAND_FILL);
_grid->set_v_size_flags(SIZE_EXPAND_FILL); _grid->set_v_size_flags(SIZE_EXPAND_FILL);
add_button(PaintCanvas::TOOL_PENCIL, "Pencil", "Edit", "EditorIcons"); add_tool_button(PaintCanvas::TOOL_PENCIL, "Pencil", "Edit", "EditorIcons");
add_button(PaintCanvas::TOOL_BRUSH, "Brush", "CanvasItem", "EditorIcons"); add_tool_button(PaintCanvas::TOOL_BRUSH, "Brush", "CanvasItem", "EditorIcons");
add_button(PaintCanvas::TOOL_BUCKET, "Bucket", "Bucket", "EditorIcons"); add_tool_button(PaintCanvas::TOOL_BUCKET, "Bucket", "Bucket", "EditorIcons");
add_button(PaintCanvas::TOOL_RAINBOW, "Rainbow", "StyleBoxLine", "EditorIcons"); add_tool_button(PaintCanvas::TOOL_RAINBOW, "Rainbow", "StyleBoxLine", "EditorIcons");
add_button(PaintCanvas::TOOL_LINE, "Line", "CurveLinear", "EditorIcons"); add_tool_button(PaintCanvas::TOOL_LINE, "Line", "CurveLinear", "EditorIcons");
add_button(PaintCanvas::TOOL_RECT, "Rect", "Panels1", "EditorIcons"); add_tool_button(PaintCanvas::TOOL_RECT, "Rect", "Panels1", "EditorIcons");
add_button(PaintCanvas::TOOL_DARKEN, "Darken", "ArrowDown", "EditorIcons"); add_tool_button(PaintCanvas::TOOL_DARKEN, "Darken", "ArrowDown", "EditorIcons");
add_button(PaintCanvas::TOOL_BRIGHTEN, "Brighten", "ArrowUp", "EditorIcons"); add_tool_button(PaintCanvas::TOOL_BRIGHTEN, "Brighten", "ArrowUp", "EditorIcons");
add_button(PaintCanvas::TOOL_COLORPICKER, "Colorpicker", "ColorPick", "EditorIcons"); add_tool_button(PaintCanvas::TOOL_COLORPICKER, "Colorpicker", "ColorPick", "EditorIcons");
add_button(PaintCanvas::TOOL_CUT, "Cut", "ActionCut", "EditorIcons"); add_tool_button(PaintCanvas::TOOL_CUT, "Cut", "ActionCut", "EditorIcons");
add_button(PaintCanvas::TOOL_PASTECUT, "Pastecut", "ActionCopy", "EditorIcons"); add_tool_button(PaintCanvas::TOOL_PASTECUT, "Pastecut", "ActionCopy", "EditorIcons");
add_action_button("_on_undo_pressed", "Undo", "ArrowLeft", "EditorIcons");
add_action_button("_on_redo_pressed", "Redo", "ArrowRight", "EditorIcons");
_brush_prefabs = memnew(HFlowContainer); _brush_prefabs = memnew(HFlowContainer);
box_container->add_child(_brush_prefabs); box_container->add_child(_brush_prefabs);
@ -216,10 +239,28 @@ void PaintToolsPropertyInspector::_on_brush_size_changed() {
_brush_size_label->set_text(itos(paint_canvas->get_brush_size())); _brush_size_label->set_text(itos(paint_canvas->get_brush_size()));
} }
void PaintToolsPropertyInspector::_on_undo_pressed() {
PaintCanvas *paint_canvas = Object::cast_to<PaintCanvas>(ObjectDB::get_instance(_paint_canvas));
ERR_FAIL_COND(!paint_canvas);
//paint_canvas->undo_action();
}
void PaintToolsPropertyInspector::_on_redo_pressed() {
PaintCanvas *paint_canvas = Object::cast_to<PaintCanvas>(ObjectDB::get_instance(_paint_canvas));
ERR_FAIL_COND(!paint_canvas);
//paint_canvas->redo_action();
}
void PaintToolsPropertyInspector::_bind_methods() { void PaintToolsPropertyInspector::_bind_methods() {
ClassDB::bind_method(D_METHOD("_on_button_toggled"), &PaintToolsPropertyInspector::_on_button_toggled); ClassDB::bind_method(D_METHOD("_on_button_toggled"), &PaintToolsPropertyInspector::_on_button_toggled);
ClassDB::bind_method(D_METHOD("_on_tool_changed"), &PaintToolsPropertyInspector::_on_tool_changed); ClassDB::bind_method(D_METHOD("_on_tool_changed"), &PaintToolsPropertyInspector::_on_tool_changed);
ClassDB::bind_method(D_METHOD("_on_brush_prefab_button_pressed"), &PaintToolsPropertyInspector::_on_brush_prefab_button_pressed); ClassDB::bind_method(D_METHOD("_on_brush_prefab_button_pressed"), &PaintToolsPropertyInspector::_on_brush_prefab_button_pressed);
ClassDB::bind_method(D_METHOD("_on_brush_size_slider_value_changed"), &PaintToolsPropertyInspector::_on_brush_size_slider_value_changed); ClassDB::bind_method(D_METHOD("_on_brush_size_slider_value_changed"), &PaintToolsPropertyInspector::_on_brush_size_slider_value_changed);
ClassDB::bind_method(D_METHOD("_on_brush_size_changed"), &PaintToolsPropertyInspector::_on_brush_size_changed); ClassDB::bind_method(D_METHOD("_on_brush_size_changed"), &PaintToolsPropertyInspector::_on_brush_size_changed);
ClassDB::bind_method(D_METHOD("_on_undo_pressed"), &PaintToolsPropertyInspector::_on_undo_pressed);
ClassDB::bind_method(D_METHOD("_on_redo_pressed"), &PaintToolsPropertyInspector::_on_redo_pressed);
} }

View File

@ -39,7 +39,8 @@ class PaintToolsPropertyInspector : public PaintCustomPropertyInspector {
GDCLASS(PaintToolsPropertyInspector, PaintCustomPropertyInspector); GDCLASS(PaintToolsPropertyInspector, PaintCustomPropertyInspector);
public: public:
void add_button(int id, const String &hint, const String &icon, const String &theme_type); void add_tool_button(int id, const String &hint, const String &icon, const String &theme_type);
void add_action_button(const String &callback, const String &hint, const String &icon, const String &theme_type);
void add_brush_prefab(int id, const Ref<Texture> &normal_texture, const Ref<Texture> &hover_texture); void add_brush_prefab(int id, const Ref<Texture> &normal_texture, const Ref<Texture> &hover_texture);
void _on_paint_node_selected(Node *paint_node); void _on_paint_node_selected(Node *paint_node);
@ -53,6 +54,8 @@ protected:
void _on_brush_prefab_button_pressed(const int id); void _on_brush_prefab_button_pressed(const int id);
void _on_brush_size_slider_value_changed(const float value); void _on_brush_size_slider_value_changed(const float value);
void _on_brush_size_changed(); void _on_brush_size_changed();
void _on_undo_pressed();
void _on_redo_pressed();
static void _bind_methods(); static void _bind_methods();