diff options
author | anbr <vdr07@deltab.de> | 2014-05-04 12:03:11 +0200 |
---|---|---|
committer | anbr <vdr07@deltab.de> | 2014-05-04 12:03:11 +0200 |
commit | 1972932a11b837966abfb867cde6adaec3c96008 (patch) | |
tree | d1e72e8975d4da9475c132d4ff8338172d66054d | |
parent | 3d87cc0b6a062a39b9385f33bdec88ee25967776 (diff) | |
download | vdr-plugin-targavfd-1972932a11b837966abfb867cde6adaec3c96008.tar.gz vdr-plugin-targavfd-1972932a11b837966abfb867cde6adaec3c96008.tar.bz2 |
Refactoring draw text - scroll routine
-rw-r--r-- | vfd.c | 55 | ||||
-rw-r--r-- | vfd.h | 9 | ||||
-rw-r--r-- | watch.c | 95 | ||||
-rw-r--r-- | watch.h | 3 |
4 files changed, 72 insertions, 90 deletions
@@ -270,6 +270,10 @@ cVFD::cVFD() lastIconState = 0; framebuf = NULL; backingstore = NULL; + + m_nScrollOffset = -1; + m_bScrollBackward = false; + m_bScrollNeeded = false; } cVFD::~cVFD() { @@ -474,6 +478,57 @@ int cVFD::DrawTextEclipsed(int x, int y, const char* string, int nMaxWidth /* = return w; } +void cVFD::RestartScrolled() { + m_nScrollOffset = 0; + m_bScrollBackward = false; + m_bScrollNeeded = true; +} + +int cVFD::DrawTextScrolled(int x, int y, const char* string, bool bCenter) +{ + int w = pFont->Width(string); + int nAlign = 0; + if(bCenter) { + nAlign = (this->Width() - w) / 2; + if(nAlign < 0) { + nAlign = 0; + } + } + nAlign += x; + int iRet = this->DrawText(nAlign - m_nScrollOffset,y, string); + if((nAlign + (w - m_nScrollOffset)) == iRet) + iRet = 0; // Text fits into screen + else + iRet = 1; // Text large then screen + + if(m_bScrollNeeded) { + switch(iRet) { + case 0: + if(m_nScrollOffset <= 0) { + m_nScrollOffset = 0; + m_bScrollBackward = false; + m_bScrollNeeded = false; + break; //Fit to screen + } + m_bScrollBackward = true; + case 2: + case 1: + if(m_bScrollBackward) m_nScrollOffset -= 2; + else m_nScrollOffset += 2; + if(m_nScrollOffset >= 0) { + break; + } + case -1: + m_nScrollOffset = 0; + m_bScrollBackward = false; + m_bScrollNeeded = false; + break; + } + } + return iRet; +} + + /** * Height of framebuffer from current device. */ @@ -74,6 +74,10 @@ class cVFD : public cVFDQueue { unsigned int lastIconState; unsigned int m_iSizeYb; + int m_nScrollOffset; + bool m_bScrollBackward; + bool m_bScrollNeeded; + protected: cVFDFont* pFont; @@ -91,6 +95,11 @@ public: void clear (); int DrawText(int x, int y, const char* string, int nMaxWidth = 1024); int DrawTextEclipsed(int x, int y, const char* string, int nMaxWidth = 1024); + + int DrawTextScrolled(int x, int y, const char* string, bool bCenter); + inline bool NeedScrolled() const { return m_nScrollOffset > 0 || m_bScrollBackward; }; + void RestartScrolled(); + int Height() const; int Width() const; bool Rectangle(int x1, int y1, int x2, int y2, bool filled); @@ -69,10 +69,6 @@ cVFDWatch::cVFDWatch() currentTime = NULL; m_eWatchMode = eLiveTV; - - m_nScrollOffset = -1; - m_bScrollBackward = false; - m_bScrollNeeded = false; } cVFDWatch::~cVFDWatch() @@ -414,53 +410,16 @@ bool cVFDWatch::RenderScreenSinglePage(bool bReDraw) { if(bForce) { - m_nScrollOffset = 0; - m_bScrollBackward = false; - m_bScrollNeeded = true; + this->RestartScrolled(); } - if(bForce || bReDraw || m_nScrollOffset > 0 || m_bScrollBackward) { + if(bForce || bReDraw || this->NeedScrolled()) { this->clear(); if(scRender) { - - int iRet = -1; - int w = pFont->Width(*scRender); if(theSetup.m_nRenderMode == eRenderMode_DualLine) { - iRet = this->DrawText(0 - m_nScrollOffset,pFont->Height(), *scRender); - if((w - m_nScrollOffset) == iRet) - iRet = 0; // Text fits into screen - else - iRet = 1; // Text large then screen + this->DrawTextScrolled(0,pFont->Height(), *scRender, false); } else { int nTop = (theSetup.m_cHeight - pFont->Height())/2; - iRet = this->DrawText(0 - m_nScrollOffset,nTop<0?0:nTop, *scRender); - if((w - m_nScrollOffset) == iRet) - iRet = 0; // Text fits into screen - else - iRet = 1; // Text large then screen - } - if(m_bScrollNeeded) { - switch(iRet) { - case 0: - if(m_nScrollOffset <= 0) { - m_nScrollOffset = 0; - m_bScrollBackward = false; - m_bScrollNeeded = false; - break; //Fit to screen - } - m_bScrollBackward = true; - case 2: - case 1: - if(m_bScrollBackward) m_nScrollOffset -= 2; - else m_nScrollOffset += 2; - if(m_nScrollOffset >= 0) { - break; - } - case -1: - m_nScrollOffset = 0; - m_bScrollBackward = false; - m_bScrollNeeded = false; - break; - } + this->DrawTextScrolled(0,nTop<0?0:nTop, *scRender, false); } } @@ -538,50 +497,13 @@ bool cVFDWatch::RenderScreenPages(bool bReDraw, unsigned int& nPage, unsigned in bool cVFDWatch::RenderText(bool bForce, bool bReDraw, cString* scText) { if(bForce) { - m_nScrollOffset = 0; - m_bScrollBackward = false; - m_bScrollNeeded = true; + this->RestartScrolled(); } - if(bForce || bReDraw || m_nScrollOffset > 0 || m_bScrollBackward) { + if(bForce || bReDraw || this->NeedScrolled()) { this->clear(); if(scText) { - int iRet = -1; int nTop = (theSetup.m_cHeight - pFont->Height())/2; - int w = pFont->Width(*scText); - int nAlign = (this->Width() - w) / 2; - if(nAlign < 0) { - nAlign = 0; - } - iRet = this->DrawText(nAlign - m_nScrollOffset,nTop<0?0:nTop, *scText); - if((nAlign + (w - m_nScrollOffset)) == iRet) - iRet = 0; // Text fits into screen - else - iRet = 1; // Text large then screen - - if(m_bScrollNeeded) { - switch(iRet) { - case 0: - if(m_nScrollOffset <= 0) { - m_nScrollOffset = 0; - m_bScrollBackward = false; - m_bScrollNeeded = false; - break; //Fit to screen - } - m_bScrollBackward = true; - case 2: - case 1: - if(m_bScrollBackward) m_nScrollOffset -= 2; - else m_nScrollOffset += 2; - if(m_nScrollOffset >= 0) { - break; - } - case -1: - m_nScrollOffset = 0; - m_bScrollBackward = false; - m_bScrollNeeded = false; - break; - } - } + this->DrawTextScrolled(0,nTop<0?0:nTop,*scText,true); } m_bUpdateScreen = false; @@ -911,8 +833,7 @@ void cVFDWatch::Channel(int ChannelNumber) } m_eWatchMode = eLiveTV; m_bUpdateScreen = true; - m_nScrollOffset = 0; - m_bScrollBackward = false; + this->RestartScrolled(); } bool cVFDWatch::Program() { @@ -54,9 +54,6 @@ private: eWatchMode m_eWatchMode; - int m_nScrollOffset; - bool m_bScrollBackward; - bool m_bScrollNeeded; bool m_bUpdateScreen; int m_nCardIsRecording[MAXDEVICES]; |