Merge pull request #12372 from ISylvox/patch9rect-to-ninepatchrect

Finish Transition of Patch9Rect to NinePatchRect

[ci skip]
This commit is contained in:
Rémi Verschelde 2017-10-24 09:10:00 +02:00 committed by GitHub
commit fffaec9da9
6 changed files with 55 additions and 55 deletions

View File

@ -45,7 +45,7 @@
#include "scene/2d/screen_button.h" #include "scene/2d/screen_button.h"
#include "scene/2d/sprite.h" #include "scene/2d/sprite.h"
#include "scene/gui/grid_container.h" #include "scene/gui/grid_container.h"
#include "scene/gui/patch_9_rect.h" #include "scene/gui/nine_patch_rect.h"
#include "scene/main/canvas_layer.h" #include "scene/main/canvas_layer.h"
#include "scene/main/viewport.h" #include "scene/main/viewport.h"
#include "scene/resources/packed_scene.h" #include "scene/resources/packed_scene.h"

View File

@ -48,8 +48,8 @@ void TextureRegionEditor::_region_draw() {
Ref<Texture> base_tex = NULL; Ref<Texture> base_tex = NULL;
if (node_sprite) if (node_sprite)
base_tex = node_sprite->get_texture(); base_tex = node_sprite->get_texture();
else if (node_patch9) else if (node_ninepatch)
base_tex = node_patch9->get_texture(); base_tex = node_ninepatch->get_texture();
else if (obj_styleBox.is_valid()) else if (obj_styleBox.is_valid())
base_tex = obj_styleBox->get_texture(); base_tex = obj_styleBox->get_texture();
else if (atlas_tex.is_valid()) else if (atlas_tex.is_valid())
@ -177,12 +177,12 @@ void TextureRegionEditor::_region_draw() {
updating_scroll = false; updating_scroll = false;
float margins[4]; float margins[4];
if (node_patch9 || obj_styleBox.is_valid()) { if (node_ninepatch || obj_styleBox.is_valid()) {
if (node_patch9) { if (node_ninepatch) {
margins[0] = node_patch9->get_patch_margin(MARGIN_TOP); margins[0] = node_ninepatch->get_patch_margin(MARGIN_TOP);
margins[1] = node_patch9->get_patch_margin(MARGIN_BOTTOM); margins[1] = node_ninepatch->get_patch_margin(MARGIN_BOTTOM);
margins[2] = node_patch9->get_patch_margin(MARGIN_LEFT); margins[2] = node_ninepatch->get_patch_margin(MARGIN_LEFT);
margins[3] = node_patch9->get_patch_margin(MARGIN_RIGHT); margins[3] = node_ninepatch->get_patch_margin(MARGIN_RIGHT);
} else if (obj_styleBox.is_valid()) { } else if (obj_styleBox.is_valid()) {
margins[0] = obj_styleBox->get_margin_size(MARGIN_TOP); margins[0] = obj_styleBox->get_margin_size(MARGIN_TOP);
margins[1] = obj_styleBox->get_margin_size(MARGIN_BOTTOM); margins[1] = obj_styleBox->get_margin_size(MARGIN_BOTTOM);
@ -225,14 +225,14 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
if (mb->get_button_index() == BUTTON_LEFT) { if (mb->get_button_index() == BUTTON_LEFT) {
if (mb->is_pressed()) { if (mb->is_pressed()) {
if (node_patch9 || obj_styleBox.is_valid()) { if (node_ninepatch || obj_styleBox.is_valid()) {
edited_margin = -1; edited_margin = -1;
float margins[4]; float margins[4];
if (node_patch9) { if (node_ninepatch) {
margins[0] = node_patch9->get_patch_margin(MARGIN_TOP); margins[0] = node_ninepatch->get_patch_margin(MARGIN_TOP);
margins[1] = node_patch9->get_patch_margin(MARGIN_BOTTOM); margins[1] = node_ninepatch->get_patch_margin(MARGIN_BOTTOM);
margins[2] = node_patch9->get_patch_margin(MARGIN_LEFT); margins[2] = node_ninepatch->get_patch_margin(MARGIN_LEFT);
margins[3] = node_patch9->get_patch_margin(MARGIN_RIGHT); margins[3] = node_ninepatch->get_patch_margin(MARGIN_RIGHT);
} else if (obj_styleBox.is_valid()) { } else if (obj_styleBox.is_valid()) {
margins[0] = obj_styleBox->get_margin_size(MARGIN_TOP); margins[0] = obj_styleBox->get_margin_size(MARGIN_TOP);
margins[1] = obj_styleBox->get_margin_size(MARGIN_BOTTOM); margins[1] = obj_styleBox->get_margin_size(MARGIN_BOTTOM);
@ -272,8 +272,8 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
Rect2 r; Rect2 r;
if (node_sprite) if (node_sprite)
r = node_sprite->get_region_rect(); r = node_sprite->get_region_rect();
else if (node_patch9) else if (node_ninepatch)
r = node_patch9->get_region_rect(); r = node_ninepatch->get_region_rect();
else if (obj_styleBox.is_valid()) else if (obj_styleBox.is_valid())
r = obj_styleBox->get_region_rect(); r = obj_styleBox->get_region_rect();
else if (atlas_tex.is_valid()) else if (atlas_tex.is_valid())
@ -285,9 +285,9 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
if (node_sprite) { if (node_sprite) {
undo_redo->add_do_method(node_sprite, "set_region_rect", rect); undo_redo->add_do_method(node_sprite, "set_region_rect", rect);
undo_redo->add_undo_method(node_sprite, "set_region_rect", node_sprite->get_region_rect()); undo_redo->add_undo_method(node_sprite, "set_region_rect", node_sprite->get_region_rect());
} else if (node_patch9) { } else if (node_ninepatch) {
undo_redo->add_do_method(node_patch9, "set_region_rect", rect); undo_redo->add_do_method(node_ninepatch, "set_region_rect", rect);
undo_redo->add_undo_method(node_patch9, "set_region_rect", node_patch9->get_region_rect()); undo_redo->add_undo_method(node_ninepatch, "set_region_rect", node_ninepatch->get_region_rect());
} else if (obj_styleBox.is_valid()) { } else if (obj_styleBox.is_valid()) {
undo_redo->add_do_method(obj_styleBox.ptr(), "set_region_rect", rect); undo_redo->add_do_method(obj_styleBox.ptr(), "set_region_rect", rect);
undo_redo->add_undo_method(obj_styleBox.ptr(), "set_region_rect", obj_styleBox->get_region_rect()); undo_redo->add_undo_method(obj_styleBox.ptr(), "set_region_rect", obj_styleBox->get_region_rect());
@ -310,8 +310,8 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
drag = true; drag = true;
if (node_sprite) if (node_sprite)
rect_prev = node_sprite->get_region_rect(); rect_prev = node_sprite->get_region_rect();
else if (node_patch9) else if (node_ninepatch)
rect_prev = node_patch9->get_region_rect(); rect_prev = node_ninepatch->get_region_rect();
else if (obj_styleBox.is_valid()) else if (obj_styleBox.is_valid())
rect_prev = obj_styleBox->get_region_rect(); rect_prev = obj_styleBox->get_region_rect();
else if (atlas_tex.is_valid()) else if (atlas_tex.is_valid())
@ -334,9 +334,9 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
if (edited_margin >= 0) { if (edited_margin >= 0) {
undo_redo->create_action("Set Margin"); undo_redo->create_action("Set Margin");
static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT }; static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT };
if (node_patch9) { if (node_ninepatch) {
undo_redo->add_do_method(node_patch9, "set_patch_margin", m[edited_margin], node_patch9->get_patch_margin(m[edited_margin])); undo_redo->add_do_method(node_ninepatch, "set_patch_margin", m[edited_margin], node_ninepatch->get_patch_margin(m[edited_margin]));
undo_redo->add_undo_method(node_patch9, "set_patch_margin", m[edited_margin], prev_margin); undo_redo->add_undo_method(node_ninepatch, "set_patch_margin", m[edited_margin], prev_margin);
} else if (obj_styleBox.is_valid()) { } else if (obj_styleBox.is_valid()) {
undo_redo->add_do_method(obj_styleBox.ptr(), "set_margin_size", m[edited_margin], obj_styleBox->get_margin_size(m[edited_margin])); undo_redo->add_do_method(obj_styleBox.ptr(), "set_margin_size", m[edited_margin], obj_styleBox->get_margin_size(m[edited_margin]));
undo_redo->add_undo_method(obj_styleBox.ptr(), "set_margin_size", m[edited_margin], prev_margin); undo_redo->add_undo_method(obj_styleBox.ptr(), "set_margin_size", m[edited_margin], prev_margin);
@ -351,11 +351,11 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
} else if (atlas_tex.is_valid()) { } else if (atlas_tex.is_valid()) {
undo_redo->add_do_method(atlas_tex.ptr(), "set_region", atlas_tex->get_region()); undo_redo->add_do_method(atlas_tex.ptr(), "set_region", atlas_tex->get_region());
undo_redo->add_undo_method(atlas_tex.ptr(), "set_region", rect_prev); undo_redo->add_undo_method(atlas_tex.ptr(), "set_region", rect_prev);
} else if (node_patch9) { } else if (node_ninepatch) {
// FIXME: Is this intentional? // FIXME: Is this intentional?
} else if (node_patch9) { } else if (node_ninepatch) {
undo_redo->add_do_method(node_patch9, "set_region_rect", node_patch9->get_region_rect()); undo_redo->add_do_method(node_ninepatch, "set_region_rect", node_ninepatch->get_region_rect());
undo_redo->add_undo_method(node_patch9, "set_region_rect", rect_prev); undo_redo->add_undo_method(node_ninepatch, "set_region_rect", rect_prev);
} else if (obj_styleBox.is_valid()) { } else if (obj_styleBox.is_valid()) {
undo_redo->add_do_method(obj_styleBox.ptr(), "set_region_rect", obj_styleBox->get_region_rect()); undo_redo->add_do_method(obj_styleBox.ptr(), "set_region_rect", obj_styleBox->get_region_rect());
undo_redo->add_undo_method(obj_styleBox.ptr(), "set_region_rect", rect_prev); undo_redo->add_undo_method(obj_styleBox.ptr(), "set_region_rect", rect_prev);
@ -375,8 +375,8 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
drag = false; drag = false;
if (edited_margin >= 0) { if (edited_margin >= 0) {
static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT }; static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT };
if (node_patch9) if (node_ninepatch)
node_patch9->set_patch_margin(m[edited_margin], prev_margin); node_ninepatch->set_patch_margin(m[edited_margin], prev_margin);
if (obj_styleBox.is_valid()) if (obj_styleBox.is_valid())
obj_styleBox->set_margin_size(m[edited_margin], prev_margin); obj_styleBox->set_margin_size(m[edited_margin], prev_margin);
edited_margin = -1; edited_margin = -1;
@ -422,8 +422,8 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
if (new_margin < 0) if (new_margin < 0)
new_margin = 0; new_margin = 0;
static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT }; static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT };
if (node_patch9) if (node_ninepatch)
node_patch9->set_patch_margin(m[edited_margin], new_margin); node_ninepatch->set_patch_margin(m[edited_margin], new_margin);
if (obj_styleBox.is_valid()) if (obj_styleBox.is_valid())
obj_styleBox->set_margin_size(m[edited_margin], new_margin); obj_styleBox->set_margin_size(m[edited_margin], new_margin);
} else { } else {
@ -573,8 +573,8 @@ void TextureRegionEditor::_zoom_out() {
void TextureRegionEditor::apply_rect(const Rect2 &rect) { void TextureRegionEditor::apply_rect(const Rect2 &rect) {
if (node_sprite) if (node_sprite)
node_sprite->set_region_rect(rect); node_sprite->set_region_rect(rect);
else if (node_patch9) else if (node_ninepatch)
node_patch9->set_region_rect(rect); node_ninepatch->set_region_rect(rect);
else if (obj_styleBox.is_valid()) else if (obj_styleBox.is_valid())
obj_styleBox->set_region_rect(rect); obj_styleBox->set_region_rect(rect);
else if (atlas_tex.is_valid()) else if (atlas_tex.is_valid())
@ -593,8 +593,8 @@ void TextureRegionEditor::_notification(int p_what) {
} }
void TextureRegionEditor::_node_removed(Object *p_obj) { void TextureRegionEditor::_node_removed(Object *p_obj) {
if (p_obj == node_sprite || p_obj == node_patch9 || p_obj == obj_styleBox.ptr() || p_obj == atlas_tex.ptr()) { if (p_obj == node_sprite || p_obj == node_ninepatch || p_obj == obj_styleBox.ptr() || p_obj == atlas_tex.ptr()) {
node_patch9 = NULL; node_ninepatch = NULL;
node_sprite = NULL; node_sprite = NULL;
obj_styleBox = Ref<StyleBox>(NULL); obj_styleBox = Ref<StyleBox>(NULL);
atlas_tex = Ref<AtlasTexture>(NULL); atlas_tex = Ref<AtlasTexture>(NULL);
@ -623,15 +623,15 @@ void TextureRegionEditor::_bind_methods() {
void TextureRegionEditor::edit(Object *p_obj) { void TextureRegionEditor::edit(Object *p_obj) {
if (node_sprite) if (node_sprite)
node_sprite->remove_change_receptor(this); node_sprite->remove_change_receptor(this);
if (node_patch9) if (node_ninepatch)
node_patch9->remove_change_receptor(this); node_ninepatch->remove_change_receptor(this);
if (obj_styleBox.is_valid()) if (obj_styleBox.is_valid())
obj_styleBox->remove_change_receptor(this); obj_styleBox->remove_change_receptor(this);
if (atlas_tex.is_valid()) if (atlas_tex.is_valid())
atlas_tex->remove_change_receptor(this); atlas_tex->remove_change_receptor(this);
if (p_obj) { if (p_obj) {
node_sprite = Object::cast_to<Sprite>(p_obj); node_sprite = Object::cast_to<Sprite>(p_obj);
node_patch9 = Object::cast_to<NinePatchRect>(p_obj); node_ninepatch = Object::cast_to<NinePatchRect>(p_obj);
if (Object::cast_to<StyleBoxTexture>(p_obj)) if (Object::cast_to<StyleBoxTexture>(p_obj))
obj_styleBox = Ref<StyleBoxTexture>(Object::cast_to<StyleBoxTexture>(p_obj)); obj_styleBox = Ref<StyleBoxTexture>(Object::cast_to<StyleBoxTexture>(p_obj));
if (Object::cast_to<AtlasTexture>(p_obj)) if (Object::cast_to<AtlasTexture>(p_obj))
@ -640,7 +640,7 @@ void TextureRegionEditor::edit(Object *p_obj) {
_edit_region(); _edit_region();
} else { } else {
node_sprite = NULL; node_sprite = NULL;
node_patch9 = NULL; node_ninepatch = NULL;
obj_styleBox = Ref<StyleBoxTexture>(NULL); obj_styleBox = Ref<StyleBoxTexture>(NULL);
atlas_tex = Ref<AtlasTexture>(NULL); atlas_tex = Ref<AtlasTexture>(NULL);
} }
@ -659,8 +659,8 @@ void TextureRegionEditor::_edit_region() {
Ref<Texture> texture = NULL; Ref<Texture> texture = NULL;
if (node_sprite) if (node_sprite)
texture = node_sprite->get_texture(); texture = node_sprite->get_texture();
else if (node_patch9) else if (node_ninepatch)
texture = node_patch9->get_texture(); texture = node_ninepatch->get_texture();
else if (obj_styleBox.is_valid()) else if (obj_styleBox.is_valid())
texture = obj_styleBox->get_texture(); texture = obj_styleBox->get_texture();
else if (atlas_tex.is_valid()) else if (atlas_tex.is_valid())
@ -726,8 +726,8 @@ void TextureRegionEditor::_edit_region() {
if (node_sprite) if (node_sprite)
rect = node_sprite->get_region_rect(); rect = node_sprite->get_region_rect();
else if (node_patch9) else if (node_ninepatch)
rect = node_patch9->get_region_rect(); rect = node_ninepatch->get_region_rect();
else if (obj_styleBox.is_valid()) else if (obj_styleBox.is_valid())
rect = obj_styleBox->get_region_rect(); rect = obj_styleBox->get_region_rect();
else if (atlas_tex.is_valid()) else if (atlas_tex.is_valid())
@ -747,7 +747,7 @@ Vector2 TextureRegionEditor::snap_point(Vector2 p_target) const {
TextureRegionEditor::TextureRegionEditor(EditorNode *p_editor) { TextureRegionEditor::TextureRegionEditor(EditorNode *p_editor) {
node_sprite = NULL; node_sprite = NULL;
node_patch9 = NULL; node_ninepatch = NULL;
obj_styleBox = Ref<StyleBoxTexture>(NULL); obj_styleBox = Ref<StyleBoxTexture>(NULL);
atlas_tex = Ref<AtlasTexture>(NULL); atlas_tex = Ref<AtlasTexture>(NULL);
editor = p_editor; editor = p_editor;

View File

@ -37,7 +37,7 @@
#include "editor/editor_node.h" #include "editor/editor_node.h"
#include "editor/editor_plugin.h" #include "editor/editor_plugin.h"
#include "scene/2d/sprite.h" #include "scene/2d/sprite.h"
#include "scene/gui/patch_9_rect.h" #include "scene/gui/nine_patch_rect.h"
#include "scene/resources/style_box.h" #include "scene/resources/style_box.h"
#include "scene/resources/texture.h" #include "scene/resources/texture.h"
@ -82,7 +82,7 @@ class TextureRegionEditor : public Control {
Vector2 snap_step; Vector2 snap_step;
Vector2 snap_separation; Vector2 snap_separation;
NinePatchRect *node_patch9; NinePatchRect *node_ninepatch;
Sprite *node_sprite; Sprite *node_sprite;
Ref<StyleBoxTexture> obj_styleBox; Ref<StyleBoxTexture> obj_styleBox;
Ref<AtlasTexture> atlas_tex; Ref<AtlasTexture> atlas_tex;

View File

@ -1,5 +1,5 @@
/*************************************************************************/ /*************************************************************************/
/* patch_9_rect.cpp */ /* nine_patch_rect.cpp */
/*************************************************************************/ /*************************************************************************/
/* This file is part of: */ /* This file is part of: */
/* GODOT ENGINE */ /* GODOT ENGINE */
@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#include "patch_9_rect.h" #include "nine_patch_rect.h"
#include "servers/visual_server.h" #include "servers/visual_server.h"

View File

@ -1,5 +1,5 @@
/*************************************************************************/ /*************************************************************************/
/* patch_9_rect.h */ /* nine_patch_rect.h */
/*************************************************************************/ /*************************************************************************/
/* This file is part of: */ /* This file is part of: */
/* GODOT ENGINE */ /* GODOT ENGINE */
@ -27,8 +27,8 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifndef PATCH_9_FRAME_H #ifndef NINE_PATCH_RECT_H
#define PATCH_9_FRAME_H #define NINE_PATCH_RECT_H
#include "scene/gui/control.h" #include "scene/gui/control.h"
/** /**
@ -81,4 +81,4 @@ public:
}; };
VARIANT_ENUM_CAST(NinePatchRect::AxisStretchMode) VARIANT_ENUM_CAST(NinePatchRect::AxisStretchMode)
#endif // PATCH_9_FRAME_H #endif // NINE_PATCH_RECT_H

View File

@ -86,7 +86,7 @@
#include "scene/gui/option_button.h" #include "scene/gui/option_button.h"
#include "scene/gui/panel.h" #include "scene/gui/panel.h"
#include "scene/gui/panel_container.h" #include "scene/gui/panel_container.h"
#include "scene/gui/patch_9_rect.h" #include "scene/gui/nine_patch_rect.h"
#include "scene/gui/popup_menu.h" #include "scene/gui/popup_menu.h"
#include "scene/gui/progress_bar.h" #include "scene/gui/progress_bar.h"
#include "scene/gui/reference_rect.h" #include "scene/gui/reference_rect.h"