diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/browserbox.cpp | 57 | ||||
-rw-r--r-- | src/gui/browserbox.h | 6 |
2 files changed, 35 insertions, 28 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( diff --git a/src/gui/browserbox.h b/src/gui/browserbox.h index 3a829381..ccef76e5 100644 --- a/src/gui/browserbox.h +++ b/src/gui/browserbox.h @@ -135,11 +135,11 @@ class BrowserBox : public gcn::Widget, public gcn::MouseListener /** * Highlight modes for links. + * This can be used for a bitmask. */ enum { - UNDERLINE, - BACKGROUND, - BOTH + UNDERLINE = 1, + BACKGROUND = 2, }; private: |