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
View File
@@ -241,7 +241,6 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
#endif #endif
public: public:
BitmapBuffer(uint8_t format, uint16_t width, uint16_t height): BitmapBuffer(uint8_t format, uint16_t width, uint16_t height):
BitmapBufferBase<uint16_t>(format, width, height, nullptr), BitmapBufferBase<uint16_t>(format, width, height, nullptr),
dataAllocated(true) dataAllocated(true)
+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_