mirror of
https://github.com/godotengine/godot.git
synced 2025-11-01 14:11:15 +00:00
Style: Enforce braces around if blocks and loops
Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
This commit is contained in:
parent
07bc4e2f96
commit
0ee0fa42e6
683 changed files with 22803 additions and 12225 deletions
|
|
@ -50,19 +50,21 @@ void draw_margin_line(Control *edit_draw, Vector2 from, Vector2 to) {
|
|||
|
||||
void TextureRegionEditor::_region_draw() {
|
||||
Ref<Texture2D> base_tex = nullptr;
|
||||
if (node_sprite)
|
||||
if (node_sprite) {
|
||||
base_tex = node_sprite->get_texture();
|
||||
else if (node_sprite_3d)
|
||||
} else if (node_sprite_3d) {
|
||||
base_tex = node_sprite_3d->get_texture();
|
||||
else if (node_ninepatch)
|
||||
} else if (node_ninepatch) {
|
||||
base_tex = node_ninepatch->get_texture();
|
||||
else if (obj_styleBox.is_valid())
|
||||
} else if (obj_styleBox.is_valid()) {
|
||||
base_tex = obj_styleBox->get_texture();
|
||||
else if (atlas_tex.is_valid())
|
||||
} else if (atlas_tex.is_valid()) {
|
||||
base_tex = atlas_tex->get_atlas();
|
||||
}
|
||||
|
||||
if (base_tex.is_null())
|
||||
if (base_tex.is_null()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Transform2D mtx;
|
||||
mtx.elements[2] = -draw_ofs * draw_zoom;
|
||||
|
|
@ -78,45 +80,55 @@ void TextureRegionEditor::_region_draw() {
|
|||
int last_cell = 0;
|
||||
|
||||
if (snap_step.x != 0) {
|
||||
if (snap_separation.x == 0)
|
||||
if (snap_separation.x == 0) {
|
||||
for (int i = 0; i < s.width; i++) {
|
||||
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(i, 0)).x - snap_offset.x) / snap_step.x));
|
||||
if (i == 0)
|
||||
if (i == 0) {
|
||||
last_cell = cell;
|
||||
if (last_cell != cell)
|
||||
}
|
||||
if (last_cell != cell) {
|
||||
edit_draw->draw_line(Point2(i, 0), Point2(i, s.height), grid_color);
|
||||
}
|
||||
last_cell = cell;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
for (int i = 0; i < s.width; i++) {
|
||||
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(i, 0)).x - snap_offset.x) / (snap_step.x + snap_separation.x)));
|
||||
if (i == 0)
|
||||
if (i == 0) {
|
||||
last_cell = cell;
|
||||
if (last_cell != cell)
|
||||
}
|
||||
if (last_cell != cell) {
|
||||
edit_draw->draw_rect(Rect2(i - snap_separation.x * draw_zoom, 0, snap_separation.x * draw_zoom, s.height), grid_color);
|
||||
}
|
||||
last_cell = cell;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (snap_step.y != 0) {
|
||||
if (snap_separation.y == 0)
|
||||
if (snap_separation.y == 0) {
|
||||
for (int i = 0; i < s.height; i++) {
|
||||
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(0, i)).y - snap_offset.y) / snap_step.y));
|
||||
if (i == 0)
|
||||
if (i == 0) {
|
||||
last_cell = cell;
|
||||
if (last_cell != cell)
|
||||
}
|
||||
if (last_cell != cell) {
|
||||
edit_draw->draw_line(Point2(0, i), Point2(s.width, i), grid_color);
|
||||
}
|
||||
last_cell = cell;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
for (int i = 0; i < s.height; i++) {
|
||||
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(0, i)).y - snap_offset.y) / (snap_step.y + snap_separation.y)));
|
||||
if (i == 0)
|
||||
if (i == 0) {
|
||||
last_cell = cell;
|
||||
if (last_cell != cell)
|
||||
}
|
||||
if (last_cell != cell) {
|
||||
edit_draw->draw_rect(Rect2(0, i - snap_separation.y * draw_zoom, s.width, snap_separation.y * draw_zoom), grid_color);
|
||||
}
|
||||
last_cell = cell;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (snap_mode == SNAP_AUTOSLICE) {
|
||||
for (List<Rect2>::Element *E = autoslice_cache.front(); E; E = E->next()) {
|
||||
|
|
@ -160,14 +172,16 @@ void TextureRegionEditor::_region_draw() {
|
|||
|
||||
edit_draw->draw_line(endpoints[i] - draw_ofs * draw_zoom, endpoints[next] - draw_ofs * draw_zoom, color, 2);
|
||||
|
||||
if (snap_mode != SNAP_AUTOSLICE)
|
||||
if (snap_mode != SNAP_AUTOSLICE) {
|
||||
edit_draw->draw_texture(select_handle, (endpoints[i] + ofs - (select_handle->get_size() / 2)).floor() - draw_ofs * draw_zoom);
|
||||
}
|
||||
|
||||
ofs = (endpoints[next] - endpoints[i]) / 2;
|
||||
ofs += (endpoints[next] - endpoints[i]).tangent().normalized() * (select_handle->get_size().width / 2);
|
||||
|
||||
if (snap_mode != SNAP_AUTOSLICE)
|
||||
if (snap_mode != SNAP_AUTOSLICE) {
|
||||
edit_draw->draw_texture(select_handle, (endpoints[i] + ofs - (select_handle->get_size() / 2)).floor() - draw_ofs * draw_zoom);
|
||||
}
|
||||
|
||||
scroll_rect.expand_to(raw_endpoints[i]);
|
||||
}
|
||||
|
|
@ -306,16 +320,17 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
|
|||
rect = E->get();
|
||||
if (Input::get_singleton()->is_key_pressed(KEY_CONTROL) && !(Input::get_singleton()->is_key_pressed(KEY_SHIFT | KEY_ALT))) {
|
||||
Rect2 r;
|
||||
if (node_sprite)
|
||||
if (node_sprite) {
|
||||
r = node_sprite->get_region_rect();
|
||||
else if (node_sprite_3d)
|
||||
} else if (node_sprite_3d) {
|
||||
r = node_sprite_3d->get_region_rect();
|
||||
else if (node_ninepatch)
|
||||
} else if (node_ninepatch) {
|
||||
r = node_ninepatch->get_region_rect();
|
||||
else if (obj_styleBox.is_valid())
|
||||
} else if (obj_styleBox.is_valid()) {
|
||||
r = obj_styleBox->get_region_rect();
|
||||
else if (atlas_tex.is_valid())
|
||||
} else if (atlas_tex.is_valid()) {
|
||||
r = atlas_tex->get_region();
|
||||
}
|
||||
rect.expand_to(r.position);
|
||||
rect.expand_to(r.position + r.size);
|
||||
}
|
||||
|
|
@ -346,21 +361,23 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
|
|||
}
|
||||
} else if (edited_margin < 0) {
|
||||
drag_from = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y));
|
||||
if (snap_mode == SNAP_PIXEL)
|
||||
if (snap_mode == SNAP_PIXEL) {
|
||||
drag_from = drag_from.snapped(Vector2(1, 1));
|
||||
else if (snap_mode == SNAP_GRID)
|
||||
} else if (snap_mode == SNAP_GRID) {
|
||||
drag_from = snap_point(drag_from);
|
||||
}
|
||||
drag = true;
|
||||
if (node_sprite)
|
||||
if (node_sprite) {
|
||||
rect_prev = node_sprite->get_region_rect();
|
||||
else if (node_sprite_3d)
|
||||
} else if (node_sprite_3d) {
|
||||
rect_prev = node_sprite_3d->get_region_rect();
|
||||
else if (node_ninepatch)
|
||||
} else if (node_ninepatch) {
|
||||
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();
|
||||
else if (atlas_tex.is_valid())
|
||||
} else if (atlas_tex.is_valid()) {
|
||||
rect_prev = atlas_tex->get_region();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
Vector2 tuv = endpoints[i];
|
||||
|
|
@ -422,10 +439,12 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
|
|||
drag = false;
|
||||
if (edited_margin >= 0) {
|
||||
static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT };
|
||||
if (node_ninepatch)
|
||||
if (node_ninepatch) {
|
||||
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);
|
||||
}
|
||||
edited_margin = -1;
|
||||
} else {
|
||||
apply_rect(rect_prev);
|
||||
|
|
@ -452,30 +471,35 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
|
|||
} else if (drag) {
|
||||
if (edited_margin >= 0) {
|
||||
float new_margin = 0;
|
||||
if (edited_margin == 0)
|
||||
if (edited_margin == 0) {
|
||||
new_margin = prev_margin + (mm->get_position().y - drag_from.y) / draw_zoom;
|
||||
else if (edited_margin == 1)
|
||||
} else if (edited_margin == 1) {
|
||||
new_margin = prev_margin - (mm->get_position().y - drag_from.y) / draw_zoom;
|
||||
else if (edited_margin == 2)
|
||||
} else if (edited_margin == 2) {
|
||||
new_margin = prev_margin + (mm->get_position().x - drag_from.x) / draw_zoom;
|
||||
else if (edited_margin == 3)
|
||||
} else if (edited_margin == 3) {
|
||||
new_margin = prev_margin - (mm->get_position().x - drag_from.x) / draw_zoom;
|
||||
else
|
||||
} else {
|
||||
ERR_PRINT("Unexpected edited_margin");
|
||||
}
|
||||
|
||||
if (new_margin < 0)
|
||||
if (new_margin < 0) {
|
||||
new_margin = 0;
|
||||
}
|
||||
static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT };
|
||||
if (node_ninepatch)
|
||||
if (node_ninepatch) {
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
Vector2 new_pos = mtx.affine_inverse().xform(mm->get_position());
|
||||
if (snap_mode == SNAP_PIXEL)
|
||||
if (snap_mode == SNAP_PIXEL) {
|
||||
new_pos = new_pos.snapped(Vector2(1, 1));
|
||||
else if (snap_mode == SNAP_GRID)
|
||||
} else if (snap_mode == SNAP_GRID) {
|
||||
new_pos = snap_point(new_pos);
|
||||
}
|
||||
|
||||
if (creating) {
|
||||
rect = Rect2(drag_from, Size2());
|
||||
|
|
@ -553,8 +577,9 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
|
|||
}
|
||||
|
||||
void TextureRegionEditor::_scroll_changed(float) {
|
||||
if (updating_scroll)
|
||||
if (updating_scroll) {
|
||||
return;
|
||||
}
|
||||
|
||||
draw_ofs.x = hscroll->get_value();
|
||||
draw_ofs.y = vscroll->get_value();
|
||||
|
|
@ -564,10 +589,11 @@ void TextureRegionEditor::_scroll_changed(float) {
|
|||
void TextureRegionEditor::_set_snap_mode(int p_mode) {
|
||||
snap_mode = p_mode;
|
||||
|
||||
if (snap_mode == SNAP_GRID)
|
||||
if (snap_mode == SNAP_GRID) {
|
||||
hb_grid->show();
|
||||
else
|
||||
} else {
|
||||
hb_grid->hide();
|
||||
}
|
||||
|
||||
if (snap_mode == SNAP_AUTOSLICE && is_visible() && autoslice_is_dirty) {
|
||||
_update_autoslice();
|
||||
|
|
@ -607,8 +633,9 @@ void TextureRegionEditor::_set_snap_sep_y(float p_val) {
|
|||
}
|
||||
|
||||
void TextureRegionEditor::_zoom_on_position(float p_zoom, Point2 p_position) {
|
||||
if (p_zoom < 0.25 || p_zoom > 8)
|
||||
if (p_zoom < 0.25 || p_zoom > 8) {
|
||||
return;
|
||||
}
|
||||
|
||||
float prev_zoom = draw_zoom;
|
||||
draw_zoom = p_zoom;
|
||||
|
|
@ -633,32 +660,34 @@ void TextureRegionEditor::_zoom_out() {
|
|||
}
|
||||
|
||||
void TextureRegionEditor::apply_rect(const Rect2 &p_rect) {
|
||||
if (node_sprite)
|
||||
if (node_sprite) {
|
||||
node_sprite->set_region_rect(p_rect);
|
||||
else if (node_sprite_3d)
|
||||
} else if (node_sprite_3d) {
|
||||
node_sprite_3d->set_region_rect(p_rect);
|
||||
else if (node_ninepatch)
|
||||
} else if (node_ninepatch) {
|
||||
node_ninepatch->set_region_rect(p_rect);
|
||||
else if (obj_styleBox.is_valid())
|
||||
} else if (obj_styleBox.is_valid()) {
|
||||
obj_styleBox->set_region_rect(p_rect);
|
||||
else if (atlas_tex.is_valid())
|
||||
} else if (atlas_tex.is_valid()) {
|
||||
atlas_tex->set_region(p_rect);
|
||||
}
|
||||
}
|
||||
|
||||
void TextureRegionEditor::_update_rect() {
|
||||
if (node_sprite)
|
||||
if (node_sprite) {
|
||||
rect = node_sprite->get_region_rect();
|
||||
else if (node_sprite_3d)
|
||||
} else if (node_sprite_3d) {
|
||||
rect = node_sprite_3d->get_region_rect();
|
||||
else if (node_ninepatch) {
|
||||
} else if (node_ninepatch) {
|
||||
rect = node_ninepatch->get_region_rect();
|
||||
if (rect == Rect2()) {
|
||||
rect = Rect2(Vector2(), node_ninepatch->get_texture()->get_size());
|
||||
}
|
||||
} else if (obj_styleBox.is_valid())
|
||||
} else if (obj_styleBox.is_valid()) {
|
||||
rect = obj_styleBox->get_region_rect();
|
||||
else if (atlas_tex.is_valid())
|
||||
} else if (atlas_tex.is_valid()) {
|
||||
rect = atlas_tex->get_region();
|
||||
}
|
||||
}
|
||||
|
||||
void TextureRegionEditor::_update_autoslice() {
|
||||
|
|
@ -666,16 +695,17 @@ void TextureRegionEditor::_update_autoslice() {
|
|||
autoslice_cache.clear();
|
||||
|
||||
Ref<Texture2D> texture = nullptr;
|
||||
if (node_sprite)
|
||||
if (node_sprite) {
|
||||
texture = node_sprite->get_texture();
|
||||
else if (node_sprite_3d)
|
||||
} else if (node_sprite_3d) {
|
||||
texture = node_sprite_3d->get_texture();
|
||||
else if (node_ninepatch)
|
||||
} else if (node_ninepatch) {
|
||||
texture = node_ninepatch->get_texture();
|
||||
else if (obj_styleBox.is_valid())
|
||||
} else if (obj_styleBox.is_valid()) {
|
||||
texture = obj_styleBox->get_texture();
|
||||
else if (atlas_tex.is_valid())
|
||||
} else if (atlas_tex.is_valid()) {
|
||||
texture = atlas_tex->get_atlas();
|
||||
}
|
||||
|
||||
if (texture.is_null()) {
|
||||
return;
|
||||
|
|
@ -700,8 +730,9 @@ void TextureRegionEditor::_update_autoslice() {
|
|||
autoslice_cache.erase(F->prev());
|
||||
queue_erase = false;
|
||||
}
|
||||
if (F == E)
|
||||
if (F == E) {
|
||||
continue;
|
||||
}
|
||||
if (E->get().grow(1).intersects(F->get())) {
|
||||
E->get().expand_to(F->get().position);
|
||||
E->get().expand_to(F->get().position + F->get().size);
|
||||
|
|
@ -797,24 +828,31 @@ Sprite2D *TextureRegionEditor::get_sprite() {
|
|||
}
|
||||
|
||||
void TextureRegionEditor::edit(Object *p_obj) {
|
||||
if (node_sprite)
|
||||
if (node_sprite) {
|
||||
node_sprite->remove_change_receptor(this);
|
||||
if (node_sprite_3d)
|
||||
}
|
||||
if (node_sprite_3d) {
|
||||
node_sprite_3d->remove_change_receptor(this);
|
||||
if (node_ninepatch)
|
||||
}
|
||||
if (node_ninepatch) {
|
||||
node_ninepatch->remove_change_receptor(this);
|
||||
if (obj_styleBox.is_valid())
|
||||
}
|
||||
if (obj_styleBox.is_valid()) {
|
||||
obj_styleBox->remove_change_receptor(this);
|
||||
if (atlas_tex.is_valid())
|
||||
}
|
||||
if (atlas_tex.is_valid()) {
|
||||
atlas_tex->remove_change_receptor(this);
|
||||
}
|
||||
if (p_obj) {
|
||||
node_sprite = Object::cast_to<Sprite2D>(p_obj);
|
||||
node_sprite_3d = Object::cast_to<Sprite3D>(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));
|
||||
if (Object::cast_to<AtlasTexture>(p_obj))
|
||||
}
|
||||
if (Object::cast_to<AtlasTexture>(p_obj)) {
|
||||
atlas_tex = Ref<AtlasTexture>(Object::cast_to<AtlasTexture>(p_obj));
|
||||
}
|
||||
p_obj->add_change_receptor(this);
|
||||
_edit_region();
|
||||
} else {
|
||||
|
|
@ -834,24 +872,27 @@ void TextureRegionEditor::edit(Object *p_obj) {
|
|||
}
|
||||
|
||||
void TextureRegionEditor::_changed_callback(Object *p_changed, const char *p_prop) {
|
||||
if (!is_visible())
|
||||
if (!is_visible()) {
|
||||
return;
|
||||
if (p_prop == StringName("atlas") || p_prop == StringName("texture"))
|
||||
}
|
||||
if (p_prop == StringName("atlas") || p_prop == StringName("texture")) {
|
||||
_edit_region();
|
||||
}
|
||||
}
|
||||
|
||||
void TextureRegionEditor::_edit_region() {
|
||||
Ref<Texture2D> texture = nullptr;
|
||||
if (node_sprite)
|
||||
if (node_sprite) {
|
||||
texture = node_sprite->get_texture();
|
||||
else if (node_sprite_3d)
|
||||
} else if (node_sprite_3d) {
|
||||
texture = node_sprite_3d->get_texture();
|
||||
else if (node_ninepatch)
|
||||
} else if (node_ninepatch) {
|
||||
texture = node_ninepatch->get_texture();
|
||||
else if (obj_styleBox.is_valid())
|
||||
} else if (obj_styleBox.is_valid()) {
|
||||
texture = obj_styleBox->get_texture();
|
||||
else if (atlas_tex.is_valid())
|
||||
} else if (atlas_tex.is_valid()) {
|
||||
texture = atlas_tex->get_atlas();
|
||||
}
|
||||
|
||||
if (texture.is_null()) {
|
||||
_zoom_reset();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue