From 310355a00b2de6dd86d0e7c2dc9c41e4ad691ceb Mon Sep 17 00:00:00 2001 From: NP v/d Spek Date: Sun, 12 Feb 2023 17:03:53 +0100 Subject: [PATCH] Fix check for empty clipping array (#4421) --- esphome/components/display/display_buffer.cpp | 10 ++-- esphome/components/display/display_buffer.h | 58 ++++++++----------- 2 files changed, 28 insertions(+), 40 deletions(-) diff --git a/esphome/components/display/display_buffer.cpp b/esphome/components/display/display_buffer.cpp index 1b24ca94b9..9fe4137a14 100644 --- a/esphome/components/display/display_buffer.cpp +++ b/esphome/components/display/display_buffer.cpp @@ -16,11 +16,11 @@ const Color COLOR_OFF(0, 0, 0, 0); const Color COLOR_ON(255, 255, 255, 255); void Rect::expand(int16_t horizontal, int16_t vertical) { - if ((*this).is_set() && ((*this).w >= (-2 * horizontal)) && ((*this).h >= (-2 * vertical))) { - (*this).x = (*this).x - horizontal; - (*this).y = (*this).y - vertical; - (*this).w = (*this).w + (2 * horizontal); - (*this).h = (*this).h + (2 * vertical); + if (this->is_set() && (this->w >= (-2 * horizontal)) && (this->h >= (-2 * vertical))) { + this->x = this->x - horizontal; + this->y = this->y - vertical; + this->w = this->w + (2 * horizontal); + this->h = this->h + (2 * vertical); } } diff --git a/esphome/components/display/display_buffer.h b/esphome/components/display/display_buffer.h index 03d64f80d3..3763da8041 100644 --- a/esphome/components/display/display_buffer.h +++ b/esphome/components/display/display_buffer.h @@ -400,60 +400,48 @@ class DisplayBuffer { */ virtual DisplayType get_display_type() = 0; - /// - /// Set the clipping rectangle for further drawing - /// - /// \param[in] rect: Pointer to Rect for clipping (or NULL for entire screen) - /// - /// \return true if success, false if error - /// + /** Set the clipping rectangle for further drawing + * + * @param[in] rect: Pointer to Rect for clipping (or NULL for entire screen) + * + * return true if success, false if error + */ void start_clipping(Rect rect); void start_clipping(int16_t left, int16_t top, int16_t right, int16_t bottom) { start_clipping(Rect(left, top, right - left, bottom - top)); }; - /// - /// Add a rectangular region to the invalidation region - /// - This is usually called when an element has been modified - /// - /// \param[in] rect: Rectangle to add to the invalidation region - /// - /// \return none - /// + /** Add a rectangular region to the invalidation region + * - This is usually called when an element has been modified + * + * @param[in] rect: Rectangle to add to the invalidation region + */ void extend_clipping(Rect rect); void extend_clipping(int16_t left, int16_t top, int16_t right, int16_t bottom) { this->extend_clipping(Rect(left, top, right - left, bottom - top)); }; - /// - /// substract a rectangular region to the invalidation region - /// - This is usually called when an element has been modified - /// - /// \param[in] rect: Rectangle to add to the invalidation region - /// - /// \return none - /// + /** substract a rectangular region to the invalidation region + * - This is usually called when an element has been modified + * + * @param[in] rect: Rectangle to add to the invalidation region + */ void shrink_clipping(Rect rect); void shrink_clipping(uint16_t left, uint16_t top, uint16_t right, uint16_t bottom) { this->shrink_clipping(Rect(left, top, right - left, bottom - top)); }; - /// - /// Reset the invalidation region - /// - /// \return none - /// + /** Reset the invalidation region + */ void end_clipping(); - /// - /// Get the current the clipping rectangle - /// - /// - /// \return rect for active clipping region - /// + /** Get the current the clipping rectangle + * + * return rect for active clipping region + */ Rect get_clipping(); - bool is_clipping() const { return this->clipping_rectangle_.empty(); } + bool is_clipping() const { return !this->clipping_rectangle_.empty(); } protected: void vprintf_(int x, int y, Font *font, Color color, TextAlign align, const char *format, va_list arg);