You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
General enhancements to the Polygon2D, TextureRegion, and TileSet editors
This commit is contained in:
@@ -169,15 +169,24 @@ void TextureRegionEditor::_region_draw() {
|
||||
updating_scroll = true;
|
||||
hscroll->set_min(scroll_rect.position.x);
|
||||
hscroll->set_max(scroll_rect.position.x + scroll_rect.size.x);
|
||||
hscroll->set_page(edit_draw->get_size().x);
|
||||
hscroll->set_value(draw_ofs.x);
|
||||
hscroll->set_step(0.001);
|
||||
if (ABS(scroll_rect.position.x - (scroll_rect.position.x + scroll_rect.size.x)) <= edit_draw->get_size().x) {
|
||||
hscroll->hide();
|
||||
} else {
|
||||
hscroll->show();
|
||||
hscroll->set_page(edit_draw->get_size().x);
|
||||
hscroll->set_value(draw_ofs.x);
|
||||
}
|
||||
|
||||
vscroll->set_min(scroll_rect.position.y);
|
||||
vscroll->set_max(scroll_rect.position.y + scroll_rect.size.y);
|
||||
vscroll->set_page(edit_draw->get_size().y);
|
||||
vscroll->set_value(draw_ofs.y);
|
||||
vscroll->set_step(0.001);
|
||||
if (ABS(scroll_rect.position.y - (scroll_rect.position.y + scroll_rect.size.y)) <= edit_draw->get_size().y) {
|
||||
vscroll->hide();
|
||||
draw_ofs.y = scroll_rect.position.y;
|
||||
} else {
|
||||
vscroll->show();
|
||||
vscroll->set_page(edit_draw->get_size().y);
|
||||
vscroll->set_value(draw_ofs.y);
|
||||
}
|
||||
updating_scroll = false;
|
||||
|
||||
float margins[4];
|
||||
@@ -299,6 +308,8 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
|
||||
undo_redo->add_do_method(atlas_tex.ptr(), "set_region", rect);
|
||||
undo_redo->add_undo_method(atlas_tex.ptr(), "set_region", atlas_tex->get_region());
|
||||
}
|
||||
undo_redo->add_do_method(this, "_update_rect");
|
||||
undo_redo->add_undo_method(this, "_update_rect");
|
||||
undo_redo->add_do_method(edit_draw, "update");
|
||||
undo_redo->add_undo_method(edit_draw, "update");
|
||||
undo_redo->commit_action();
|
||||
@@ -336,7 +347,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
|
||||
|
||||
} else if (drag) {
|
||||
if (edited_margin >= 0) {
|
||||
undo_redo->create_action("Set Margin");
|
||||
undo_redo->create_action(TTR("Set Margin"));
|
||||
static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT };
|
||||
if (node_ninepatch) {
|
||||
undo_redo->add_do_method(node_ninepatch, "set_patch_margin", m[edited_margin], node_ninepatch->get_patch_margin(m[edited_margin]));
|
||||
@@ -348,7 +359,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
|
||||
}
|
||||
edited_margin = -1;
|
||||
} else {
|
||||
undo_redo->create_action("Set Region Rect");
|
||||
undo_redo->create_action(TTR("Set Region Rect"));
|
||||
if (node_sprite) {
|
||||
undo_redo->add_do_method(node_sprite, "set_region_rect", node_sprite->get_region_rect());
|
||||
undo_redo->add_undo_method(node_sprite, "set_region_rect", rect_prev);
|
||||
@@ -364,6 +375,8 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
|
||||
}
|
||||
drag_index = -1;
|
||||
}
|
||||
undo_redo->add_do_method(this, "_update_rect");
|
||||
undo_redo->add_undo_method(this, "_update_rect");
|
||||
undo_redo->add_do_method(edit_draw, "update");
|
||||
undo_redo->add_undo_method(edit_draw, "update");
|
||||
undo_redo->commit_action();
|
||||
@@ -509,10 +522,7 @@ void TextureRegionEditor::_scroll_changed(float) {
|
||||
}
|
||||
|
||||
void TextureRegionEditor::_set_snap_mode(int p_mode) {
|
||||
snap_mode_button->get_popup()->set_item_checked(snap_mode, false);
|
||||
snap_mode = p_mode;
|
||||
snap_mode_button->set_text(snap_mode_button->get_popup()->get_item_text(p_mode));
|
||||
snap_mode_button->get_popup()->set_item_checked(snap_mode, true);
|
||||
|
||||
if (snap_mode == SNAP_GRID)
|
||||
hb_grid->show();
|
||||
@@ -577,15 +587,26 @@ void TextureRegionEditor::_zoom_out() {
|
||||
}
|
||||
}
|
||||
|
||||
void TextureRegionEditor::apply_rect(const Rect2 &rect) {
|
||||
void TextureRegionEditor::apply_rect(const Rect2 &p_rect) {
|
||||
if (node_sprite)
|
||||
node_sprite->set_region_rect(rect);
|
||||
node_sprite->set_region_rect(p_rect);
|
||||
else if (node_ninepatch)
|
||||
node_ninepatch->set_region_rect(rect);
|
||||
node_ninepatch->set_region_rect(p_rect);
|
||||
else if (obj_styleBox.is_valid())
|
||||
obj_styleBox->set_region_rect(rect);
|
||||
obj_styleBox->set_region_rect(p_rect);
|
||||
else if (atlas_tex.is_valid())
|
||||
atlas_tex->set_region(rect);
|
||||
atlas_tex->set_region(p_rect);
|
||||
}
|
||||
|
||||
void TextureRegionEditor::_update_rect() {
|
||||
if (node_sprite)
|
||||
rect = node_sprite->get_region_rect();
|
||||
else if (node_ninepatch)
|
||||
rect = node_ninepatch->get_region_rect();
|
||||
else if (obj_styleBox.is_valid())
|
||||
rect = obj_styleBox->get_region_rect();
|
||||
else if (atlas_tex.is_valid())
|
||||
rect = atlas_tex->get_region();
|
||||
}
|
||||
|
||||
void TextureRegionEditor::_update_autoslice() {
|
||||
@@ -657,6 +678,10 @@ void TextureRegionEditor::_update_autoslice() {
|
||||
|
||||
void TextureRegionEditor::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ENTER_TREE:
|
||||
case NOTIFICATION_THEME_CHANGED: {
|
||||
edit_draw->add_style_override("panel", get_stylebox("bg", "Tree"));
|
||||
} break;
|
||||
case NOTIFICATION_READY: {
|
||||
zoom_out->set_icon(get_icon("ZoomLess", "EditorIcons"));
|
||||
zoom_reset->set_icon(get_icon("ZoomReset", "EditorIcons"));
|
||||
@@ -669,7 +694,7 @@ void TextureRegionEditor::_notification(int p_what) {
|
||||
} break;
|
||||
case MainLoop::NOTIFICATION_WM_FOCUS_IN: {
|
||||
// This happens when the user leaves the Editor and returns,
|
||||
// he/she could have changed the textures, so the cache is cleared
|
||||
// they could have changed the textures, so the cache is cleared.
|
||||
cache_map.clear();
|
||||
_edit_region();
|
||||
} break;
|
||||
@@ -702,6 +727,7 @@ void TextureRegionEditor::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("_zoom_in"), &TextureRegionEditor::_zoom_in);
|
||||
ClassDB::bind_method(D_METHOD("_zoom_reset"), &TextureRegionEditor::_zoom_reset);
|
||||
ClassDB::bind_method(D_METHOD("_zoom_out"), &TextureRegionEditor::_zoom_out);
|
||||
ClassDB::bind_method(D_METHOD("_update_rect"), &TextureRegionEditor::_update_rect);
|
||||
}
|
||||
|
||||
bool TextureRegionEditor::is_stylebox() {
|
||||
@@ -774,6 +800,9 @@ void TextureRegionEditor::_edit_region() {
|
||||
texture = atlas_tex->get_atlas();
|
||||
|
||||
if (texture.is_null()) {
|
||||
_zoom_reset();
|
||||
hscroll->hide();
|
||||
vscroll->hide();
|
||||
edit_draw->update();
|
||||
return;
|
||||
}
|
||||
@@ -790,15 +819,7 @@ void TextureRegionEditor::_edit_region() {
|
||||
}
|
||||
}
|
||||
|
||||
if (node_sprite)
|
||||
rect = node_sprite->get_region_rect();
|
||||
else if (node_ninepatch)
|
||||
rect = node_ninepatch->get_region_rect();
|
||||
else if (obj_styleBox.is_valid())
|
||||
rect = obj_styleBox->get_region_rect();
|
||||
else if (atlas_tex.is_valid())
|
||||
rect = atlas_tex->get_region();
|
||||
|
||||
_update_rect();
|
||||
edit_draw->update();
|
||||
}
|
||||
|
||||
@@ -826,30 +847,23 @@ TextureRegionEditor::TextureRegionEditor(EditorNode *p_editor) {
|
||||
drag_index = -1;
|
||||
drag = false;
|
||||
|
||||
VBoxContainer *main_vb = memnew(VBoxContainer);
|
||||
add_child(main_vb);
|
||||
main_vb->set_anchors_and_margins_preset(Control::PRESET_WIDE);
|
||||
HBoxContainer *hb_tools = memnew(HBoxContainer);
|
||||
main_vb->add_child(hb_tools);
|
||||
|
||||
add_child(hb_tools);
|
||||
hb_tools->add_child(memnew(Label(TTR("Snap Mode:"))));
|
||||
|
||||
snap_mode_button = memnew(MenuButton);
|
||||
snap_mode_button = memnew(OptionButton);
|
||||
hb_tools->add_child(snap_mode_button);
|
||||
snap_mode_button->set_text(TTR("<None>"));
|
||||
PopupMenu *p = snap_mode_button->get_popup();
|
||||
p->set_hide_on_checkable_item_selection(false);
|
||||
p->add_radio_check_item(TTR("<None>"), 0);
|
||||
p->add_radio_check_item(TTR("Pixel Snap"), 1);
|
||||
p->add_radio_check_item(TTR("Grid Snap"), 2);
|
||||
p->add_radio_check_item(TTR("Auto Slice"), 3);
|
||||
p->set_item_checked(0, true);
|
||||
p->connect("id_pressed", this, "_set_snap_mode");
|
||||
hb_grid = memnew(HBoxContainer);
|
||||
//hb_tools->add_child(hb_grid);
|
||||
main_vb->add_child(hb_grid);
|
||||
hb_grid->add_child(memnew(VSeparator));
|
||||
snap_mode_button->add_item(TTR("None"), 0);
|
||||
snap_mode_button->add_item(TTR("Pixel Snap"), 1);
|
||||
snap_mode_button->add_item(TTR("Grid Snap"), 2);
|
||||
snap_mode_button->add_item(TTR("Auto Slice"), 3);
|
||||
snap_mode_button->select(0);
|
||||
snap_mode_button->connect("item_selected", this, "_set_snap_mode");
|
||||
|
||||
hb_grid = memnew(HBoxContainer);
|
||||
hb_tools->add_child(hb_grid);
|
||||
|
||||
hb_grid->add_child(memnew(VSeparator));
|
||||
hb_grid->add_child(memnew(Label(TTR("Offset:"))));
|
||||
|
||||
sb_off_x = memnew(SpinBox);
|
||||
@@ -914,42 +928,47 @@ TextureRegionEditor::TextureRegionEditor(EditorNode *p_editor) {
|
||||
|
||||
hb_grid->hide();
|
||||
|
||||
HBoxContainer *main_hb = memnew(HBoxContainer);
|
||||
main_vb->add_child(main_hb);
|
||||
edit_draw = memnew(Control);
|
||||
main_hb->add_child(edit_draw);
|
||||
main_hb->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
edit_draw->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
|
||||
Control *separator = memnew(Control);
|
||||
separator->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
||||
hb_tools->add_child(separator);
|
||||
|
||||
zoom_out = memnew(ToolButton);
|
||||
zoom_out->connect("pressed", this, "_zoom_out");
|
||||
hb_tools->add_child(zoom_out);
|
||||
|
||||
zoom_reset = memnew(ToolButton);
|
||||
zoom_reset->connect("pressed", this, "_zoom_reset");
|
||||
hb_tools->add_child(zoom_reset);
|
||||
|
||||
zoom_in = memnew(ToolButton);
|
||||
zoom_in->connect("pressed", this, "_zoom_in");
|
||||
hb_tools->add_child(zoom_in);
|
||||
|
||||
vscroll = memnew(VScrollBar);
|
||||
main_hb->add_child(vscroll);
|
||||
vscroll->connect("value_changed", this, "_scroll_changed");
|
||||
hscroll = memnew(HScrollBar);
|
||||
main_vb->add_child(hscroll);
|
||||
hscroll->connect("value_changed", this, "_scroll_changed");
|
||||
|
||||
edit_draw = memnew(Panel);
|
||||
add_child(edit_draw);
|
||||
edit_draw->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
edit_draw->connect("draw", this, "_region_draw");
|
||||
edit_draw->connect("gui_input", this, "_region_input");
|
||||
draw_zoom = 1.0;
|
||||
updating_scroll = false;
|
||||
|
||||
draw_zoom = 1.0;
|
||||
edit_draw->set_clip_contents(true);
|
||||
|
||||
HBoxContainer *zoom_hb = memnew(HBoxContainer);
|
||||
edit_draw->add_child(zoom_hb);
|
||||
zoom_hb->set_begin(Point2(5, 5));
|
||||
|
||||
zoom_out = memnew(ToolButton);
|
||||
zoom_out->set_tooltip(TTR("Zoom Out"));
|
||||
zoom_out->connect("pressed", this, "_zoom_out");
|
||||
zoom_hb->add_child(zoom_out);
|
||||
|
||||
zoom_reset = memnew(ToolButton);
|
||||
zoom_out->set_tooltip(TTR("Zoom Reset"));
|
||||
zoom_reset->connect("pressed", this, "_zoom_reset");
|
||||
zoom_hb->add_child(zoom_reset);
|
||||
|
||||
zoom_in = memnew(ToolButton);
|
||||
zoom_out->set_tooltip(TTR("Zoom In"));
|
||||
zoom_in->connect("pressed", this, "_zoom_in");
|
||||
zoom_hb->add_child(zoom_in);
|
||||
|
||||
vscroll = memnew(VScrollBar);
|
||||
vscroll->set_step(0.001);
|
||||
edit_draw->add_child(vscroll);
|
||||
vscroll->set_anchors_and_margins_preset(PRESET_RIGHT_WIDE);
|
||||
vscroll->connect("value_changed", this, "_scroll_changed");
|
||||
hscroll = memnew(HScrollBar);
|
||||
hscroll->set_step(0.001);
|
||||
edit_draw->add_child(hscroll);
|
||||
hscroll->set_anchors_and_margins_preset(PRESET_BOTTOM_WIDE);
|
||||
hscroll->set_margin(MARGIN_RIGHT, -vscroll->get_size().x * EDSCALE);
|
||||
hscroll->connect("value_changed", this, "_scroll_changed");
|
||||
|
||||
updating_scroll = false;
|
||||
}
|
||||
|
||||
void TextureRegionEditorPlugin::edit(Object *p_object) {
|
||||
@@ -978,7 +997,6 @@ void TextureRegionEditorPlugin::make_visible(bool p_visible) {
|
||||
Dictionary TextureRegionEditorPlugin::get_state() const {
|
||||
|
||||
Dictionary state;
|
||||
state["zoom"] = region_editor->draw_zoom;
|
||||
state["snap_offset"] = region_editor->snap_offset;
|
||||
state["snap_step"] = region_editor->snap_step;
|
||||
state["snap_separation"] = region_editor->snap_separation;
|
||||
@@ -989,10 +1007,6 @@ Dictionary TextureRegionEditorPlugin::get_state() const {
|
||||
void TextureRegionEditorPlugin::set_state(const Dictionary &p_state) {
|
||||
|
||||
Dictionary state = p_state;
|
||||
if (state.has("zoom")) {
|
||||
region_editor->draw_zoom = p_state["zoom"];
|
||||
}
|
||||
|
||||
if (state.has("snap_step")) {
|
||||
Vector2 s = state["snap_step"];
|
||||
region_editor->sb_step_x->set_value(s.x);
|
||||
@@ -1016,6 +1030,7 @@ void TextureRegionEditorPlugin::set_state(const Dictionary &p_state) {
|
||||
|
||||
if (state.has("snap_mode")) {
|
||||
region_editor->_set_snap_mode(state["snap_mode"]);
|
||||
region_editor->snap_mode_button->select(state["snap_mode"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user