Splash screens: support more, and JPEGs
This commit is contained in:
parent
19aa0332f2
commit
b35b8c6147
3 changed files with 30 additions and 12 deletions
|
@ -50,11 +50,16 @@ string_list defaultSplashScreenPaths()
|
||||||
{
|
{
|
||||||
string_list result;
|
string_list result;
|
||||||
SGPath tpath = globals->get_fg_root() / "Textures";
|
SGPath tpath = globals->get_fg_root() / "Textures";
|
||||||
simgear::Dir d(tpath);
|
auto paths = simgear::Dir(tpath).children(simgear::Dir::TYPE_FILE);
|
||||||
for (auto c : d.children(simgear::Dir::TYPE_FILE, ".png")) {
|
paths.erase(std::remove_if(paths.begin(), paths.end(), [](const SGPath& p) {
|
||||||
if (c.file_base().find("Splash") == 0) {
|
const auto f = p.file();
|
||||||
result.push_back(c.utf8Str());
|
if (f.find("Splash") != 0) return true;
|
||||||
}
|
const auto ext = p.extension();
|
||||||
|
return ext != "png" && ext != "jpg";
|
||||||
|
}), paths.end());
|
||||||
|
|
||||||
|
for (auto c : paths) {
|
||||||
|
result.push_back(c.utf8Str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -35,7 +35,8 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
onUrlsListChanged: {
|
onUrlsListChanged: {
|
||||||
__currentUrl = 0;
|
var len = preview.urlsList.length;
|
||||||
|
__currentUrl = Math.floor(Math.random() * len)
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
#include <simgear/math/sg_random.h>
|
#include <simgear/math/sg_random.h>
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
|
#include <simgear/misc/sg_dir.hxx>
|
||||||
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
|
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
|
||||||
|
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
|
@ -453,13 +454,24 @@ std::string SplashScreen::selectSplashImage()
|
||||||
return paths.at(index).utf8Str();
|
return paths.at(index).utf8Str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// no splash screen specified - select random image
|
// no splash screen specified - use one of the default ones
|
||||||
SGPath tpath = globals->get_fg_root() / "Textures";
|
SGPath tpath = globals->get_fg_root() / "Textures";
|
||||||
int num = (int)(sg_random() * 3.0 + 1.0);
|
paths = simgear::Dir(tpath).children(simgear::Dir::TYPE_FILE);
|
||||||
std::ostringstream oss;
|
paths.erase(std::remove_if(paths.begin(), paths.end(), [](const SGPath& p) {
|
||||||
oss << "Splash" << num << ".png";
|
const auto f = p.file();
|
||||||
tpath.append(oss.str());
|
if (f.find("Splash") != 0) return true;
|
||||||
return tpath.utf8Str();
|
const auto ext = p.extension();
|
||||||
|
return ext != "png" && ext != "jpg";
|
||||||
|
}), paths.end());
|
||||||
|
|
||||||
|
if (!paths.empty()) {
|
||||||
|
// Select a random useable texture
|
||||||
|
const int index = (int)(sg_random() * paths.size());
|
||||||
|
return paths.at(index).utf8Str();
|
||||||
|
}
|
||||||
|
|
||||||
|
SG_LOG(SG_GUI, SG_ALERT, "Couldn't find any splash screens at all");
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplashScreen::doUpdate()
|
void SplashScreen::doUpdate()
|
||||||
|
|
Loading…
Add table
Reference in a new issue