Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nine patch of circular TextureProgressBar #54345

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions scene/gui/texture_progress_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ void TextureProgressBar::draw_nine_patch_stretched(const Ref<Texture2D> &p_textu
}

void TextureProgressBar::_notification(int p_what) {
const float corners[12] = { -0.125, -0.375, -0.625, -0.875, 0.125, 0.375, 0.625, 0.875, 1.125, 1.375, 1.625, 1.875 };
switch (p_what) {
case NOTIFICATION_DRAW: {
if (nine_patch_stretch && (mode == FILL_LEFT_TO_RIGHT || mode == FILL_RIGHT_TO_LEFT || mode == FILL_TOP_TO_BOTTOM || mode == FILL_BOTTOM_TO_TOP || mode == FILL_BILINEAR_LEFT_AND_RIGHT || mode == FILL_BILINEAR_TOP_AND_BOTTOM)) {
Expand Down Expand Up @@ -452,7 +451,7 @@ void TextureProgressBar::_notification(int p_what) {
float val = get_as_ratio() * rad_max_degrees / 360;
if (val == 1) {
Rect2 region = Rect2(progress_offset, s);
Rect2 source = Rect2(Point2(), s);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just changing that line to:

Rect2 source = Rect2(Point2(), progress->get_size());

should fix the case when val == 1 which seemed to be the problem in here. And that case seems to be simpler/faster so I'd opt for keeping it in (instead of removing it like you did).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kleonc Yes, you're right. Better keep it this way.

Rect2 source = Rect2(Point2(), progress->get_size());
draw_texture_rect_region(progress, region, source, tint_progress);
} else if (val != 0) {
Array pts;
Expand All @@ -466,16 +465,14 @@ void TextureProgressBar::_notification(int p_what) {
}

float end = start + direction * val;
pts.append(start);
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) {
pts.append(corners[i]);
}
pts.append(from);
for (float corner = Math::floor(from * 4 + 0.5) * 0.25 + 0.125; corner < to; corner += 0.25) {
pts.append(corner);
}
pts.sort();
pts.append(to);

Vector<Point2> uvs;
Vector<Point2> points;
uvs.push_back(get_relative_center());
Expand All @@ -492,6 +489,8 @@ void TextureProgressBar::_notification(int p_what) {
colors.push_back(tint_progress);
draw_polygon(points, colors, uvs, progress);
}

// Draw a reference cross.
if (Engine::get_singleton()->is_editor_hint()) {
Point2 p;

Expand Down