summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-03-03 22:39:35 +0300
committerAndrei Karas <akaras@inbox.ru>2016-03-03 22:39:35 +0300
commitf0f135493b2951af8661c8d7e7396c713164a723 (patch)
tree5fa4af6eb22cae8650cbd96d7dd7211223950414
parent4039ef116901d4513c3535cc119dc40abd8e14df (diff)
downloadmv-f0f135493b2951af8661c8d7e7396c713164a723.tar.gz
mv-f0f135493b2951af8661c8d7e7396c713164a723.tar.bz2
mv-f0f135493b2951af8661c8d7e7396c713164a723.tar.xz
mv-f0f135493b2951af8661c8d7e7396c713164a723.zip
Improve a bit calculations in viewport.
-rw-r--r--src/dyetool/gui/viewport.cpp4
-rw-r--r--src/dyetool/gui/viewport.h2
-rw-r--r--src/gui/gui.cpp2
-rw-r--r--src/gui/viewport.cpp30
-rw-r--r--src/gui/viewport.h10
5 files changed, 40 insertions, 8 deletions
diff --git a/src/dyetool/gui/viewport.cpp b/src/dyetool/gui/viewport.cpp
index 786b7a4f1..48c79609c 100644
--- a/src/dyetool/gui/viewport.cpp
+++ b/src/dyetool/gui/viewport.cpp
@@ -263,3 +263,7 @@ bool Viewport::leftMouseAction()
{
return false;
}
+
+void Viewport::videoResized()
+{
+}
diff --git a/src/dyetool/gui/viewport.h b/src/dyetool/gui/viewport.h
index 763371338..e5159976b 100644
--- a/src/dyetool/gui/viewport.h
+++ b/src/dyetool/gui/viewport.h
@@ -152,6 +152,8 @@ class Viewport final : public WindowContainer,
void setCameraRelativeY(const int n)
{ mCameraRelativeY = n; }
+ void videoResized();
+
int mMouseX; /**< Current mouse position in pixels. */
int mMouseY; /**< Current mouse position in pixels. */
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index db03887fb..cb91f09c4 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -526,6 +526,8 @@ void Gui::videoResized() const
top->adjustAfterResize(oldWidth, oldHeight);
}
+ if (viewport)
+ viewport->videoResized();
Widget::distributeWindowResizeEvent();
}
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 341477c0f..8855c651f 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -77,6 +77,8 @@ Viewport::Viewport() :
mMousePressY(0),
mPixelViewX(0),
mPixelViewY(0),
+ mMidTileX(0),
+ mMidTileY(0),
mLocalWalkTime(-1),
mCameraRelativeX(0),
mCameraRelativeY(0),
@@ -100,6 +102,7 @@ Viewport::Viewport() :
config.addListener("longmouseclick", this);
setFocusable(true);
+ updateMidVars();
}
Viewport::~Viewport()
@@ -134,14 +137,10 @@ void Viewport::draw(Graphics *const graphics)
lastTick = tick_time;
// Calculate viewpoint
- const int midTileX = (graphics->mWidth + mScrollCenterOffsetX) / 2;
- const int midTileY = (graphics->mHeight + mScrollCenterOffsetY) / 2;
const Vector &playerPos = localPlayer->getPosition();
- const int player_x = CAST_S32(playerPos.x)
- - midTileX + mCameraRelativeX;
- const int player_y = CAST_S32(playerPos.y)
- - midTileY + mCameraRelativeY;
+ const int player_x = CAST_S32(playerPos.x) - mMidTileX;
+ const int player_y = CAST_S32(playerPos.y) - mMidTileY;
if (mScrollLaziness < 1)
mScrollLaziness = 1; // Avoids division by zero
@@ -950,6 +949,7 @@ void Viewport::toggleCameraMode()
{
mCameraRelativeX = 0;
mCameraRelativeY = 0;
+ updateMidVars();
}
UpdateStatusListener::distributeEvent();
}
@@ -974,6 +974,7 @@ void Viewport::moveCamera(const int dx, const int dy)
{
mCameraRelativeX += dx;
mCameraRelativeY += dy;
+ updateMidVars();
}
void Viewport::moveCameraToActor(const BeingId actorId,
@@ -990,6 +991,7 @@ void Viewport::moveCameraToActor(const BeingId actorId,
settings.cameraMode = 1;
mCameraRelativeX = CAST_S32(actorPos.x - playerPos.x) + x;
mCameraRelativeY = CAST_S32(actorPos.y - playerPos.y) + y;
+ updateMidVars();
}
void Viewport::moveCameraToPosition(const int x, const int y)
@@ -1002,6 +1004,7 @@ void Viewport::moveCameraToPosition(const int x, const int y)
mCameraRelativeX = x - CAST_S32(playerPos.x);
mCameraRelativeY = y - CAST_S32(playerPos.y);
+ updateMidVars();
}
void Viewport::moveCameraRelative(const int x, const int y)
@@ -1009,6 +1012,7 @@ void Viewport::moveCameraRelative(const int x, const int y)
settings.cameraMode = 1;
mCameraRelativeX += x;
mCameraRelativeY += y;
+ updateMidVars();
}
void Viewport::returnCamera()
@@ -1016,6 +1020,7 @@ void Viewport::returnCamera()
settings.cameraMode = 0;
mCameraRelativeX = 0;
mCameraRelativeY = 0;
+ updateMidVars();
}
void Viewport::validateSpeed()
@@ -1027,3 +1032,16 @@ void Viewport::validateSpeed()
Game::instance()->setValidSpeed();
}
}
+
+void Viewport::updateMidVars()
+{
+ mMidTileX = (mainGraphics->mWidth + mScrollCenterOffsetX) / 2
+ - mCameraRelativeX;
+ mMidTileY = (mainGraphics->mHeight + mScrollCenterOffsetY) / 2
+ - mCameraRelativeY;
+}
+
+void Viewport::videoResized()
+{
+ updateMidVars();
+}
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index a03137761..fa02f244b 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -154,10 +154,10 @@ class Viewport final : public WindowContainer,
{ return mCameraRelativeY; }
void setCameraRelativeX(const int n)
- { mCameraRelativeX = n; }
+ { mCameraRelativeX = n; updateMidVars(); }
void setCameraRelativeY(const int n)
- { mCameraRelativeY = n; }
+ { mCameraRelativeY = n; updateMidVars(); }
void moveCameraToActor(const BeingId actorId,
const int x = 0,
@@ -171,6 +171,8 @@ class Viewport final : public WindowContainer,
void getMouseTile(int &destX, int &destY) const;
+ void videoResized();
+
int mMouseX; /**< Current mouse position in pixels. */
int mMouseY; /**< Current mouse position in pixels. */
@@ -180,6 +182,8 @@ class Viewport final : public WindowContainer,
/// Clears any matching hovers
void clearHover(const ActorSprite *const actor);
+ void updateMidVars();
+
static void validateSpeed();
private:
@@ -227,6 +231,8 @@ class Viewport final : public WindowContainer,
int mMousePressY;
int mPixelViewX; /**< Current viewpoint in pixels. */
int mPixelViewY; /**< Current viewpoint in pixels. */
+ int mMidTileX;
+ int mMidTileY;
int mLocalWalkTime; /**< Timestamp before the next walk can be sent. */