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

Added border_radius keyword for draw.rect and drawing of one circle quadrant, fixed bounding rects #1494

Merged
merged 9 commits into from
Nov 14, 2019
Binary file modified docs/reST/ref/code_examples/draw_module_example.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 13 additions & 2 deletions docs/reST/ref/code_examples/draw_module_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@

# Draw a solid rectangle
pygame.draw.rect(screen, BLACK, [150, 10, 50, 20])


# Draw a rectangle with rounded corners
pygame.draw.rect(screen, GREEN, [115, 210, 70, 40], 10, border_radius=15)
pygame.draw.rect(screen, RED, [135, 260, 50, 30], 0, border_radius=10, border_top_left_radius=0,
border_bottom_right_radius=15)

# Draw an ellipse outline, using a rectangle as the outside boundaries
pygame.draw.ellipse(screen, RED, [225, 10, 50, 20], 2)

Expand All @@ -74,7 +79,13 @@

# Draw a circle
pygame.draw.circle(screen, BLUE, [60, 250], 40)


# Draw only one circle quadrant
pygame.draw.circle(screen, BLUE, [250, 250], 40, 0, draw_top_right=True)
pygame.draw.circle(screen, RED, [250, 250], 40, 30, draw_top_left=True)
pygame.draw.circle(screen, GREEN, [250, 250], 40, 20, draw_bottom_left=True)
pygame.draw.circle(screen, BLACK, [250, 250], 40, 10, draw_bottom_right=True)

# Go ahead and update the screen with what we've drawn.
# This MUST happen after all the other drawing commands.
pygame.display.flip()
Expand Down
31 changes: 29 additions & 2 deletions docs/reST/ref/draw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object around the draw calls (see :func:`pygame.Surface.lock` and

| :sl:`draw a rectangle`
| :sg:`rect(surface, color, rect) -> Rect`
| :sg:`rect(surface, color, rect, width=0) -> Rect`
| :sg:`rect(surface, color, rect, width=0, border_radius=0, border_radius=-1, border_top_left_radius=-1, border_top_right_radius=-1, border_bottom_left_radius=-1) -> Rect`

Draws a rectangle on the given surface.

Expand All @@ -70,6 +70,22 @@ object around the draw calls (see :func:`pygame.Surface.lock` and
outside the original boundary of the rect. For more details on
how the thickness for edge lines grow, refer to the ``width`` notes
of the :func:`pygame.draw.line` function.
:param int border_radius: (optional) used for drawing rectangle with rounded corners.
The supported range is [0, min(height, width) / 2], with 0 representing a rectangle
without rounded corners.
:param int border_top_left_radius: (optional) used for setting the value of top left
border. If you don't set this value, it will use the border_radius value.
:param int border_top_right_radius: (optional) used for setting the value of top right
border. If you don't set this value, it will use the border_radius value.
:param int border_bottom_left_radius: (optional) used for setting the value of bottom left
border. If you don't set this value, it will use the border_radius value.
:param int border_bottom_right_radius: (optional) used for setting the value of bottom right
border. If you don't set this value, it will use the border_radius value.

| if ``border_radius < 1`` it will draw rectangle without rounded corners
| if any of border radii has the value ``< 0`` it will use value of the border_radius
| If sum of radii on the same side of the rectangle is greater than the rect size the radii
| will get scaled

:returns: a rect bounding the changed pixels, if nothing is drawn the
bounding rect's position will be the position of the given ``rect``
Expand Down Expand Up @@ -137,7 +153,7 @@ object around the draw calls (see :func:`pygame.Surface.lock` and

| :sl:`draw a circle`
| :sg:`circle(surface, color, center, radius) -> Rect`
| :sg:`circle(surface, color, center, radius, width=0) -> Rect`
| :sg:`circle(surface, color, center, radius, width=0, draw_top_right=None, draw_top_left=None, draw_bottom_left=None, draw_bottom_right=None) -> Rect`

Draws a circle on the given surface.

Expand All @@ -163,6 +179,17 @@ object around the draw calls (see :func:`pygame.Surface.lock` and
.. note::
When using ``width`` values ``> 1``, the edge lines will only grow
inward.
:param bool draw_top_right: (optional) if this is set to True it than the top right corner
of the circle will be drawn
:param bool draw_top_left: (optional) if this is set to True it than the top left corner
of the circle will be drawn
:param bool draw_bottom_left: (optional) if this is set to True it than the bottom left corner
of the circle will be drawn
:param bool draw_bottom_right: (optional) if this is set to True it than the bottom right corner
of the circle will be drawn

| if any of the draw_circle_part is True than it will draw all circle parts that have the True
| value, otherwise it will draw the entire circle.

:returns: a rect bounding the changed pixels, if nothing is drawn the
bounding rect's position will be the ``center`` parameter value (float
Expand Down
8 changes: 4 additions & 4 deletions src_c/doc/draw_doc.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* Auto generated file: with makeref.py . Docs go in docs/reST/ref/ . */
#define DOC_PYGAMEDRAW "pygame module for drawing shapes"
#define DOC_PYGAMEDRAWRECT "rect(surface, color, rect) -> Rect\nrect(surface, color, rect, width=0) -> Rect\ndraw a rectangle"
#define DOC_PYGAMEDRAWRECT "rect(surface, color, rect) -> Rect\nrect(surface, color, rect, width=0, border_radius=0, border_radius=-1, border_top_left_radius=-1, border_top_right_radius=-1, border_bottom_left_radius=-1) -> Rect\ndraw a rectangle"
#define DOC_PYGAMEDRAWPOLYGON "polygon(surface, color, points) -> Rect\npolygon(surface, color, points, width=0) -> Rect\ndraw a polygon"
#define DOC_PYGAMEDRAWCIRCLE "circle(surface, color, center, radius) -> Rect\ncircle(surface, color, center, radius, width=0) -> Rect\ndraw a circle"
#define DOC_PYGAMEDRAWCIRCLE "circle(surface, color, center, radius) -> Rect\ncircle(surface, color, center, radius, width=0, draw_top_right=None, draw_top_left=None, draw_bottom_left=None, draw_bottom_right=None) -> Rect\ndraw a circle"
#define DOC_PYGAMEDRAWELLIPSE "ellipse(surface, color, rect) -> Rect\nellipse(surface, color, rect, width=0) -> Rect\ndraw an ellipse"
#define DOC_PYGAMEDRAWARC "arc(surface, color, rect, start_angle, stop_angle) -> Rect\narc(surface, color, rect, start_angle, stop_angle, width=1) -> Rect\ndraw an elliptical arc"
#define DOC_PYGAMEDRAWLINE "line(surface, color, start_pos, end_pos, width) -> Rect\nline(surface, color, start_pos, end_pos, width=1) -> Rect\ndraw a straight line"
Expand All @@ -20,7 +20,7 @@ pygame module for drawing shapes

pygame.draw.rect
rect(surface, color, rect) -> Rect
rect(surface, color, rect, width=0) -> Rect
rect(surface, color, rect, width=0, border_radius=0, border_radius=-1, border_top_left_radius=-1, border_top_right_radius=-1, border_bottom_left_radius=-1) -> Rect
draw a rectangle

pygame.draw.polygon
Expand All @@ -30,7 +30,7 @@ draw a polygon

pygame.draw.circle
circle(surface, color, center, radius) -> Rect
circle(surface, color, center, radius, width=0) -> Rect
circle(surface, color, center, radius, width=0, draw_top_right=None, draw_top_left=None, draw_bottom_left=None, draw_bottom_right=None) -> Rect
draw a circle

pygame.draw.ellipse
Expand Down