From 8fe41a86734d87463fabc55e472c0574e823e84a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 21 Feb 2020 14:29:34 +0100 Subject: [PATCH] [python/modkandinsky] fillRect accepts negative width and height --- python/port/mod/kandinsky/modkandinsky.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/python/port/mod/kandinsky/modkandinsky.cpp b/python/port/mod/kandinsky/modkandinsky.cpp index c9579236b..27b7ec5b1 100644 --- a/python/port/mod/kandinsky/modkandinsky.cpp +++ b/python/port/mod/kandinsky/modkandinsky.cpp @@ -85,13 +85,21 @@ mp_obj_t modkandinsky_draw_string(size_t n_args, const mp_obj_t * args) { } mp_obj_t modkandinsky_fill_rect(size_t n_args, const mp_obj_t * args) { - KDRect rect( - mp_obj_get_int(args[0]), - mp_obj_get_int(args[1]), - mp_obj_get_int(args[2]), - mp_obj_get_int(args[3]) - ); + mp_int_t x = mp_obj_get_int(args[0]); + mp_int_t y = mp_obj_get_int(args[1]); + mp_int_t width = mp_obj_get_int(args[2]); + mp_int_t height = mp_obj_get_int(args[3]); + if (width < 0) { + width = -width; + x = x - width; + } + if (height < 0) { + height = -height; + y = y - height; + } + KDRect rect(x, y, width, height); KDColor color = ColorForTuple(args[4]); + MicroPython::ExecutionEnvironment::currentExecutionEnvironment()->displaySandbox(); KDIonContext::sharedContext()->fillRect(rect, color); // Cf comment on modkandinsky_draw_string