]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/states/SelectSpell.cpp
cached some of the battle coordinates
[l2e.git] / src / battle / states / SelectSpell.cpp
index d7941c8e917212c58753a2b645e6b5875ebf37d1..7b918b4c98c762b71015c4213870bcf093c6bf4f 100644 (file)
@@ -1,10 +1,3 @@
-/*
- * SelectSpell.cpp
- *
- *  Created on: Aug 8, 2012
- *      Author: holy
- */
-
 #include "SelectSpell.h"
 
 #include "SelectAttackType.h"
 #include "../../app/Input.h"
 #include "../../common/Spell.h"
 #include "../../graphics/Frame.h"
+#include "../../math/Vector.h"
 
 using app::Application;
 using app::Input;
 using common::Spell;
-using geometry::Vector;
+using math::Vector;
 using graphics::Frame;
 
 namespace battle {
 
 void SelectSpell::OnEnterState(SDL_Surface *screen) {
-
+       OnResize(screen->w, screen->h);
 }
 
 void SelectSpell::OnExitState(SDL_Surface *screen) {
@@ -46,7 +40,23 @@ void SelectSpell::OnPauseState(SDL_Surface *screen) {
 
 
 void SelectSpell::OnResize(int width, int height) {
+       const Vector<int> offset = battle->ScreenOffset();
+
+       const Resources &res = battle->Res();
+       const Frame &frame = *res.selectFrame;
+
+       framePosition = offset + frame.BorderSize();
+       frameSize = Vector<int>(
+                       battle->Width() - 2 * frame.BorderWidth(),
+                       res.normalFont->CharHeight() * 13);
+
+       headlinePosition = offset + Vector<int>(
+                       2 * frame.BorderWidth() + res.normalFont->CharWidth(),
+                       2 * frame.BorderHeight());
 
+       menuPosition = offset + Vector<int>(
+                       2 * frame.BorderWidth() + res.normalFont->CharWidth(),
+                       2 * frame.BorderHeight() + 2 * res.normalFont->CharHeight());
 }
 
 
@@ -93,40 +103,29 @@ void SelectSpell::HandleEvents(const Input &input) {
        }
 }
 
-void SelectSpell::UpdateWorld(float deltaT) {
+void SelectSpell::UpdateWorld(Uint32 deltaT) {
 
 }
 
 void SelectSpell::Render(SDL_Surface *screen) {
        parent->Render(screen);
-       Vector<int> offset(battle->CalculateScreenOffset(screen));
-       RenderFrame(screen, offset);
-       RenderHeadline(screen, offset);
-       RenderMenu(screen, offset);
+       RenderFrame(screen);
+       RenderHeadline(screen);
+       RenderMenu(screen);
 }
 
-void SelectSpell::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
-       const Frame *frame(battle->Res().selectFrame);
-       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 Frame &frame = *battle->Res().selectFrame;
+       frame.Draw(screen, framePosition, frameSize.X(), frameSize.Y());
 }
 
-void SelectSpell::RenderHeadline(SDL_Surface *screen, const Vector<int> &offset) {
-       const Resources &res(battle->Res());
-       Vector<int> position(
-                       2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
-                       2 * res.selectFrame->BorderHeight());
-       res.normalFont->DrawString(res.spellMenuHeadline, screen, position + offset);
+void SelectSpell::RenderHeadline(SDL_Surface *screen) {
+       const Resources &res = battle->Res();
+       res.normalFont->DrawString(res.spellMenuHeadline, screen, headlinePosition);
 }
 
-void SelectSpell::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
-       const Resources &res(battle->Res());
-       Vector<int> position(
-                       2 * res.selectFrame->BorderWidth() + res.normalFont->CharWidth(),
-                       2 * res.selectFrame->BorderHeight() + 2 * res.normalFont->CharHeight());
-       battle->ActiveHero().SpellMenu().Draw(screen, position + offset);
+void SelectSpell::RenderMenu(SDL_Surface *screen) {
+       battle->ActiveHero().SpellMenu().Draw(screen, menuPosition);
 }
 
 }