diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2007-05-07 16:22:54 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2007-05-07 16:22:54 +0000 |
commit | 8313edcc163bfecd1c41a7faf55f51379189b92b (patch) | |
tree | ebb6f1db2038b3277aca90efe4061c5b8e1820c4 | |
parent | 279b74f292a45709afcddeea6667d0096d06fd3f (diff) | |
download | mana-8313edcc163bfecd1c41a7faf55f51379189b92b.tar.gz mana-8313edcc163bfecd1c41a7faf55f51379189b92b.tar.bz2 mana-8313edcc163bfecd1c41a7faf55f51379189b92b.tar.xz mana-8313edcc163bfecd1c41a7faf55f51379189b92b.zip |
Fixed positioning of monster names and target circles.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | src/animatedsprite.cpp | 24 | ||||
-rw-r--r-- | src/animatedsprite.h | 12 | ||||
-rw-r--r-- | src/being.cpp | 26 | ||||
-rw-r--r-- | src/being.h | 12 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 33 | ||||
-rw-r--r-- | src/sprite.h | 16 |
7 files changed, 116 insertions, 15 deletions
@@ -1,5 +1,13 @@ 2007-05-02 Philipp Sehmisch <tmw@crushnet.org> + * src/sprite.h, src/being.cpp, src/being.h, src/animatedsprite.cpp, + src/animatedsprite.h: Added methods to get the width and height of the + graphical representation of a sprite. + * src/gui/viewport.cpp: Fixed positioning of monster names and target + circles. + +2007-05-02 Philipp Sehmisch <tmw@crushnet.org> + * src/particle.cpp: Fixed a compiler warning. 2007-05-02 Björn Steinbrink <B.Steinbrink@gmx.de> diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 7260a512..c1e89ff0 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -197,3 +197,27 @@ AnimatedSprite::setDirection(SpriteDirection direction) } } } + +int +AnimatedSprite::getWidth() const +{ + if (mFrame) + { + return mFrame->image->getWidth(); + } + else { + return 0; + } +} + +int +AnimatedSprite::getHeight() const +{ + if (mFrame) + { + return mFrame->image->getHeight(); + } + else { + return 0; + } +} diff --git a/src/animatedsprite.h b/src/animatedsprite.h index 101ff159..d77d08f5 100644 --- a/src/animatedsprite.h +++ b/src/animatedsprite.h @@ -86,6 +86,18 @@ class AnimatedSprite draw(Graphics* graphics, int posX, int posY) const; /** + * gets the width in pixels of the image of the current frame + */ + int + getWidth() const; + + /** + * gets the height in pixels of the image of the current frame + */ + int + getHeight() const; + + /** * Sets the direction. */ void diff --git a/src/being.cpp b/src/being.cpp index db7751bf..8ddd1e89 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -511,3 +511,29 @@ Being::getOffset(char pos, char neg) const return offset; } + + +int +Being::getWidth() const +{ + if (mSprites[BASE_SPRITE]) + { + return mSprites[BASE_SPRITE]->getWidth(); + } + else { + return 0; + } +}; + + +int +Being::getHeight() const +{ + if (mSprites[BASE_SPRITE]) + { + return mSprites[BASE_SPRITE]->getHeight(); + } + else { + return 0; + } +}; diff --git a/src/being.h b/src/being.h index 5dbd845b..a1f59c91 100644 --- a/src/being.h +++ b/src/being.h @@ -350,6 +350,18 @@ class Being : public Sprite int getYOffset() const { return getOffset(UP, DOWN); } + /** + * Returns the horizontal size of the current base sprite of the being + */ + virtual int + getWidth() const; + + /** + * Returns the vertical size of the current base sprite of the being + */ + virtual int + getHeight() const; + std::auto_ptr<Equipment> mEquipment; /** diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 84634ca6..3def2055 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -41,6 +41,7 @@ #include "../resources/animation.h" #include "../resources/monsterinfo.h" #include "../resources/resourcemanager.h" +#include "../resources/image.h" #include "../resources/imageset.h" #include "../utils/tostring.h" @@ -272,26 +273,28 @@ Viewport::drawTargetCursor(Graphics *graphics) Being *target = player_node->getTarget(); if (target) { + // Calculate target circle position + // Find whether target is in range int rangeX = abs(target->mX - player_node->mX); int rangeY = abs(target->mY - player_node->mY); int attackRange = player_node->getAttackRange(); - // Draw the target cursor, which one depends if the target is in range + // get the correct target cursors graphic + Image* targetCursor; if (rangeX > attackRange || rangeY > attackRange) { - // Draw the out of range cursor - graphics->drawImage(mTargetCursorOutRange->getCurrentImage(), - target->getPixelX() - (int) mViewX, - target->getPixelY() - (int) mViewY); + targetCursor = mTargetCursorOutRange->getCurrentImage(); } - else - { - // Draw the in range cursor - graphics->drawImage(mTargetCursorInRange->getCurrentImage(), - target->getPixelX() - (int) mViewX, - target->getPixelY() - (int) mViewY); + else { + targetCursor = mTargetCursorInRange->getCurrentImage(); } + + // Draw the target cursor at the correct position + int posX = target->getPixelX() + 16 - targetCursor->getWidth() / 2 - (int) mViewX; + int posY = target->getPixelY() + 16 - targetCursor->getHeight() / 2 - (int) mViewY; + + graphics->drawImage(targetCursor, posX, posY); } } @@ -306,10 +309,10 @@ Viewport::drawTargetName(Graphics *graphics) graphics->setColor(gcn::Color(255, 32, 32)); const MonsterInfo &mi = static_cast<Monster*>(target)->getInfo(); - graphics->drawText(mi.getName(), - target->getPixelX() - (int) mViewX + 15, - target->getPixelY() - (int) mViewY - 42, - gcn::Graphics::CENTER); + int posX = target->getPixelX() + 16 - (int)mViewX; + int posY = target->getPixelY() + 16 - target->getHeight() - (int)mViewY; + + graphics->drawText(mi.getName(), posX, posY, gcn::Graphics::CENTER); } } diff --git a/src/sprite.h b/src/sprite.h index 51811149..89780519 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -50,6 +50,22 @@ class Sprite draw(Graphics *graphics, int offsetX, int offsetY) const = 0; /** + * Returns the horizontal size of the sprites graphical representation + * in pixels or 0 when it is undefined. + */ + virtual int + getWidth() const + { return 0; } + + /** + * Returns the vertical size of the sprites graphical representation + * in pixels or 0 when it is undefined. + */ + virtual int + getHeight() const + { return 0; } + + /** * Returns the pixel Y coordinate of the sprite. */ virtual int |