You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +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:
@@ -65,8 +65,9 @@ CurveEditor::CurveEditor() {
|
||||
}
|
||||
|
||||
void CurveEditor::set_curve(Ref<Curve> curve) {
|
||||
if (curve == _curve_ref)
|
||||
if (curve == _curve_ref) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_curve_ref.is_valid()) {
|
||||
_curve_ref->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CurveEditor::_curve_changed));
|
||||
@@ -95,8 +96,9 @@ Size2 CurveEditor::get_minimum_size() const {
|
||||
}
|
||||
|
||||
void CurveEditor::_notification(int p_what) {
|
||||
if (p_what == NOTIFICATION_DRAW)
|
||||
if (p_what == NOTIFICATION_DRAW) {
|
||||
_draw();
|
||||
}
|
||||
}
|
||||
|
||||
void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) {
|
||||
@@ -108,8 +110,9 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) {
|
||||
Vector2 mpos = mb.get_position();
|
||||
|
||||
_selected_tangent = get_tangent_at(mpos);
|
||||
if (_selected_tangent == TANGENT_NONE)
|
||||
if (_selected_tangent == TANGENT_NONE) {
|
||||
set_selected_point(get_point_at(mpos));
|
||||
}
|
||||
|
||||
switch (mb.get_button_index()) {
|
||||
case BUTTON_RIGHT:
|
||||
@@ -182,10 +185,11 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) {
|
||||
set_selected_point(i);
|
||||
|
||||
// This is to prevent the user from losing a point out of view.
|
||||
if (point_pos.y < curve.get_min_value())
|
||||
if (point_pos.y < curve.get_min_value()) {
|
||||
point_pos.y = curve.get_min_value();
|
||||
else if (point_pos.y > curve.get_max_value())
|
||||
} else if (point_pos.y > curve.get_max_value()) {
|
||||
point_pos.y = curve.get_max_value();
|
||||
}
|
||||
|
||||
curve.set_point_value(_selected_point, point_pos.y);
|
||||
|
||||
@@ -198,10 +202,11 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) {
|
||||
Vector2 dir = (control_pos - point_pos).normalized();
|
||||
|
||||
real_t tangent;
|
||||
if (!Math::is_zero_approx(dir.x))
|
||||
if (!Math::is_zero_approx(dir.x)) {
|
||||
tangent = dir.y / dir.x;
|
||||
else
|
||||
} else {
|
||||
tangent = 9999 * (dir.y >= 0 ? 1 : -1);
|
||||
}
|
||||
|
||||
bool link = !Input::get_singleton()->is_key_pressed(KEY_SHIFT);
|
||||
|
||||
@@ -209,14 +214,16 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) {
|
||||
curve.set_point_left_tangent(_selected_point, tangent);
|
||||
|
||||
// Note: if a tangent is set to linear, it shouldn't be linked to the other
|
||||
if (link && _selected_point != (curve.get_point_count() - 1) && curve.get_point_right_mode(_selected_point) != Curve::TANGENT_LINEAR)
|
||||
if (link && _selected_point != (curve.get_point_count() - 1) && curve.get_point_right_mode(_selected_point) != Curve::TANGENT_LINEAR) {
|
||||
curve.set_point_right_tangent(_selected_point, tangent);
|
||||
}
|
||||
|
||||
} else {
|
||||
curve.set_point_right_tangent(_selected_point, tangent);
|
||||
|
||||
if (link && _selected_point != 0 && curve.get_point_left_mode(_selected_point) != Curve::TANGENT_LINEAR)
|
||||
if (link && _selected_point != 0 && curve.get_point_left_mode(_selected_point) != Curve::TANGENT_LINEAR) {
|
||||
curve.set_point_left_tangent(_selected_point, tangent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -231,8 +238,9 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) {
|
||||
const InputEventKey &key = **key_ref;
|
||||
|
||||
if (key.is_pressed() && _selected_point != -1) {
|
||||
if (key.get_keycode() == KEY_DELETE)
|
||||
if (key.get_keycode() == KEY_DELETE) {
|
||||
remove_point(_selected_point);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -351,8 +359,9 @@ void CurveEditor::open_context_menu(Vector2 pos) {
|
||||
_context_menu->set_item_checked(_context_menu->get_item_index(CONTEXT_LINEAR), is_linear);
|
||||
|
||||
} else {
|
||||
if (_selected_point > 0 || _selected_point + 1 < _curve_ref->get_point_count())
|
||||
if (_selected_point > 0 || _selected_point + 1 < _curve_ref->get_point_count()) {
|
||||
_context_menu->add_separator();
|
||||
}
|
||||
|
||||
if (_selected_point > 0) {
|
||||
_context_menu->add_check_item(TTR("Left Linear"), CONTEXT_LEFT_LINEAR);
|
||||
@@ -377,8 +386,9 @@ void CurveEditor::open_context_menu(Vector2 pos) {
|
||||
}
|
||||
|
||||
int CurveEditor::get_point_at(Vector2 pos) const {
|
||||
if (_curve_ref.is_null())
|
||||
if (_curve_ref.is_null()) {
|
||||
return -1;
|
||||
}
|
||||
const Curve &curve = **_curve_ref;
|
||||
|
||||
const float r = _hover_radius * _hover_radius;
|
||||
@@ -394,8 +404,9 @@ int CurveEditor::get_point_at(Vector2 pos) const {
|
||||
}
|
||||
|
||||
CurveEditor::TangentIndex CurveEditor::get_tangent_at(Vector2 pos) const {
|
||||
if (_curve_ref.is_null() || _selected_point < 0)
|
||||
if (_curve_ref.is_null() || _selected_point < 0) {
|
||||
return TANGENT_NONE;
|
||||
}
|
||||
|
||||
if (_selected_point != 0) {
|
||||
Vector2 control_pos = get_tangent_view_pos(_selected_point, TANGENT_LEFT);
|
||||
@@ -421,10 +432,11 @@ void CurveEditor::add_point(Vector2 pos) {
|
||||
ur.create_action(TTR("Remove Curve Point"));
|
||||
|
||||
Vector2 point_pos = get_world_pos(pos);
|
||||
if (point_pos.y < 0.0)
|
||||
if (point_pos.y < 0.0) {
|
||||
point_pos.y = 0.0;
|
||||
else if (point_pos.y > 1.0)
|
||||
} else if (point_pos.y > 1.0) {
|
||||
point_pos.y = 1.0;
|
||||
}
|
||||
|
||||
// Small trick to get the point index to feed the undo method
|
||||
int i = _curve_ref->add_point(point_pos);
|
||||
@@ -447,11 +459,13 @@ void CurveEditor::remove_point(int index) {
|
||||
ur.add_do_method(*_curve_ref, "remove_point", index);
|
||||
ur.add_undo_method(*_curve_ref, "add_point", p.pos, p.left_tangent, p.right_tangent, p.left_mode, p.right_mode);
|
||||
|
||||
if (index == _selected_point)
|
||||
if (index == _selected_point) {
|
||||
set_selected_point(-1);
|
||||
}
|
||||
|
||||
if (index == _hover_point)
|
||||
if (index == _hover_point) {
|
||||
set_hover_point_index(-1);
|
||||
}
|
||||
|
||||
ur.commit_action();
|
||||
}
|
||||
@@ -462,8 +476,9 @@ void CurveEditor::toggle_linear(TangentIndex tangent) {
|
||||
UndoRedo &ur = *EditorNode::get_singleton()->get_undo_redo();
|
||||
ur.create_action(TTR("Toggle Curve Linear Tangent"));
|
||||
|
||||
if (tangent == TANGENT_NONE)
|
||||
if (tangent == TANGENT_NONE) {
|
||||
tangent = _selected_tangent;
|
||||
}
|
||||
|
||||
if (tangent == TANGENT_LEFT) {
|
||||
bool is_linear = _curve_ref->get_point_left_mode(_selected_point) == Curve::TANGENT_LINEAR;
|
||||
@@ -530,10 +545,11 @@ void CurveEditor::update_view_transform() {
|
||||
|
||||
Vector2 CurveEditor::get_tangent_view_pos(int i, TangentIndex tangent) const {
|
||||
Vector2 dir;
|
||||
if (tangent == TANGENT_LEFT)
|
||||
if (tangent == TANGENT_LEFT) {
|
||||
dir = -Vector2(1, _curve_ref->get_point_left_tangent(i));
|
||||
else
|
||||
} else {
|
||||
dir = Vector2(1, _curve_ref->get_point_right_tangent(i));
|
||||
}
|
||||
|
||||
Vector2 point_pos = get_view_pos(_curve_ref->get_point_position(i));
|
||||
Vector2 control_pos = get_view_pos(_curve_ref->get_point_position(i) + dir);
|
||||
@@ -605,8 +621,9 @@ struct CanvasItemPlotCurve {
|
||||
};
|
||||
|
||||
void CurveEditor::_draw() {
|
||||
if (_curve_ref.is_null())
|
||||
if (_curve_ref.is_null()) {
|
||||
return;
|
||||
}
|
||||
Curve &curve = **_curve_ref;
|
||||
|
||||
update_view_transform();
|
||||
|
||||
Reference in New Issue
Block a user