|
From: Tapio V. <aa...@us...> - 2012-02-20 17:24:10
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Mon Feb 20 07:15:24 2012 +0200
Load a random background if background loading fails (screen_sing).
- Added empty() for Surface, allows testing if the loading has failed.
---
game/screen_sing.cc | 30 +++++-------------------------
game/surface.cc | 2 +-
game/surface.hh | 1 +
3 files changed, 7 insertions(+), 26 deletions(-)
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 6b5ff3d..7b16fb4 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -135,26 +135,7 @@ void ScreenSing::reloadGL() {
m_help.reset(new Surface(getThemePath("instrumenthelp.svg")));
m_progress.reset(new ProgressBar(getThemePath("sing_progressbg.svg"), getThemePath("sing_progressfg.svg"), ProgressBar::HORIZONTAL, 0.01f, 0.01f, true));
// Load background
- bool foundbg = false;
- if (!m_song->background.empty()) { // Load bg image
- try {
- m_background.reset(new Surface(m_song->path + m_song->background));
- foundbg = true;
- } catch (std::exception& e) {
- m_song->background = "";
- std::cerr << e.what() << std::endl;
- }
- }
- // Use random bg if specified fails (also for tracks with video)
- if (!foundbg) {
- sm->loading(_("Random background..."), 0.65);
- try {
- std::string bgpath = m_backgrounds.getRandom();
- m_background.reset(new Surface(bgpath));
- } catch (std::exception& e) {
- std::cerr << e.what() << std::endl;
- }
- }
+ if (!m_song->background.empty()) m_background.reset(new Surface(m_song->path + m_song->background));
}
void ScreenSing::exit() {
@@ -444,11 +425,10 @@ void ScreenSing::draw() {
Transform ft(farTransform());
double ar = arMax;
// Background image
- if (m_background) {
- ar = m_background->dimensions.ar();
- if (ar > arMax || (m_video && ar > arMin)) fillBG(); // Fill white background to avoid black borders
- m_background->draw();
- } else fillBG(); // Blank
+ if (!m_background || m_background->empty()) m_background.reset(new Surface(m_backgrounds.getRandom()));
+ ar = m_background->dimensions.ar();
+ if (ar > arMax || (m_video && ar > arMin)) fillBG(); // Fill white background to avoid black borders
+ m_background->draw();
// Webcam
if (m_cam && config["graphic/webcam"].b()) m_cam->render();
// Video
diff --git a/game/surface.cc b/game/surface.cc
index a25e2f6..8f9bd1c 100644
--- a/game/surface.cc
+++ b/game/surface.cc
@@ -195,6 +195,6 @@ void Surface::load(Bitmap const& bitmap) {
}
void Surface::draw() const {
- if (m_width * m_height > 0.0) m_texture.draw(dimensions, TexCoords(tex.x1 * m_width, tex.y1 * m_height, tex.x2 * m_width, tex.y2 * m_height));
+ if (!empty()) m_texture.draw(dimensions, TexCoords(tex.x1 * m_width, tex.y1 * m_height, tex.x2 * m_width, tex.y2 * m_height));
}
diff --git a/game/surface.hh b/game/surface.hh
index 57a926e..055550f 100644
--- a/game/surface.hh
+++ b/game/surface.hh
@@ -221,6 +221,7 @@ class Surface {
/// creates surface from file
Surface(std::string const& filename);
~Surface();
+ bool empty() const { return m_width * m_height == 0; } ///< Test if the loading has failed
/// draws surface
void draw() const;
/// loads surface into buffer
|