Don't perform a hit test outside the page's bounds

pull/593/head
Evil Eye 4 years ago
parent 0818a10df2
commit 56ede535b5

@ -115,6 +115,7 @@
Bug #5906: Sunglare doesn't work with Mesa drivers and AMD GPUs Bug #5906: Sunglare doesn't work with Mesa drivers and AMD GPUs
Bug #5912: ImprovedBound mod doesn't work Bug #5912: ImprovedBound mod doesn't work
Bug #5914: BM: The Swimmer can't reach destination Bug #5914: BM: The Swimmer can't reach destination
Bug #5923: Clicking on empty spaces between journal entries might show random topics
Bug #5934: AddItem command doesn't accept negative values Bug #5934: AddItem command doesn't accept negative values
Feature #390: 3rd person look "over the shoulder" Feature #390: 3rd person look "over the shoulder"
Feature #832: OpenMW-CS: Handle deleted references Feature #832: OpenMW-CS: Handle deleted references

@ -1,5 +1,7 @@
#include "bookpage.hpp" #include "bookpage.hpp"
#include <optional>
#include "MyGUI_RenderItem.h" #include "MyGUI_RenderItem.h"
#include "MyGUI_RenderManager.h" #include "MyGUI_RenderManager.h"
#include "MyGUI_TextureUtility.h" #include "MyGUI_TextureUtility.h"
@ -894,6 +896,27 @@ protected:
return mIsPageReset || (mPage != page); return mIsPageReset || (mPage != page);
} }
std::optional<MyGUI::IntPoint> getAdjustedPos(int left, int top, bool move = false)
{
if (!mBook)
return {};
if (mPage >= mBook->mPages.size())
return {};
MyGUI::IntPoint pos (left, top);
#if MYGUI_VERSION < MYGUI_DEFINE_VERSION(3,2,3)
// work around inconsistency in MyGUI where the mouse press coordinates aren't
// transformed by the current Layer (even though mouse *move* events are).
if(!move)
pos = mNode->getLayer()->getPosition(left, top);
#endif
pos.left -= mCroppedParent->getAbsoluteLeft ();
pos.top -= mCroppedParent->getAbsoluteTop ();
pos.top += mViewTop;
return pos;
}
public: public:
typedef TypesetBookImpl::StyleImpl Style; typedef TypesetBookImpl::StyleImpl Style;
@ -952,16 +975,10 @@ public:
void onMouseMove (int left, int top) void onMouseMove (int left, int top)
{ {
if (!mBook) Style * hit = nullptr;
return; if(auto pos = getAdjustedPos(left, top, true))
if(pos->top <= mViewBottom)
if (mPage >= mBook->mPages.size()) hit = mBook->hitTestWithMargin (pos->left, pos->top);
return;
left -= mCroppedParent->getAbsoluteLeft ();
top -= mCroppedParent->getAbsoluteTop ();
Style * hit = mBook->hitTestWithMargin (left, mViewTop + top);
if (mLastDown == MyGUI::MouseButton::None) if (mLastDown == MyGUI::MouseButton::None)
{ {
@ -991,24 +1008,11 @@ public:
void onMouseButtonPressed (int left, int top, MyGUI::MouseButton id) void onMouseButtonPressed (int left, int top, MyGUI::MouseButton id)
{ {
if (!mBook) auto pos = getAdjustedPos(left, top);
return;
if (mPage >= mBook->mPages.size()) if (pos && mLastDown == MyGUI::MouseButton::None)
return;
// work around inconsistency in MyGUI where the mouse press coordinates aren't
// transformed by the current Layer (even though mouse *move* events are).
MyGUI::IntPoint pos (left, top);
#if MYGUI_VERSION < MYGUI_DEFINE_VERSION(3,2,3)
pos = mNode->getLayer()->getPosition(left, top);
#endif
pos.left -= mCroppedParent->getAbsoluteLeft ();
pos.top -= mCroppedParent->getAbsoluteTop ();
if (mLastDown == MyGUI::MouseButton::None)
{ {
mFocusItem = mBook->hitTestWithMargin (pos.left, mViewTop + pos.top); mFocusItem = pos->top <= mViewBottom ? mBook->hitTestWithMargin (pos->left, pos->top) : nullptr;
mItemActive = true; mItemActive = true;
dirtyFocusItem (); dirtyFocusItem ();
@ -1019,25 +1023,11 @@ public:
void onMouseButtonReleased(int left, int top, MyGUI::MouseButton id) void onMouseButtonReleased(int left, int top, MyGUI::MouseButton id)
{ {
if (!mBook) auto pos = getAdjustedPos(left, top);
return;
if (mPage >= mBook->mPages.size())
return;
// work around inconsistency in MyGUI where the mouse release coordinates aren't
// transformed by the current Layer (even though mouse *move* events are).
MyGUI::IntPoint pos (left, top);
#if MYGUI_VERSION < MYGUI_DEFINE_VERSION(3,2,3)
pos = mNode->getLayer()->getPosition(left, top);
#endif
pos.left -= mCroppedParent->getAbsoluteLeft ();
pos.top -= mCroppedParent->getAbsoluteTop ();
if (mLastDown == id) if (pos && mLastDown == id)
{ {
Style * item = mBook->hitTestWithMargin (pos.left, mViewTop + pos.top); Style * item = pos->top <= mViewBottom ? mBook->hitTestWithMargin (pos->left, pos->top) : nullptr;
bool clicked = mFocusItem == item; bool clicked = mFocusItem == item;

Loading…
Cancel
Save