Browse Source

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 <jim.mussared@gmail.com>
pull/9026/head
Jim Mussared 2 years ago
committed by Damien George
parent
commit
127b340438
  1. 10
      docs/library/framebuf.rst
  2. 14
      extmod/modframebuf.c

10
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
------------

14
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;

Loading…
Cancel
Save