Skip to content

Commit

Permalink
Merge pull request #78 from benburrill/main
Browse files Browse the repository at this point in the history
  • Loading branch information
djhoese authored Apr 13, 2023
2 parents aa0d0e8 + 5671e66 commit 9f29836
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
44 changes: 43 additions & 1 deletion aggdraw.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
#include "agg_conv_stroke.h"
#include "agg_conv_transform.h"
#include "agg_ellipse.h"
#include "agg_rounded_rect.h"
#if defined(HAVE_FREETYPE2)
#include "agg_font_freetype.h"
#endif
Expand Down Expand Up @@ -1314,7 +1315,8 @@ const char *draw_rectangle_doc = "Draw a rectangle.\n"
"Parameters\n"
"----------\n"
"xy : iterable\n"
" A Python sequence (x, y, x, y, …).\n"
" A 4-element Python sequence (x, y, x, y), with the\n"
" upper left corner given first.\n"
"pen : Pen\n"
" Optional pen object created by the `Pen` factory.\n"
"brush : Brush\n"
Expand Down Expand Up @@ -1343,6 +1345,45 @@ draw_rectangle(DrawObject* self, PyObject* args)
return Py_None;
}

const char *draw_rounded_rectangle_doc = "Draw a rounded rectangle.\n"
"\n"
"If a brush is given, it is used to fill the rounded rectangle.\n"
"If a pen is given, it is used to draw an outline around the rounded rectangle.\n"
"Either one (or both) can be left out.\n"
"\n"
"Parameters\n"
"----------\n"
"xy : iterable\n"
" A 4-element Python sequence (x, y, x, y), with the\n"
" upper left corner given first.\n"
"radius : float\n"
" The corner radius\n"
"pen : Pen\n"
" Optional pen object created by the `Pen` factory.\n"
"brush : Brush\n"
" Optional brush object created by the `Brush` factory.\n";

static PyObject*
draw_rounded_rectangle(DrawObject* self, PyObject* args)
{
float x0, y0, x1, y1, r;
PyObject* brush = NULL;
PyObject* pen = NULL;
if (!PyArg_ParseTuple(args, "(ffff)f|OO:rounded_rectangle",
&x0, &y0, &x1, &y1, &r, &brush, &pen))
return NULL;

agg::path_storage path;
agg::rounded_rect rr(x0, y0, x1, y1, r);
rr.approximation_scale(1);
path.concat_path(rr);

self->draw->draw(path, pen, brush);

Py_INCREF(Py_None);
return Py_None;
}

const char *draw_path_doc = "Draw the given path.\n"
"\n"
"If a brush is given, it is used to fill the path.\n"
Expand Down Expand Up @@ -1738,6 +1779,7 @@ static PyMethodDef draw_methods[] = {
{"line", (PyCFunction) draw_line, METH_VARARGS, draw_line_doc},
{"polygon", (PyCFunction) draw_polygon, METH_VARARGS, draw_polygon_doc},
{"rectangle", (PyCFunction) draw_rectangle, METH_VARARGS, draw_rectangle_doc},
{"rounded_rectangle", (PyCFunction) draw_rounded_rectangle, METH_VARARGS, draw_rounded_rectangle_doc},

#if defined(HAVE_FREETYPE2)
{"text", (PyCFunction) draw_text, METH_VARARGS, draw_text_doc},
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def _get_freetype_with_pkgconfig():
"agg/src/agg_arc.cpp",
"agg/src/agg_bezier_arc.cpp",
"agg/src/agg_curves.cpp",
"agg/src/agg_rounded_rect.cpp",
"agg/src/agg_trans_affine.cpp",
"agg/src/agg_vcgen_contour.cpp",
# "agg2/src/agg_vcgen_dash.cpp",
Expand Down

0 comments on commit 9f29836

Please sign in to comment.