Skip to content

Commit 2920882

Browse files
committed
Add a scene painter tool
1 parent c2202d3 commit 2920882

File tree

6 files changed

+843
-2
lines changed

6 files changed

+843
-2
lines changed

editor/docks/filesystem_dock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ class FileSystemDock : public VBoxContainer {
421421
FileListDisplayMode get_file_list_display_mode() const { return file_list_display_mode; }
422422

423423
Tree *get_tree_control() { return tree; }
424+
ItemList *get_list_control() { return files; }
424425

425426
void add_resource_tooltip_plugin(const Ref<EditorResourceTooltipPlugin> &p_plugin);
426427
void remove_resource_tooltip_plugin(const Ref<EditorResourceTooltipPlugin> &p_plugin);

editor/register_editor_types.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
#include "editor/scene/material_editor_plugin.h"
112112
#include "editor/scene/packed_scene_editor_plugin.h"
113113
#include "editor/scene/resource_preloader_editor_plugin.h"
114+
#include "editor/scene/scene_paint_editor_plugin.h"
114115
#include "editor/scene/sprite_frames_editor_plugin.h"
115116
#include "editor/scene/texture/bit_map_editor_plugin.h"
116117
#include "editor/scene/texture/gradient_texture_2d_editor_plugin.h"
@@ -273,6 +274,7 @@ void register_editor_types() {
273274
EditorPlugins::add_by_type<Sprite2DEditorPlugin>();
274275
EditorPlugins::add_by_type<TileSetEditorPlugin>();
275276
EditorPlugins::add_by_type<TileMapEditorPlugin>();
277+
EditorPlugins::add_by_type<ScenePaintEditorPlugin>();
276278
#ifndef DISABLE_DEPRECATED
277279
EditorPlugins::add_by_type<ParallaxBackgroundEditorPlugin>();
278280
#endif

editor/scene/canvas_item_editor_plugin.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,7 +2476,7 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) {
24762476
}
24772477
}
24782478

2479-
if (b.is_valid() && b->is_pressed() && b->get_button_index() == MouseButton::RIGHT) {
2479+
if (b.is_valid() && b->is_pressed() && b->get_button_index() == MouseButton::RIGHT && tool != TOOL_SCENE_PAINT) {
24802480
add_node_menu->clear();
24812481
add_node_menu->add_icon_item(get_editor_theme_icon(SNAME("Add")), TTRC("Add Node Here..."), ADD_NODE);
24822482
add_node_menu->add_icon_item(get_editor_theme_icon(SNAME("Instance")), TTRC("Instantiate Scene Here..."), ADD_INSTANCE);
@@ -4095,6 +4095,10 @@ void CanvasItemEditor::_draw_viewport() {
40954095
_draw_message();
40964096
}
40974097

4098+
void CanvasItemEditor::get_canvas_items_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items, bool p_allow_locked) {
4099+
_get_canvas_items_at_pos(p_pos, r_items, p_allow_locked);
4100+
}
4101+
40984102
void CanvasItemEditor::update_viewport() {
40994103
_update_scrollbars();
41004104
viewport->queue_redraw();
@@ -4107,6 +4111,7 @@ void CanvasItemEditor::set_current_tool(Tool p_tool) {
41074111
void CanvasItemEditor::_update_editor_settings() {
41084112
button_center_view->set_button_icon(get_editor_theme_icon(SNAME("CenterView")));
41094113
select_button->set_button_icon(get_editor_theme_icon(SNAME("ToolSelect")));
4114+
scene_paint_button->set_button_icon(get_editor_theme_icon(SNAME("Paint")));
41104115
select_sb->set_texture(get_editor_theme_icon(SNAME("EditorRect2D")));
41114116
list_select_button->set_button_icon(get_editor_theme_icon(SNAME("ListSelect")));
41124117
move_button->set_button_icon(get_editor_theme_icon(SNAME("ToolMove")));
@@ -4432,7 +4437,7 @@ void CanvasItemEditor::_button_toggle_grid_snap(bool p_status) {
44324437
}
44334438

44344439
void CanvasItemEditor::_button_tool_select(int p_index) {
4435-
Button *tb[TOOL_MAX] = { select_button, list_select_button, move_button, scale_button, rotate_button, pivot_button, pan_button, ruler_button };
4440+
Button *tb[TOOL_MAX] = { select_button, scene_paint_button, list_select_button, move_button, scale_button, rotate_button, pivot_button, pan_button, ruler_button };
44364441
for (int i = 0; i < TOOL_MAX; i++) {
44374442
tb[i]->set_pressed(i == p_index);
44384443
}
@@ -4453,6 +4458,7 @@ void CanvasItemEditor::_button_tool_select(int p_index) {
44534458

44544459
viewport->queue_redraw();
44554460
_update_cursor();
4461+
emit_signal("canvas_item_tool_changed", tool);
44564462
}
44574463

44584464
void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation, bool p_scale, bool p_on_existing) {
@@ -4989,6 +4995,7 @@ void CanvasItemEditor::_bind_methods() {
49894995

49904996
ADD_SIGNAL(MethodInfo("item_lock_status_changed"));
49914997
ADD_SIGNAL(MethodInfo("item_group_status_changed"));
4998+
ADD_SIGNAL(MethodInfo("canvas_item_tool_changed", PropertyInfo(Variant::INT, "tool")));
49924999
}
49935000

49945001
Dictionary CanvasItemEditor::get_state() const {
@@ -5463,6 +5470,15 @@ CanvasItemEditor::CanvasItemEditor() {
54635470
select_button->set_shortcut_context(this);
54645471
select_button->set_accessibility_name(TTRC("Select Mode"));
54655472

5473+
scene_paint_button = memnew(Button);
5474+
scene_paint_button->set_theme_type_variation(SceneStringName(FlatButton));
5475+
main_menu_hbox->add_child(scene_paint_button);
5476+
scene_paint_button->set_toggle_mode(true);
5477+
scene_paint_button->connect(SceneStringName(pressed), callable_mp(this, &CanvasItemEditor::_button_tool_select).bind(TOOL_SCENE_PAINT));
5478+
scene_paint_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/scene_paint_mode", TTRC("Scene Paint Mode"), Key::B, true));
5479+
scene_paint_button->set_shortcut_context(this);
5480+
scene_paint_button->set_accessibility_name(TTRC("Scene Paint Mode"));
5481+
54665482
main_menu_hbox->add_child(memnew(VSeparator));
54675483

54685484
move_button = memnew(Button);

editor/scene/canvas_item_editor_plugin.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class CanvasItemEditor : public VBoxContainer {
7575
public:
7676
enum Tool {
7777
TOOL_SELECT,
78+
TOOL_SCENE_PAINT,
7879
TOOL_LIST_SELECT,
7980
TOOL_MOVE,
8081
TOOL_SCALE,
@@ -262,6 +263,7 @@ class CanvasItemEditor : public VBoxContainer {
262263

263264
MenuOption last_option;
264265

266+
public:
265267
struct _SelectResult {
266268
CanvasItem *item = nullptr;
267269
real_t z_index = 0;
@@ -270,6 +272,8 @@ class CanvasItemEditor : public VBoxContainer {
270272
return has_z && p_rr.has_z ? p_rr.z_index < z_index : p_rr.has_z;
271273
}
272274
};
275+
276+
private:
273277
Vector<_SelectResult> selection_results;
274278
Vector<_SelectResult> selection_results_menu;
275279

@@ -314,6 +318,7 @@ class CanvasItemEditor : public VBoxContainer {
314318
Button *select_button = nullptr;
315319

316320
Button *move_button = nullptr;
321+
Button *scene_paint_button = nullptr;
317322
Button *scale_button = nullptr;
318323
Button *rotate_button = nullptr;
319324

@@ -575,6 +580,8 @@ class CanvasItemEditor : public VBoxContainer {
575580

576581
Control *get_controls_container() { return controls_vb; }
577582

583+
void get_canvas_items_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items, bool p_allow_locked = false);
584+
578585
void update_viewport();
579586

580587
Tool get_current_tool() { return tool; }

0 commit comments

Comments
 (0)