summaryrefslogtreecommitdiff
path: root/src/gui/viewport.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-09-05 17:56:24 +0300
committerAndrei Karas <akaras@inbox.ru>2011-09-05 17:56:24 +0300
commit83117a93393329cc61a76614e4ca5686efa56154 (patch)
treeaf491de891fcb35c93c83645a546b9481f7d3bf6 /src/gui/viewport.cpp
parent70a2f900b22258278fde443ec2e3416c56d4f5b5 (diff)
downloadManaVerse-83117a93393329cc61a76614e4ca5686efa56154.tar.gz
ManaVerse-83117a93393329cc61a76614e4ca5686efa56154.tar.bz2
ManaVerse-83117a93393329cc61a76614e4ca5686efa56154.tar.xz
ManaVerse-83117a93393329cc61a76614e4ca5686efa56154.zip
Add option to enable/disable lazy scrolling.
Diffstat (limited to 'src/gui/viewport.cpp')
-rw-r--r--src/gui/viewport.cpp106
1 files changed, 62 insertions, 44 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index b6e09c011..073697459 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -80,11 +80,13 @@ Viewport::Viewport():
mScrollCenterOffsetY = config.getIntValue("ScrollCenterOffsetY");
mShowBeingPopup = config.getBoolValue("showBeingPopup");
mSelfMouseHeal = config.getBoolValue("selfMouseHeal");
+ mEnableLazyScrolling = config.getBoolValue("enableLazyScrolling");
config.addListener("ScrollLaziness", this);
config.addListener("ScrollRadius", this);
config.addListener("showBeingPopup", this);
config.addListener("selfMouseHeal", this);
+ config.addListener("enableLazyScrolling", this);
mPopupMenu = new PopupMenu;
mBeingPopup = new BeingPopup;
@@ -99,6 +101,7 @@ Viewport::~Viewport()
config.removeListener("ScrollRadius", this);
config.removeListener("showBeingPopup", this);
config.removeListener("selfMouseHeal", this);
+ config.removeListener("enableLazyScrolling", this);
delete mPopupMenu;
mPopupMenu = 0;
@@ -150,59 +153,67 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
int cnt = 0;
- // Apply lazy scrolling
- while (lastTick < tick_time && cnt < 32)
+ if (mEnableLazyScrolling)
{
- if (player_x > static_cast<int>(mPixelViewX) + mScrollRadius)
+ // Apply lazy scrolling
+ while (lastTick < tick_time && cnt < 32)
{
- mPixelViewX += static_cast<float>(player_x
- - static_cast<int>(mPixelViewX) - mScrollRadius) /
+ if (player_x > static_cast<int>(mPixelViewX) + mScrollRadius)
+ {
+ mPixelViewX += static_cast<float>(player_x
+ - static_cast<int>(mPixelViewX) - mScrollRadius) /
+ static_cast<float>(mScrollLaziness);
+ }
+ if (player_x < static_cast<int>(mPixelViewX) - mScrollRadius)
+ {
+ mPixelViewX += static_cast<float>(player_x
+ - static_cast<int>(mPixelViewX) + mScrollRadius) /
+ static_cast<float>(mScrollLaziness);
+ }
+ if (player_y > static_cast<int>(mPixelViewY) + mScrollRadius)
+ {
+ mPixelViewY += static_cast<float>(player_y
+ - static_cast<int>(mPixelViewY) - mScrollRadius) /
static_cast<float>(mScrollLaziness);
- }
- if (player_x < static_cast<int>(mPixelViewX) - mScrollRadius)
- {
- mPixelViewX += static_cast<float>(player_x
- - static_cast<int>(mPixelViewX) + mScrollRadius) /
+ }
+ if (player_y < static_cast<int>(mPixelViewY) - mScrollRadius)
+ {
+ mPixelViewY += static_cast<float>(player_y
+ - static_cast<int>(mPixelViewY) + mScrollRadius) /
static_cast<float>(mScrollLaziness);
+ }
+ lastTick ++;
+ cnt ++;
}
- if (player_y > static_cast<int>(mPixelViewY) + mScrollRadius)
- {
- mPixelViewY += static_cast<float>(player_y
- - static_cast<int>(mPixelViewY) - mScrollRadius) /
- static_cast<float>(mScrollLaziness);
- }
- if (player_y < static_cast<int>(mPixelViewY) - mScrollRadius)
- {
- mPixelViewY += static_cast<float>(player_y
- - static_cast<int>(mPixelViewY) + mScrollRadius) /
- static_cast<float>(mScrollLaziness);
- }
- lastTick ++;
- cnt ++;
- }
- // Auto center when player is off screen
- if (cnt > 30 || player_x - static_cast<int>(mPixelViewX)
- > graphics->mWidth / 2 || static_cast<int>(mPixelViewX)
- - player_x > graphics->mWidth / 2 || static_cast<int>(mPixelViewY)
- - player_y > graphics->getHeight() / 2 || player_y
- - static_cast<int>(mPixelViewY) > graphics->getHeight() / 2)
- {
- if (player_x <= 0 || player_y <= 0)
+ // Auto center when player is off screen
+ if (cnt > 30 || player_x - static_cast<int>(mPixelViewX)
+ > graphics->mWidth / 2 || static_cast<int>(mPixelViewX)
+ - player_x > graphics->mWidth / 2 || static_cast<int>(mPixelViewY)
+ - player_y > graphics->getHeight() / 2 || player_y
+ - static_cast<int>(mPixelViewY) > graphics->getHeight() / 2)
{
- if (debugChatTab)
- debugChatTab->chatLog("incorrect player position!");
- logger->log("incorrect player position: %d, %d, %d, %d",
- player_x, player_y, (int)mPixelViewX, (int)mPixelViewY);
- if (player_node)
+ if (player_x <= 0 || player_y <= 0)
{
- logger->log("tile position: %d, %d",
- player_node->getTileX(), player_node->getTileY());
+ if (debugChatTab)
+ debugChatTab->chatLog("incorrect player position!");
+ logger->log("incorrect player position: %d, %d, %d, %d",
+ player_x, player_y, (int)mPixelViewX, (int)mPixelViewY);
+ if (player_node)
+ {
+ logger->log("tile position: %d, %d",
+ player_node->getTileX(), player_node->getTileY());
+ }
}
+ mPixelViewX = static_cast<float>(player_x);
+ mPixelViewY = static_cast<float>(player_y);
}
+ }
+ else
+ {
mPixelViewX = static_cast<float>(player_x);
mPixelViewY = static_cast<float>(player_y);
- };
+ }
// Don't move camera so that the end of the map is on screen
const int viewXmax =
@@ -693,9 +704,16 @@ void Viewport::closePopupMenu()
void Viewport::optionChanged(const std::string &name A_UNUSED)
{
- mScrollLaziness = config.getIntValue("ScrollLaziness");
- mScrollRadius = config.getIntValue("ScrollRadius");
- mShowBeingPopup = config.getBoolValue("showBeingPopup");
+ if (name == "ScrollLaziness")
+ mScrollLaziness = config.getIntValue("ScrollLaziness");
+ else if (name == "ScrollRadius")
+ mScrollRadius = config.getIntValue("ScrollRadius");
+ else if (name == "showBeingPopup")
+ mShowBeingPopup = config.getBoolValue("showBeingPopup");
+ else if (name == "selfMouseHeal")
+ mSelfMouseHeal = config.getBoolValue("selfMouseHeal");
+ else if (name == "enableLazyScrolling")
+ mEnableLazyScrolling = config.getBoolValue("enableLazyScrolling");
}
void Viewport::mouseMoved(gcn::MouseEvent &event A_UNUSED)