CTextBox: add/modify methodes for screen handlings

- split hasChanged() into hasChangedPos(), hasChangedDim()
- add return value bool to enableBackgroundPaint(), enableSaveScreen()
- add clearScreenBuffer(), for unified usage in destructor and functions
- add OnAfterRefresh() as a signal/slot handler, this allows to use
 external methodes as callbacks after painted text


Origin commit data
------------------
Commit: a2171dad4a
Author: Thilo Graf <dbt@novatux.de>
Date: 2015-11-18 (Wed, 18 Nov 2015)

Origin message was:
------------------
CTextBox: add/modify methodes for screen handlings

- split hasChanged() into hasChangedPos(), hasChangedDim()
- add return value bool to enableBackgroundPaint(), enableSaveScreen()
- add clearScreenBuffer(), for unified usage in destructor and functions
- add OnAfterRefresh() as a signal/slot handler, this allows to use
 external methodes as callbacks after painted text
This commit is contained in:
2015-11-18 17:13:43 +01:00
parent 81dbd1d536
commit d5ce36ab27
2 changed files with 58 additions and 21 deletions

View File

@@ -135,7 +135,7 @@ CTextBox::~CTextBox()
//TRACE("[CTextBox] del\r\n"); //TRACE("[CTextBox] del\r\n");
m_cLineArray.clear(); m_cLineArray.clear();
//hide(); //hide();
delete[] m_bgpixbuf; clearScreenBuffer();
} }
void CTextBox::initVar(void) void CTextBox::initVar(void)
@@ -515,10 +515,8 @@ void CTextBox::refreshScroll(void)
//first init is done in initVar() and reinit done in reInitToCompareVar() //first init is done in initVar() and reinit done in reInitToCompareVar()
bool CTextBox::hasChanged(int* x, int* y, int* dx, int* dy) bool CTextBox::hasChanged(int* x, int* y, int* dx, int* dy)
{ {
if ( m_old_x != *x if ( hasChangedPos(x, y)
|| m_old_y != *y || hasChangedDim(dx, dy)
|| m_old_dx != *dx
|| m_old_dy != *dy
|| m_old_textBackgroundColor != m_textBackgroundColor || m_old_textBackgroundColor != m_textBackgroundColor
|| m_old_textColor != m_textColor || m_old_textColor != m_textColor
|| m_old_nBgRadius != m_nBgRadius || m_old_nBgRadius != m_nBgRadius
@@ -528,6 +526,17 @@ bool CTextBox::hasChanged(int* x, int* y, int* dx, int* dy)
} }
return false; return false;
} }
bool CTextBox::hasChangedPos(int* x, int* y)
{
return (m_old_x != *x || m_old_y != *y);
}
bool CTextBox::hasChangedDim(int* dx, int* dy)
{
return (m_old_dx != *dx || m_old_dy != *dy);
}
void CTextBox::reInitToCompareVar(int* x, int* y, int* dx, int* dy) void CTextBox::reInitToCompareVar(int* x, int* y, int* dx, int* dy)
{ {
m_old_x = *x; m_old_x = *x;
@@ -560,13 +569,14 @@ void CTextBox::refreshText(void)
//find changes //find changes
bool has_changed = hasChanged(&ax, &ay, &dx, &dy); bool has_changed = hasChanged(&ax, &ay, &dx, &dy);
//destroy pixel buffer on changed property values //clean up possible screen on any changes
if (has_changed){ if (has_changed && m_bgpixbuf){
if (m_bgpixbuf){ /*TODO/FIXME: in some cases could be required, that we must restore old saved screen. eg. if a text without bg was painted
//TRACE("[CTextBox] %s destroy ol pixel buffer, has changes %d\r\n", __FUNCTION__, __LINE__); * and another text should be painted as next on the same position like current text, but new text will be overpaint and is
delete[] m_bgpixbuf; * not visible. It's currently solvable only with appropriate order of text items
m_bgpixbuf = NULL; */
} frameBuffer->RestoreScreen(m_old_x, m_old_y, m_old_dx, m_old_dy, m_bgpixbuf);
clearScreenBuffer();
} }
//detect corrupt position values //detect corrupt position values
@@ -589,11 +599,7 @@ void CTextBox::refreshText(void)
//Paint Text Background //Paint Text Background
bool allow_paint_bg = (m_old_cText != m_cText || has_changed || m_has_scrolled); bool allow_paint_bg = (m_old_cText != m_cText || has_changed || m_has_scrolled);
if (m_nPaintBackground){ if (m_nPaintBackground){
if (m_bgpixbuf){ clearScreenBuffer();
//TRACE("[CTextBox] %s destroy bg %d\r\n", __FUNCTION__, __LINE__);
delete[] m_bgpixbuf;
m_bgpixbuf = NULL;
}
if (allow_paint_bg){ if (allow_paint_bg){
//TRACE("[CTextBox] %s paint bg %d\r\n", __FUNCTION__, __LINE__); //TRACE("[CTextBox] %s paint bg %d\r\n", __FUNCTION__, __LINE__);
frameBuffer->paintBoxRel(ax, ay, dx, dy, m_textBackgroundColor, m_nBgRadius, m_nBgRadiusType); frameBuffer->paintBoxRel(ax, ay, dx, dy, m_textBackgroundColor, m_nBgRadius, m_nBgRadiusType);
@@ -713,6 +719,7 @@ void CTextBox::refresh(void)
//Paint text //Paint text
refreshScroll(); refreshScroll();
refreshText(); refreshText();
OnAfterRefresh();
} }
@@ -772,3 +779,28 @@ void CTextBox::hide (void)
frameBuffer = NULL; frameBuffer = NULL;
} }
bool CTextBox::clearScreenBuffer()
{
if(m_bgpixbuf){
//TRACE("[CTextBox] %s destroy bg %d\r\n", __FUNCTION__, __LINE__);
delete[] m_bgpixbuf;
m_bgpixbuf = NULL;
return true;
}
return false;
}
bool CTextBox::enableSaveScreen(bool mode)
{
if (m_SaveScreen == mode)
return false;
if (!m_SaveScreen || m_SaveScreen != mode)
clearScreenBuffer();
m_SaveScreen = mode;
return true;
}

View File

@@ -62,7 +62,7 @@
#include <driver/fb_window.h> #include <driver/fb_window.h>
#include <gui/color.h> #include <gui/color.h>
#include <gui/customcolor.h> #include <gui/customcolor.h>
#include <sigc++/signal.h>
#define TRACE printf #define TRACE printf
#define TRACE_1 printf #define TRACE_1 printf
@@ -81,7 +81,7 @@ class CBox
int iHeight; int iHeight;
}; };
class CTextBox class CTextBox : public sigc::trackable
{ {
public: public:
/* Variables */ /* Variables */
@@ -110,6 +110,8 @@ class CTextBox
void reSizeMainFrameHeight(int maxTextHeight); void reSizeMainFrameHeight(int maxTextHeight);
bool hasChanged(int* x, int* y, int* dx, int* dy); bool hasChanged(int* x, int* y, int* dx, int* dy);
bool hasChangedPos(int* x, int* y);
bool hasChangedDim(int* dx, int* dy);
void reInitToCompareVar(int* x, int* y, int* dx, int* dy); void reInitToCompareVar(int* x, int* y, int* dx, int* dy);
/* Variables */ /* Variables */
@@ -179,8 +181,9 @@ class CTextBox
void refresh(void); void refresh(void);
void scrollPageDown(const int pages); void scrollPageDown(const int pages);
void scrollPageUp(const int pages); void scrollPageUp(const int pages);
void enableBackgroundPaint(bool mode = true){m_nPaintBackground = mode;}; void enableBackgroundPaint(bool mode = true){m_nPaintBackground = mode;}
void enableSaveScreen(bool mode = true){m_SaveScreen = mode;}; //enable screen saving behind chars, is required for transparent text paint, returns true if mode was changed
bool enableSaveScreen(bool mode = true);
bool setText(const std::string* newText, int max_width = 0, bool force_repaint = true); bool setText(const std::string* newText, int max_width = 0, bool force_repaint = true);
void setTextColor(fb_pixel_t color_text){ m_textColor = color_text;}; void setTextColor(fb_pixel_t color_text){ m_textColor = color_text;};
void setBackGroundRadius(const int radius, const int type = CORNER_ALL){m_nBgRadius = radius; m_nBgRadiusType = type;}; void setBackGroundRadius(const int radius, const int type = CORNER_ALL){m_nBgRadius = radius; m_nBgRadiusType = type;};
@@ -207,6 +210,8 @@ class CTextBox
inline int getTextMode() {return m_nMode;}; inline int getTextMode() {return m_nMode;};
void paint (void); void paint (void);
void hide (void); void hide (void);
bool clearScreenBuffer();
sigc::signal<void> OnAfterRefresh;
}; };
#endif // !defined(AFX_TEXTBOX_H__208DED01_ABEC_491C_A632_5B21057DC5D8__INCLUDED_) #endif // !defined(AFX_TEXTBOX_H__208DED01_ABEC_491C_A632_5B21057DC5D8__INCLUDED_)