- type = GRADIENT;
- gradient_top = top;
- gradient_bottom = bottom;
-
- if (gradient_top.red > 1.0 || gradient_top.green > 1.0
- || gradient_top.blue > 1.0 || gradient_top.alpha > 1.0)
- msg_warning("top gradient color has values above 1.0");
- if (gradient_bottom.red > 1.0 || gradient_bottom.green > 1.0
- || gradient_bottom.blue > 1.0 || gradient_bottom.alpha > 1.0)
- msg_warning("bottom gradient color has values above 1.0");
-
- image.release();
+ Sizef level(Sector::current()->get_width(), Sector::current()->get_height());
+ Sizef screen(SCREEN_WIDTH, SCREEN_HEIGHT);
+ Sizef parallax_image_size = (1.0f - speed) * screen + level * speed;
+ Rectf cliprect = context.get_cliprect();
+
+ int start_x = static_cast<int>(floorf((cliprect.get_left() - (pos_.x - image->get_width() /2.0f)) / image->get_width()));
+ int end_x = static_cast<int>(ceilf((cliprect.get_right() - (pos_.x + image->get_width() /2.0f)) / image->get_width()))+1;
+ int start_y = static_cast<int>(floorf((cliprect.get_top() - (pos_.y - image->get_height()/2.0f)) / image->get_height()));
+ int end_y = static_cast<int>(ceilf((cliprect.get_bottom() - (pos_.y + image->get_height()/2.0f)) / image->get_height()))+1;
+
+ switch(alignment)
+ {
+ case LEFT_ALIGNMENT:
+ for(int y = start_y; y < end_y; ++y)
+ {
+ Vector p(pos_.x - parallax_image_size.width / 2.0f,
+ pos_.y + y * image->get_height() - image->get_height() / 2.0f);
+ context.draw_surface(image, p, layer);
+ }
+ break;
+
+ case RIGHT_ALIGNMENT:
+ for(int y = start_y; y < end_y; ++y)
+ {
+ Vector p(pos_.x + parallax_image_size.width / 2.0f - image->get_width(),
+ pos_.y + y * image->get_height() - image->get_height() / 2.0f);
+ context.draw_surface(image, p, layer);
+ }
+ break;
+
+ case TOP_ALIGNMENT:
+ for(int x = start_x; x < end_x; ++x)
+ {
+ Vector p(pos_.x + x * image->get_width() - image->get_width() / 2.0f,
+ pos_.y - parallax_image_size.height / 2.0f);
+ context.draw_surface(image, p, layer);
+ }
+ break;
+
+ case BOTTOM_ALIGNMENT:
+ for(int x = start_x; x < end_x; ++x)
+ {
+ Vector p(pos_.x + x * image->get_width() - image->get_width() / 2.0f,
+ pos_.y - image->get_height() + parallax_image_size.height / 2.0f);
+ context.draw_surface(image, p, layer);
+ }
+ break;
+
+ case NO_ALIGNMENT:
+ for(int y = start_y; y < end_y; ++y)
+ for(int x = start_x; x < end_x; ++x)
+ {
+ Vector p(pos_.x + x * image->get_width() - image->get_width()/2,
+ pos_.y + y * image->get_height() - image->get_height()/2);
+
+ if (image_top.get() != NULL && (y < 0))
+ {
+ context.draw_surface(image_top, p, layer);
+ }
+ else if (image_bottom.get() != NULL && (y > 0))
+ {
+ context.draw_surface(image_bottom, p, layer);
+ }
+ else
+ {
+ context.draw_surface(image, p, layer);
+ }
+ }
+ break;
+ }