--- /dev/null
+#include "CapsuleNameMenu.h"
+
+#include "CapsuleMenu.h"
+#include "Resources.h"
+#include "../app/Application.h"
+#include "../app/Input.h"
+#include "../common/Inventory.h"
+#include "../common/Item.h"
+#include "../common/GameConfig.h"
+#include "../common/GameState.h"
+#include "../graphics/Font.h"
+#include "../graphics/Frame.h"
+
+#include <cstring>
+
+using app::Input;
+using common::Capsule;
+using common::Inventory;
+using common::Item;
+using geometry::Vector;
+using graphics::Font;
+using graphics::Frame;
+
+namespace menu {
+
+CapsuleNameMenu::CapsuleNameMenu(CapsuleMenu *parent)
+: parent(parent)
+, cursor(5) {
+ std::strncpy(buffer, GetCapsule().Name(), 6);
+ buffer[5] = '\0';
+}
+
+
+void CapsuleNameMenu::OnEnterState(SDL_Surface *) {
+
+}
+
+void CapsuleNameMenu::OnExitState(SDL_Surface *) {
+
+}
+
+void CapsuleNameMenu::OnResumeState(SDL_Surface *) {
+
+}
+
+void CapsuleNameMenu::OnPauseState(SDL_Surface *) {
+
+}
+
+
+void CapsuleNameMenu::OnResize(int width, int height) {
+
+}
+
+
+void CapsuleNameMenu::HandleEvents(const Input &input) {
+ if (input.JustPressed(Input::START)) {
+ Ctrl().PopState();
+ }
+}
+
+void CapsuleNameMenu::UpdateWorld(float deltaT) {
+
+}
+
+void CapsuleNameMenu::Render(SDL_Surface *screen) {
+ const Font &font(*parent->Res().statusFont);
+ const Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
+ const Vector<int> nameOffset(
+ 4 * font.CharWidth(),
+ 4 * font.CharHeight() - font.CharHeight() / 8);
+ const Vector<int> alphaOffset(
+ 4 * font.CharWidth(),
+ 7 * font.CharHeight() - font.CharHeight() / 8);
+
+ parent->RenderBackground(screen);
+ RenderName(screen, offset + nameOffset);
+ RenderAlphabet(screen, offset + alphaOffset);
+}
+
+void CapsuleNameMenu::RenderName(SDL_Surface *screen, const Vector<int> &offset) const {
+ const Font &font(*parent->Res().normalFont);
+ const Frame &frame(*parent->Res().statusFrame);
+ const Vector<int> labelOffset(2 * font.CharWidth(), font.CharHeight());
+ const Vector<int> namebgOffset(8 * font.CharWidth(), 0);
+ const Vector<int> nameOffset(13 * font.CharWidth(), font.CharHeight());
+
+ frame.Draw(screen, offset, 8 * font.CharWidth(), 3 * font.CharHeight());
+ font.DrawString(parent->Res().capsuleNameLabel, screen, offset + labelOffset, 5);
+ frame.Draw(screen, offset + namebgOffset, 16 * font.CharWidth(), 3 * font.CharHeight());
+ font.DrawString(buffer, screen, offset + nameOffset, 5);
+}
+
+void CapsuleNameMenu::RenderAlphabet(SDL_Surface *screen, const Vector<int> &offset) const {
+ const Font &font(*parent->Res().normalFont);
+ const Frame &frame(*parent->Res().statusFrame);
+
+ frame.Draw(screen, offset, 24 * font.CharWidth(), 17 * font.CharHeight());
+}
+
+
+int CapsuleNameMenu::Width() const {
+ return parent->Width();
+}
+
+int CapsuleNameMenu::Height() const {
+ return parent->Height();
+}
+
+const Capsule &CapsuleNameMenu::GetCapsule() const {
+ return parent->GetCapsule();
+}
+
+}
--- /dev/null
+#ifndef MENU_CAPSULENAMEMENU_H_
+#define MENU_CAPSULENAMEMENU_H_
+
+#include "fwd.h"
+#include "../app/State.h"
+#include "../common/fwd.h"
+#include "../geometry/Vector.h"
+
+namespace menu {
+
+class CapsuleMenu;
+
+class CapsuleNameMenu
+: public app::State {
+
+public:
+ explicit CapsuleNameMenu(CapsuleMenu *parent);
+
+public:
+ virtual void HandleEvents(const app::Input &);
+ virtual void UpdateWorld(float deltaT);
+ virtual void Render(SDL_Surface *);
+
+public:
+ int Width() const;
+ int Height() const;
+
+private:
+ virtual void OnEnterState(SDL_Surface *screen);
+ virtual void OnExitState(SDL_Surface *screen);
+ virtual void OnResumeState(SDL_Surface *screen);
+ virtual void OnPauseState(SDL_Surface *screen);
+
+ virtual void OnResize(int width, int height);
+
+ const common::Capsule &GetCapsule() const;
+
+ void LoadInventory();
+
+ void RenderName(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+ void RenderAlphabet(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+
+private:
+ CapsuleMenu *parent;
+ int cursor;
+ char buffer[6];
+
+};
+
+}
+
+#endif /* MENU_CAPSULENAMEMENU_H_ */