Implement / port PaintNavbar.

This commit is contained in:
Relintai 2022-04-16 20:57:42 +02:00
parent e540e4e414
commit 0d917718dd
5 changed files with 256 additions and 143 deletions

View File

@ -24,142 +24,221 @@ SOFTWARE.
#include "paint_navbar.h" #include "paint_navbar.h"
/* #include "paint_canvas.h"
tool #include "paint_window.h"
extends MenuButton
var popup = get_popup() #include "scene/gui/label.h"
signal item_pressed #include "scene/gui/menu_button.h"
#include "scene/gui/popup_menu.h"
func _ready(): #include "dialogs/paint_canvas_dialog.h"
popup.connect("id_pressed", self, "id_pressed") #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): void PaintNavbar::handle_menu_item_pressed(const int id) {
emit_signal("item_pressed", name, popup.get_item_text(id), 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() { break;
/* case MENU_GRID_TOGGLE:
editor = owner canvas->toggle_grid();
paint_canvas = editor.find_node("PaintCanvas") break;
case MENU_GRID_CHANGE_SIZE:
for i in get_node("Buttons").get_children(): paint_window->paint_change_grid_size_dialog->popup_centered();
i.connect("item_pressed", self, "button_pressed") break;
*/ case MENU_MAGIC_CHANGE_SINGLE_COLOR:
} break;
void PaintNavbar::button_pressed(const String &button_name, Node *button_item, const int id) { case MENU_MAGIC_CHANGE_COLOR_RANGE:
/* break;
# print("pressed: ", button_name) case MENU_MAGIC_HSV_NOISE:
# print("pressed item is: '%s'" % button_item) break;
case MENU_MAGIC_HSV_COLOR_MODULATION:
match button_name: break;
"File": case MENU_EDITOR_SETTINGS:
handle_file_menu(button_item, id) paint_window->paint_settings_dialog->popup_centered();
"Edit": break;
handle_edit_menu(button_item, id) default:
"Canvas": break;
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)
*/
} }
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() { bool PaintNavbar::is_any_menu_open() {
/* if (file_menu_button->get_popup()->is_visible() || edit_menu_button->get_popup()->is_visible() ||
for child in $Buttons.get_children(): canvas_menu_button->get_popup()->is_visible() || layer_menu_button->get_popup()->is_visible() ||
if child.get_popup().visible: grid_menu_button->get_popup()->is_visible() || magic_menu_button->get_popup()->is_visible() ||
return true editor_menu_button->get_popup()->is_visible()) {
return false return true;
*/ }
return false; return false;
} }
PaintNavbar::PaintNavbar() { 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() { PaintNavbar::~PaintNavbar() {
} }
void PaintNavbar::_bind_methods() { void PaintNavbar::_bind_methods() {
ClassDB::bind_method(D_METHOD("handle_menu_item_pressed"), &PaintNavbar::handle_menu_item_pressed);
} }

View File

@ -25,35 +25,67 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include "scene/gui/control.h" #include "scene/gui/box_container.h"
class PaintNavbar : public Control { class PaintWindow;
GDCLASS(PaintNavbar, Control); class PaintCanvas;
class MenuButton;
class PaintNavbar : public BoxContainer {
GDCLASS(PaintNavbar, BoxContainer);
public: public:
void _ready(); enum {
void button_pressed(const String &button_name, Node *button_item, const int id); MENU_FILE_NEW = 0,
MENU_FILE_SAVE,
MENU_FILE_LOAD,
void handle_file_menu(const String &pressed_item, const int id); MENU_EDIT_UNDO,
void handle_edit_menu(const String &pressed_item, const int id); MENU_EDIT_REDO,
void handle_canvas_menu(const String &pressed_item, const int id); MENU_EDIT_CUT,
void handle_layer_menu(const String &pressed_item, const int id); MENU_EDIT_COPY,
void handle_grid_menu(const String &pressed_item, const int id); 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(); bool is_any_menu_open();
PaintNavbar(); PaintNavbar();
~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: protected:
static void _bind_methods(); static void _bind_methods();
/*
var editor
var paint_canvas
*/
}; };
#endif #endif

View File

@ -25,10 +25,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include "scene/gui/control.h" #include "scene/gui/dialogs.h"
class PaintSettings : public Control { class PaintSettings : public WindowDialog {
GDCLASS(PaintSettings, Control); GDCLASS(PaintSettings, WindowDialog);
public: public:
void _enter_tree(); void _enter_tree();

View File

@ -28,11 +28,13 @@ SOFTWARE.
#include "paint_canvas.h" #include "paint_canvas.h"
#include "paint_canvas_layer.h" #include "paint_canvas_layer.h"
#include "paint_color_grid.h" #include "paint_color_grid.h"
#include "paint_navbar.h"
#include "paint_layer_button.h" #include "paint_layer_button.h"
#include "paint_navbar.h"
#include "scene/resources/style_box.h" #include "scene/resources/style_box.h"
#include "scene/gui/button.h"
#include "scene/gui/check_button.h" #include "scene/gui/check_button.h"
#include "scene/gui/color_picker.h"
#include "scene/gui/label.h" #include "scene/gui/label.h"
#include "scene/gui/margin_container.h" #include "scene/gui/margin_container.h"
#include "scene/gui/panel_container.h" #include "scene/gui/panel_container.h"
@ -40,8 +42,6 @@ SOFTWARE.
#include "scene/gui/scroll_container.h" #include "scene/gui/scroll_container.h"
#include "scene/gui/slider.h" #include "scene/gui/slider.h"
#include "scene/gui/texture_button.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_canvas_dialog.h"
#include "dialogs/paint_change_grid_size_dialog.h" #include "dialogs/paint_change_grid_size_dialog.h"
@ -930,6 +930,7 @@ PaintWindow::PaintWindow() {
//Main Content Top (Navbar) //Main Content Top (Navbar)
navbar = memnew(PaintNavbar); navbar = memnew(PaintNavbar);
navbar->paint_window = this;
navbar->set_h_size_flags(SIZE_EXPAND_FILL); navbar->set_h_size_flags(SIZE_EXPAND_FILL);
main_content_container->add_child(navbar); main_content_container->add_child(navbar);
@ -1056,6 +1057,7 @@ PaintWindow::PaintWindow() {
paint_canvas->set_size(Size2(256, 256)); paint_canvas->set_size(Size2(256, 256));
paint_canvas->set_anchors_and_margins_preset(Control::PRESET_CENTER); paint_canvas->set_anchors_and_margins_preset(Control::PRESET_CENTER);
paint_canvas_container->add_child(paint_canvas); paint_canvas_container->add_child(paint_canvas);
navbar->canvas = paint_canvas;
//Main Content Mid (App) -- Right Panel //Main Content Mid (App) -- Right Panel
PanelContainer *mid_right_panel_container = memnew(PanelContainer); PanelContainer *mid_right_panel_container = memnew(PanelContainer);

View File

@ -30,7 +30,7 @@ void register_paint_types() {
//ClassDB::register_class<MeshDataResource>(); //ClassDB::register_class<MeshDataResource>();
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
//EditorPlugins::add_by_type<PaintEditorPlugin>(); EditorPlugins::add_by_type<PaintEditorPlugin>();
#endif #endif
} }