From 94c6ab1ddd0878b7bb78648c1b76bbc3b94eb69a Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Thu, 5 Mar 2020 23:07:17 +0100 Subject: [PATCH] New BufferedWindow class for avoiding redrawing a window which doesn't need --- .../thirdparty/libopenui/src/bitmapbuffer.h | 3 +- .../thirdparty/libopenui/src/bufferedwindow.h | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 radio/src/thirdparty/libopenui/src/bufferedwindow.h diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.h b/radio/src/thirdparty/libopenui/src/bitmapbuffer.h index f238a312a..0a9a4387a 100755 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.h +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.h @@ -241,7 +241,6 @@ class BitmapBuffer: public BitmapBufferBase #endif public: - BitmapBuffer(uint8_t format, uint16_t width, uint16_t height): BitmapBufferBase(format, width, height, nullptr), dataAllocated(true) @@ -390,7 +389,7 @@ class BitmapBuffer: public BitmapBufferBase coord_t drawNumber(coord_t x, coord_t y, int32_t val, LcdFlags flags = 0, uint8_t len = 0, const char * prefix = nullptr, const char * suffix = nullptr); template - void drawBitmap(coord_t x, coord_t y, const T * bmp, coord_t srcx=0, coord_t srcy=0, coord_t w=0, coord_t h=0, float scale=0) + void drawBitmap(coord_t x, coord_t y, const T * bmp, coord_t srcx = 0, coord_t srcy = 0, coord_t w = 0, coord_t h = 0, float scale = 0) { if (!data || !bmp) return; diff --git a/radio/src/thirdparty/libopenui/src/bufferedwindow.h b/radio/src/thirdparty/libopenui/src/bufferedwindow.h new file mode 100644 index 000000000..7a7826f8d --- /dev/null +++ b/radio/src/thirdparty/libopenui/src/bufferedwindow.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) OpenTX + * + * Source: + * https://github.com/opentx/libopenui + * + * This file is a part of libopenui library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ + +#ifndef _BUFFERED_WINDOW_H_ +#define _BUFFERED_WINDOW_H_ + +#include "window.h" + +class BufferedWindow: public Window +{ + public: + BufferedWindow(Window * parent, const rect_t & rect): + Window(parent, rect, OPAQUE) + { + } + + ~BufferedWindow() override + { + delete bitmap; + } + + void paint(BitmapBuffer * dc) override + { + 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); + } + } + + protected: + BitmapBuffer * bitmap = nullptr; + virtual void paintInit(BitmapBuffer * dc) = 0; +}; + +#endif // _BUFFERED_WINDOW_H_