From 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= <rverschelde@gmail.com> Date: Thu, 14 May 2020 13:23:58 +0200 Subject: Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027. --- scene/2d/parallax_background.cpp | 26 -------------------------- 1 file changed, 26 deletions(-) (limited to 'scene/2d/parallax_background.cpp') diff --git a/scene/2d/parallax_background.cpp b/scene/2d/parallax_background.cpp index 0d5f74a265..6930307840 100644 --- a/scene/2d/parallax_background.cpp +++ b/scene/2d/parallax_background.cpp @@ -32,24 +32,19 @@ #include "parallax_layer.h" void ParallaxBackground::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - group_name = "__cameras_" + itos(get_viewport().get_id()); add_to_group(group_name); } break; case NOTIFICATION_EXIT_TREE: { - remove_from_group(group_name); } break; } } void ParallaxBackground::_camera_moved(const Transform2D &p_transform, const Point2 &p_screen_offset) { - screen_offset = p_screen_offset; set_scroll_scale(p_transform.get_scale().dot(Vector2(0.5, 0.5))); @@ -57,24 +52,20 @@ void ParallaxBackground::_camera_moved(const Transform2D &p_transform, const Poi } void ParallaxBackground::set_scroll_scale(float p_scale) { - scale = p_scale; } float ParallaxBackground::get_scroll_scale() const { - return scale; } void ParallaxBackground::set_scroll_offset(const Point2 &p_ofs) { - offset = p_ofs; _update_scroll(); } void ParallaxBackground::_update_scroll() { - if (!is_inside_tree()) return; @@ -84,7 +75,6 @@ void ParallaxBackground::_update_scroll() { ofs = -ofs; if (limit_begin.x < limit_end.x) { - if (ofs.x < limit_begin.x) ofs.x = limit_begin.x; else if (ofs.x + vps.x > limit_end.x) @@ -92,7 +82,6 @@ void ParallaxBackground::_update_scroll() { } if (limit_begin.y < limit_end.y) { - if (ofs.y < limit_begin.y) ofs.y = limit_begin.y; else if (ofs.y + vps.y > limit_end.y) @@ -103,7 +92,6 @@ void ParallaxBackground::_update_scroll() { final_offset = ofs; for (int i = 0; i < get_child_count(); i++) { - ParallaxLayer *l = Object::cast_to<ParallaxLayer>(get_child(i)); if (!l) continue; @@ -116,71 +104,58 @@ void ParallaxBackground::_update_scroll() { } Point2 ParallaxBackground::get_scroll_offset() const { - return offset; } void ParallaxBackground::set_scroll_base_offset(const Point2 &p_ofs) { - base_offset = p_ofs; _update_scroll(); } Point2 ParallaxBackground::get_scroll_base_offset() const { - return base_offset; } void ParallaxBackground::set_scroll_base_scale(const Point2 &p_ofs) { - base_scale = p_ofs; _update_scroll(); } Point2 ParallaxBackground::get_scroll_base_scale() const { - return base_scale; } void ParallaxBackground::set_limit_begin(const Point2 &p_ofs) { - limit_begin = p_ofs; _update_scroll(); } Point2 ParallaxBackground::get_limit_begin() const { - return limit_begin; } void ParallaxBackground::set_limit_end(const Point2 &p_ofs) { - limit_end = p_ofs; _update_scroll(); } Point2 ParallaxBackground::get_limit_end() const { - return limit_end; } void ParallaxBackground::set_ignore_camera_zoom(bool ignore) { - ignore_camera_zoom = ignore; } bool ParallaxBackground::is_ignore_camera_zoom() { - return ignore_camera_zoom; } Vector2 ParallaxBackground::get_final_offset() const { - return final_offset; } void ParallaxBackground::_bind_methods() { - ClassDB::bind_method(D_METHOD("_camera_moved"), &ParallaxBackground::_camera_moved); ClassDB::bind_method(D_METHOD("set_scroll_offset", "ofs"), &ParallaxBackground::set_scroll_offset); ClassDB::bind_method(D_METHOD("get_scroll_offset"), &ParallaxBackground::get_scroll_offset); @@ -205,7 +180,6 @@ void ParallaxBackground::_bind_methods() { } ParallaxBackground::ParallaxBackground() { - scale = 1.0; set_layer(-100); //behind all by default -- cgit v1.2.3 From 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= <rverschelde@gmail.com> Date: Thu, 14 May 2020 16:41:43 +0200 Subject: 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 --- scene/2d/parallax_background.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'scene/2d/parallax_background.cpp') diff --git a/scene/2d/parallax_background.cpp b/scene/2d/parallax_background.cpp index 6930307840..416622e6d5 100644 --- a/scene/2d/parallax_background.cpp +++ b/scene/2d/parallax_background.cpp @@ -66,8 +66,9 @@ void ParallaxBackground::set_scroll_offset(const Point2 &p_ofs) { } void ParallaxBackground::_update_scroll() { - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } Vector2 ofs = base_offset + offset * base_scale; @@ -75,17 +76,19 @@ void ParallaxBackground::_update_scroll() { ofs = -ofs; if (limit_begin.x < limit_end.x) { - if (ofs.x < limit_begin.x) + if (ofs.x < limit_begin.x) { ofs.x = limit_begin.x; - else if (ofs.x + vps.x > limit_end.x) + } else if (ofs.x + vps.x > limit_end.x) { ofs.x = limit_end.x - vps.x; + } } if (limit_begin.y < limit_end.y) { - if (ofs.y < limit_begin.y) + if (ofs.y < limit_begin.y) { ofs.y = limit_begin.y; - else if (ofs.y + vps.y > limit_end.y) + } else if (ofs.y + vps.y > limit_end.y) { ofs.y = limit_end.y - vps.y; + } } ofs = -ofs; @@ -93,13 +96,15 @@ void ParallaxBackground::_update_scroll() { for (int i = 0; i < get_child_count(); i++) { ParallaxLayer *l = Object::cast_to<ParallaxLayer>(get_child(i)); - if (!l) + if (!l) { continue; + } - if (ignore_camera_zoom) + if (ignore_camera_zoom) { l->set_base_offset_and_scale(ofs, 1.0, screen_offset); - else + } else { l->set_base_offset_and_scale(ofs, scale, screen_offset); + } } } -- cgit v1.2.3