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 a886d49565
commit a2171dad4a
2 changed files with 58 additions and 21 deletions

View File

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