-
-
Notifications
You must be signed in to change notification settings - Fork 168
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 round rect with negative values #2303
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -972,9 +972,15 @@ rect(PyObject *self, PyObject *args, PyObject *kwargs) | |||||||
rect->y += rect->h; | ||||||||
rect->h = -rect->h; | ||||||||
} | ||||||||
// Ignore negative values | ||||||||
radius = MAX(radius, 0); | ||||||||
top_left_radius = MAX(top_left_radius, 0); | ||||||||
top_right_radius = MAX(top_right_radius, 0); | ||||||||
bottom_left_radius = MAX(bottom_left_radius, 0); | ||||||||
bottom_right_radius = MAX(bottom_right_radius, 0); | ||||||||
|
||||||||
if (width > rect->w / 2 || width > rect->h / 2) { | ||||||||
width = MAX(rect->w / 2, rect->h / 2); | ||||||||
width = 0; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how this change is helping fix the issue, it looks like it will change behaviour against what is documented There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't do much. I do it just because of this line Line 2497 in 2e864cd
Line 2497 in 2e864cd
Line 2525 in 2e864cd
|
||||||||
} | ||||||||
|
||||||||
draw_round_rect(surf, rect->x, rect->y, rect->x + rect->w - 1, | ||||||||
|
@@ -2472,13 +2478,13 @@ draw_round_rect(SDL_Surface *surf, int x1, int y1, int x2, int y2, int radius, | |||||||
{ | ||||||||
int pts[16], i; | ||||||||
float q_top, q_left, q_bottom, q_right, f; | ||||||||
if (top_left < 0) | ||||||||
if (!top_left) | ||||||||
top_left = radius; | ||||||||
if (top_right < 0) | ||||||||
if (!top_right) | ||||||||
top_right = radius; | ||||||||
if (bottom_left < 0) | ||||||||
if (!bottom_left) | ||||||||
bottom_left = radius; | ||||||||
if (bottom_right < 0) | ||||||||
if (!bottom_right) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I understand from the docs if any of these values are 0, the corner should have no rounded, and if the value is negative (default) it should "inherit" radius. This fix seems to be breaking whatever is documented in my understand, correct me if I'm missing something There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait a second, you are probably right. Gonna check tomorrow. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. He is right. This way a I could imagine this breaking usage if somebody used the popular GUI button pattern of three rounded corners (set via |
||||||||
bottom_right = radius; | ||||||||
if ((top_left + top_right) > (x2 - x1 + 1) || | ||||||||
(bottom_left + bottom_right) > (x2 - x1 + 1) || | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of simply ignoring negative values here, we could raise an error if this is negative instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That could be another solution indeed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
silently clamping it to 0 vs raising an error
I'm not sure which is preferable when using the code. I tend to be against silent things. Make is explicit, not implicit.