From 83117a93393329cc61a76614e4ca5686efa56154 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 5 Sep 2011 17:56:24 +0300 Subject: Add option to enable/disable lazy scrolling. --- src/defaults.cpp | 1 + src/gui/setup_other.cpp | 3 ++ src/gui/viewport.cpp | 106 ++++++++++++++++++++++++++++-------------------- src/gui/viewport.h | 1 + 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(mPixelViewX) + mScrollRadius) + // Apply lazy scrolling + while (lastTick < tick_time && cnt < 32) { - mPixelViewX += static_cast(player_x - - static_cast(mPixelViewX) - mScrollRadius) / + if (player_x > static_cast(mPixelViewX) + mScrollRadius) + { + mPixelViewX += static_cast(player_x + - static_cast(mPixelViewX) - mScrollRadius) / + static_cast(mScrollLaziness); + } + if (player_x < static_cast(mPixelViewX) - mScrollRadius) + { + mPixelViewX += static_cast(player_x + - static_cast(mPixelViewX) + mScrollRadius) / + static_cast(mScrollLaziness); + } + if (player_y > static_cast(mPixelViewY) + mScrollRadius) + { + mPixelViewY += static_cast(player_y + - static_cast(mPixelViewY) - mScrollRadius) / static_cast(mScrollLaziness); - } - if (player_x < static_cast(mPixelViewX) - mScrollRadius) - { - mPixelViewX += static_cast(player_x - - static_cast(mPixelViewX) + mScrollRadius) / + } + if (player_y < static_cast(mPixelViewY) - mScrollRadius) + { + mPixelViewY += static_cast(player_y + - static_cast(mPixelViewY) + mScrollRadius) / static_cast(mScrollLaziness); + } + lastTick ++; + cnt ++; } - if (player_y > static_cast(mPixelViewY) + mScrollRadius) - { - mPixelViewY += static_cast(player_y - - static_cast(mPixelViewY) - mScrollRadius) / - static_cast(mScrollLaziness); - } - if (player_y < static_cast(mPixelViewY) - mScrollRadius) - { - mPixelViewY += static_cast(player_y - - static_cast(mPixelViewY) + mScrollRadius) / - static_cast(mScrollLaziness); - } - lastTick ++; - cnt ++; - } - // Auto center when player is off screen - if (cnt > 30 || player_x - static_cast(mPixelViewX) - > graphics->mWidth / 2 || static_cast(mPixelViewX) - - player_x > graphics->mWidth / 2 || static_cast(mPixelViewY) - - player_y > graphics->getHeight() / 2 || player_y - - static_cast(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(mPixelViewX) + > graphics->mWidth / 2 || static_cast(mPixelViewX) + - player_x > graphics->mWidth / 2 || static_cast(mPixelViewY) + - player_y > graphics->getHeight() / 2 || player_y + - static_cast(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(player_x); + mPixelViewY = static_cast(player_y); } + } + else + { mPixelViewX = static_cast(player_x); mPixelViewY = static_cast(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. */ -- cgit v1.2.3-70-g09d2