#include "textscroller.h" void cTextScroll::SetText(const char *text, cRect position, tColor colorFg, tColor colorBg, cFont *font, tColor colorExtraTextFg) { if( Osd == NULL ) return; Text = text; Font = font; Position = position; ColorFg = colorFg; ColorBg = colorBg; ColorExtraTextFg = colorExtraTextFg; cRect drawPort(0, 0, font->Width(Text.c_str()), Position.Height()); if( Osd && Pixmap ) Osd->DestroyPixmap(Pixmap); Pixmap = CreatePixmap(Layer, Position, drawPort); dsyslog("skinflatplus: TextScrollerPixmap left: %d top: %d width: %d height: %d", Position.Left(), Position.Top(), Position.Width(), Position.Height()); dsyslog("skinflatplus: TextScrollerPixmap drawPort left: %d top: %d width: %d height: %d", drawPort.Left(), drawPort.Top(), drawPort.Width(), drawPort.Height()); Pixmap->Fill( colorBg ); Draw(); } cPixmap *cTextScroll::CreatePixmap(int Layer, const cRect &ViewPort, const cRect &DrawPort) { cSize maxPixmapSize = Osd->MaxPixmapSize(); cRect SafeDrawPort( DrawPort.X(), DrawPort.Y(), DrawPort.Width(), DrawPort.Height()); if( DrawPort.Width() > maxPixmapSize.Width() ) { dsyslog("Try to create Pixmap (%d x %d) > MaxPixmapSize (%d x %d)-> cut Pixmap to MaxPixmapSize", DrawPort.Width(), DrawPort.Height(), maxPixmapSize.Width(), maxPixmapSize.Height() ); SafeDrawPort.SetWidth(maxPixmapSize.Width()); } if( DrawPort.Height() > maxPixmapSize.Height() ) { dsyslog("Try to create Pixmap (%d x %d) > MaxPixmapSize (%d x %d)-> cut Pixmap to MaxPixmapSize", DrawPort.Width(), DrawPort.Height(), maxPixmapSize.Width(), maxPixmapSize.Height() ); SafeDrawPort.SetHeight(maxPixmapSize.Height()); } return Osd->CreatePixmap(Layer, ViewPort, SafeDrawPort); } void cTextScroll::UpdateViewPortWidth(int w) { cRect viewPort = Pixmap->ViewPort(); viewPort.SetWidth(viewPort.Width() - w); Pixmap->SetViewPort(viewPort); } void cTextScroll::Reset(void) { if( !Pixmap ) return; Pixmap->SetDrawPortPoint(cPoint(0, 0)); waitSteps = WAITSTEPS; } void cTextScroll::Draw(void) { if( !Pixmap ) return; if( ColorExtraTextFg ) { std::string tilde = Text; size_t found = tilde.find(" ~ "); size_t found2 = tilde.find("~"); if( found != std::string::npos ) { std::string first = tilde.substr(0, found); std::string second = tilde.substr(found +2, tilde.length() ); Pixmap->DrawText(cPoint(0, 0), first.c_str(), ColorFg, ColorBg, Font); int l = Font->Width( first.c_str() ); Pixmap->DrawText(cPoint(l, 0), second.c_str(), ColorExtraTextFg, ColorBg, Font); } else if ( found2 != std::string::npos ) { std::string first = tilde.substr(0, found2); std::string second = tilde.substr(found2 +1, tilde.length() ); Pixmap->DrawText(cPoint(0, 0), first.c_str(), ColorFg, ColorBg, Font); int l = Font->Width( first.c_str() ); l += Font->Width("X"); Pixmap->DrawText(cPoint(l, 0), second.c_str(), ColorExtraTextFg, ColorBg, Font); } else Pixmap->DrawText(cPoint(0, 0), Text.c_str(), ColorFg, ColorBg, Font); } else { Pixmap->DrawText(cPoint(0, 0), Text.c_str(), ColorFg, ColorBg, Font); } } void cTextScroll::DoStep(void) { if( !Pixmap ) return; // wait at the beginning for better read if( waitSteps > 0 ) { waitSteps--; return; } // wait after return to the front if( ResetX ) { ResetX = false; Pixmap->SetDrawPortPoint(cPoint(0, 0)); waitSteps = WAITSTEPS; return; } int drawPortX = Pixmap->DrawPort().X(); if( isReserveStep ) drawPortX += PixelsPerStep; else drawPortX -= PixelsPerStep; int maxX = Pixmap->DrawPort().Width() - Pixmap->ViewPort().Width(); maxX *= -1; if( ScrollType == 0 ) { if( drawPortX <= maxX ) { drawPortX += PixelsPerStep; ResetX = true; waitSteps = WAITSTEPS; } } else if( ScrollType == 1 ) { if( drawPortX <= maxX ) { isReserveStep = true; waitSteps = WAITSTEPS; } else if( drawPortX > 0 ) { isReserveStep = false; waitSteps = WAITSTEPS; } } Pixmap->SetDrawPortPoint(cPoint(drawPortX, 0)); } cTextScrollers::cTextScrollers() { Layer = 2; } cTextScrollers::~cTextScrollers() { } void cTextScrollers::Clear(void) { Cancel(-1); while( Active() ) cCondWait::SleepMs(10); std::vector::iterator it; for( it = Scrollers.begin(); it != Scrollers.end(); it++) { delete *it; } Scrollers.clear(); } void cTextScrollers::AddScroller(const char *text, cRect position, tColor colorFg, tColor colorBg, cFont *font, tColor ColorExtraTextFg) { Cancel(-1); while( Active() ) cCondWait::SleepMs(10); Scrollers.push_back( new cTextScroll(Osd, scrollType, scrollStep, (int)((double)WAITDELAY / (double)scrollDelay), Layer) ); Scrollers.back()->SetText(text, position, colorFg, colorBg, font, ColorExtraTextFg); StartScrolling(); } void cTextScrollers::UpdateViewPortWidth(int w) { std::vector::iterator it; for( it = Scrollers.begin(); it != Scrollers.end(); it++) { cPixmap::Lock(); (*it)->UpdateViewPortWidth(w); cPixmap::Unlock(); } } void cTextScrollers::StartScrolling(void) { if( !Running() && Scrollers.size() > 0 ) { Start(); } } void cTextScrollers::Action(void) { // wait 1 second so the osd is finished for(int i = 0; i < 100 && Running(); i++ ) { cCondWait::SleepMs(10); } if( !Running() ) return; std::vector::iterator it; for( it = Scrollers.begin(); it != Scrollers.end(); it++) { if( !Running() ) return; cPixmap::Lock(); (*it)->Reset(); cPixmap::Unlock(); } while( Running() ) { if (Running()) cCondWait::SleepMs(scrollDelay); std::vector::iterator it; for( it = Scrollers.begin(); it != Scrollers.end(); it++) { if( !Running() ) return; cPixmap::Lock(); (*it)->DoStep(); cPixmap::Unlock(); } if( Running() ) Osd->Flush(); } }