3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2004 Matthias Braun <matze@braunis.de
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include "background.h"
23 #include "screen/drawing_context.h"
25 Background::Background()
26 : type(INVALID), image(0)
30 Background::~Background()
36 Background::action(float)
41 Background::set_image(const std::string& name, float speed)
47 image = new Surface(datadir + "/images/background/" + name, IGNORE_ALPHA);
51 Background::set_gradient(Color top, Color bottom)
55 gradient_bottom = bottom;
59 Background::draw(DrawingContext& context)
61 if(type == GRADIENT) {
62 context.draw_gradient(gradient_top, gradient_bottom, LAYER_BACKGROUND0);
63 } else if(type == IMAGE) {
64 int sx = int(-context.get_translation().x * float(speed/100.))
65 % image->w - image->w;
66 int sy = int(-context.get_translation().y * float(speed/100.))
67 % image->h - image->h;
68 context.push_transform();
69 context.set_translation(Vector(0, 0));
70 for(int x = sx; x < screen->w; x += image->w)
71 for(int y = sy; y < screen->h; y += image->h)
72 context.draw_surface(image, Vector(x, y), LAYER_BACKGROUND0);
73 context.pop_transform();