Skip to content

Commit 127b340

Browse files
jimmodpgeorge
authored andcommitted
extmod/modframebuf: Add fill argument to rect().
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]>
1 parent af1f167 commit 127b340

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

docs/library/framebuf.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ The following methods draw shapes onto the FrameBuffer.
7777
methods draw horizontal and vertical lines respectively up to
7878
a given length.
7979

80-
.. method:: FrameBuffer.rect(x, y, w, h, c)
81-
.. method:: FrameBuffer.fill_rect(x, y, w, h, c)
80+
.. method:: FrameBuffer.rect(x, y, w, h, c[, f])
8281

83-
Draw a rectangle at the given location, size and color. The `rect`
84-
method draws only a 1 pixel outline whereas the `fill_rect` method
85-
draws both the outline and interior.
82+
Draw a rectangle at the given location, size and color.
83+
84+
The optional *f* parameter can be set to ``True`` to fill the rectangle.
85+
Otherwise just a one pixel outline is drawn.
8686

8787
Drawing text
8888
------------

extmod/modframebuf.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,17 @@ STATIC mp_obj_t framebuf_rect(size_t n_args, const mp_obj_t *args_in) {
384384
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args_in[0]);
385385
mp_int_t args[5]; // x, y, w, h, col
386386
framebuf_args(args_in, args, 5);
387-
fill_rect(self, args[0], args[1], args[2], 1, args[4]);
388-
fill_rect(self, args[0], args[1] + args[3] - 1, args[2], 1, args[4]);
389-
fill_rect(self, args[0], args[1], 1, args[3], args[4]);
390-
fill_rect(self, args[0] + args[2] - 1, args[1], 1, args[3], args[4]);
387+
if (n_args > 6 && mp_obj_is_true(args_in[6])) {
388+
fill_rect(self, args[0], args[1], args[2], args[3], args[4]);
389+
} else {
390+
fill_rect(self, args[0], args[1], args[2], 1, args[4]);
391+
fill_rect(self, args[0], args[1] + args[3] - 1, args[2], 1, args[4]);
392+
fill_rect(self, args[0], args[1], 1, args[3], args[4]);
393+
fill_rect(self, args[0] + args[2] - 1, args[1], 1, args[3], args[4]);
394+
}
391395
return mp_const_none;
392396
}
393-
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_rect_obj, 6, 6, framebuf_rect);
397+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_rect_obj, 6, 7, framebuf_rect);
394398

395399
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) {
396400
mp_int_t dx = x2 - x1;

0 commit comments

Comments
 (0)