diff --git a/modules/paint/SCsub b/modules/paint/SCsub index b781d55ca..5492bf7d6 100644 --- a/modules/paint/SCsub +++ b/modules/paint/SCsub @@ -30,6 +30,9 @@ module_env.add_source_files(env.modules_sources,"ui/paint_canvas_background.cpp" module_env.add_source_files(env.modules_sources,"ui/paint_selection_box.cpp") module_env.add_source_files(env.modules_sources,"ui/paint_visual_grid.cpp") +module_env.add_source_files(env.modules_sources,"ui/paint_sidebar.cpp") +module_env.add_source_files(env.modules_sources,"ui/paint_sidebar_module.cpp") + module_env.add_source_files(env.modules_sources,"paint_utilities.cpp") module_env.add_source_files(env.modules_sources,"bush_prefabs.cpp") diff --git a/modules/paint/config.py b/modules/paint/config.py index d05f08034..2c30e3a78 100644 --- a/modules/paint/config.py +++ b/modules/paint/config.py @@ -27,7 +27,10 @@ def get_doc_classes(): "PaintNode", "PaintCanvas", - "PaintProject" + "PaintProject", + + "PaintSidebar", + "PaintSidebarModule", ] def get_doc_path(): diff --git a/modules/paint/register_types.cpp b/modules/paint/register_types.cpp index 887c9b1d0..72f469180 100644 --- a/modules/paint/register_types.cpp +++ b/modules/paint/register_types.cpp @@ -44,8 +44,11 @@ SOFTWARE. #include "ui/paint_selection_box.h" #include "ui/paint_visual_grid.h" -#include "nodes/paint_node.h" +#include "ui/paint_sidebar.h" +#include "ui/paint_sidebar_module.h" + #include "nodes/paint_canvas.h" +#include "nodes/paint_node.h" #include "nodes/paint_project.h" #ifdef TOOLS_ENABLED @@ -76,6 +79,9 @@ void register_paint_types() { ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); diff --git a/modules/paint/ui/paint_sidebar.cpp b/modules/paint/ui/paint_sidebar.cpp new file mode 100644 index 000000000..1fec4e105 --- /dev/null +++ b/modules/paint/ui/paint_sidebar.cpp @@ -0,0 +1,75 @@ +/* +Copyright (c) 2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "paint_sidebar.h" + +#include "../nodes/paint_node.h" +#include "paint_sidebar_module.h" +#include "scene/gui/box_container.h" + +void PaintSidebar::add_module(PaintSidebarModule *module) { + ERR_FAIL_COND(!module); + + _main_container->add_child(module); +} +void PaintSidebar::remove_module(PaintSidebarModule *module) { + ERR_FAIL_COND(!module); + + _main_container->remove_child(module); +} + +void PaintSidebar::add_module_bind(Node *module) { + PaintSidebarModule *m = Object::cast_to(module); + add_module(m); +} +void PaintSidebar::remove_module_bind(Node *module) { + PaintSidebarModule *m = Object::cast_to(module); + remove_module(m); +} + +PaintSidebar::PaintSidebar() { + _main_container = memnew(VBoxContainer); + add_child(_main_container); +} + +void PaintSidebar::on_paint_node_selected(PaintNode *paint_node) { + for (int i = 0; i < _main_container->get_child_count(); ++i) { + PaintSidebarModule *module = Object::cast_to(_main_container->get_child(i)); + + if (module) { + module->on_paint_node_selected(paint_node); + } + } +} +void PaintSidebar::on_paint_node_selected_bind(Node *paint_node) { + PaintNode *m = Object::cast_to(paint_node); + on_paint_node_selected(m); +} + +PaintSidebar::~PaintSidebar() { +} + +void PaintSidebar::_bind_methods() { + ClassDB::bind_method(D_METHOD("add_module", "module"), &PaintSidebar::add_module_bind); + ClassDB::bind_method(D_METHOD("remove_module", "module"), &PaintSidebar::remove_module_bind); + ClassDB::bind_method(D_METHOD("on_paint_node_selected", "paint_node"), &PaintSidebar::on_paint_node_selected_bind); +} diff --git a/modules/paint/ui/paint_sidebar.h b/modules/paint/ui/paint_sidebar.h new file mode 100644 index 000000000..610b091dc --- /dev/null +++ b/modules/paint/ui/paint_sidebar.h @@ -0,0 +1,54 @@ +#ifndef PAINT_SIDEBAR_H +#define PAINT_SIDEBAR_H + +/* +Copyright (c) 2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "scene/gui/panel_container.h" + +class VBoxContainer; +class PaintSidebarModule; +class PaintNode; + +class PaintSidebar : public PanelContainer { + GDCLASS(PaintSidebar, PanelContainer); + +public: + void add_module(PaintSidebarModule *module); + void remove_module(PaintSidebarModule *module); + + void add_module_bind(Node *module); + void remove_module_bind(Node *module); + + void on_paint_node_selected(PaintNode *paint_node); + void on_paint_node_selected_bind(Node *paint_node); + + PaintSidebar(); + ~PaintSidebar(); + +protected: + static void _bind_methods(); + + VBoxContainer *_main_container; +}; + +#endif diff --git a/modules/paint/ui/paint_sidebar_module.cpp b/modules/paint/ui/paint_sidebar_module.cpp new file mode 100644 index 000000000..e450fb6af --- /dev/null +++ b/modules/paint/ui/paint_sidebar_module.cpp @@ -0,0 +1,45 @@ +/* +Copyright (c) 2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "paint_sidebar_module.h" + +void PaintSidebarModule::on_paint_node_selected(PaintNode *paint_node) { + call("_on_paint_node_selected", paint_node); +} +void PaintSidebarModule::on_paint_node_selected_bind(Node *paint_node) { + call("_on_paint_node_selected", paint_node); +} +void PaintSidebarModule::_on_paint_node_selected(Node *paint_node) { +} + +PaintSidebarModule::PaintSidebarModule() { +} + +PaintSidebarModule::~PaintSidebarModule() { +} + +void PaintSidebarModule::_bind_methods() { + BIND_VMETHOD(MethodInfo("_on_paint_node_selected", PropertyInfo(Variant::OBJECT, "paint_node", PROPERTY_HINT_RESOURCE_TYPE, "PaintNode"))); + + ClassDB::bind_method(D_METHOD("on_paint_node_selected", "paint_node"), &PaintSidebarModule::on_paint_node_selected_bind); + ClassDB::bind_method(D_METHOD("_on_paint_node_selected", "paint_node"), &PaintSidebarModule::_on_paint_node_selected); +} diff --git a/modules/paint/ui/paint_sidebar_module.h b/modules/paint/ui/paint_sidebar_module.h new file mode 100644 index 000000000..a52fbe39c --- /dev/null +++ b/modules/paint/ui/paint_sidebar_module.h @@ -0,0 +1,45 @@ +#ifndef PAINT_SIDEBAR_MODULE_H +#define PAINT_SIDEBAR_MODULE_H + +/* +Copyright (c) 2022 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "scene/gui/panel_container.h" + +class PaintNode; + +class PaintSidebarModule : public PanelContainer { + GDCLASS(PaintSidebarModule, PanelContainer); + +public: + void on_paint_node_selected(PaintNode *paint_node); + void on_paint_node_selected_bind(Node *paint_node); + virtual void _on_paint_node_selected(Node *paint_node); + + PaintSidebarModule(); + ~PaintSidebarModule(); + +protected: + static void _bind_methods(); +}; + +#endif