From 74fa59ebec0d6ac476543fb52e8b83860fb490e7 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Wed, 18 Mar 2020 11:46:04 +0100 Subject: [PATCH] BufferedWindow splitted into OpaqueBufferedWindow and TransparentBufferedWindow --- .../thirdparty/libopenui/src/bufferedwindow.h | 69 +++++++++++++++---- 1 file changed, 54 insertions(+), 15 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/bufferedwindow.h b/radio/src/thirdparty/libopenui/src/bufferedwindow.h index 7a7826f8d..74aa70e24 100644 --- a/radio/src/thirdparty/libopenui/src/bufferedwindow.h +++ b/radio/src/thirdparty/libopenui/src/bufferedwindow.h @@ -22,34 +22,73 @@ #include "window.h" -class BufferedWindow: public Window +template +class BufferedWindow: public T { public: - BufferedWindow(Window * parent, const rect_t & rect): - Window(parent, rect, OPAQUE) - { - } + using T::T; ~BufferedWindow() override { delete bitmap; } - void paint(BitmapBuffer * dc) override + void forcePaint() { - if (!bitmap) { - paintInit(dc); - bitmap = new BitmapBuffer(BMP_RGB565, width(), height()); - bitmap->drawBitmap(0, 0, dc, dc->getOffsetX(), dc->getOffsetY()); - } - else { - dc->drawBitmap(0, 0, bitmap); - } + paintUpdateNeeded = true; + T::invalidate(); } protected: BitmapBuffer * bitmap = nullptr; - virtual void paintInit(BitmapBuffer * dc) = 0; + bool paintUpdateNeeded = false; + virtual void paintUpdate(BitmapBuffer * dc) = 0; +}; + +template +class OpaqueBufferedWindow: public BufferedWindow +{ + public: + using BufferedWindow::BufferedWindow; + + void paint(BitmapBuffer * dc) override + { + if (!this->bitmap) { + this->bitmap = new BitmapBuffer(BMP_RGB565, T::width(), T::height()); + this->paintUpdateNeeded = true; + } + + if (this->paintUpdateNeeded) { + this->paintUpdate(this->bitmap); + this->paintUpdateNeeded = false; + } + + dc->drawBitmap(0, 0, this->bitmap); + } +}; + +template +class TransparentBufferedWindow: public BufferedWindow +{ + public: + using BufferedWindow::BufferedWindow; + + void paint(BitmapBuffer * dc) override + { + if (!BufferedWindow::bitmap) { + this->bitmap = new BitmapBuffer(BMP_RGB565, T::width(), T::height()); + this->paintUpdateNeeded = true; + } + + if (this->paintUpdateNeeded) { + this->paintUpdate(dc); + this->bitmap->drawBitmap(0, 0, dc, dc->getOffsetX(), dc->getOffsetY()); + this->paintUpdateNeeded = false; + } + else { + dc->drawBitmap(0, 0, this->bitmap); + } + } }; #endif // _BUFFERED_WINDOW_H_