summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/defaults.cpp1
-rw-r--r--src/gui/setup_other.cpp3
-rw-r--r--src/gui/viewport.cpp106
-rw-r--r--src/gui/viewport.h1
4 files changed, 67 insertions, 44 deletions
diff --git a/src/defaults.cpp b/src/defaults.cpp
index 7c0d8148c..4a82a83a9 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -217,6 +217,7 @@ DefaultsData* getConfigDefaults()
AddDEF(configData, "enableReorderSprites", true);
AddDEF(configData, "showip", false);
AddDEF(configData, "seflMouseHeal", true);
+ AddDEF(configData, "enableLazyScrolling", true);
return configData;
}
diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp
index 1cad4c594..36c6f0436 100644
--- a/src/gui/setup_other.cpp
+++ b/src/gui/setup_other.cpp
@@ -84,6 +84,9 @@ Setup_Other::Setup_Other()
new SetupItemCheckBox(_("Draw hotkeys on map"), "", "drawHotKeys",
this, "drawHotKeysEvent");
+ new SetupItemCheckBox(_("Enable lazy scrolling"), "", "enableLazyScrolling",
+ this, "enableLazyScrollingEvent");
+
new SetupItemLabel(_("Moving"), "", this);
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)
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index 50c81aff4..8823928a3 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -286,6 +286,7 @@ class Viewport : public WindowContainer, public gcn::MouseListener,
int mScrollLaziness;
bool mShowBeingPopup;
bool mSelfMouseHeal;
+ bool mEnableLazyScrolling;
int mScrollCenterOffsetX;
int mScrollCenterOffsetY;
int mMouseX; /**< Current mouse position in pixels. */