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

Add Graphics RoundedRectangle #3048

Merged
merged 8 commits into from Jul 7, 2015
Merged

Add Graphics RoundedRectangle #3048

merged 8 commits into from Jul 7, 2015

Conversation

orlovol
Copy link
Contributor

@orlovol orlovol commented Feb 18, 2015

Added a new vertex instruction - RoundedRectangle.
This allows to create rectangles with rounded corners on the canvas, just like Ellipse, Rectangle and such.
Dimensions for each corner can be specified by tuples for elliptical corners, or by numbers for circular corners.
Segments parameter defines number of segments for smoothness of all corners.
Imports and factory register allow to use RoundedRectangle both from code and .kv file.
Basic documentation and commentaries are provided.

Preview:
rounded_rect

@orlovol orlovol changed the title Graphics RoundedRectangle Add Graphics RoundedRectangle Feb 18, 2015
@inclement
Copy link
Member

This looks really nice. Would you be able to add a simple example to the canvas examples folder? If you have it still, the app you used for the screenshot would be fine.

Thanks!

@orlovol
Copy link
Contributor Author

orlovol commented Feb 25, 2015

I've added a similar example, both with kvlang and python syntax.
roundedrect

@orlovol
Copy link
Contributor Author

orlovol commented Feb 26, 2015

Added possibility to set different number of segments for different corners by using list of integers (along with the single integer).
This can be useful in situations, where large figure has one small round corner and one big. To make big corner very round there should be lots of segments, while such amount is not needed for the small one.
Also it allows to cut some of the corners.


# number of vertices for arc, including start & end
theta = (angle_end - angle_start) / segments
tangetial_factor = tan(theta)
Copy link
Member

Choose a reason for hiding this comment

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

Small typo -> should be tangential

@inclement
Copy link
Member

This looks good to me, I think it can be merged, though I've noted a small typo that would be nice to fix.

@orlovol
Copy link
Contributor Author

orlovol commented Mar 21, 2015

@inclement thanks for noticing, i've added a fix.

There's a small issue with current code though:
Very small figures with segments=1 and biggest radius (a rhombus-like figure) look ugly. Opposing corners on vertical and/or horizontal axes seem misaligned.
I have a fix for that, but it involves reducing maximum radius by one, so for a figure of size 100x100, maximum radius would be 49, instead of 50. Therefore, user can draw perfect tiny rhombuses, but slightly imperfect circular figures. However, with adequate radius and number of segments this is insignificant.

I wonder if all these features even must be a part of "rounded" rectangle, perhaps it should just "do one thing well", and leave rhombuses to Mesh?

akshayaurora added a commit that referenced this pull request Jul 7, 2015
@akshayaurora akshayaurora merged commit 2c9d8a1 into kivy:master Jul 7, 2015
@akshayaurora
Copy link
Member

@hey-sancho nice work 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants