Add a theme preview switcher to the 2D viewport
This commit adds a new View submenu that allows switching between the project theme (default), the editor theme, and the default theme. The last selected option is stored per project and is restored when reloading the project.
This commit is contained in:
parent
512182f147
commit
fc01e2e7f6
4 changed files with 85 additions and 5 deletions
|
|
@ -1034,6 +1034,22 @@ void CanvasItemEditor::_on_grid_menu_id_pressed(int p_id) {
|
|||
viewport->queue_redraw();
|
||||
}
|
||||
|
||||
void CanvasItemEditor::_switch_theme_preview(int p_mode) {
|
||||
view_menu->get_popup()->hide();
|
||||
|
||||
if (theme_preview == p_mode) {
|
||||
return;
|
||||
}
|
||||
theme_preview = (ThemePreviewMode)p_mode;
|
||||
EditorSettings::get_singleton()->set_project_metadata("2d_editor", "theme_preview", theme_preview);
|
||||
|
||||
for (int i = 0; i < THEME_PREVIEW_MAX; i++) {
|
||||
theme_menu->set_item_checked(i, i == theme_preview);
|
||||
}
|
||||
|
||||
EditorNode::get_singleton()->update_preview_themes(theme_preview);
|
||||
}
|
||||
|
||||
bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_event) {
|
||||
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
||||
Ref<InputEventMouseButton> b = p_event;
|
||||
|
|
@ -5322,6 +5338,20 @@ CanvasItemEditor::CanvasItemEditor() {
|
|||
p->add_separator();
|
||||
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/preview_canvas_scale", TTR("Preview Canvas Scale")), PREVIEW_CANVAS_SCALE);
|
||||
|
||||
theme_menu = memnew(PopupMenu);
|
||||
theme_menu->connect("id_pressed", callable_mp(this, &CanvasItemEditor::_switch_theme_preview));
|
||||
theme_menu->set_name("ThemeMenu");
|
||||
theme_menu->add_radio_check_item(TTR("Project theme"), THEME_PREVIEW_PROJECT);
|
||||
theme_menu->add_radio_check_item(TTR("Editor theme"), THEME_PREVIEW_EDITOR);
|
||||
theme_menu->add_radio_check_item(TTR("Default theme"), THEME_PREVIEW_DEFAULT);
|
||||
p->add_child(theme_menu);
|
||||
p->add_submenu_item(TTR("Preview Theme"), "ThemeMenu");
|
||||
|
||||
theme_preview = (ThemePreviewMode)(int)EditorSettings::get_singleton()->get_project_metadata("2d_editor", "theme_preview", THEME_PREVIEW_PROJECT);
|
||||
for (int i = 0; i < THEME_PREVIEW_MAX; i++) {
|
||||
theme_menu->set_item_checked(i, i == theme_preview);
|
||||
}
|
||||
|
||||
main_menu_hbox->add_child(memnew(VSeparator));
|
||||
|
||||
// Contextual toolbars.
|
||||
|
|
|
|||
|
|
@ -325,6 +325,7 @@ private:
|
|||
Button *override_camera_button = nullptr;
|
||||
MenuButton *view_menu = nullptr;
|
||||
PopupMenu *grid_menu = nullptr;
|
||||
PopupMenu *theme_menu = nullptr;
|
||||
HBoxContainer *animation_hb = nullptr;
|
||||
MenuButton *animation_menu = nullptr;
|
||||
|
||||
|
|
@ -404,6 +405,19 @@ private:
|
|||
void _prepare_grid_menu();
|
||||
void _on_grid_menu_id_pressed(int p_id);
|
||||
|
||||
public:
|
||||
enum ThemePreviewMode {
|
||||
THEME_PREVIEW_PROJECT,
|
||||
THEME_PREVIEW_EDITOR,
|
||||
THEME_PREVIEW_DEFAULT,
|
||||
|
||||
THEME_PREVIEW_MAX // The number of options for enumerating.
|
||||
};
|
||||
|
||||
private:
|
||||
ThemePreviewMode theme_preview = THEME_PREVIEW_PROJECT;
|
||||
void _switch_theme_preview(int p_mode);
|
||||
|
||||
List<CanvasItem *> _get_edited_canvas_items(bool retrieve_locked = false, bool remove_canvas_item_if_parent_in_selection = true) const;
|
||||
Rect2 _get_encompassing_rect_from_list(List<CanvasItem *> p_list);
|
||||
void _expand_encompassing_rect_using_children(Rect2 &r_rect, const Node *p_node, bool &r_first, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D(), bool include_locked_nodes = true);
|
||||
|
|
@ -558,6 +572,8 @@ public:
|
|||
|
||||
virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override;
|
||||
|
||||
ThemePreviewMode get_theme_preview() const { return theme_preview; }
|
||||
|
||||
EditorSelection *editor_selection = nullptr;
|
||||
|
||||
CanvasItemEditor();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue