X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fbackground.cpp;h=a8c5edc28dd1f6f975938f6c84022ce8002efacc;hb=e8a1d89d3d0f4824d3d906ca67149afec0a75e4b;hp=15333dd20dda4be64f68dc30be667ee66fb7e6d3;hpb=ef57479f613b900b73eba8e8f4d026aae0de25cc;p=supertux.git diff --git a/src/object/background.cpp b/src/object/background.cpp index 15333dd20..a8c5edc28 100644 --- a/src/object/background.cpp +++ b/src/object/background.cpp @@ -25,6 +25,7 @@ #include "video/drawing_context.h" #include "lisp/lisp.h" #include "lisp/writer.h" +#include "object_factory.h" Background::Background() : type(INVALID), layer(LAYER_BACKGROUND0), image(0) @@ -38,12 +39,12 @@ Background::Background(const lisp::Lisp& reader) if(reader.get("image", imagefile) && reader.get("speed", speed)) { set_image(imagefile, speed); + } else { + std::vector bkgd_top_color, bkgd_bottom_color; + if(reader.get_vector("top_color", bkgd_top_color) && + reader.get_vector("bottom_color", bkgd_bottom_color)) + set_gradient(Color(bkgd_top_color), Color(bkgd_bottom_color)); } - - std::vector bkgd_top_color, bkgd_bottom_color; - if(reader.get_vector("top_color", bkgd_top_color) && - reader.get_vector("bottom_color", bkgd_bottom_color)) - set_gradient(Color(bkgd_top_color), Color(bkgd_bottom_color)); } Background::~Background() @@ -102,7 +103,7 @@ Background::set_gradient(Color top, Color bottom) gradient_bottom = bottom; delete image; - image = new Surface(top, bottom, screen->w, screen->h); + image = new Surface(top, bottom, SCREEN_WIDTH, SCREEN_HEIGHT); } void @@ -121,10 +122,11 @@ Background::draw(DrawingContext& context) 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) + for(int x = sx; x < SCREEN_WIDTH; x += image->w) + for(int y = sy; y < SCREEN_HEIGHT; y += image->h) context.draw_surface(image, Vector(x, y), layer); context.pop_transform(); } } +IMPLEMENT_FACTORY(Background, "background");