select correct item in ReloadableScrollingText and ReloadableText when scroll is detected

Signed-off-by: Vincent-FK <vincent.buso@funkey-project.com>
This commit is contained in:
Vincent-FK 2020-03-16 00:58:06 +01:00
parent 7950bffc2e
commit bcac9e6f4d
7 changed files with 50 additions and 32 deletions

View File

@ -33,9 +33,10 @@ Image * ImageBuilder::CreateImage(std::string path, Page &p, std::string name, f
std::string prefix = Utils::combinePath(path, name);
std::string file;
printf(" findMatchingFile, prefix = %s, file = %s\n", prefix.c_str(), file.c_str());
//printf(" findMatchingFile, prefix = %s, extensions = %s\n", prefix.c_str(), extensions.c_str());
if(Utils::findMatchingFile(prefix, extensions, file))
{
//printf(" fFound Matching File, prefix = %s, file = %s\n", prefix.c_str(), file.c_str());
image = new Image(file, "", p, scaleX, scaleY, dithering);
}

View File

@ -414,13 +414,9 @@ void ReloadableMedia::reloadTexture( bool previousItem )
}
}
// if image and artwork was not specified, fall back to displaying text
// if image and artwork was not specified, image fall back
if(!loadedComponent_ && imageFallback_)
{
//loadedComponent_ = new Text(selectedItem->fullTitle, page, FfntInst_, scaleX_, scaleY_);
/*baseViewInfo.ImageWidth = loadedComponent_->baseViewInfo.ImageWidth;
baseViewInfo.ImageHeight = loadedComponent_->baseViewInfo.ImageHeight;*/
std::string imagePath;
ImageBuilder imageBuild;
imagePath = Utils::combinePath(Configuration::absolutePath, "collections", collectionName );
@ -428,19 +424,13 @@ void ReloadableMedia::reloadTexture( bool previousItem )
loadedComponent_ = imageBuild.CreateImage( imagePath, page, std::string("fallback"), scaleX_, scaleY_, ditheringAuthorized_ );
}
// if image and artwork was not specified, fall back to displaying text
// if image and artwork was not specified, and no image fallback, fall back to displaying text
if(!loadedComponent_ && textFallback_)
{
loadedComponent_ = new Text(selectedItem->fullTitle, page, FfntInst_, scaleX_, scaleY_);
baseViewInfo.ImageWidth = loadedComponent_->baseViewInfo.ImageWidth;
baseViewInfo.ImageHeight = loadedComponent_->baseViewInfo.ImageHeight;
}
/*if(imageAndText_){
loadedComponent_ = new Text(selectedItem->fullTitle, page, FfntInst_, scaleX_, scaleY_);
baseViewInfo.ImageWidth = loadedComponent_->baseViewInfo.ImageWidth;
baseViewInfo.ImageHeight = loadedComponent_->baseViewInfo.ImageHeight;
}*/
}

View File

@ -105,12 +105,17 @@ void ReloadableScrollingText::update(float dt)
}
}
if (newItemSelected ||
(newScrollItemSelected && getMenuScrollReload()))
{
reloadTexture( );
newItemSelected = false;
}
// Reload media
if (newItemSelected)
{
reloadTexture();
newItemSelected = false;
}
else if(newScrollItemSelected && getMenuScrollReload())
{
reloadTexture(true);
newScrollItemSelected = false;
}
Component::update(dt);
}
@ -141,8 +146,12 @@ void ReloadableScrollingText::initializeFonts( )
fontInst_->initialize( );
}
void ReloadableScrollingText::reloadTexture( )
{
reloadTexture(false);
}
void ReloadableScrollingText::reloadTexture( bool previousItem )
{
needRender_ = true;
@ -159,11 +168,15 @@ void ReloadableScrollingText::reloadTexture( )
text_.clear( );
Item *selectedItem = page.getSelectedItem( displayOffset_ );
if (!selectedItem)
{
return;
}
/* Select item to reload */
Item *selectedItem = NULL;
if(previousItem){
selectedItem = page.getPreviousSelectedItem(displayOffset_);
}
else{
selectedItem = page.getSelectedItem(displayOffset_);
}
if(!selectedItem) return;
config_.getProperty( "currentCollection", currentCollection_ );

View File

@ -36,6 +36,7 @@ public:
private:
void reloadTexture( );
void reloadTexture( bool previousItem );
void loadText( std::string collection, std::string type, std::string basename, std::string filepath, bool systemMode );
Configuration &config_;
bool systemMode_;

View File

@ -58,12 +58,16 @@ ReloadableText::~ReloadableText()
void ReloadableText::update(float dt)
{
if (newItemSelected ||
(newScrollItemSelected && getMenuScrollReload()) ||
type_ == "time")
{
ReloadTexture();
newItemSelected = false;
}
else if(newScrollItemSelected && getMenuScrollReload())
{
ReloadTexture(true);
newScrollItemSelected = false;
}
// needs to be ran at the end to prevent the NewItemSelected flag from being detected
Component::update(dt);
@ -103,7 +107,11 @@ void ReloadableText::deInitializeFonts()
}
void ReloadableText::ReloadTexture()
void ReloadableText::ReloadTexture(){
ReloadTexture(false);
}
void ReloadableText::ReloadTexture( bool previousItem )
{
if (imageInst_ != NULL)
{
@ -111,7 +119,14 @@ void ReloadableText::ReloadTexture()
imageInst_ = NULL;
}
Item *selectedItem = page.getSelectedItem( displayOffset_ );
/* Select item to reload */
Item *selectedItem = NULL;
if(previousItem){
selectedItem = page.getPreviousSelectedItem(displayOffset_);
}
else{
selectedItem = page.getSelectedItem(displayOffset_);
}
if (selectedItem != NULL)
{

View File

@ -35,7 +35,8 @@ public:
void initializeFonts();
private:
void ReloadTexture();
void ReloadTexture( );
void ReloadTexture( bool previousItem );
Configuration &config_;
Text *imageInst_;

View File

@ -148,8 +148,6 @@ void Page::onNewItemSelected()
if(!(activeMenu_.size() > 0 && activeMenu_[0])) return;
selectedItem_ = activeMenu_[0]->getSelectedItem();
//printf("onNewItemSelected\n");
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{
for(std::vector<ScrollingList *>::iterator it2 = menus_[std::distance(menus_.begin(), it)].begin(); it2 != menus_[std::distance(menus_.begin(), it)].end(); it2++)
@ -172,7 +170,6 @@ void Page::onNewScrollItemSelected()
if(!(activeMenu_.size() > 0 && activeMenu_[0])) return;
selectedItem_ = activeMenu_[0]->getSelectedItem();
//printf("onNewScrollItemSelected\n");
for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it)
{