diff options
Diffstat (limited to 'scene/gui/texture_progress.cpp')
-rw-r--r-- | scene/gui/texture_progress.cpp | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/scene/gui/texture_progress.cpp b/scene/gui/texture_progress.cpp index 5edb10958c..484b14d11c 100644 --- a/scene/gui/texture_progress.cpp +++ b/scene/gui/texture_progress.cpp @@ -77,14 +77,15 @@ bool TextureProgress::get_nine_patch_stretch() const { } Size2 TextureProgress::get_minimum_size() const { - if (nine_patch_stretch) + if (nine_patch_stretch) { return Size2(stretch_margin[MARGIN_LEFT] + stretch_margin[MARGIN_RIGHT], stretch_margin[MARGIN_TOP] + stretch_margin[MARGIN_BOTTOM]); - else if (under.is_valid()) + } else if (under.is_valid()) { return under->get_size(); - else if (over.is_valid()) + } else if (over.is_valid()) { return over->get_size(); - else if (progress.is_valid()) + } else if (progress.is_valid()) { return progress->get_size(); + } return Size2(1, 1); } @@ -127,13 +128,16 @@ Color TextureProgress::get_tint_over() const { } Point2 TextureProgress::unit_val_to_uv(float val) { - if (progress.is_null()) + if (progress.is_null()) { return Point2(); + } - if (val < 0) + if (val < 0) { val += 1; - if (val > 1) + } + if (val > 1) { val -= 1; + } Point2 p = get_relative_center(); @@ -151,40 +155,46 @@ Point2 TextureProgress::unit_val_to_uv(float val) { for (int edge = 0; edge < 4; edge++) { if (edge == 0) { - if (dir.x > 0) + if (dir.x > 0) { continue; + } cq = -(edgeLeft - p.x); dir.x *= 2.0 * cq; cp = -dir.x; } else if (edge == 1) { - if (dir.x < 0) + if (dir.x < 0) { continue; + } cq = (edgeRight - p.x); dir.x *= 2.0 * cq; cp = dir.x; } else if (edge == 2) { - if (dir.y > 0) + if (dir.y > 0) { continue; + } cq = -(edgeBottom - p.y); dir.y *= 2.0 * cq; cp = -dir.y; } else if (edge == 3) { - if (dir.y < 0) + if (dir.y < 0) { continue; + } cq = (edgeTop - p.y); dir.y *= 2.0 * cq; cp = dir.y; } cr = cq / cp; - if (cr >= 0 && cr < t1) + if (cr >= 0 && cr < t1) { t1 = cr; + } } return (p + t1 * dir); } Point2 TextureProgress::get_relative_center() { - if (progress.is_null()) + if (progress.is_null()) { return Point2(); + } Point2 p = progress->get_size() / 2; p += rad_center_off; p.x /= progress->get_width(); @@ -311,8 +321,9 @@ void TextureProgress::_notification(int p_what) { draw_nine_patch_stretched(over, FILL_LEFT_TO_RIGHT, 1.0, tint_over); } } else { - if (under.is_valid()) + if (under.is_valid()) { draw_texture(under, Point2(), tint_under); + } if (progress.is_valid()) { Size2 s = progress->get_size(); switch (mode) { @@ -335,8 +346,9 @@ void TextureProgress::_notification(int p_what) { case FILL_CLOCKWISE: case FILL_COUNTER_CLOCKWISE: case FILL_CLOCKWISE_AND_COUNTER_CLOCKWISE: { - if (nine_patch_stretch) + if (nine_patch_stretch) { s = get_size(); + } float val = get_as_ratio() * rad_max_degrees / 360; if (val == 1) { @@ -358,9 +370,11 @@ void TextureProgress::_notification(int p_what) { pts.append(end); float from = MIN(start, end); float to = MAX(start, end); - for (int i = 0; i < 12; i++) - if (corners[i] > from && corners[i] < to) + for (int i = 0; i < 12; i++) { + if (corners[i] > from && corners[i] < to) { pts.append(corners[i]); + } + } pts.sort(); Vector<Point2> uvs; Vector<Point2> points; @@ -368,8 +382,9 @@ void TextureProgress::_notification(int p_what) { points.push_back(Point2(s.x * get_relative_center().x, s.y * get_relative_center().y)); for (int i = 0; i < pts.size(); i++) { Point2 uv = unit_val_to_uv(pts[i]); - if (uvs.find(uv) >= 0) + if (uvs.find(uv) >= 0) { continue; + } uvs.push_back(uv); points.push_back(Point2(uv.x * s.x, uv.y * s.y)); } @@ -380,10 +395,11 @@ void TextureProgress::_notification(int p_what) { if (Engine::get_singleton()->is_editor_hint()) { Point2 p; - if (nine_patch_stretch) + if (nine_patch_stretch) { p = get_size(); - else + } else { p = progress->get_size(); + } p.x *= get_relative_center().x; p.y *= get_relative_center().y; @@ -404,10 +420,10 @@ void TextureProgress::_notification(int p_what) { draw_texture_rect_region(progress, Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), tint_progress); } } - if (over.is_valid()) + if (over.is_valid()) { draw_texture(over, Point2(), tint_over); + } } - } break; } } @@ -423,10 +439,12 @@ int TextureProgress::get_fill_mode() { } void TextureProgress::set_radial_initial_angle(float p_angle) { - while (p_angle > 360) + while (p_angle > 360) { p_angle -= 360; - while (p_angle < 0) + } + while (p_angle < 0) { p_angle += 360; + } rad_init_angle = p_angle; update(); } |