diff options
author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2006-03-08 23:19:02 +0000 |
---|---|---|
committer | Björn Steinbrink <B.Steinbrink@gmx.de> | 2006-03-08 23:19:02 +0000 |
commit | 0aca9d9da8a0817d0651168620c985a6813bf954 (patch) | |
tree | 0e0226a32792952340d5e2b48ed33b70b19b1602 /src/gui | |
parent | 38ac38af6ea1c6643fcae3aeb11b80354b923126 (diff) | |
download | mana-0aca9d9da8a0817d0651168620c985a6813bf954.tar.gz mana-0aca9d9da8a0817d0651168620c985a6813bf954.tar.bz2 mana-0aca9d9da8a0817d0651168620c985a6813bf954.tar.xz mana-0aca9d9da8a0817d0651168620c985a6813bf954.zip |
Make the MouseOverLink functor dynamic and use a STL algorithm in one more place.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/browserbox.cpp | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index 8a636679..1f67670e 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -229,22 +229,21 @@ void BrowserBox::clearRows() mSelectedLink = -1; } -struct MouseOverLinkFunctor +struct MouseOverLink { + MouseOverLink(int x, int y) : mX(x),mY(y) { } bool operator() (BROWSER_LINK &link) { return (mX >= link.x1 && mX < link.x2 && mY >= link.y1 && mY < link.y2); } int mX, mY; -} mouseOverLink; +}; void BrowserBox::mousePress(int mx, int my, int button) { - mouseOverLink.mX = mx; - mouseOverLink.mY = my; - - LinkIterator i = find_if(mLinks.begin(), mLinks.end(), mouseOverLink); + LinkIterator i = find_if(mLinks.begin(), mLinks.end(), + MouseOverLink(mx, my)); if (i != mLinks.end()) { mLinkHandler->handleLink(i->link); @@ -253,19 +252,10 @@ void BrowserBox::mousePress(int mx, int my, int button) void BrowserBox::mouseMotion(int mx, int my) { - mouseOverLink.mX = mx; - mouseOverLink.mY = my; - - mSelectedLink = -1; + LinkIterator i = find_if(mLinks.begin(), mLinks.end(), + MouseOverLink(mx, my)); - for (unsigned int i = 0; i < mLinks.size(); i++) - { - if (mouseOverLink(mLinks[i])) - { - mSelectedLink = (int) i; - break; - } - } + mSelectedLink = (i != mLinks.end()) ? (i - mLinks.begin()) : -1; } void BrowserBox::draw(gcn::Graphics* graphics) |