Added Sprite::draw() method for drawing sprites to a Surface.
svn-id: r41654
This commit is contained in:
parent
a6355466d0
commit
1fe88abf6b
2 changed files with 23 additions and 0 deletions
|
@ -22,8 +22,10 @@
|
||||||
* $Id$
|
* $Id$
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "common/stream.h"
|
#include "common/stream.h"
|
||||||
|
|
||||||
|
#include "draci/draci.h"
|
||||||
#include "draci/sprite.h"
|
#include "draci/sprite.h"
|
||||||
|
|
||||||
namespace Draci {
|
namespace Draci {
|
||||||
|
@ -75,6 +77,23 @@ Sprite::Sprite(byte *sprite_data, uint16 length, uint16 x, uint16 y,
|
||||||
Sprite::~Sprite() {
|
Sprite::~Sprite() {
|
||||||
delete[] _data;
|
delete[] _data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Sprite::draw(Surface *surface) const {
|
||||||
|
byte *dst = (byte *)surface->getBasePtr(_x, _y);
|
||||||
|
byte *src = _data;
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < _height; ++i) {
|
||||||
|
for(unsigned int j = 0; j < _width; ++j, ++src) {
|
||||||
|
if (*src != surface->getTransparentColour())
|
||||||
|
dst[j] = *src;
|
||||||
|
}
|
||||||
|
|
||||||
|
dst += surface->pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
Common::Rect r(_x, _y, _x + _width, _y + _height);
|
||||||
|
surface->markDirtyRect(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // End of namespace Draci
|
} // End of namespace Draci
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
#ifndef DRACI_SPRITE_H
|
#ifndef DRACI_SPRITE_H
|
||||||
#define DRACI_SPRITE_H
|
#define DRACI_SPRITE_H
|
||||||
|
|
||||||
|
#include "draci/surface.h"
|
||||||
|
|
||||||
namespace Draci {
|
namespace Draci {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,6 +54,8 @@ public:
|
||||||
|
|
||||||
~Sprite();
|
~Sprite();
|
||||||
|
|
||||||
|
void draw(Surface *surface) const;
|
||||||
|
|
||||||
byte *_data;
|
byte *_data;
|
||||||
uint16 _width;
|
uint16 _width;
|
||||||
uint16 _height;
|
uint16 _height;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue