]> git.localhorst.tv Git - l2e.git/commitdiff
switched some (x,y) and (w,h) pairs to vectors
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 22 Aug 2012 21:17:03 +0000 (23:17 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 22 Aug 2012 21:17:03 +0000 (23:17 +0200)
17 files changed:
src/battle/AttackTypeMenu.cpp
src/battle/AttackTypeMenu.h
src/battle/BattleState.h
src/battle/HeroTag.cpp
src/battle/HeroTag.h
src/battle/SmallHeroTag.cpp
src/battle/SmallHeroTag.h
src/battle/states/PerformAttacks.cpp
src/battle/states/RunState.cpp
src/battle/states/SelectIkari.cpp
src/battle/states/SelectItem.cpp
src/battle/states/SelectSpell.cpp
src/graphics/Animation.h
src/graphics/Frame.cpp
src/graphics/Frame.h
src/graphics/Sprite.cpp
src/graphics/Sprite.h

index b18c5221021aca9c32b8618a74b1e0abba78e308..f9786fb2c2405d1da0311e4038d9d93975cf6ca4 100644 (file)
@@ -15,11 +15,11 @@ using geometry::Vector;
 namespace battle {
 
 void AttackTypeMenu::Render(SDL_Surface *screen, const geometry::Vector<int> &position) {
-       Vector<int> swordOffset(IconWidth(), IconHeight());
-       Vector<int> magicOffset(IconWidth(), 0);
-       Vector<int> defendOffset(2 * IconWidth(), IconHeight());
-       Vector<int> ikariOffset(IconWidth(), 2 * IconHeight());
-       Vector<int> itemOffset(0, IconHeight());
+       const Vector<int> &swordOffset(IconSize());
+       const Vector<int> magicOffset(IconWidth(), 0);
+       const Vector<int> defendOffset(2 * IconWidth(), IconHeight());
+       const Vector<int> ikariOffset(IconWidth(), 2 * IconHeight());
+       const Vector<int> itemOffset(0, IconHeight());
 
        icons->Draw(screen, position + swordOffset, AttackChoice::SWORD, (selected == AttackChoice::SWORD) ? 1 : 0);
        icons->Draw(screen, position + magicOffset, AttackChoice::MAGIC, (selected == AttackChoice::MAGIC) ? 1 : 0);
index d31d63babf03593b07dac87eaa93473d94f2ab81..db07443fd7e008ba26c7045e6108beb162a61cba 100644 (file)
@@ -29,8 +29,10 @@ public:
 
        int Width() const { return 3 * IconWidth(); }
        int Height() const { return 3 * IconHeight(); }
+       geometry::Vector<int> Size() const { return 3 * IconSize(); }
        int IconWidth() const { return icons->Width(); }
        int IconHeight() const { return icons->Height(); }
+       const geometry::Vector<int> &IconSize() const { return icons->Size(); }
 
 private:
        const graphics::Sprite *icons;
index 27953cd013cd5e050aa9d2bded9a20eeb78856f8..806b4af59154525475ce3765532dc9600e2c3c6b 100644 (file)
@@ -139,6 +139,7 @@ public:
        }
        int Width() const { return background->w; }
        int Height() const { return background->h; }
+       geometry::Vector<int> Size() const { return geometry::Vector<int>(Width(), Height()); }
 
        void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
        void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
index 7938250910aa284a2f2f9946c9f685be5914088c..f94581b698a957b04e30e9625f385f5689a787d4 100644 (file)
@@ -26,12 +26,12 @@ const graphics::Sprite *HeroTag::HeroSprite() const {
        return battle->HeroAt(index).Sprite();
 }
 
-void HeroTag::Render(SDL_Surface *screen, int width, int height, Vector<int> position, bool active) const {
+void HeroTag::Render(SDL_Surface *screen, int width, int height, const Vector<int> &position, bool active) const {
        const Resources &r(battle->Res());
 
        // frame
        const Frame *frame(active ? r.activeHeroTagFrame : r.heroTagFrame);
-       Vector<int> frameOffset(frame->BorderWidth(), frame->BorderHeight());
+       Vector<int> frameOffset(frame->BorderSize());
        Vector<int> alignOffset((index % 2) ? 4 * r.heroTagFont->CharWidth() : 0, 0);
        frame->Draw(screen, position, width, height);
 
index 43dc66112a4da947404105d9a65fd6bd7a649452..8750081148cb8c94b58c845d411cf6cfd462947a 100644 (file)
@@ -35,7 +35,7 @@ public:
        const graphics::Sprite *HeroSprite() const;
        geometry::Vector<int> HeroOffset() const;
 
-       void Render(SDL_Surface *screen, int width, int height, geometry::Vector<int> position, bool active) const;
+       void Render(SDL_Surface *screen, int width, int height, const geometry::Vector<int> &position, bool active) const;
 
 private:
        const BattleState *battle;
index 0bc160a33b4078f35465db81700408cf94a08a96..a70dbfecd2b1e4f577c1d9053ec46f3c6ae5af34 100644 (file)
@@ -20,7 +20,7 @@ using graphics::Sprite;
 
 namespace battle {
 
-void SmallHeroTag::Render(SDL_Surface *screen, int width, int height, geometry::Vector<int> position) const {
+void SmallHeroTag::Render(SDL_Surface *screen, int width, int height, const geometry::Vector<int> &position) const {
        const Resources &r(battle->Res());
        const Frame *frame((index == battle->MaxHeroes() - 1) ? r.lastSmallHeroTagFrame : r.smallHeroTagFrame);
        const Font *font(r.normalFont);
@@ -32,7 +32,7 @@ void SmallHeroTag::Render(SDL_Surface *screen, int width, int height, geometry::
                const Hero &hero(battle->HeroAt(index));
 
                int gaugeWidth(width - 2 * frame->BorderWidth() - labels->Width());
-               Vector<int> nameOffset(frame->BorderWidth(), frame->BorderHeight());
+               Vector<int> nameOffset(frame->BorderSize());
                Vector<int> hpLabelOffset(nameOffset.X(), nameOffset.Y() + font->CharHeight());
                Vector<int> mpLabelOffset(hpLabelOffset.X(), hpLabelOffset.Y() + font->CharHeight());
                Vector<int> ipLabelOffset(mpLabelOffset.X(), mpLabelOffset.Y() + font->CharHeight());
index acd2d3158a13f83d80c995dfa08d0a57e769e5aa..c17d540c0609d98dc0d793113cc043ec0c6ddede 100644 (file)
@@ -29,7 +29,7 @@ public:
        SmallHeroTag(const BattleState *battle, int heroIndex)
        : battle(battle), index(heroIndex) { }
 
-       void Render(SDL_Surface *screen, int width, int height, geometry::Vector<int> position) const;
+       void Render(SDL_Surface *screen, int width, int height, const geometry::Vector<int> &position) const;
 
 private:
        const BattleState *battle;
index a01a8fe0c540dd5b3b5c611b4dff52354fd72b20..19fccb08d7384539add191705bfc160c5f097d9b 100644 (file)
@@ -228,7 +228,7 @@ void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector<int> &offs
        if (!titleBarText || !titleBarTimer.Running()) return;
 
        int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight());
-       battle->Res().titleFrame->Draw(screen, Vector<int>(offset.X(), offset.Y()), battle->Width(), height);
+       battle->Res().titleFrame->Draw(screen, offset, battle->Width(), height);
 
        Vector<int> textPosition(
                        (battle->Width() - (std::strlen(titleBarText) * battle->Res().titleFont->CharWidth())) / 2,
index a22f43816a0006612066ba5ad290df8fd070548d..e1f6f4bcdd89058dc65b260849202e872606df54 100644 (file)
@@ -68,7 +68,7 @@ void RunState::Render(SDL_Surface *screen) {
 
 void RunState::RenderTitleBar(SDL_Surface *screen, const Vector<int> &offset) {
        int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight());
-       battle->Res().titleFrame->Draw(screen, Vector<int>(offset.X(), offset.Y()), battle->Width(), height);
+       battle->Res().titleFrame->Draw(screen, offset, battle->Width(), height);
 
        Vector<int> textPosition(
                        (battle->Width() - (std::strlen(battle->Res().escapeText) * battle->Res().titleFont->CharWidth())) / 2,
index 7647e2898f2c11cf80b2275c414b651d6048aa77..87436b0faad8d862a58f82f185013d309a8f4fc9 100644 (file)
@@ -108,7 +108,7 @@ void SelectIkari::Render(SDL_Surface *screen) {
 
 void SelectIkari::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
        const Frame *frame(battle->Res().selectFrame);
-       Vector<int> position(frame->BorderWidth(), frame->BorderHeight());
+       Vector<int> position(frame->BorderSize());
        int width(battle->Width() - 2 * frame->BorderWidth());
        int height(battle->Res().normalFont->CharHeight() * 13);
        frame->Draw(screen, position + offset, width, height);
index f58a78eaf72fa9eb9c658d7f75b5af8ab3fbd395..68f844f02994e6b81a736ee61b260ca7fbca29cc 100644 (file)
@@ -107,7 +107,7 @@ void SelectItem::Render(SDL_Surface *screen) {
 
 void SelectItem::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
        const Frame *frame(battle->Res().selectFrame);
-       Vector<int> position(frame->BorderWidth(), frame->BorderHeight());
+       Vector<int> position(frame->BorderSize());
        int width(battle->Width() - 2 * frame->BorderWidth());
        int height(battle->Res().normalFont->CharHeight() * 13);
        frame->Draw(screen, position + offset, width, height);
index 65cd8ccdc70173c2ab0e9106588ca249a6fb705f..0c1dec4e0dd47ab47180119b679a722fc7047c1d 100644 (file)
@@ -108,7 +108,7 @@ void SelectSpell::Render(SDL_Surface *screen) {
 
 void SelectSpell::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
        const Frame *frame(battle->Res().selectFrame);
-       Vector<int> position(frame->BorderWidth(), frame->BorderHeight());
+       Vector<int> position(frame->BorderSize());
        int width(battle->Width() - 2 * frame->BorderWidth());
        int height(battle->Res().normalFont->CharHeight() * 13);
        frame->Draw(screen, position + offset, width, height);
index e26bca9c2cc889b9c39ef466442394dfa798d04c..208f6bdb19e7b95d9dbc20a417498608f14dc64b 100644 (file)
@@ -97,8 +97,7 @@ public:
                Draw(dest, position + offset);
        }
        void DrawCenter(SDL_Surface *dest, geometry::Vector<int> position) const {
-               geometry::Vector<int> offset(-sprite->Width() / 2, -sprite->Height() / 2);
-               Draw(dest, position + offset);
+               Draw(dest, position - (sprite->Size() / 2));
        }
        void DrawCenterBottom(SDL_Surface *dest, geometry::Vector<int> position) const {
                geometry::Vector<int> offset(-sprite->Width() / 2, -sprite->Height());
index 1c51c454cad056f9a56f9734e0f490426e2860d4..a152ee76c8efa152825dc514938e100df97c3736 100644 (file)
@@ -15,83 +15,83 @@ namespace graphics {
 void Frame::Draw(SDL_Surface *dest, const Vector<int> &position, int width, int height) const {
        // top-left corner
        SDL_Rect srcRect;
-       srcRect.x = xOffset;
-       srcRect.y = yOffset;
-       srcRect.w = borderWidth;
-       srcRect.h = borderHeight;
+       srcRect.x = offset.X();
+       srcRect.y = offset.Y();
+       srcRect.w = BorderWidth();
+       srcRect.h = BorderHeight();
        SDL_Rect destRect;
        destRect.x = position.X();
        destRect.y = position.Y();
        SDL_BlitSurface(surface, &srcRect, dest, &destRect);
 
        // top border
-       srcRect.x += borderWidth;
-       srcRect.w = repeatWidth;
-       destRect.x += borderWidth;
-       int fullRepeatWidth(width - (2 * borderWidth));
+       srcRect.x += BorderWidth();
+       srcRect.w = RepeatWidth();
+       destRect.x += BorderWidth();
+       int fullRepeatWidth(width - (2 * BorderWidth()));
        int repeatCursor(0);
        while (repeatCursor < fullRepeatWidth) {
                SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-               destRect.x += repeatWidth;
-               repeatCursor += repeatWidth;
+               destRect.x += RepeatWidth();
+               repeatCursor += RepeatWidth();
        }
 
        // top-right corner
-       srcRect.x += repeatWidth;
-       srcRect.w = borderWidth;
+       srcRect.x += RepeatWidth();
+       srcRect.w = BorderWidth();
        SDL_BlitSurface(surface, &srcRect, dest, &destRect);
 
        // middle
-       destRect.y += borderHeight;
-       int fullRepeatHeight(height - (2 * borderHeight));
+       destRect.y += BorderHeight();
+       int fullRepeatHeight(height - (2 * BorderHeight()));
        int hRepeatCursor(0);
        while (hRepeatCursor < fullRepeatHeight) {
 
                // left border
-               srcRect.x = xOffset;
-               srcRect.y = yOffset + borderHeight;
-               srcRect.w = borderWidth;
-               srcRect.h = repeatHeight;
+               srcRect.x = offset.X();
+               srcRect.y = offset.Y() + BorderHeight();
+               srcRect.w = BorderWidth();
+               srcRect.h = RepeatHeight();
                destRect.x = position.X();
                SDL_BlitSurface(surface, &srcRect, dest, &destRect);
 
                // fill
                repeatCursor = 0;
-               srcRect.x += borderWidth;
-               srcRect.w = repeatWidth;
-               destRect.x += borderWidth;
+               srcRect.x += BorderWidth();
+               srcRect.w = RepeatWidth();
+               destRect.x += BorderWidth();
                while (repeatCursor < fullRepeatWidth) {
                        SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-                       destRect.x += repeatWidth;
-                       repeatCursor += repeatWidth;
+                       destRect.x += RepeatWidth();
+                       repeatCursor += RepeatWidth();
                }
 
                // right border
-               srcRect.x += repeatWidth;
-               srcRect.w = borderWidth;
+               srcRect.x += RepeatWidth();
+               srcRect.w = BorderWidth();
                SDL_BlitSurface(surface, &srcRect, dest, &destRect);
 
-               destRect.y += repeatHeight;
-               hRepeatCursor += repeatHeight;
+               destRect.y += RepeatHeight();
+               hRepeatCursor += RepeatHeight();
        }
 
        // bottom-left corner
-       srcRect.x = xOffset;
-       srcRect.y = yOffset + borderHeight + repeatHeight;
-       srcRect.w = borderWidth;
-       srcRect.h = borderHeight;
+       srcRect.x = offset.X();
+       srcRect.y = offset.Y() + BorderHeight() + RepeatHeight();
+       srcRect.w = BorderWidth();
+       srcRect.h = BorderHeight();
        destRect.x = position.X();
        SDL_BlitSurface(surface, &srcRect, dest, &destRect);
 
        // bottom border
-       srcRect.x += borderWidth;
-       srcRect.w = repeatWidth;
-       destRect.x += borderWidth;
+       srcRect.x += BorderWidth();
+       srcRect.w = RepeatWidth();
+       destRect.x += BorderWidth();
        repeatCursor = 0;
        while (repeatCursor < fullRepeatWidth) {
                SDL_BlitSurface(surface, &srcRect, dest, &destRect);
-               destRect.x += repeatWidth;
-               repeatCursor += repeatWidth;
+               destRect.x += RepeatWidth();
+               repeatCursor += RepeatWidth();
        }
        if (fullRepeatWidth < fullRepeatWidth) {
                srcRect.w = fullRepeatWidth - fullRepeatWidth;
@@ -100,8 +100,8 @@ void Frame::Draw(SDL_Surface *dest, const Vector<int> &position, int width, int
        }
 
        // bottom-right corner
-       srcRect.x += repeatWidth;
-       srcRect.w = borderWidth;
+       srcRect.x += RepeatWidth();
+       srcRect.w = BorderWidth();
        SDL_BlitSurface(surface, &srcRect, dest, &destRect);
 }
 
index 74ce1f7600e18198bf4ad5ed46a97df6b6d6860f..09674cc62d2f63a97dc50a327a2c6df2c33a0fd4 100644 (file)
@@ -18,23 +18,24 @@ class Frame {
 
 public:
        Frame(SDL_Surface *s, int borderWidth, int borderHeight, int repeatWidth = 1, int repeatHeight = 1, int xOffset = 0, int yOffset = 0)
-       : surface(s), borderWidth(borderWidth), borderHeight(borderHeight), repeatWidth(repeatWidth), repeatHeight(repeatHeight), xOffset(xOffset), yOffset(yOffset) { }
+       : surface(s), borderSize(borderWidth, borderHeight), repeatSize(repeatWidth, repeatHeight), offset(xOffset, yOffset) { }
 
 public:
-       int MinWidth() const { return 2 * borderWidth; }
-       int MinHeight() const { return 2 * borderHeight; }
-       int BorderWidth() const { return borderWidth; }
-       int BorderHeight() const { return borderHeight; }
+       int MinWidth() const { return 2 * BorderWidth(); }
+       int MinHeight() const { return 2 * BorderHeight(); }
+       int BorderWidth() const { return BorderSize().X(); }
+       int BorderHeight() const { return BorderSize().Y(); }
+       const geometry::Vector<int> BorderSize() const { return borderSize; }
+       int RepeatWidth() const { return RepeatSize().X(); }
+       int RepeatHeight() const { return RepeatSize().Y(); }
+       const geometry::Vector<int> RepeatSize() const { return repeatSize; }
        void Draw(SDL_Surface *dest, const geometry::Vector<int> &position, int width, int height) const;
 
 private:
        SDL_Surface *surface;
-       int borderWidth;
-       int borderHeight;
-       int repeatWidth;
-       int repeatHeight;
-       int xOffset;
-       int yOffset;
+       geometry::Vector<int> borderSize;
+       geometry::Vector<int> repeatSize;
+       geometry::Vector<int> offset;
 
 };
 
index 2c092deb2c85f8ae6b807025d4704a5220e247d1..67bde8d09ba60f35e9ed85ea1e742d55ed9459e9 100644 (file)
@@ -13,8 +13,8 @@ namespace graphics {
 
 void Sprite::Draw(SDL_Surface *dest, const Vector<int> &position, int col, int row) const {
        SDL_Rect srcRect, destRect;
-       srcRect.x = xOffset + col * Width();
-       srcRect.y = yOffset + row * Height();
+       srcRect.x = offset.X() + col * Width();
+       srcRect.y = offset.Y() + row * Height();
        srcRect.w = Width();
        srcRect.h = Height();
        destRect.x = position.X();
index 942d98e51e5e7424d791d657aa7ab94d4371ace3..f6f3b7b566d58cfa969d973767353c39cfea8b7e 100644 (file)
@@ -18,19 +18,19 @@ class Sprite {
 
 public:
        Sprite(SDL_Surface *s, int width, int height, int xOffset = 0, int yOffset = 0)
-       : surface(s), width(width), height(height), xOffset(xOffset), yOffset(yOffset) { }
+       : surface(s), size(width, height), offset(xOffset, yOffset) { }
 
 public:
-       int Width() const { return width; }
-       int Height() const { return height; }
+       int Width() const { return size.X(); }
+       int Height() const { return size.Y(); }
+       const geometry::Vector<int> &Size() const { return size; }
        void Draw(SDL_Surface *dest, const geometry::Vector<int> &position, int col = 0, int row = 0) const;
        void DrawTopRight(SDL_Surface *dest, const geometry::Vector<int> &position, int col = 0, int row = 0) const {
                geometry::Vector<int> offset(-Width(), 0);
                Draw(dest, position + offset, col, row);
        }
        void DrawCenter(SDL_Surface *dest, const geometry::Vector<int> &position, int col = 0, int row = 0) const {
-               geometry::Vector<int> offset(-Width() / 2, -Height() / 2);
-               Draw(dest, position + offset, col, row);
+               Draw(dest, position - (Size() / 2), col, row);
        }
        void DrawCenterBottom(SDL_Surface *dest, const geometry::Vector<int> &position, int col = 0, int row = 0) const {
                geometry::Vector<int> offset(-Width() / 2, -Height());
@@ -39,10 +39,8 @@ public:
 
 private:
        SDL_Surface *surface;
-       int width;
-       int height;
-       int xOffset;
-       int yOffset;
+       geometry::Vector<int> size;
+       geometry::Vector<int> offset;
 
 };