diff --git a/RetroFE/Source/Graphics/Component/Component.cpp b/RetroFE/Source/Graphics/Component/Component.cpp index 038de5d..8f08dd8 100644 --- a/RetroFE/Source/Graphics/Component/Component.cpp +++ b/RetroFE/Source/Graphics/Component/Component.cpp @@ -144,6 +144,11 @@ bool Component::isIdle() return (currentTweenComplete_ || animationType_ == "idle" || animationType_ == "menuIdle"); } +bool Component::mustRender() +{ + return false; +} + bool Component::isMenuScrolling() { return (!currentTweenComplete_ && animationType_ == "menuScroll"); diff --git a/RetroFE/Source/Graphics/Component/Component.h b/RetroFE/Source/Graphics/Component/Component.h index 42c2506..7d6cad4 100644 --- a/RetroFE/Source/Graphics/Component/Component.h +++ b/RetroFE/Source/Graphics/Component/Component.h @@ -33,6 +33,7 @@ public: virtual void allocateGraphicsMemory(); virtual void deInitializeFonts(); virtual void initializeFonts(); + virtual bool mustRender(); void triggerEvent(std::string event, int menuIndex = -1); void setPlaylist(std::string name ); void setNewItemSelected(); diff --git a/RetroFE/Source/Graphics/Component/ReloadableScrollingText.cpp b/RetroFE/Source/Graphics/Component/ReloadableScrollingText.cpp index c096ae9..095007c 100644 --- a/RetroFE/Source/Graphics/Component/ReloadableScrollingText.cpp +++ b/RetroFE/Source/Graphics/Component/ReloadableScrollingText.cpp @@ -464,6 +464,7 @@ void ReloadableScrollingText::draw( ) //SDL_Texture *t = font->getTexture( ); SDL_Surface *t = font->getTexture( ); + float imageHeight = 0; float imageWidth = 0; float imageMaxWidth = 0; float imageMaxHeight = 0; @@ -484,12 +485,59 @@ void ReloadableScrollingText::draw( ) imageMaxHeight = baseViewInfo.MaxHeight; } + imageHeight = (float)font->getHeight( ); + //float scale = (float)baseViewInfo.FontSize / (float)font->getHeight( ) / scaleY_; //TODO, modify for scaling - for now, no scaling in effect float scale = 1.0f; + + // determine image width from 1st line + for ( unsigned int i = 0; i < text_[0].size( ); ++i ) + { + Font::GlyphInfo glyph; + if ( font->getRect( text_[0][i], glyph ) ) + { + if ( glyph.minX < 0 ) + { + imageWidth += glyph.minX; + } + + if ( (imageWidth + glyph.advance)*scale > imageMaxWidth ) + { + break; + } + imageWidth += glyph.advance; + + /*printf("textData_[%d]=%c, glyph.advance= %f - %d\n", i, textData_[i], glyph.advance, glyph.advance); + printf("imageWidth=%f \n", imageWidth);*/ + } + else{ + /*std::stringstream ss; + ss << "Could not find Glyph info for char: " << textData_[i]; + Logger::write(Logger::ZONE_WARNING, "Text", ss.str());*/ + } + } + + float oldWidth = baseViewInfo.Width; + float oldHeight = baseViewInfo.Height; + float oldImageWidth = baseViewInfo.ImageHeight; + float oldImageHeight = baseViewInfo.ImageWidth; + + baseViewInfo.Width = imageWidth*scale; + baseViewInfo.Height = baseViewInfo.FontSize; + baseViewInfo.ImageWidth = imageWidth; + baseViewInfo.ImageHeight = imageHeight; + float xOrigin = baseViewInfo.XRelativeToOrigin( ); float yOrigin = baseViewInfo.YRelativeToOrigin( ); + //printf("IN SCROLLABLE_TEXT - xOrigin=%f, yOrigin=%f, imageWidth=%f\n", xOrigin, yOrigin, imageWidth); + + baseViewInfo.Width = oldWidth; + baseViewInfo.Height = oldHeight; + baseViewInfo.ImageWidth = oldImageWidth; + baseViewInfo.ImageHeight = oldImageHeight; + SDL_Rect rect; @@ -518,12 +566,14 @@ void ReloadableScrollingText::draw( ) Font::GlyphInfo glyph; + //printf("text_[%d][%d] = %c, 0x%02X\n", l, i, text_[l][i], text_[l][i]); + //if (font->getRect( text_[l][i], glyph) && glyph.rect.h > 0) if (font->getRect( text_[l][i], glyph)) { SDL_Rect charRect = glyph.rect; rect.h = static_cast( charRect.h * scale * scaleY_ ); - rect.w = static_cast( charRect.w * scale * scaleX_ ); + rect.w = static_cast( charRect.w?charRect.w:glyph.advance * scale * scaleX_ ); rect.y = static_cast( yOrigin ); /*if (font->getAscent( ) < glyph.maxY) @@ -558,6 +608,9 @@ void ReloadableScrollingText::draw( ) { rect.x = static_cast( xOrigin ) + static_cast( imageMaxWidth ) + 10; // Stop handling the rest of the string } + /*else{ + rect.x += glyph.advance * scale * scaleX_; + }*/ } position += glyph.advance * scale * scaleX_; @@ -800,3 +853,15 @@ void ReloadableScrollingText::draw( ) } } } + +bool ReloadableScrollingText::mustRender( ) +{ + if ( Component::mustRender( ) ) return true; + + if (!text_.empty( ) && waitEndTime_ <= 0.0f && baseViewInfo.Alpha > 0.0f) + { + return true; + } + + return false; +} diff --git a/RetroFE/Source/Graphics/Component/ReloadableScrollingText.h b/RetroFE/Source/Graphics/Component/ReloadableScrollingText.h index e412b8c..343eff2 100644 --- a/RetroFE/Source/Graphics/Component/ReloadableScrollingText.h +++ b/RetroFE/Source/Graphics/Component/ReloadableScrollingText.h @@ -28,6 +28,7 @@ public: virtual ~ReloadableScrollingText( ); void update(float dt); void draw( ); + bool mustRender( ); void allocateGraphicsMemory( ); void freeGraphicsMemory( ); void deInitializeFonts(); diff --git a/RetroFE/Source/Graphics/Component/Text.cpp b/RetroFE/Source/Graphics/Component/Text.cpp index 2208206..1b1fff3 100644 --- a/RetroFE/Source/Graphics/Component/Text.cpp +++ b/RetroFE/Source/Graphics/Component/Text.cpp @@ -128,7 +128,6 @@ void Text::draw( ) ss << "Could not find Glyph info for char: " << textData_[i]; Logger::write(Logger::ZONE_WARNING, "Text", ss.str());*/ } - } float oldWidth = baseViewInfo.Width; @@ -144,6 +143,8 @@ void Text::draw( ) float xOrigin = baseViewInfo.XRelativeToOrigin( ); float yOrigin = baseViewInfo.YRelativeToOrigin( ); + //printf("IN TEXT %s - xOrigin=%f, yOrigin=%f\n",textData_.c_str(), xOrigin, yOrigin); + baseViewInfo.Width = oldWidth; baseViewInfo.Height = oldHeight; baseViewInfo.ImageWidth = oldImageWidth; diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index 0a44330..66d51ec 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -275,6 +275,19 @@ bool Page::isIdle() } +bool Page::mustRender() +{ + bool render = false; + + for(std::vector::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it) + { + render = (*it)->mustRender(); + } + + return render; +} + + bool Page::isGraphicsIdle() { bool idle = true; @@ -1043,9 +1056,9 @@ void Page::update(float dt) if(textStatusComponent_) { - std::string status; - config_.setProperty("status", status); - textStatusComponent_->setText(status); + std::string status; + config_.setProperty("status", status); + textStatusComponent_->setText(status); } for(std::vector::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it) diff --git a/RetroFE/Source/Graphics/Page.h b/RetroFE/Source/Graphics/Page.h index 0c925eb..21bff55 100644 --- a/RetroFE/Source/Graphics/Page.h +++ b/RetroFE/Source/Graphics/Page.h @@ -80,6 +80,7 @@ public: void setScrollOffsetIndex(unsigned int i); unsigned int getScrollOffsetIndex(); bool isIdle(); + bool mustRender(); bool isGraphicsIdle(); bool isMenuIdle(); void setStatusTextComponent(Text *t); diff --git a/RetroFE/Source/Graphics/PageBuilder.cpp b/RetroFE/Source/Graphics/PageBuilder.cpp index 198fb55..d2660e7 100644 --- a/RetroFE/Source/Graphics/PageBuilder.cpp +++ b/RetroFE/Source/Graphics/PageBuilder.cpp @@ -739,6 +739,7 @@ void PageBuilder::loadReloadableImages(xml_node<> *layout, std::string tagName, { c->setMenuScrollReload(true); } + c->allocateGraphicsMemory( ); } } else diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index 466b535..5ce76a3 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -991,8 +991,9 @@ void RetroFE::run( ) } // ------- Check if previous update of page needed to be rendered ------- - if(!currentPage_->isIdle( ) || splashMode){ - forceRender(true); + if(!currentPage_->isIdle( ) || currentPage_->mustRender( ) || splashMode){ + //printf("Not idle\n"); + forceRender(true); } // Force refresh variables