[Scummvm-cvs-logs] SF.net SVN: scummvm:[42835] scummvm/branches/gsoc2009-draci/engines/draci
dkasak13 at users.sourceforge.net
dkasak13 at users.sourceforge.net
Mon Jul 27 06:15:00 CEST 2009
Revision: 42835
http://scummvm.svn.sourceforge.net/scummvm/?rev=42835&view=rev
Author: dkasak13
Date: 2009-07-27 04:14:59 +0000 (Mon, 27 Jul 2009)
Log Message:
-----------
* Added Sprite::getPixel() (takes into account whether a sprite is mirrored or scaled)
* Made the Text class internally store a Common::String instead of a byte *
Modified Paths:
--------------
scummvm/branches/gsoc2009-draci/engines/draci/sprite.cpp
scummvm/branches/gsoc2009-draci/engines/draci/sprite.h
Modified: scummvm/branches/gsoc2009-draci/engines/draci/sprite.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/sprite.cpp 2009-07-27 03:57:43 UTC (rev 42834)
+++ scummvm/branches/gsoc2009-draci/engines/draci/sprite.cpp 2009-07-27 04:14:59 UTC (rev 42835)
@@ -126,6 +126,28 @@
_mirror = false;
}
+
+int Sprite::getPixel(int x, int y) const {
+
+ Common::Rect rect = getRect();
+
+ int dy = y - rect.top;
+ int dx = x - rect.left;
+
+ // Calculate scaling factors
+ double scaleX = double(_scaledWidth) / _width;
+ double scaleY = double(_scaledHeight) / _height;
+
+ int sy = lround(dy * scaleY);
+ int sx = lround(dx * scaleX);
+
+ if (_mirror)
+ return _data[sy * _width + (_width - sx)];
+ else
+ return _data[sy * _width + sx];
+}
+
+
void Sprite::drawScaled(Surface *surface, bool markDirty) const {
Common::Rect sourceRect(0, 0, _width, _height);
@@ -269,6 +291,7 @@
surface->markDirtyRect(destRect);
}
}
+
Common::Rect Sprite::getRect(bool scaled) const {
if (scaled)
@@ -279,15 +302,11 @@
Text::Text(const Common::String &str, Font *font, byte fontColour,
int x, int y, uint spacing) {
- uint len = str.size();
- _length = len;
-
_x = x;
_y = y;
_delay = 0;
- _text = new byte[len];
- memcpy(_text, str.c_str(), len);
+ _text = str;
_spacing = spacing;
_colour = fontColour;
@@ -295,27 +314,17 @@
_font = font;
_width = _font->getStringWidth(str, _spacing);
- _height = _font->getFontHeight();
+ _height = _font->getStringHeight(str);
_scaledWidth = _width;
_scaledHeight = _height;
}
-Text::~Text() {
- delete[] _text;
-}
-
void Text::setText(const Common::String &str) {
- delete[] _text;
-
- uint len = str.size();
- _length = len;
-
_width = _font->getStringWidth(str, _spacing);
- _height = _font->getFontHeight();
+ _height = _font->getStringHeight(str);
- _text = new byte[len];
- memcpy(_text, str.c_str(), len);
+ _text = str;
}
void Text::setColour(byte fontColour) {
@@ -328,7 +337,8 @@
void Text::draw(Surface *surface, bool markDirty) const {
_font->setColour(_colour);
- _font->drawString(surface, _text, _length, _x, _y, _spacing);
+
+ _font->drawString(surface, _text, _x, _y, _spacing);
}
// TODO: Handle scaled parameter properly by implementing Text scaling
Modified: scummvm/branches/gsoc2009-draci/engines/draci/sprite.h
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/sprite.h 2009-07-27 03:57:43 UTC (rev 42834)
+++ scummvm/branches/gsoc2009-draci/engines/draci/sprite.h 2009-07-27 04:14:59 UTC (rev 42835)
@@ -31,6 +31,8 @@
namespace Draci {
+enum DrawableType { kDrawableText, kDrawableSprite };
+
class Drawable {
public:
@@ -60,6 +62,8 @@
int getDelay() const { return _delay; }
virtual Common::Rect getRect(bool scaled = true) const = 0;
+
+ virtual DrawableType getType() const = 0;
protected:
uint _width; //!< Width of the sprite
@@ -105,7 +109,10 @@
Common::Rect getRect(bool scaled = true) const;
const byte *getBuffer() const { return _data; }
+ int getPixel(int x, int y) const;
+ DrawableType getType() const { return kDrawableSprite; }
+
private:
byte *_data; //!< Pointer to a buffer containing raw sprite data (row-wise)
bool _mirror;
@@ -116,7 +123,7 @@
public:
Text(const Common::String &str, Font *font, byte fontColour,
int x, int y, uint spacing = 0);
- ~Text();
+ ~Text() {};
void setText(const Common::String &str);
void setColour(byte fontColour);
@@ -130,8 +137,10 @@
void drawScaled(Surface *surface, bool markDirty = true) const { draw(surface, markDirty); }
Common::Rect getRect(bool) const;
+ DrawableType getType() const { return kDrawableText; }
+
private:
- byte *_text;
+ Common::String _text;
uint _length;
uint8 _colour;
uint _spacing;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list