#include "msg.hpp"
Background::Background()
- : type(INVALID), layer(LAYER_BACKGROUND0), image_top(0), image(0), image_bottom(0)
+ : type(INVALID), layer(LAYER_BACKGROUND0)
{
}
Background::Background(const lisp::Lisp& reader)
- : type(INVALID), layer(LAYER_BACKGROUND0), image_top(0), image(0), image_bottom(0)
+ : type(INVALID), layer(LAYER_BACKGROUND0)
{
// read position, defaults to (0,0)
float px = 0;
speed_y = 1.0;
reader.get("layer", layer);
- if(reader.get("image", imagefile)
- && reader.get("speed", speed)) {
+ if(reader.get("image", imagefile) && reader.get("speed", speed)) {
set_image(imagefile, speed);
reader.get("speed-y", speed_y);
- if (reader.get("image-top", imagefile_top)) image_top = new Surface(imagefile_top);
- if (reader.get("image-bottom", imagefile_bottom)) image_bottom = new Surface(imagefile_bottom);
+ if (reader.get("image-top", imagefile_top)) {
+ image_top.reset(new Surface(imagefile_top));
+ }
+ if (reader.get("image-bottom", imagefile_bottom)) {
+ image_bottom.reset(new Surface(imagefile_bottom));
+ }
} else {
std::vector<float> bkgd_top_color, bkgd_bottom_color;
if(reader.get_vector("top_color", bkgd_top_color) &&
Background::~Background()
{
- delete image;
}
void
writer.start_list("background");
if(type == IMAGE) {
- if (image_top) writer.write_string("image-top", imagefile_top);
+ if (image_top.get() != NULL)
+ writer.write_string("image-top", imagefile_top);
+
writer.write_string("image", imagefile);
- if (image_bottom) writer.write_string("image-bottom", imagefile_bottom);
+ if (image_bottom.get() != NULL)
+ writer.write_string("image-bottom", imagefile_bottom);
+
writer.write_float("speed", speed);
writer.write_float("speed-y", speed_y);
} else if(type == GRADIENT) {
this->imagefile = name;
this->speed = speed;
- delete image;
- image = new Surface(name);
+ image.reset(new Surface(name));
}
void
|| gradient_bottom.blue > 1.0 || gradient_bottom.alpha > 1.0)
msg_warning("bottom gradient color has values above 1.0");
- delete image;
- image = NULL;
+ image.release();
}
void
context.draw_gradient(gradient_top, gradient_bottom, layer);
context.pop_transform();
} else if(type == IMAGE) {
- if(!image)
+ if(image.get() == NULL)
return;
int w = (int) image->get_width();
context.set_translation(Vector(0, 0));
for(int x = sx; x < SCREEN_WIDTH; x += w) {
for(int y = sy; y < SCREEN_HEIGHT; y += h) {
- if (image_top && (y < center_image_py)) {
- context.draw_surface(image_top, Vector(x, y), layer);
+ if (image_top.get() != NULL && (y < center_image_py)) {
+ context.draw_surface(image_top.get(), Vector(x, y), layer);
continue;
}
- if (image_bottom && (y >= bottom_image_py)) {
- context.draw_surface(image_bottom, Vector(x, y), layer);
+ if (image_bottom.get() != NULL && (y >= bottom_image_py)) {
+ context.draw_surface(image_bottom.get(), Vector(x, y), layer);
continue;
}
- context.draw_surface(image, Vector(x, y), layer);
+ context.draw_surface(image.get(), Vector(x, y), layer);
}
}
context.pop_transform();
#ifndef SUPERTUX_BACKGROUND_H
#define SUPERTUX_BACKGROUND_H
+#include <memory>
#include "video/surface.hpp"
#include "video/drawing_context.hpp"
#include "game_object.hpp"
Vector pos; /**< coordinates of upper-left corner of image */
float speed; /**< scroll-speed in horizontal direction */
float speed_y; /**< scroll-speed in vertical direction */
- Surface* image_top; /**< image to draw above pos */
- Surface* image; /**< image to draw, anchored at pos */
- Surface* image_bottom; /**< image to draw below pos+<screenheight> */
+ std::auto_ptr<Surface> image_top; /**< image to draw above pos */
+ std::auto_ptr<Surface> image; /**< image to draw, anchored at pos */
+ std::auto_ptr<Surface> image_bottom; /**< image to draw below pos+<screenheight> */
Color gradient_top, gradient_bottom;
};