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);
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;
}
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);
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);
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;
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);
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());
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;
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,
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,
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);
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);
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);
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());
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;
}
// bottom-right corner
- srcRect.x += repeatWidth;
- srcRect.w = borderWidth;
+ srcRect.x += RepeatWidth();
+ srcRect.w = BorderWidth();
SDL_BlitSurface(surface, &srcRect, dest, &destRect);
}
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;
};
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();
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());
private:
SDL_Surface *surface;
- int width;
- int height;
- int xOffset;
- int yOffset;
+ geometry::Vector<int> size;
+ geometry::Vector<int> offset;
};