Skip to content

Commit

Permalink
extmod/modframebuf: Add fill argument to rect().
Browse files Browse the repository at this point in the history
We plan to add `ellipse` and `poly` methods, but rather than having to
implement a `fill_xyz` version of each, we can make them take an optional
fill argument. This commit add this to `rect` as a starting point.

Signed-off-by: Jim Mussared <[email protected]>
  • Loading branch information
jimmo authored and dpgeorge committed Aug 19, 2022
1 parent af1f167 commit 127b340
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 5 additions & 5 deletions docs/library/framebuf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ The following methods draw shapes onto the FrameBuffer.
methods draw horizontal and vertical lines respectively up to
a given length.

.. method:: FrameBuffer.rect(x, y, w, h, c)
.. method:: FrameBuffer.fill_rect(x, y, w, h, c)
.. method:: FrameBuffer.rect(x, y, w, h, c[, f])

Draw a rectangle at the given location, size and color. The `rect`
method draws only a 1 pixel outline whereas the `fill_rect` method
draws both the outline and interior.
Draw a rectangle at the given location, size and color.

The optional *f* parameter can be set to ``True`` to fill the rectangle.
Otherwise just a one pixel outline is drawn.

Drawing text
------------
Expand Down
14 changes: 9 additions & 5 deletions extmod/modframebuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,17 @@ STATIC mp_obj_t framebuf_rect(size_t n_args, const mp_obj_t *args_in) {
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args_in[0]);
mp_int_t args[5]; // x, y, w, h, col
framebuf_args(args_in, args, 5);
fill_rect(self, args[0], args[1], args[2], 1, args[4]);
fill_rect(self, args[0], args[1] + args[3] - 1, args[2], 1, args[4]);
fill_rect(self, args[0], args[1], 1, args[3], args[4]);
fill_rect(self, args[0] + args[2] - 1, args[1], 1, args[3], args[4]);
if (n_args > 6 && mp_obj_is_true(args_in[6])) {
fill_rect(self, args[0], args[1], args[2], args[3], args[4]);
} else {
fill_rect(self, args[0], args[1], args[2], 1, args[4]);
fill_rect(self, args[0], args[1] + args[3] - 1, args[2], 1, args[4]);
fill_rect(self, args[0], args[1], 1, args[3], args[4]);
fill_rect(self, args[0] + args[2] - 1, args[1], 1, args[3], args[4]);
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_rect_obj, 6, 6, framebuf_rect);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_rect_obj, 6, 7, framebuf_rect);

STATIC void line(const mp_obj_framebuf_t *fb, mp_int_t x1, mp_int_t y1, mp_int_t x2, mp_int_t y2, mp_int_t col) {
mp_int_t dx = x2 - x1;
Expand Down

0 comments on commit 127b340

Please sign in to comment.