diff --git a/modules/paint/paint_navbar.cpp b/modules/paint/paint_navbar.cpp index d076904ef..2e47c99c8 100644 --- a/modules/paint/paint_navbar.cpp +++ b/modules/paint/paint_navbar.cpp @@ -24,142 +24,221 @@ SOFTWARE. #include "paint_navbar.h" -/* -tool -extends MenuButton +#include "paint_canvas.h" +#include "paint_window.h" -var popup = get_popup() -signal item_pressed +#include "scene/gui/label.h" +#include "scene/gui/menu_button.h" +#include "scene/gui/popup_menu.h" -func _ready(): - popup.connect("id_pressed", self, "id_pressed") +#include "dialogs/paint_canvas_dialog.h" +#include "dialogs/paint_change_grid_size_dialog.h" +#include "dialogs/paint_load_file_dialog.h" +#include "dialogs/paint_save_file_dialog.h" +#include "paint_canvas_layer.h" +#include "paint_settings.h" -func id_pressed(id): - emit_signal("item_pressed", name, popup.get_item_text(id), id) +void PaintNavbar::handle_menu_item_pressed(const int id) { + switch (id) { + case MENU_FILE_NEW: + paint_window->paint_canvas_dialog->popup_centered(); + break; + case MENU_FILE_SAVE: + paint_window->paint_save_file_dialog->popup_centered(); + break; + case MENU_FILE_LOAD: + paint_window->paint_load_file_dialog->popup_centered(); + break; + case MENU_EDIT_UNDO: + break; + case MENU_EDIT_REDO: + break; + case MENU_EDIT_CUT: + break; + case MENU_EDIT_COPY: + break; + case MENU_EDIT_PASTE: + break; + case MENU_CANVAS_CHANGE_SIZE: + paint_window->paint_canvas_dialog->popup_centered(); + break; + case MENU_CANVAS_CROP_TO_CONTENT: + canvas->crop_to_content(); + break; + case MENU_LAYER_ADD: + paint_window->add_new_layer(); + break; + case MENU_LAYER_DELETE: + paint_window->remove_active_layer(); + break; + case MENU_LAYER_DUPLICATE: + paint_window->duplicate_active_layer(); + break; + case MENU_LAYER_CLEAR: + canvas->clear_active_layer(); + break; + case MENU_LAYER_TOGGLE_ALPHA_LOCKED: -*/ + //owner.paint_canvas.active_layer.toggle_alpha_locked() + //$Buttons/Layer.get_popup().set_item_checked(id, not $Buttons/Layer.get_popup().is_item_checked(id)) + //owner.find_node("LockAlpha").pressed = $Buttons/Layer.get_popup().is_item_checked(id) -void PaintNavbar::_ready() { - /* - editor = owner - paint_canvas = editor.find_node("PaintCanvas") - - for i in get_node("Buttons").get_children(): - i.connect("item_pressed", self, "button_pressed") - */ -} -void PaintNavbar::button_pressed(const String &button_name, Node *button_item, const int id) { - /* -# print("pressed: ", button_name) -# print("pressed item is: '%s'" % button_item) - - match button_name: - "File": - handle_file_menu(button_item, id) - "Edit": - handle_edit_menu(button_item, id) - "Canvas": - handle_canvas_menu(button_item, id) - "Layer": - handle_layer_menu(button_item, id) - "Grid": - handle_grid_menu(button_item, id) - "Magic": - handle_magic_menu(button_item, id) - "Editor": - handle_editor_menu(button_item, id) - */ + break; + case MENU_GRID_TOGGLE: + canvas->toggle_grid(); + break; + case MENU_GRID_CHANGE_SIZE: + paint_window->paint_change_grid_size_dialog->popup_centered(); + break; + case MENU_MAGIC_CHANGE_SINGLE_COLOR: + break; + case MENU_MAGIC_CHANGE_COLOR_RANGE: + break; + case MENU_MAGIC_HSV_NOISE: + break; + case MENU_MAGIC_HSV_COLOR_MODULATION: + break; + case MENU_EDITOR_SETTINGS: + paint_window->paint_settings_dialog->popup_centered(); + break; + default: + break; + } } -void PaintNavbar::handle_file_menu(const String &pressed_item, const int id) { - /* - match pressed_item: - "Save": - owner.get_node("SaveFileDialog").show() - "Load": - owner.get_node("LoadFileDialog").show() - "New": - owner.get_node("ConfirmationDialog").show() - */ -} -void PaintNavbar::handle_edit_menu(const String &pressed_item, const int id) { - /* - match pressed_item: - "Add Layer": - editor.add_new_layer() - */ -} -void PaintNavbar::handle_canvas_menu(const String &pressed_item, const int id) { - /* - match pressed_item: - "Change Size": - owner.get_node("ChangeCanvasSize").show() - "Crop To Content": - owner.paint_canvas.crop_to_content() - */ -} -void PaintNavbar::handle_layer_menu(const String &pressed_item, const int id) { - /* - match pressed_item: - "Add Layer": - editor.add_new_layer() - "Delete Layer": - editor.remove_active_layer() - "Duplicate Layer": - editor.duplicate_active_layer() - "Clear Layer": - owner.paint_canvas.clear_active_layer() - "Toggle Alpha Locked": - owner.paint_canvas.active_layer.toggle_alpha_locked() - $Buttons/Layer.get_popup().set_item_checked(id, not $Buttons/Layer.get_popup().is_item_checked(id)) - owner.find_node("LockAlpha").pressed = $Buttons/Layer.get_popup().is_item_checked(id) - */ -} -void PaintNavbar::handle_grid_menu(const String &pressed_item, const int id) { - /* - match pressed_item: - "Change Grid Size": - owner.get_node("ChangeGridSizeDialog").show() - "Toggle Grid": - owner.paint_canvas.toggle_grid() - */ -} - -void PaintNavbar::handle_magic_menu(const String &pressed_item, const int id) { - /* - match pressed_item: - "Add Layer": - editor.add_new_layer() - */ -} -void PaintNavbar::handle_editor_menu(const String &pressed_item, const int id) { - /* - match pressed_item: - "Settings": - owner.get_node("Settings").show() - "Toggle Grid": - var grids_node = owner.find_node("Grids") - grids_node.visible = !grids_node.visible - "Reset Canvas Position": - owner.paint_canvas_node.rect_position = Vector2(0, 0) - */ -} bool PaintNavbar::is_any_menu_open() { - /* - for child in $Buttons.get_children(): - if child.get_popup().visible: - return true - return false - */ + if (file_menu_button->get_popup()->is_visible() || edit_menu_button->get_popup()->is_visible() || + canvas_menu_button->get_popup()->is_visible() || layer_menu_button->get_popup()->is_visible() || + grid_menu_button->get_popup()->is_visible() || magic_menu_button->get_popup()->is_visible() || + editor_menu_button->get_popup()->is_visible()) { + return true; + } return false; } PaintNavbar::PaintNavbar() { + paint_window = nullptr; + canvas = nullptr; + + HBoxContainer *button_hbox_container = memnew(HBoxContainer); + add_child(button_hbox_container); + + file_menu_button = memnew(MenuButton); + file_menu_button->set_switch_on_hover(true); + file_menu_button->set_text("File"); + file_menu_button->set_flat(false); + file_menu_button->set_h_size_flags(Control::SIZE_EXPAND_FILL); + file_menu_button->set_v_size_flags(Control::SIZE_EXPAND_FILL); + button_hbox_container->add_child(file_menu_button); + + PopupMenu *menu = file_menu_button->get_popup(); + menu->add_item("New", MENU_FILE_NEW); + menu->add_item("Save", MENU_FILE_SAVE); + menu->add_item("Load", MENU_FILE_LOAD); + menu->connect("id_pressed", this, "handle_menu_item_pressed"); + + edit_menu_button = memnew(MenuButton); + edit_menu_button->set_switch_on_hover(true); + edit_menu_button->set_text("Edit"); + edit_menu_button->set_disabled(true); + edit_menu_button->set_flat(false); + edit_menu_button->set_h_size_flags(Control::SIZE_EXPAND_FILL); + edit_menu_button->set_v_size_flags(Control::SIZE_EXPAND_FILL); + button_hbox_container->add_child(edit_menu_button); + + menu = edit_menu_button->get_popup(); + menu->add_item("Undo", MENU_EDIT_UNDO); + menu->add_item("Redo", MENU_EDIT_REDO); + menu->add_item("Cut", MENU_EDIT_CUT); + menu->add_item("Copy", MENU_EDIT_COPY); + menu->add_item("Paste", MENU_EDIT_PASTE); + menu->connect("id_pressed", this, "handle_menu_item_pressed"); + + canvas_menu_button = memnew(MenuButton); + canvas_menu_button->set_switch_on_hover(true); + canvas_menu_button->set_text("Canvas"); + canvas_menu_button->set_flat(false); + canvas_menu_button->set_h_size_flags(Control::SIZE_EXPAND_FILL); + canvas_menu_button->set_v_size_flags(Control::SIZE_EXPAND_FILL); + button_hbox_container->add_child(canvas_menu_button); + + menu = canvas_menu_button->get_popup(); + menu->add_item("Change Size", MENU_CANVAS_CHANGE_SIZE); + //menu->add_item("Crop To Content", MENU_CANVAS_CROP_TO_CONTENT); + menu->connect("id_pressed", this, "handle_menu_item_pressed"); + + layer_menu_button = memnew(MenuButton); + layer_menu_button->set_switch_on_hover(true); + layer_menu_button->set_text("Layer"); + layer_menu_button->set_flat(false); + layer_menu_button->set_h_size_flags(Control::SIZE_EXPAND_FILL); + layer_menu_button->set_v_size_flags(Control::SIZE_EXPAND_FILL); + button_hbox_container->add_child(layer_menu_button); + + menu = layer_menu_button->get_popup(); + menu->add_item("Add Layer", MENU_LAYER_ADD); + menu->add_item("Delete Layer", MENU_LAYER_DELETE); + menu->add_item("Duplicate Layer", MENU_LAYER_DUPLICATE); + menu->add_item("Clear Layer", MENU_LAYER_CLEAR); + menu->add_separator(); + menu->add_check_item("Toggle Alpha Locked", MENU_LAYER_TOGGLE_ALPHA_LOCKED); + menu->connect("id_pressed", this, "handle_menu_item_pressed"); + + grid_menu_button = memnew(MenuButton); + grid_menu_button->set_switch_on_hover(true); + grid_menu_button->set_text("Grid"); + grid_menu_button->set_flat(false); + grid_menu_button->set_h_size_flags(Control::SIZE_EXPAND_FILL); + grid_menu_button->set_v_size_flags(Control::SIZE_EXPAND_FILL); + button_hbox_container->add_child(grid_menu_button); + + menu = grid_menu_button->get_popup(); + menu->add_item("Toggle Grid", MENU_GRID_TOGGLE); + menu->add_item("Change Grid Size", MENU_GRID_CHANGE_SIZE); + menu->connect("id_pressed", this, "handle_menu_item_pressed"); + + magic_menu_button = memnew(MenuButton); + magic_menu_button->set_switch_on_hover(true); + magic_menu_button->set_text("Magic"); + magic_menu_button->set_flat(false); + magic_menu_button->set_h_size_flags(Control::SIZE_EXPAND_FILL); + magic_menu_button->set_v_size_flags(Control::SIZE_EXPAND_FILL); + button_hbox_container->add_child(magic_menu_button); + + menu = magic_menu_button->get_popup(); + menu->add_item("Change Single Color", MENU_MAGIC_CHANGE_SINGLE_COLOR); + menu->add_item("Change Color Range", MENU_MAGIC_CHANGE_COLOR_RANGE); + menu->add_item("HSV Noise", MENU_MAGIC_HSV_NOISE); + menu->add_item("HSV Color Modulation", MENU_MAGIC_HSV_COLOR_MODULATION); + menu->connect("id_pressed", this, "handle_menu_item_pressed"); + + editor_menu_button = memnew(MenuButton); + editor_menu_button->set_switch_on_hover(true); + editor_menu_button->set_text("Editor"); + editor_menu_button->set_flat(false); + editor_menu_button->set_h_size_flags(Control::SIZE_EXPAND_FILL); + editor_menu_button->set_v_size_flags(Control::SIZE_EXPAND_FILL); + button_hbox_container->add_child(editor_menu_button); + + menu = editor_menu_button->get_popup(); + menu->add_item("Settings", MENU_EDITOR_SETTINGS); + menu->connect("id_pressed", this, "handle_menu_item_pressed"); + + Control *spacer = memnew(Control); + spacer->set_h_size_flags(Control::SIZE_EXPAND_FILL); + add_child(spacer); + + Label *urlabel = memnew(Label); + urlabel->set_text("Undo (Z) Redo (Y)"); + urlabel->set_align(Label::ALIGN_CENTER); + urlabel->set_valign(Label::VALIGN_CENTER); + add_child(spacer); } PaintNavbar::~PaintNavbar() { } void PaintNavbar::_bind_methods() { + ClassDB::bind_method(D_METHOD("handle_menu_item_pressed"), &PaintNavbar::handle_menu_item_pressed); } diff --git a/modules/paint/paint_navbar.h b/modules/paint/paint_navbar.h index 068c8088e..a87288284 100644 --- a/modules/paint/paint_navbar.h +++ b/modules/paint/paint_navbar.h @@ -25,35 +25,67 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "scene/gui/control.h" +#include "scene/gui/box_container.h" -class PaintNavbar : public Control { - GDCLASS(PaintNavbar, Control); +class PaintWindow; +class PaintCanvas; +class MenuButton; + +class PaintNavbar : public BoxContainer { + GDCLASS(PaintNavbar, BoxContainer); public: - void _ready(); - void button_pressed(const String &button_name, Node *button_item, const int id); + enum { + MENU_FILE_NEW = 0, + MENU_FILE_SAVE, + MENU_FILE_LOAD, - void handle_file_menu(const String &pressed_item, const int id); - void handle_edit_menu(const String &pressed_item, const int id); - void handle_canvas_menu(const String &pressed_item, const int id); - void handle_layer_menu(const String &pressed_item, const int id); - void handle_grid_menu(const String &pressed_item, const int id); + MENU_EDIT_UNDO, + MENU_EDIT_REDO, + MENU_EDIT_CUT, + MENU_EDIT_COPY, + MENU_EDIT_PASTE, + + MENU_CANVAS_CHANGE_SIZE, + MENU_CANVAS_CROP_TO_CONTENT, + + MENU_LAYER_ADD, + MENU_LAYER_DELETE, + MENU_LAYER_DUPLICATE, + MENU_LAYER_CLEAR, + MENU_LAYER_TOGGLE_ALPHA_LOCKED, + + MENU_GRID_TOGGLE, + MENU_GRID_CHANGE_SIZE, + + MENU_MAGIC_CHANGE_SINGLE_COLOR, + MENU_MAGIC_CHANGE_COLOR_RANGE, + MENU_MAGIC_HSV_NOISE, + MENU_MAGIC_HSV_COLOR_MODULATION, + + MENU_EDITOR_SETTINGS, + }; + + void handle_menu_item_pressed(const int id); - void handle_magic_menu(const String &pressed_item, const int id); - void handle_editor_menu(const String &pressed_item, const int id); bool is_any_menu_open(); PaintNavbar(); ~PaintNavbar(); + PaintWindow *paint_window; + PaintCanvas *canvas; + + MenuButton *file_menu_button; + MenuButton *edit_menu_button; + MenuButton *canvas_menu_button; + MenuButton *layer_menu_button; + MenuButton *grid_menu_button; + MenuButton *magic_menu_button; + MenuButton *editor_menu_button; + protected: static void _bind_methods(); - - /* - var editor - var paint_canvas - */ }; #endif diff --git a/modules/paint/paint_settings.h b/modules/paint/paint_settings.h index 02f3b2991..43dabf09e 100644 --- a/modules/paint/paint_settings.h +++ b/modules/paint/paint_settings.h @@ -25,10 +25,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "scene/gui/control.h" +#include "scene/gui/dialogs.h" -class PaintSettings : public Control { - GDCLASS(PaintSettings, Control); +class PaintSettings : public WindowDialog { + GDCLASS(PaintSettings, WindowDialog); public: void _enter_tree(); diff --git a/modules/paint/paint_window.cpp b/modules/paint/paint_window.cpp index c6bff9a27..2b0628e08 100644 --- a/modules/paint/paint_window.cpp +++ b/modules/paint/paint_window.cpp @@ -28,11 +28,13 @@ SOFTWARE. #include "paint_canvas.h" #include "paint_canvas_layer.h" #include "paint_color_grid.h" -#include "paint_navbar.h" #include "paint_layer_button.h" +#include "paint_navbar.h" #include "scene/resources/style_box.h" +#include "scene/gui/button.h" #include "scene/gui/check_button.h" +#include "scene/gui/color_picker.h" #include "scene/gui/label.h" #include "scene/gui/margin_container.h" #include "scene/gui/panel_container.h" @@ -40,8 +42,6 @@ SOFTWARE. #include "scene/gui/scroll_container.h" #include "scene/gui/slider.h" #include "scene/gui/texture_button.h" -#include "scene/gui/button.h" -#include "scene/gui/color_picker.h" #include "dialogs/paint_canvas_dialog.h" #include "dialogs/paint_change_grid_size_dialog.h" @@ -930,6 +930,7 @@ PaintWindow::PaintWindow() { //Main Content Top (Navbar) navbar = memnew(PaintNavbar); + navbar->paint_window = this; navbar->set_h_size_flags(SIZE_EXPAND_FILL); main_content_container->add_child(navbar); @@ -1056,6 +1057,7 @@ PaintWindow::PaintWindow() { paint_canvas->set_size(Size2(256, 256)); paint_canvas->set_anchors_and_margins_preset(Control::PRESET_CENTER); paint_canvas_container->add_child(paint_canvas); + navbar->canvas = paint_canvas; //Main Content Mid (App) -- Right Panel PanelContainer *mid_right_panel_container = memnew(PanelContainer); diff --git a/modules/paint/register_types.cpp b/modules/paint/register_types.cpp index 403d88d35..383f4b5c9 100644 --- a/modules/paint/register_types.cpp +++ b/modules/paint/register_types.cpp @@ -30,7 +30,7 @@ void register_paint_types() { //ClassDB::register_class(); #ifdef TOOLS_ENABLED - //EditorPlugins::add_by_type(); + EditorPlugins::add_by_type(); #endif }