Use correct resource path and check for errors on splash screen creation

This commit is contained in:
Simon Fels 2017-05-03 08:20:31 +02:00
commit f094550279
3 changed files with 24 additions and 1 deletions

View file

@ -41,6 +41,10 @@ void anbox::SystemConfiguration::set_data_path(const std::string &path) {
data_path = path;
}
void anbox::SystemConfiguration::set_resource_path(const std::string &path) {
resource_path = path;
}
fs::path anbox::SystemConfiguration::data_dir() const {
return data_path;
}
@ -76,6 +80,10 @@ std::string anbox::SystemConfiguration::application_item_dir() const {
return dir.string();
}
std::string anbox::SystemConfiguration::resource_dir() const {
return resource_path.string();
}
anbox::SystemConfiguration& anbox::SystemConfiguration::instance() {
static SystemConfiguration config;
return config;

View file

@ -31,6 +31,7 @@ class SystemConfiguration {
virtual ~SystemConfiguration() = default;
void set_data_path(const std::string &path);
void set_resource_path(const std::string &path);
boost::filesystem::path data_dir() const;
std::string rootfs_dir() const;
@ -40,11 +41,13 @@ class SystemConfiguration {
std::string container_socket_path() const;
std::string input_device_dir() const;
std::string application_item_dir() const;
std::string resource_dir() const;
protected:
SystemConfiguration() = default;
boost::filesystem::path data_path = "/var/lib/anbox";
boost::filesystem::path resource_path = "/usr/share/anbox";
};
} // namespace anbox

View file

@ -16,6 +16,7 @@
*/
#include "anbox/ui/splash_screen.h"
#include "anbox/config.h"
#include "anbox/utils.h"
#include <SDL2/SDL_image.h>
@ -37,11 +38,22 @@ SplashScreen::SplashScreen() {
}
auto surface = SDL_GetWindowSurface(window_);
if (!surface)
BOOST_THROW_EXCEPTION(std::runtime_error("Could not retrieve surface for our window"));
SDL_FillRect(surface, nullptr, SDL_MapRGB(surface->format, 0xee, 0xee, 0xee));
SDL_UpdateWindowSurface(window_);
auto renderer = SDL_CreateRenderer(window_, -1, SDL_RENDERER_ACCELERATED);
auto img = IMG_LoadTexture(renderer, "/snap/anbox/current/snap/gui/icon.png");
if (!renderer)
BOOST_THROW_EXCEPTION(std::runtime_error("Could not create renderer"));
const auto icon_path = utils::string_format("%s/ui/icon.png", SystemConfiguration::instance().resource_dir());
auto img = IMG_LoadTexture(renderer, icon_path.c_str());
if (!img) {
const auto msg = utils::string_format("Failed to create texture from %s", icon_path);
BOOST_THROW_EXCEPTION(std::runtime_error(msg));
}
const auto tex_width = 128, tex_height = 128;
SDL_Rect r{(width - tex_width) / 2, (height - tex_height) / 2, 128, 128};