New BufferedWindow class for avoiding redrawing a window which doesn't need

This commit is contained in:
Bertrand Songis
2020-03-05 23:07:17 +01:00
parent 4e47630eec
commit 94c6ab1ddd
2 changed files with 56 additions and 2 deletions
+1 -2
View File
@@ -241,7 +241,6 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
#endif
public:
BitmapBuffer(uint8_t format, uint16_t width, uint16_t height):
BitmapBufferBase<uint16_t>(format, width, height, nullptr),
dataAllocated(true)
@@ -390,7 +389,7 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
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<class T>
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;
+55
View File
@@ -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_