diff --git a/docs/library/framebuf.rst b/docs/library/framebuf.rst index 098ada8153..7024616653 100644 --- a/docs/library/framebuf.rst +++ b/docs/library/framebuf.rst @@ -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 ------------ diff --git a/extmod/modframebuf.c b/extmod/modframebuf.c index fe32e44a26..590bd08545 100644 --- a/extmod/modframebuf.c +++ b/extmod/modframebuf.c @@ -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;