From: Daniel Karbach Date: Wed, 22 Aug 2012 21:17:03 +0000 (+0200) Subject: switched some (x,y) and (w,h) pairs to vectors X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;h=d20fa78a0dcbc95a69bb6077d2081d42b74a2d1a;hp=0542849dfccfec1ce1477265fa0fee2401a8fb23;p=l2e.git switched some (x,y) and (w,h) pairs to vectors --- diff --git a/src/battle/AttackTypeMenu.cpp b/src/battle/AttackTypeMenu.cpp index b18c522..f9786fb 100644 --- a/src/battle/AttackTypeMenu.cpp +++ b/src/battle/AttackTypeMenu.cpp @@ -15,11 +15,11 @@ using geometry::Vector; namespace battle { void AttackTypeMenu::Render(SDL_Surface *screen, const geometry::Vector &position) { - Vector swordOffset(IconWidth(), IconHeight()); - Vector magicOffset(IconWidth(), 0); - Vector defendOffset(2 * IconWidth(), IconHeight()); - Vector ikariOffset(IconWidth(), 2 * IconHeight()); - Vector itemOffset(0, IconHeight()); + const Vector &swordOffset(IconSize()); + const Vector magicOffset(IconWidth(), 0); + const Vector defendOffset(2 * IconWidth(), IconHeight()); + const Vector ikariOffset(IconWidth(), 2 * IconHeight()); + const Vector 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); diff --git a/src/battle/AttackTypeMenu.h b/src/battle/AttackTypeMenu.h index d31d63b..db07443 100644 --- a/src/battle/AttackTypeMenu.h +++ b/src/battle/AttackTypeMenu.h @@ -29,8 +29,10 @@ public: int Width() const { return 3 * IconWidth(); } int Height() const { return 3 * IconHeight(); } + geometry::Vector Size() const { return 3 * IconSize(); } int IconWidth() const { return icons->Width(); } int IconHeight() const { return icons->Height(); } + const geometry::Vector &IconSize() const { return icons->Size(); } private: const graphics::Sprite *icons; diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index 27953cd..806b4af 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -139,6 +139,7 @@ public: } int Width() const { return background->w; } int Height() const { return background->h; } + geometry::Vector Size() const { return geometry::Vector(Width(), Height()); } void RenderBackground(SDL_Surface *screen, const geometry::Vector &offset); void RenderMonsters(SDL_Surface *screen, const geometry::Vector &offset); diff --git a/src/battle/HeroTag.cpp b/src/battle/HeroTag.cpp index 7938250..f94581b 100644 --- a/src/battle/HeroTag.cpp +++ b/src/battle/HeroTag.cpp @@ -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 position, bool active) const { +void HeroTag::Render(SDL_Surface *screen, int width, int height, const Vector &position, bool active) const { const Resources &r(battle->Res()); // frame const Frame *frame(active ? r.activeHeroTagFrame : r.heroTagFrame); - Vector frameOffset(frame->BorderWidth(), frame->BorderHeight()); + Vector frameOffset(frame->BorderSize()); Vector alignOffset((index % 2) ? 4 * r.heroTagFont->CharWidth() : 0, 0); frame->Draw(screen, position, width, height); diff --git a/src/battle/HeroTag.h b/src/battle/HeroTag.h index 43dc661..8750081 100644 --- a/src/battle/HeroTag.h +++ b/src/battle/HeroTag.h @@ -35,7 +35,7 @@ public: const graphics::Sprite *HeroSprite() const; geometry::Vector HeroOffset() const; - void Render(SDL_Surface *screen, int width, int height, geometry::Vector position, bool active) const; + void Render(SDL_Surface *screen, int width, int height, const geometry::Vector &position, bool active) const; private: const BattleState *battle; diff --git a/src/battle/SmallHeroTag.cpp b/src/battle/SmallHeroTag.cpp index 0bc160a..a70dbfe 100644 --- a/src/battle/SmallHeroTag.cpp +++ b/src/battle/SmallHeroTag.cpp @@ -20,7 +20,7 @@ using graphics::Sprite; namespace battle { -void SmallHeroTag::Render(SDL_Surface *screen, int width, int height, geometry::Vector position) const { +void SmallHeroTag::Render(SDL_Surface *screen, int width, int height, const geometry::Vector &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 nameOffset(frame->BorderWidth(), frame->BorderHeight()); + Vector nameOffset(frame->BorderSize()); Vector hpLabelOffset(nameOffset.X(), nameOffset.Y() + font->CharHeight()); Vector mpLabelOffset(hpLabelOffset.X(), hpLabelOffset.Y() + font->CharHeight()); Vector ipLabelOffset(mpLabelOffset.X(), mpLabelOffset.Y() + font->CharHeight()); diff --git a/src/battle/SmallHeroTag.h b/src/battle/SmallHeroTag.h index acd2d31..c17d540 100644 --- a/src/battle/SmallHeroTag.h +++ b/src/battle/SmallHeroTag.h @@ -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 position) const; + void Render(SDL_Surface *screen, int width, int height, const geometry::Vector &position) const; private: const BattleState *battle; diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp index a01a8fe..19fccb0 100644 --- a/src/battle/states/PerformAttacks.cpp +++ b/src/battle/states/PerformAttacks.cpp @@ -228,7 +228,7 @@ void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector &offs if (!titleBarText || !titleBarTimer.Running()) return; int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight()); - battle->Res().titleFrame->Draw(screen, Vector(offset.X(), offset.Y()), battle->Width(), height); + battle->Res().titleFrame->Draw(screen, offset, battle->Width(), height); Vector textPosition( (battle->Width() - (std::strlen(titleBarText) * battle->Res().titleFont->CharWidth())) / 2, diff --git a/src/battle/states/RunState.cpp b/src/battle/states/RunState.cpp index a22f438..e1f6f4b 100644 --- a/src/battle/states/RunState.cpp +++ b/src/battle/states/RunState.cpp @@ -68,7 +68,7 @@ void RunState::Render(SDL_Surface *screen) { void RunState::RenderTitleBar(SDL_Surface *screen, const Vector &offset) { int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight()); - battle->Res().titleFrame->Draw(screen, Vector(offset.X(), offset.Y()), battle->Width(), height); + battle->Res().titleFrame->Draw(screen, offset, battle->Width(), height); Vector textPosition( (battle->Width() - (std::strlen(battle->Res().escapeText) * battle->Res().titleFont->CharWidth())) / 2, diff --git a/src/battle/states/SelectIkari.cpp b/src/battle/states/SelectIkari.cpp index 7647e28..87436b0 100644 --- a/src/battle/states/SelectIkari.cpp +++ b/src/battle/states/SelectIkari.cpp @@ -108,7 +108,7 @@ void SelectIkari::Render(SDL_Surface *screen) { void SelectIkari::RenderFrame(SDL_Surface *screen, const Vector &offset) { const Frame *frame(battle->Res().selectFrame); - Vector position(frame->BorderWidth(), frame->BorderHeight()); + Vector position(frame->BorderSize()); int width(battle->Width() - 2 * frame->BorderWidth()); int height(battle->Res().normalFont->CharHeight() * 13); frame->Draw(screen, position + offset, width, height); diff --git a/src/battle/states/SelectItem.cpp b/src/battle/states/SelectItem.cpp index f58a78e..68f844f 100644 --- a/src/battle/states/SelectItem.cpp +++ b/src/battle/states/SelectItem.cpp @@ -107,7 +107,7 @@ void SelectItem::Render(SDL_Surface *screen) { void SelectItem::RenderFrame(SDL_Surface *screen, const Vector &offset) { const Frame *frame(battle->Res().selectFrame); - Vector position(frame->BorderWidth(), frame->BorderHeight()); + Vector position(frame->BorderSize()); int width(battle->Width() - 2 * frame->BorderWidth()); int height(battle->Res().normalFont->CharHeight() * 13); frame->Draw(screen, position + offset, width, height); diff --git a/src/battle/states/SelectSpell.cpp b/src/battle/states/SelectSpell.cpp index 65cd8cc..0c1dec4 100644 --- a/src/battle/states/SelectSpell.cpp +++ b/src/battle/states/SelectSpell.cpp @@ -108,7 +108,7 @@ void SelectSpell::Render(SDL_Surface *screen) { void SelectSpell::RenderFrame(SDL_Surface *screen, const Vector &offset) { const Frame *frame(battle->Res().selectFrame); - Vector position(frame->BorderWidth(), frame->BorderHeight()); + Vector position(frame->BorderSize()); int width(battle->Width() - 2 * frame->BorderWidth()); int height(battle->Res().normalFont->CharHeight() * 13); frame->Draw(screen, position + offset, width, height); diff --git a/src/graphics/Animation.h b/src/graphics/Animation.h index e26bca9..208f6bd 100644 --- a/src/graphics/Animation.h +++ b/src/graphics/Animation.h @@ -97,8 +97,7 @@ public: Draw(dest, position + offset); } void DrawCenter(SDL_Surface *dest, geometry::Vector position) const { - geometry::Vector offset(-sprite->Width() / 2, -sprite->Height() / 2); - Draw(dest, position + offset); + Draw(dest, position - (sprite->Size() / 2)); } void DrawCenterBottom(SDL_Surface *dest, geometry::Vector position) const { geometry::Vector offset(-sprite->Width() / 2, -sprite->Height()); diff --git a/src/graphics/Frame.cpp b/src/graphics/Frame.cpp index 1c51c45..a152ee7 100644 --- a/src/graphics/Frame.cpp +++ b/src/graphics/Frame.cpp @@ -15,83 +15,83 @@ namespace graphics { void Frame::Draw(SDL_Surface *dest, const Vector &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 &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); } diff --git a/src/graphics/Frame.h b/src/graphics/Frame.h index 74ce1f7..09674cc 100644 --- a/src/graphics/Frame.h +++ b/src/graphics/Frame.h @@ -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 BorderSize() const { return borderSize; } + int RepeatWidth() const { return RepeatSize().X(); } + int RepeatHeight() const { return RepeatSize().Y(); } + const geometry::Vector RepeatSize() const { return repeatSize; } void Draw(SDL_Surface *dest, const geometry::Vector &position, int width, int height) const; private: SDL_Surface *surface; - int borderWidth; - int borderHeight; - int repeatWidth; - int repeatHeight; - int xOffset; - int yOffset; + geometry::Vector borderSize; + geometry::Vector repeatSize; + geometry::Vector offset; }; diff --git a/src/graphics/Sprite.cpp b/src/graphics/Sprite.cpp index 2c092de..67bde8d 100644 --- a/src/graphics/Sprite.cpp +++ b/src/graphics/Sprite.cpp @@ -13,8 +13,8 @@ namespace graphics { void Sprite::Draw(SDL_Surface *dest, const Vector &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(); diff --git a/src/graphics/Sprite.h b/src/graphics/Sprite.h index 942d98e..f6f3b7b 100644 --- a/src/graphics/Sprite.h +++ b/src/graphics/Sprite.h @@ -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 &Size() const { return size; } void Draw(SDL_Surface *dest, const geometry::Vector &position, int col = 0, int row = 0) const; void DrawTopRight(SDL_Surface *dest, const geometry::Vector &position, int col = 0, int row = 0) const { geometry::Vector offset(-Width(), 0); Draw(dest, position + offset, col, row); } void DrawCenter(SDL_Surface *dest, const geometry::Vector &position, int col = 0, int row = 0) const { - geometry::Vector 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 &position, int col = 0, int row = 0) const { geometry::Vector offset(-Width() / 2, -Height()); @@ -39,10 +39,8 @@ public: private: SDL_Surface *surface; - int width; - int height; - int xOffset; - int yOffset; + geometry::Vector size; + geometry::Vector offset; };