X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbackground.cpp;h=56506e5ba592b45eaa5fd3a7b2da9254a72ef9c5;hb=875ef8eb7e93726bc67dfa7f05da946250e588d4;hp=1effc167131416e66587134ce5eedc873338b8e2;hpb=2074a5e3f8167dec24989c008ddadda14687a3a6;p=supertux.git diff --git a/src/background.cpp b/src/background.cpp index 1effc1671..56506e5ba 100644 --- a/src/background.cpp +++ b/src/background.cpp @@ -16,33 +16,33 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "background.h" -#include "globals.h" +#include + +#include "background.h" +#include "app/globals.h" #include "camera.h" -#include "screen/drawing_context.h" -#include "lispwriter.h" +#include "video/drawing_context.h" +#include "utils/lispwriter.h" Background::Background() - : type(INVALID), image(0) + : type(INVALID), layer(LAYER_BACKGROUND0), image(0) { } Background::Background(LispReader& reader) - : type(INVALID), image(0) + : type(INVALID), layer(LAYER_BACKGROUND0), image(0) { + reader.read_int("layer", layer); if(reader.read_string("image", imagefile) && reader.read_float("speed", speed)) { set_image(imagefile, speed); } - int tr, tg, tb, br, bg, bb; - if(reader.read_int("top_red", tr) && reader.read_int("top_green", tg) - && reader.read_int("top_blue", tb) && reader.read_int("bottom_red", br) - && reader.read_int("bottom_green", br) - && reader.read_int("bottom_blue", bb)) { - set_gradient(Color(tr, tg, tb), Color(br, bg, bb)); - } + std::vector bkgd_top_color, bkgd_bottom_color; + if(reader.read_int_vector("top_color", bkgd_top_color) && + reader.read_int_vector("bottom_color", bkgd_bottom_color)) + set_gradient(Color(bkgd_top_color), Color(bkgd_bottom_color)); } Background::~Background() @@ -62,13 +62,17 @@ Background::write(LispWriter& writer) writer.write_string("image", imagefile); writer.write_float("speed", speed); } else if(type == GRADIENT) { - writer.write_int("top_red", gradient_top.red); - writer.write_int("top_green", gradient_top.green); - writer.write_int("top_blue", gradient_top.blue); - writer.write_int("bottom_red", gradient_bottom.red); - writer.write_int("bottom_green", gradient_bottom.green); - writer.write_int("bottom_blue", gradient_bottom.blue); + std::vector bkgd_top_color, bkgd_bottom_color; + bkgd_top_color.push_back(gradient_top.red); + bkgd_top_color.push_back(gradient_top.green); + bkgd_top_color.push_back(gradient_top.blue); + bkgd_bottom_color.push_back(gradient_top.red); + bkgd_bottom_color.push_back(gradient_top.green); + bkgd_bottom_color.push_back(gradient_top.blue); + writer.write_int_vector("top_color", bkgd_top_color); + writer.write_int_vector("bottom_color", bkgd_bottom_color); } + writer.write_int("layer", layer); writer.end_list("background"); } @@ -86,7 +90,7 @@ Background::set_image(const std::string& name, float speed) this->speed = speed; delete image; - image = new Surface(datadir + "/images/background/" + name, IGNORE_ALPHA); + image = new Surface(datadir + "/images/background/" + name, false); } void @@ -95,23 +99,37 @@ Background::set_gradient(Color top, Color bottom) type = GRADIENT; gradient_top = top; gradient_bottom = bottom; + + delete image; + image = new Surface(top, bottom, screen->w, screen->h); } void Background::draw(DrawingContext& context) { if(type == GRADIENT) { - context.draw_gradient(gradient_top, gradient_bottom, LAYER_BACKGROUND0); + /* In case we are using OpenGL just draw the gradient, else (software mode) + use the cache. */ + if(use_gl) + context.draw_gradient(gradient_top, gradient_bottom, layer); + else + { + context.push_transform(); + context.set_translation(Vector(0, 0)); + context.draw_surface(image, Vector(0, 0), layer); + context.pop_transform(); + } } else if(type == IMAGE) { - int sx = int(-context.get_translation().x * speed) - % image->w - image->w; - int sy = int(-context.get_translation().y * speed) - % image->h - image->h; + if(!image) + return; + + int sx = int(-context.get_translation().x * speed) % image->w - image->w; + int sy = int(-context.get_translation().y * speed) % image->h - image->h; context.push_transform(); context.set_translation(Vector(0, 0)); for(int x = sx; x < screen->w; x += image->w) for(int y = sy; y < screen->h; y += image->h) - context.draw_surface(image, Vector(x, y), LAYER_BACKGROUND0); + context.draw_surface(image, Vector(x, y), layer); context.pop_transform(); } }