{
int i;
- Surface *hh = hud_head.get();
- if (!hh)
- return;
+ if (hud_head)
+ {
+ context.push_transform();
+ context.set_translation(Vector(0, 0));
- context.push_transform();
- context.set_translation(Vector(0, 0));
+ for (i = 0; i < hit_points; ++i)
+ {
+ context.draw_surface(hud_head, Vector(BORDER_X + (i * hud_head->get_width()), BORDER_Y + 1), LAYER_FOREGROUND1);
+ }
- for (i = 0; i < hit_points; ++i)
- {
- context.draw_surface(hh, Vector(BORDER_X + (i * hh->get_width()), BORDER_Y + 1), LAYER_FOREGROUND1);
+ context.pop_transform();
}
-
- context.pop_transform();
}
void
Font* Button::info_font = 0;
-Button::Button(Surface* image_, std::string info_, SDLKey binding_) :
+Button::Button(SurfacePtr image_, std::string info_, SDLKey binding_) :
pos(),
size(),
image(),
#include <string>
#include "math/vector.hpp"
+#include "video/surface_ptr.hpp"
-class Surface;
class DrawingContext;
class Font;
class ButtonGroup;
class Button
{
public:
- Button(Surface* image_, std::string info_, SDLKey binding_);
+ Button(SurfacePtr image_, std::string info_, SDLKey binding_);
Button(const Button& rhs);
~Button();
Vector pos;
Vector size;
- Surface* image;
+ SurfacePtr image;
SDLKey binding;
int id;
ALIGN_LEFT, LAYER_GUI, text_color);
// Draw right side
- context.draw_surface(arrow_left.get(),
+ context.draw_surface(arrow_left,
Vector(right - list_width - roff - roff, y_pos - 8),
LAYER_GUI);
- context.draw_surface(arrow_right.get(),
+ context.draw_surface(arrow_right,
Vector(right - roff, y_pos - 8),
LAYER_GUI);
context.draw_text(Resources::normal_font, pitem.list[pitem.selected],
context.draw_text(Resources::Resources::normal_font, pitem.text,
Vector(pos_x, y_pos - int(Resources::normal_font->get_height()/2)),
ALIGN_CENTER, LAYER_GUI, text_color);
- context.draw_surface(back.get(),
+ context.draw_surface(back,
Vector(x_pos + text_width/2 + 16, y_pos - 8),
LAYER_GUI);
break;
ALIGN_LEFT, LAYER_GUI, text_color);
if(pitem.toggled)
- context.draw_surface(checkbox_checked.get(),
+ context.draw_surface(checkbox_checked,
Vector(x_pos + (menu_width/2-16) - checkbox->get_width(), y_pos - 8),
LAYER_GUI + 1);
else
- context.draw_surface(checkbox.get(),
+ context.draw_surface(checkbox,
Vector(x_pos + (menu_width/2-16) - checkbox->get_width(), y_pos - 8),
LAYER_GUI + 1);
break;
cur_state(),
cursor()
{
- cursor = new Surface(cursor_file);
+ cursor = Surface::create(cursor_file);
cur_state = MC_NORMAL;
}
MouseCursor::~MouseCursor()
{
- delete cursor;
}
int MouseCursor::state()
#include <string>
-class Surface;
+#include "video/surface_ptr.hpp"
#define MC_STATES_NB 3
int mid_y;
int state_before_click;
int cur_state;
- Surface* cursor;
+ SurfacePtr cursor;
private:
static MouseCursor* current_;
{
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.get(), p, layer);
+ context.draw_surface(image, p, layer);
}
break;
{
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.get(), p, layer);
+ context.draw_surface(image, p, layer);
}
break;
{
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.get(), p, layer);
+ context.draw_surface(image, p, layer);
}
break;
{
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.get(), p, layer);
+ context.draw_surface(image, p, layer);
}
break;
if (image_top.get() != NULL && (y < 0))
{
- context.draw_surface(image_top.get(), p, layer);
+ context.draw_surface(image_top, p, layer);
}
else if (image_bottom.get() != NULL && (y > 0))
{
- context.draw_surface(image_bottom.get(), p, layer);
+ context.draw_surface(image_bottom, p, layer);
}
else
{
- context.draw_surface(image.get(), p, layer);
+ context.draw_surface(image, p, layer);
}
}
break;
Candle::Candle(const Reader& lisp)
: MovingSprite(lisp, "images/objects/candle/candle.sprite", LAYER_BACKGROUNDTILES+1, COLGROUP_DISABLED), burning(true),
- candle_light_1("images/objects/candle/candle-light-1.png"),
- candle_light_2("images/objects/candle/candle-light-2.png")
+ candle_light_1(Surface::create("images/objects/candle/candle-light-1.png")),
+ candle_light_2(Surface::create("images/objects/candle/candle-light-2.png"))
{
lisp.get("name", name);
lisp.get("burning", burning);
// draw on lightmap
if (burning) {
- Vector pos = get_pos() + (bbox.get_size() - candle_light_1.get_size()) / 2;
+ Vector pos = get_pos() + (bbox.get_size() - candle_light_1->get_size()) / 2;
context.push_target();
context.set_target(DrawingContext::LIGHTMAP);
// draw approx. 1 in 10 frames darker. Makes the candle flicker
if (systemRandom.rand(10) != 0) {
- context.draw_surface(&candle_light_1, pos, layer);
+ context.draw_surface(candle_light_1, pos, layer);
} else {
- context.draw_surface(&candle_light_2, pos, layer);
+ context.draw_surface(candle_light_2, pos, layer);
}
context.pop_target();
}
private:
bool burning; /**< true if candle is currently lighted */
- Surface candle_light_1; /**< drawn to lightmap */
- Surface candle_light_2; /**< drawn to lightmap (alternative image) */
+ SurfacePtr candle_light_1; /**< drawn to lightmap */
+ SurfacePtr candle_light_2; /**< drawn to lightmap (alternative image) */
};
CloudParticle* particle = new CloudParticle;
particle->pos.x = systemRandom.rand(static_cast<int>(virtual_width));
particle->pos.y = systemRandom.rand(static_cast<int>(virtual_height));
- particle->texture = cloudimage.get();
+ particle->texture = cloudimage;
particle->speed = -systemRandom.randf(25.0, 54.0);
particles.push_back(particle);
particle->pos.x = systemRandom.rand(int(virtual_width));
particle->pos.y = systemRandom.rand(int(virtual_height));
int cometsize = systemRandom.rand(2);
- particle->texture = cometimages[cometsize].get();
+ particle->texture = cometimages[cometsize];
do {
particle->speed = (cometsize+1)*30 + systemRandom.randf(3.6);
} while(particle->speed < 1);
particle->pos.x = systemRandom.randf(virtual_width);
particle->pos.y = systemRandom.randf(SCREEN_HEIGHT);
int size = systemRandom.rand(2);
- particle->texture = ghosts[size].get();
+ particle->texture = ghosts[size];
particle->speed = systemRandom.randf(std::max(50, (size * 10)), 180 + (size * 10));
particles.push_back(particle);
}
ss << int(time_left);
std::string time_text = ss.str();
- Surface* time_surf = time_surface.get();
- if (time_surf) {
- float all_width = time_surf->get_width() + Resources::normal_font->get_text_width(time_text);
- context.draw_surface(time_surf, Vector((SCREEN_WIDTH - all_width)/2, BORDER_Y + 1), LAYER_FOREGROUND1);
- context.draw_text(Resources::normal_font, time_text, Vector((SCREEN_WIDTH - all_width)/2 + time_surf->get_width(), BORDER_Y), ALIGN_LEFT, LAYER_FOREGROUND1, LevelTime::text_color);
+ if (time_surface)
+ {
+ float all_width = time_surface->get_width() + Resources::normal_font->get_text_width(time_text);
+ context.draw_surface(time_surface, Vector((SCREEN_WIDTH - all_width)/2, BORDER_Y + 1), LAYER_FOREGROUND1);
+ context.draw_text(Resources::normal_font, time_text,
+ Vector((SCREEN_WIDTH - all_width)/2 + time_surface->get_width(), BORDER_Y),
+ ALIGN_LEFT, LAYER_FOREGROUND1, LevelTime::text_color);
}
}
#include "math/vector.hpp"
#include "supertux/game_object.hpp"
#include "util/reader.hpp"
+#include "video/surface_ptr.hpp"
-class Surface;
class DisplayManager;
/**
{}
Vector pos;
- Surface* texture;
+ SurfacePtr texture;
private:
Particle(const Particle&);
#include "math/vector.hpp"
#include "supertux/game_object.hpp"
#include "supertux/sector.hpp"
+#include "video/surface_ptr.hpp"
-class Surface;
class DisplayManager;
/**
{}
Vector pos;
- Surface* texture;
+ SurfacePtr texture;
private:
Particle(const Particle&);
float px = get_pos().x + (get_bbox().p2.x - get_bbox().p1.x - airarrow.get()->get_width()) / 2;
float py = Sector::current()->camera->get_translation().y;
py += std::min(((py - (get_bbox().p2.y + 16)) / 4), 16.0f);
- context.draw_surface(airarrow.get(), Vector(px, py), LAYER_HUD - 1);
+ context.draw_surface(airarrow, Vector(px, py), LAYER_HUD - 1);
}
std::string sa_prefix = "";
particle->pos.x = systemRandom.rand(int(virtual_width));
particle->pos.y = systemRandom.rand(int(virtual_height));
int rainsize = systemRandom.rand(2);
- particle->texture = rainimages[rainsize].get();
+ particle->texture = rainimages[rainsize];
do {
particle->speed = (rainsize+1)*45 + systemRandom.randf(3.6);
} while(particle->speed < 1);
SnowParticleSystem::SnowParticleSystem()
{
- snowimages[0] = new Surface("images/objects/particles/snow2.png");
- snowimages[1] = new Surface("images/objects/particles/snow1.png");
- snowimages[2] = new Surface("images/objects/particles/snow0.png");
+ snowimages[0] = Surface::create("images/objects/particles/snow2.png");
+ snowimages[1] = Surface::create("images/objects/particles/snow1.png");
+ snowimages[2] = Surface::create("images/objects/particles/snow0.png");
virtual_width = SCREEN_WIDTH * 2;
SnowParticleSystem::~SnowParticleSystem()
{
- for(int i=0;i<3;++i)
- delete snowimages[i];
}
void SnowParticleSystem::update(float elapsed_time)
{}
};
- Surface* snowimages[3];
+ SurfacePtr snowimages[3];
private:
SnowParticleSystem(const SnowParticleSystem&);
int
Sprite::get_width() const
{
- return (int) action->surfaces[get_frame()]->get_width();
+ if((int)frame >= get_frames() || (int)frame < 0)
+ {
+ log_warning << "frame out of range: " << (int)frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl;
+ return 0;
+ }
+ else
+ {
+ return (int) action->surfaces[get_frame()]->get_width();
+ }
}
int
Sprite::get_height() const
{
+ if((int)frame >= get_frames() || (int)frame < 0)
+ {
+ log_warning << "frame out of range: " << (int)frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl;
+ return 0;
+ }
+ else
+ {
return (int) action->surfaces[get_frame()]->get_height();
+ }
}
float
{
this->frame = (float) (frame_ % get_frames());
}
- Surface* get_frame(unsigned int frame_)
+ SurfacePtr get_frame(unsigned int frame_)
{
assert(frame_ < action->surfaces.size());
return action->surfaces[frame_];
SpriteData::Action::~Action()
{
- for(std::vector<Surface*>::iterator i = surfaces.begin();
- i != surfaces.end(); ++i)
- delete *i;
}
SpriteData::SpriteData(const Reader& lisp, const std::string& basedir) :
float max_w = 0;
float max_h = 0;
for(int i = 0; static_cast<unsigned int>(i) < act_tmp->surfaces.size(); i++) {
- Surface* surface = new Surface(*(act_tmp->surfaces[i]));
+ SurfacePtr surface(new Surface(*act_tmp->surfaces[i]));
surface->hflip();
max_w = std::max(max_w, (float) surface->get_width());
max_h = std::max(max_h, (float) surface->get_height());
float max_w = 0;
float max_h = 0;
for(std::vector<std::string>::size_type i = 0; i < images.size(); i++) {
- Surface* surface = new Surface(basedir + images[i]);
+ SurfacePtr surface = Surface::create(basedir + images[i]);
max_w = std::max(max_w, (float) surface->get_width());
max_h = std::max(max_h, (float) surface->get_height());
action->surfaces.push_back(surface);
/** Frames per second */
float fps;
- std::vector<Surface*> surfaces;
+ std::vector<SurfacePtr> surfaces;
};
typedef std::map <std::string, Action*> Actions;
context.push_transform();
context.set_alpha(alpha);
- context.draw_surface(background2.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2 - background->get_width() + backgroundOffset, height - background->get_height()), layer);
- context.draw_surface(background2.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2 + backgroundOffset, height - background->get_height()), layer);
+ context.draw_surface(background2, Vector(SCREEN_WIDTH/2 - background->get_width()/2 - background->get_width() + backgroundOffset, height - background->get_height()), layer);
+ context.draw_surface(background2, Vector(SCREEN_WIDTH/2 - background->get_width()/2 + backgroundOffset, height - background->get_height()), layer);
for (int x = (SCREEN_WIDTH/2 - background->get_width()/2 - (static_cast<int>(ceilf((float)SCREEN_WIDTH / (float)background->get_width()) - 1) * background->get_width())); x < SCREEN_WIDTH; x+=background->get_width()) {
- context.draw_surface(background.get(), Vector(x, height - background->get_height()), layer);
+ context.draw_surface(background, Vector(x, height - background->get_height()), layer);
}
backgroundOffset+=10;
if (backgroundOffset > (int)background->get_width()) backgroundOffset -= (int)background->get_width();
// draw level stats while end_sequence is running
if (end_sequence) {
- level->stats.draw_endseq_panel(context, best_level_statistics, statistics_backdrop.get());
+ level->stats.draw_endseq_panel(context, best_level_statistics, statistics_backdrop);
}
}
{
// draw the scrolling arrows
if (arrow_scrollup.get() && firstline > 0)
- context.draw_surface(arrow_scrollup.get(),
+ context.draw_surface(arrow_scrollup,
Vector( x1 + width - arrow_scrollup->get_width(), // top-right corner of box
y1), LAYER_GUI);
if (arrow_scrolldown.get() && linesLeft && firstline < lines.size()-1)
- context.draw_surface(arrow_scrolldown.get(),
+ context.draw_surface(arrow_scrolldown,
Vector( x1 + width - arrow_scrolldown->get_width(), // bottom-light corner of box
y1 + height - arrow_scrolldown->get_height()),
LAYER_GUI);
Vector position = bbox.p1;
switch (lineType) {
case IMAGE:
- context.draw_surface(image.get(), Vector( (bbox.p1.x + bbox.p2.x - image->get_width()) / 2, position.y), layer);
+ context.draw_surface(image, Vector( (bbox.p1.x + bbox.p2.x - image->get_width()) / 2, position.y), layer);
break;
case NORMAL_LEFT:
context.draw_text(font, text, Vector(position.x, position.y), ALIGN_LEFT, layer, color);
context.push_transform();
context.set_translation(Vector(0, 0));
- Surface* coin_surf = coin_surface.get();
- if (coin_surf) {
- context.draw_surface(coin_surf, Vector(SCREEN_WIDTH - BORDER_X - coin_surf->get_width() - Resources::fixed_font->get_text_width(coins_text),
- BORDER_Y + 1), LAYER_HUD);
+ if (coin_surface)
+ {
+ context.draw_surface(coin_surface,
+ Vector(SCREEN_WIDTH - BORDER_X - coin_surface->get_width() - Resources::fixed_font->get_text_width(coins_text),
+ BORDER_Y + 1),
+ LAYER_HUD);
}
context.draw_text(Resources::fixed_font, coins_text, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y), ALIGN_RIGHT, LAYER_HUD, PlayerStatus::text_color);
}
void
-Statistics::draw_endseq_panel(DrawingContext& context, Statistics* best_stats, Surface* backdrop)
+Statistics::draw_endseq_panel(DrawingContext& context, Statistics* best_stats, SurfacePtr backdrop)
{
// skip draw if level was never played
// TODO: do we need this?
#include <squirrel.h>
#include "video/color.hpp"
+#include "video/surface_ptr.hpp"
namespace lisp { class Writer; }
namespace lisp { class Lisp; }
-class Surface;
class DrawingContext;
/** This class is a layer between level and worldmap to keep
void unserialize_from_squirrel(HSQUIRRELVM vm);
void draw_worldmap_info(DrawingContext& context); /**< draw worldmap stat HUD */
- void draw_endseq_panel(DrawingContext& context, Statistics* best_stats, Surface* backdrop); /**< draw panel shown during level's end sequence */
+ void draw_endseq_panel(DrawingContext& context, Statistics* best_stats, SurfacePtr backdrop); /**< draw panel shown during level's end sequence */
void zero(); /**< Set stats to zero */
void reset(); /**< Set stats (but not totals) to zero */
{
context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT),
Color(0.6f, 0.7f, 0.8f, 0.5f), 0);
- context.draw_surface(background.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2 , SCREEN_HEIGHT/2 - background->get_height()/2), 0);
+ context.draw_surface(background, Vector(SCREEN_WIDTH/2 - background->get_width()/2 , SCREEN_HEIGHT/2 - background->get_height()/2), 0);
float y = SCREEN_HEIGHT - scroll;
for(size_t i = 0; i < lines.size(); i++) {
Tile::~Tile()
{
- for(std::vector<Surface*>::iterator i = images.begin(); i != images.end();
- ++i) {
- delete *i;
- }
}
void
{
const ImageSpec& spec = *i;
- Surface* surface;
+ SurfacePtr surface;
if(spec.rect.get_width() <= 0)
{
- surface = new Surface(spec.file);
+ surface = Surface::create(spec.file);
}
else
{
- surface = new Surface(spec.file,
- Rect((int) spec.rect.p1.x,
- (int) spec.rect.p1.y,
- Size((int) spec.rect.get_width(),
- (int) spec.rect.get_height())));
+ surface = Surface::create(spec.file,
+ Rect((int) spec.rect.p1.x,
+ (int) spec.rect.p1.y,
+ Size((int) spec.rect.get_width(),
+ (int) spec.rect.get_height())));
}
images.push_back(surface);
}
private:
const TileSet& tileset;
std::vector<ImageSpec> imagespecs;
- std::vector<Surface*> images;
+ std::vector<SurfacePtr> images;
/// tile attributes
uint32_t attributes;
sector->draw(context);
// FIXME: Add something to scale the frame to the resolution of the screen
- context.draw_surface(frame.get(), Vector(0,0),LAYER_FOREGROUND1);
+ context.draw_surface(frame, Vector(0,0),LAYER_FOREGROUND1);
context.draw_text(Resources::small_font, "SuperTux " PACKAGE_VERSION "\n",
Vector(5, SCREEN_HEIGHT - 50), ALIGN_LEFT, LAYER_FOREGROUND1);
}
void
-DrawingContext::draw_surface(const Surface* surface, const Vector& position,
+DrawingContext::draw_surface(SurfacePtr surface, const Vector& position,
float angle, const Color& color, const Blend& blend,
int layer)
{
request->color = color;
request->blend = blend;
- request->request_data = const_cast<Surface*> (surface);
+ request->request_data = surface.get();
requests->push_back(request);
}
void
-DrawingContext::draw_surface(const Surface* surface, const Vector& position,
+DrawingContext::draw_surface(SurfacePtr surface, const Vector& position,
int layer)
{
draw_surface(surface, position, 0.0f, Color(1.0f, 1.0f, 1.0f), Blend(), layer);
}
void
-DrawingContext::draw_surface_part(const Surface* surface, const Vector& source,
+DrawingContext::draw_surface_part(SurfacePtr surface, const Vector& source,
const Vector& size, const Vector& dest, int layer)
{
assert(surface != 0);
SurfacePartRequest* surfacepartrequest = new(obst) SurfacePartRequest();
surfacepartrequest->size = size;
surfacepartrequest->source = source;
- surfacepartrequest->surface = surface;
+ surfacepartrequest->surface = surface.get();
// clip on screen borders
if(request->pos.x < 0) {
void init_renderer();
/// Adds a drawing request for a surface into the request list.
- void draw_surface(const Surface* surface, const Vector& position,
+ void draw_surface(SurfacePtr surface, const Vector& position,
int layer);
/// Adds a drawing request for a surface into the request list.
- void draw_surface(const Surface* surface, const Vector& position,
+ void draw_surface(SurfacePtr surface, const Vector& position,
float angle, const Color& color, const Blend& blend,
int layer);
/// Adds a drawing request for part of a surface.
- void draw_surface_part(const Surface* surface, const Vector& source,
+ void draw_surface_part(SurfacePtr surface, const Vector& source,
const Vector& size, const Vector& dest, int layer);
/// Draws a text.
void draw_text(const Font* font, const std::string& text,
{
const SurfacePartRequest* surfacepartrequest
= (SurfacePartRequest*) request.request_data;
- const Surface *surface = surfacepartrequest->surface;
+ const Surface* surface = surfacepartrequest->surface;
GLTexture *gltexture = dynamic_cast<GLTexture *>(surface->get_texture());
GLSurfaceData *surface_data = reinterpret_cast<GLSurfaceData *>(surface->get_surface_data());
{
const SurfacePartRequest* surfacepartrequest
= (SurfacePartRequest*) request.request_data;
- const Surface *surface = surfacepartrequest->surface;
+ const Surface* surface = surfacepartrequest->surface;
GLTexture *gltexture = dynamic_cast<GLTexture *>(surface->get_texture());
GLSurfaceData *surface_data = reinterpret_cast<GLSurfaceData *>(surface->get_surface_data());