diff options
author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2005-10-19 18:56:34 +0000 |
---|---|---|
committer | Björn Steinbrink <B.Steinbrink@gmx.de> | 2005-10-19 18:56:34 +0000 |
commit | 6e3e226fa66caeacd6d0c0ce216d604ca7bf89e9 (patch) | |
tree | 41e329de53e8c2912096388ff5448aa9bc404aa2 /src/gui/browserbox.cpp | |
parent | 636da3713cb4dbd6ceac6536c7e2b6bcbd6f7029 (diff) | |
download | mana-6e3e226fa66caeacd6d0c0ce216d604ca7bf89e9.tar.gz mana-6e3e226fa66caeacd6d0c0ce216d604ca7bf89e9.tar.bz2 mana-6e3e226fa66caeacd6d0c0ce216d604ca7bf89e9.tar.xz mana-6e3e226fa66caeacd6d0c0ce216d604ca7bf89e9.zip |
Code cleanup.
Diffstat (limited to 'src/gui/browserbox.cpp')
-rw-r--r-- | src/gui/browserbox.cpp | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index d89c3d86..94978200 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -23,6 +23,8 @@ #include "browserbox.h" +#include <algorithm> + #include <guichan/graphics.hpp> #include <guichan/imagefont.hpp> #include <guichan/mouseinput.hpp> @@ -39,13 +41,11 @@ int BrowserBox::instances = 0; gcn::ImageFont* BrowserBox::browserFont; BrowserBox::BrowserBox(unsigned int mode): - gcn::Widget() + gcn::Widget(), + mMode(mode), mUseLinksAndUserColors(true), mSelectedLink(-1) { - mMode = mode; setOpaque(true); - setHighlightMode(BOTH); - mUseLinksAndUserColors = true; - mSelectedLink = -1; + setHighlightMode(UNDERLINE | BACKGROUND); setFocusable(true); addMouseListener(this); @@ -158,7 +158,6 @@ void BrowserBox::addRow(const std::string& row) newRow = row; } - newRow == (newRow == "" ? " " : newRow); mTextRows.push_back(newRow); // Auto size mode @@ -184,35 +183,43 @@ void BrowserBox::clearRows() mSelectedLink = -1; } -void BrowserBox::mousePress(int mx, int my, int button) +class MouseOverLinkFunctor { - if ((button == gcn::MouseInput::LEFT) && mLinkHandler) - { - for (unsigned int i = 0; i < mLinks.size(); i++) + public: + bool operator() (BROWSER_LINK &link) { - if ((mx >= mLinks[i].x1) && (mx < mLinks[i].x2) && - (my > mLinks[i].y1) && (my < mLinks[i].y2)) - { - mLinkHandler->handleLink(mLinks[i].link); - return; - } + 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) +{ + std::vector<BROWSER_LINK>::iterator i; + + mouseOverLink.mX = mx; + mouseOverLink.mY = my; + i = find_if(mLinks.begin(), mLinks.end(), mouseOverLink); + + if (i != mLinks.end()) { + mLinkHandler->handleLink(i->link); } } void BrowserBox::mouseMotion(int mx, int my) { + mouseOverLink.mX = mx; + mouseOverLink.mY = my; + + mSelectedLink = -1; + for (unsigned int i = 0; i < mLinks.size(); i++) { - if ((mx >= mLinks[i].x1) && (mx < mLinks[i].x2) && - (my > mLinks[i].y1) && (my < mLinks[i].y2)) + if (mouseOverLink(mLinks[i])) { mSelectedLink = (int) i; - return; - } - else - { - mSelectedLink = -1; + break; } } } @@ -227,7 +234,7 @@ void BrowserBox::draw(gcn::Graphics* graphics) if (mSelectedLink >= 0) { - if ((mHighMode == BACKGROUND) || (mHighMode == BOTH)) + if ((mHighMode & BACKGROUND)) { graphics->setColor(gcn::Color(HIGHLIGHT)); graphics->fillRectangle(gcn::Rectangle( @@ -238,7 +245,7 @@ void BrowserBox::draw(gcn::Graphics* graphics) )); } - if ((mHighMode == UNDERLINE) || (mHighMode == BOTH)) + if ((mHighMode & UNDERLINE)) { graphics->setColor(gcn::Color(LINK)); graphics->drawLine( |