From 895b781629671471d1c0dab803d9d3e6a14d2643 Mon Sep 17 00:00:00 2001 From: "M. Liebmann" Date: Fri, 27 Nov 2015 12:11:54 +0100 Subject: [PATCH] CFBWindow: Add saveScreen() & restoreScreen() for using... ...in external plugins --- src/driver/fb_window.cpp | 24 ++++++++++++++++++------ src/driver/fb_window.h | 3 +++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/driver/fb_window.cpp b/src/driver/fb_window.cpp index 8d6ddfa23..306243914 100644 --- a/src/driver/fb_window.cpp +++ b/src/driver/fb_window.cpp @@ -38,17 +38,29 @@ CFBWindow::CFBWindow(const int _x, const int _y, const int _dx, const int _dy) dy = _dy; frameBuffer = CFrameBuffer::getInstance(); - Background = new fb_pixel_t [_dx * _dy]; - if (Background != NULL) - frameBuffer->SaveScreen(_x, _y, _dx, _dy, Background); - + Background = saveScreen(_x, _y, _dx, _dy); } CFBWindow::~CFBWindow(void) { if (Background != NULL) - frameBuffer->RestoreScreen(x, y, dx, dy, Background); - delete[] Background; + restoreScreen(x, y, dx, dy, Background, true); +} + +fb_pixel_t* CFBWindow::saveScreen(const int _x, const int _y, const int _dx, const int _dy) +{ + fb_pixel_t* buf = new fb_pixel_t [_dx * _dy]; + if (buf != NULL) + frameBuffer->SaveScreen(_x, _y, _dx, _dy, buf); + return buf; +} + +void CFBWindow::restoreScreen(const int _x, const int _y, const int _dx, const int _dy, fb_pixel_t* buf, bool delBuf) +{ + if (buf != NULL) + frameBuffer->RestoreScreen(_x, _y, _dx, _dy, buf); + if (delBuf) + delete[] buf; } void CFBWindow::paintBoxRel(const int _x, const int _y, const int _dx, const int _dy, const color_t _col, int radius, int type) diff --git a/src/driver/fb_window.h b/src/driver/fb_window.h index 0f9cf8a49..420557a79 100644 --- a/src/driver/fb_window.h +++ b/src/driver/fb_window.h @@ -45,6 +45,9 @@ class CFBWindow void paintBoxRel(const int _x, const int _y, const int _dx, const int _dy, const color_t _col, int radius = 0, int type = 0xF); bool paintIcon(const char * const _filename, const int _x, const int _y, const int _h = 0, const color_t _offset = 1); void RenderString(const font_t _font, const int _x, const int _y, const int _width, const char * const _text, const color_t _color, const int _boxheight = 0, const unsigned int _flags = Font::IS_UTF8); + + fb_pixel_t* saveScreen(const int _x, const int _y, const int _dx, const int _dy); + void restoreScreen(const int _x, const int _y, const int _dx, const int _dy, fb_pixel_t* buf, bool delBuf); }; #endif /* __fb_window_h__ */