ManaPlus
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
BrowserBox Class Reference

#include <browserbox.h>

Inheritance diagram for BrowserBox:
Widget MouseListener WidgetListener Widget2

Public Types

typedef std::list< std::string > TextRows
 

Public Member Functions

 BrowserBox (const Widget2 *const widget, const Opaque opaque, const std::string &skin)
 
 ~BrowserBox ()
 
void setLinkHandler (LinkHandler *linkHandler)
 
void setOpaque (Opaque opaque)
 
void setMaxRow (unsigned max)
 
void addRow (const std::string &row, const bool atTop)
 
void addRow (const std::string &cmd, const char *const text)
 
void addImage (const std::string &path)
 
void clearRows ()
 
void mousePressed (MouseEvent &event)
 
void mouseMoved (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void updateHeight ()
 
void updateSize (const bool always)
 
TextRowsgetRows ()
 
bool hasRows () const
 
void setAlwaysUpdate (const bool n)
 
void setProcessVars (const bool n)
 
void setEnableImages (const bool n)
 
void setEnableKeys (const bool n)
 
void setEnableTabs (const bool n)
 
std::string getTextAtPos (const int x, const int y) const
 
int getPadding () const
 
void setForegroundColorAll (const Color &color1, const Color &color2)
 
unsigned int getDataWidth () const
 
void moveSelectionUp ()
 
void moveSelectionDown ()
 
void selectSelection ()
 
void widgetResized (const Event &event)
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
virtual void logic ()
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
virtual void setFocusHandler (FocusHandler *const focusHandler)
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
virtual WidgetgetWidgetAt (int x, int y)
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual Rect getChildrenArea ()
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
virtual void moveToTop (Widget *widget)
 
virtual void moveToBottom (Widget *widget)
 
virtual void focusNext ()
 
virtual void focusPrevious ()
 
virtual void showWidgetPart (Widget *const widget, const Rect &area)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
virtual void postInit ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseEntered (MouseEvent &event)
 
virtual void mouseReleased (MouseEvent &event)
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
virtual void mouseDragged (MouseEvent &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetMoved (const Event &event)
 
virtual void widgetHidden (const Event &event)
 
virtual void widgetShown (const Event &event)
 

Private Types

typedef TextRows::iterator TextRowIterator
 
typedef TextRows::const_iterator TextRowCIter
 
typedef std::vector< LinePartLinePartList
 
typedef LinePartList::iterator LinePartIterator
 
typedef LinePartList::const_iterator LinePartCIter
 
typedef std::vector< BrowserLinkLinks
 
typedef Links::iterator LinkIterator
 

Private Member Functions

int calcHeight ()
 

Private Attributes

TextRows mTextRows
 
std::list< int > mTextRowLinksCount
 
LinePartList mLineParts
 
Links mLinks
 
LinkHandlermLinkHandler
 
SkinmSkin
 
unsigned int mHighlightMode
 
int mSelectedLink
 
unsigned int mMaxRows
 
int mHeight
 
int mWidth
 
int mYStart
 
time_t mUpdateTime
 
int mPadding
 
unsigned int mNewLinePadding
 
int mItemPadding
 
unsigned int mDataWidth
 
Color mHighlightColor
 
Color mHyperLinkColor
 
Color mColors [2][ColorName::COLORS_MAX]
 
Opaque mOpaque
 
bool mUseLinksAndUserColors
 
bool mUseEmotes
 
bool mAlwaysUpdate
 
bool mProcessVars
 
bool mEnableImages
 
bool mEnableKeys
 
bool mEnableTabs
 

Static Private Attributes

static ImageSetmEmotes = 0
 
static int mInstances = 0
 

Additional Inherited Members

- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 
- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

A simple browser box able to handle links and forward events to the parent conteiner.

Definition at line 47 of file browserbox.h.

Member Typedef Documentation

◆ LinePartCIter

typedef LinePartList::const_iterator BrowserBox::LinePartCIter
private

Definition at line 173 of file browserbox.h.

◆ LinePartIterator

typedef LinePartList::iterator BrowserBox::LinePartIterator
private

Definition at line 172 of file browserbox.h.

◆ LinePartList

typedef std::vector<LinePart> BrowserBox::LinePartList
private

Definition at line 171 of file browserbox.h.

◆ LinkIterator

typedef Links::iterator BrowserBox::LinkIterator
private

Definition at line 177 of file browserbox.h.

◆ Links

typedef std::vector<BrowserLink> BrowserBox::Links
private

Definition at line 176 of file browserbox.h.

◆ TextRowCIter

typedef TextRows::const_iterator BrowserBox::TextRowCIter
private

Definition at line 167 of file browserbox.h.

◆ TextRowIterator

typedef TextRows::iterator BrowserBox::TextRowIterator
private

Definition at line 166 of file browserbox.h.

◆ TextRows

typedef std::list<std::string> BrowserBox::TextRows

Definition at line 121 of file browserbox.h.

Constructor & Destructor Documentation

◆ BrowserBox()

BrowserBox::BrowserBox ( const Widget2 *const  widget,
const Opaque  opaque,
const std::string &  skin 
)

Constructor.

Definition at line 60 of file browserbox.cpp.

References Widget::addMouseListener(), Widget::addWidgetListener(), LinkHighlightMode::BACKGROUND, ThemeColorId::BACKGROUND, ColorName::BLACK, ColorName::BLUE, ColorName::BROWN, ThemeColorId::BROWSERBOX, ThemeColorId::BROWSERBOX_OUTLINE, CAST_U32, Loader::getImageSet(), Skin::getOption(), Skin::getPadding(), Widget2::getThemeColor(), Theme::getThemePath(), ColorName::GRAY, ColorName::GREEN, Theme::load(), Widget::mAllowLogic, Widget::mBackgroundColor, mEmotes, Widget::mForegroundColor, Widget2::mForegroundColor2, mHighlightMode, mInstances, mItemPadding, mNewLinePadding, mPadding, mSkin, ColorName::ORANGE, ColorName::PINK, ColorName::PURPLE, readColor(), ColorName::RED, Widget::setFocusable(), theme, LinkHighlightMode::UNDERLINE, and ColorName::YELLOW.

62  :
63  Widget(widget),
64  MouseListener(),
66  mTextRows(),
68  mLineParts(),
69  mLinks(),
70  mLinkHandler(nullptr),
71  mSkin(nullptr),
72  mHighlightMode(0),
73  mSelectedLink(-1),
74  mMaxRows(0),
75  mHeight(0),
76  mWidth(0),
77  mYStart(0),
78  mUpdateTime(-1),
79  mPadding(0),
80  mNewLinePadding(15U),
81  mItemPadding(0),
82  mDataWidth(0),
85  mOpaque(opaque),
87  mUseEmotes(true),
88  mAlwaysUpdate(true),
89  mProcessVars(false),
90  mEnableImages(false),
91  mEnableKeys(false),
92  mEnableTabs(false)
93 {
94  mAllowLogic = false;
95 
96  setFocusable(true);
97  addMouseListener(this);
98  addWidgetListener(this);
99 
101 
102  if (theme != nullptr)
103  {
104  mSkin = theme->load(skin,
105  "browserbox.xml",
106  true,
108  }
109  if (mInstances == 0)
110  {
112  "graphics/sprites/chatemotes.png", 17, 18);
113  }
114  mInstances ++;
115 
116  if (mSkin != nullptr)
117  {
120  mSkin->getOption("newLinePadding", 15));
121  mItemPadding = mSkin->getOption("itemPadding");
122  if (mSkin->getOption("highlightBackground") != 0)
124  if (mSkin->getOption("highlightUnderline") != 0)
126  }
127 
128  readColor(BLACK);
129  readColor(RED);
130  readColor(GREEN);
131  readColor(BLUE);
132  readColor(ORANGE);
133  readColor(YELLOW);
134  readColor(PINK);
135  readColor(PURPLE);
136  readColor(GRAY);
137  readColor(BROWN);
138 
141 }
#define CAST_U32
Definition: cast.h:30
bool mEnableTabs
Definition: browserbox.h:205
Color mHyperLinkColor
Definition: browserbox.h:195
LinePartList mLineParts
Definition: browserbox.h:174
unsigned int mMaxRows
Definition: browserbox.h:184
LinkHandler * mLinkHandler
Definition: browserbox.h:180
unsigned int mHighlightMode
Definition: browserbox.h:182
ImageSet * getImageSet(const std::string &imagePath, const int w, const int h)
static std::string getThemePath()
Definition: theme.h:66
bool mProcessVars
Definition: browserbox.h:202
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:178
std::list< int > mTextRowLinksCount
Definition: browserbox.h:169
Color mForegroundColor
Definition: widget.h:1085
int getOption(const std::string &name) const
Definition: skin.h:105
time_t mUpdateTime
Definition: browserbox.h:188
Links mLinks
Definition: browserbox.h:178
bool mEnableImages
Definition: browserbox.h:203
int getPadding() const
Definition: skin.h:99
Color mBackgroundColor
Definition: widget.h:1090
TextRows mTextRows
Definition: browserbox.h:168
static ImageSet * mEmotes
Definition: browserbox.h:207
Opaque mOpaque
Definition: browserbox.h:198
static int mInstances
Definition: browserbox.h:208
static Color readColor(const std::string &description)
Definition: theme.cpp:906
Widget(const Widget2 *const widget)
Definition: widget.cpp:84
bool mAllowLogic
Definition: widget.h:1159
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:291
bool mAlwaysUpdate
Definition: browserbox.h:201
bool mEnableKeys
Definition: browserbox.h:204
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:301
Color mHighlightColor
Definition: browserbox.h:194
Theme * theme
Definition: theme.cpp:61
void setFocusable(const bool focusable)
Definition: widget.cpp:191
Color mForegroundColor2
Definition: widget2.h:112
int mPadding
Definition: browserbox.h:189
bool mUseEmotes
Definition: browserbox.h:200
unsigned int mNewLinePadding
Definition: browserbox.h:190
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
bool mUseLinksAndUserColors
Definition: browserbox.h:199
Skin * mSkin
Definition: browserbox.h:181
int mItemPadding
Definition: browserbox.h:191
int mSelectedLink
Definition: browserbox.h:183
unsigned int mDataWidth
Definition: browserbox.h:192

◆ ~BrowserBox()

BrowserBox::~BrowserBox ( )

Destructor.

Definition at line 143 of file browserbox.cpp.

References Resource::decRef(), gui, mEmotes, mInstances, mSkin, Gui::removeDragged(), theme, and Theme::unload().

144 {
145  if (gui != nullptr)
146  gui->removeDragged(this);
147 
148  if (theme != nullptr)
149  {
150  theme->unload(mSkin);
151  mSkin = nullptr;
152  }
153 
154  mInstances --;
155  if (mInstances == 0)
156  {
157  if (mEmotes != nullptr)
158  {
159  mEmotes->decRef();
160  mEmotes = nullptr;
161  }
162  }
163 }
void unload(Skin *const skin)
Definition: theme.cpp:249
Gui * gui
Definition: gui.cpp:110
virtual void decRef()
Definition: resource.cpp:49
static ImageSet * mEmotes
Definition: browserbox.h:207
static int mInstances
Definition: browserbox.h:208
Theme * theme
Definition: theme.cpp:61
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1160
Skin * mSkin
Definition: browserbox.h:181

Member Function Documentation

◆ addImage()

void BrowserBox::addImage ( const std::string &  path)

Definition at line 349 of file browserbox.cpp.

References mEnableImages, mTextRowLinksCount, and mTextRows.

Referenced by setMaxRow().

350 {
351  if (!mEnableImages)
352  return;
353 
354  mTextRows.push_back("~~~" + path);
355  mTextRowLinksCount.push_back(0);
356 }
std::list< int > mTextRowLinksCount
Definition: browserbox.h:169
bool mEnableImages
Definition: browserbox.h:203
TextRows mTextRows
Definition: browserbox.h:168

◆ addRow() [1/2]

void BrowserBox::addRow ( const std::string &  row,
const bool  atTop 
)

Adds a text row to the browser.

Definition at line 170 of file browserbox.cpp.

References BrowserLink::caption, CAST_S32, CAST_SIZE, CAST_U32, ServerCommandType::font, FOR_EACH, Widget::getFont(), Font::getHeight(), PoDict::getStr(), Font::getWidth(), Widget::getWidth(), BrowserLink::link, mEnableKeys, mEnableTabs, mLinks, mMaxRows, mNewLinePadding, mProcessVars, mTextRowLinksCount, mTextRows, mUpdateTime, mUseLinksAndUserColors, BrowserBoxTools::replaceKeys(), BrowserBoxTools::replaceLinkCommands(), BrowserBoxTools::replaceTabs(), BrowserBoxTools::replaceVars(), Widget::setHeight(), translator, updateHeight(), x, BrowserLink::x1, BrowserLink::x2, y, BrowserLink::y1, and BrowserLink::y2.

Referenced by addRow(), ChatTab::addRow(), NpcDialog::addText(), NpcDialog::createSkinControls(), setMaxRow(), and QuestsWindow::showQuest().

171 {
172  std::string tmp = row;
173  std::string newRow;
174  const Font *const font = getFont();
175  int linksCount = 0;
176 
177  if (getWidth() < 0)
178  return;
179 
180  if (mProcessVars)
181  {
183  }
184 
185  // Use links and user defined colors
187  {
188  BrowserLink bLink;
189 
190  // Check for links in format "@@link|[email protected]@"
191  const uint32_t sz = CAST_U32(mTextRows.size());
192 
193  if (mEnableKeys)
194  {
196  }
197 
198  size_t idx1 = tmp.find("@@");
199  while (idx1 != std::string::npos)
200  {
201  const size_t idx2 = tmp.find('|', idx1);
202  const size_t idx3 = tmp.find("@@", idx2);
203 
204  if (idx2 == std::string::npos || idx3 == std::string::npos)
205  break;
206  bLink.link = tmp.substr(idx1 + 2, idx2 - (idx1 + 2));
207  bLink.caption = tmp.substr(idx2 + 1, idx3 - (idx2 + 1));
208  bLink.y1 = CAST_S32(sz) * font->getHeight();
209  bLink.y2 = bLink.y1 + font->getHeight();
210  if (bLink.caption.empty())
211  {
213  bLink.link);
214  if (translator != nullptr)
215  bLink.caption = translator->getStr(bLink.caption);
216  }
217 
218  newRow.append(tmp.substr(0, idx1));
219 
220  std::string tmp2 = newRow;
221  idx1 = tmp2.find("##");
222  while (idx1 != std::string::npos)
223  {
224  tmp2.erase(idx1, 3);
225  idx1 = tmp2.find("##");
226  }
227  bLink.x1 = font->getWidth(tmp2) - 1;
228  bLink.x2 = bLink.x1 + font->getWidth(bLink.caption) + 1;
229 
230  if (atTop)
231  mLinks.insert(mLinks.begin(), bLink);
232  else
233  mLinks.push_back(bLink);
234  linksCount ++;
235 
236  newRow.append("##<").append(bLink.caption);
237 
238  tmp.erase(0, idx3 + 2);
239  if (!tmp.empty())
240  newRow.append("##>");
241 
242  idx1 = tmp.find("@@");
243  }
244 
245  newRow.append(tmp);
246  }
247  // Don't use links and user defined colors
248  else
249  {
250  newRow = row;
251  }
252 
253  if (mEnableTabs)
254  {
256  }
257 
258  if (atTop)
259  {
260  mTextRows.push_front(newRow);
261  mTextRowLinksCount.push_front(linksCount);
262  }
263  else
264  {
265  mTextRows.push_back(newRow);
266  mTextRowLinksCount.push_back(linksCount);
267  }
268 
269  // discard older rows when a row limit has been set
270  if (mMaxRows > 0 && !mTextRows.empty())
271  {
272  while (mTextRows.size() > CAST_SIZE(mMaxRows))
273  {
274  mTextRows.pop_front();
275  int cnt = mTextRowLinksCount.front();
276  mTextRowLinksCount.pop_front();
277 
278  while ((cnt != 0) && !mLinks.empty())
279  {
280  mLinks.erase(mLinks.begin());
281  cnt --;
282  }
283  }
284  }
285 
286  const int fontHeight = font->getHeight();
287  unsigned int y = 0;
288  unsigned int nextChar;
289  const char *const hyphen = "~";
290  const unsigned int hyphenWidth = CAST_U32(
291  font->getWidth(hyphen));
292  unsigned int x = 0;
293 
295  {
296  std::string tempRow = *i;
297  for (uint32_t j = 0, sz = CAST_U32(tempRow.size());
298  j < sz;
299  j++)
300  {
301  const std::string character = tempRow.substr(j, 1);
302  x += CAST_U32(font->getWidth(character));
303  nextChar = j + 1;
304 
305  // Wraping between words (at blank spaces)
306  if (nextChar < sz && tempRow.at(nextChar) == ' ')
307  {
308  int nextSpacePos = CAST_U32(
309  tempRow.find(' ', (nextChar + 1)));
310  if (nextSpacePos <= 0)
311  nextSpacePos = CAST_U32(sz) - 1U;
312 
313  const unsigned int nextWordWidth =
314  CAST_U32(font->getWidth(
315  tempRow.substr(nextChar,
316  (CAST_U32(nextSpacePos) - nextChar))));
317 
318  if ((x + nextWordWidth + 10)
319  > CAST_U32(getWidth()))
320  {
321  x = mNewLinePadding; // Ident in new line
322  y += 1;
323  j ++;
324  }
325  }
326  // Wrapping looong lines (brutal force)
327  else if ((x + 2 * hyphenWidth)
328  > CAST_U32(getWidth()))
329  {
330  x = mNewLinePadding; // Ident in new line
331  y += 1;
332  }
333  }
334  }
335 
336  setHeight(fontHeight * (CAST_S32(
337  CAST_U32(mTextRows.size()) + y)));
338  mUpdateTime = 0;
339  updateHeight();
340 }
#define CAST_U32
Definition: cast.h:30
Font * getFont() const
Definition: widget.cpp:330
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
bool mEnableTabs
Definition: browserbox.h:205
int getWidth() const
Definition: widget.h:220
Definition: font.h:88
unsigned int mMaxRows
Definition: browserbox.h:184
void replaceVars(std::string &data)
bool mProcessVars
Definition: browserbox.h:202
std::list< int > mTextRowLinksCount
Definition: browserbox.h:169
time_t mUpdateTime
Definition: browserbox.h:188
Links mLinks
Definition: browserbox.h:178
#define CAST_S32
Definition: cast.h:29
TextRows mTextRows
Definition: browserbox.h:168
TextRows::const_iterator TextRowCIter
Definition: browserbox.h:167
bool mEnableKeys
Definition: browserbox.h:204
void setHeight(const int height)
Definition: widget.cpp:139
std::string replaceLinkCommands(const std::string &link)
int getWidth(const std::string &text) const
Definition: font.cpp:333
unsigned int mNewLinePadding
Definition: browserbox.h:190
#define CAST_SIZE
Definition: cast.h:33
bool mUseLinksAndUserColors
Definition: browserbox.h:199
void replaceTabs(std::string &data)
int getHeight() const
Definition: font.cpp:360
void replaceKeys(std::string &data)
const std::string getStr(const std::string &str)
Definition: podict.cpp:44
PoDict * translator
Definition: podict.cpp:27
void updateHeight()
Definition: browserbox.cpp:850

◆ addRow() [2/2]

void BrowserBox::addRow ( const std::string &  cmd,
const char *const  text 
)

Adds a menu line to the browser.

Definition at line 342 of file browserbox.cpp.

References addRow(), encodeLinkText(), and strprintf().

343 {
344  addRow(strprintf("@@%s|%[email protected]@", encodeLinkText(cmd).c_str(),
345  encodeLinkText(text).c_str()),
346  false);
347 }
std::string encodeLinkText(std::string data)
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
void addRow(const std::string &row, const bool atTop)
Definition: browserbox.cpp:170

◆ calcHeight()

int BrowserBox::calcHeight ( )
private

Definition at line 494 of file browserbox.cpp.

References ColorName::BLACK, ColorName::BLUE, boldFont, ColorName::BROWN, CAST_S32, CAST_S8, CAST_SIZE, CAST_U32, ServerCommandType::font, FOR_EACH, ImageSet::get(), Widget::getFont(), Font::getHeight(), Image::getHeight(), Loader::getImage(), Widget2::getThemeCharColor(), Font::getWidth(), Image::getWidth(), ColorName::GRAY, ColorName::GREEN, Resource::incRef(), mColors, mDataWidth, Widget::mDimension, mEmotes, mEnableImages, Widget::mForegroundColor, Widget2::mForegroundColor2, mItemPadding, mLineParts, mLinks, mNewLinePadding, mPadding, mTextRows, mUseEmotes, mUseLinksAndUserColors, ColorName::ORANGE, ColorName::PINK, ColorName::PURPLE, ColorName::RED, Widget::setWidth(), ImageSet::size(), ServerCommandType::size, anonymous_namespace{stringutils.cpp}::start, ServerCommandType::str, anonymous_namespace{libxml.cpp}::valid, Rect::width, x, BrowserLink::x1, BrowserLink::x2, y, BrowserLink::y1, BrowserLink::y2, and ColorName::YELLOW.

Referenced by draw(), getDataWidth(), and updateHeight().

495 {
496  unsigned int y = CAST_U32(mPadding);
497  int wrappedLines = 0;
498  int moreHeight = 0;
499  int maxWidth = mDimension.width - mPadding;
500  int link = 0;
501  bool bold = false;
502  unsigned int wWidth = CAST_U32(maxWidth);
503 
504  if (maxWidth < 0)
505  return 1;
506 
507  const Font *const font = getFont();
508  const int fontHeight = font->getHeight() + 2 * mItemPadding;
509  const int fontWidthMinus = font->getWidth("-");
510  const char *const hyphen = "~";
511  const int hyphenWidth = font->getWidth(hyphen);
512 
513  Color selColor[2] = {mForegroundColor, mForegroundColor2};
514  const Color textColor[2] = {mForegroundColor, mForegroundColor2};
515  mLineParts.clear();
516 
518  {
519  unsigned int x = CAST_U32(mPadding);
520  const std::string row = *(i);
521  bool wrapped = false;
522  int objects = 0;
523 
524  // Check for separator lines
525  if (row.find("---", 0) == 0)
526  {
527  const int dashWidth = fontWidthMinus;
528  for (x = CAST_U32(mPadding); x < wWidth; x ++)
529  {
530  mLineParts.push_back(LinePart(CAST_S32(x),
531  CAST_S32(y) + mItemPadding,
532  selColor[0], selColor[1], "-", false));
533  x += CAST_U32(CAST_S32(
534  dashWidth) - 2);
535  }
536 
537  y += CAST_U32(fontHeight);
538  continue;
539  }
540  else if (mEnableImages && row.find("~~~", 0) == 0)
541  {
542  std::string str = row.substr(3);
543  const size_t sz = str.size();
544  if (sz > 2 && str.substr(sz - 1) == "~")
545  str = str.substr(0, sz - 1);
546  Image *const img = Loader::getImage(str);
547  if (img != nullptr)
548  {
549  img->incRef();
550  mLineParts.push_back(LinePart(CAST_S32(x),
551  CAST_S32(y) + mItemPadding,
552  selColor[0], selColor[1], img));
553  y += CAST_U32(img->getHeight() + 2);
554  moreHeight += img->getHeight();
555  if (img->getWidth() > maxWidth)
556  maxWidth = img->getWidth() + 2;
557  }
558  continue;
559  }
560 
561  Color prevColor[2];
562  prevColor[0] = selColor[0];
563  prevColor[1] = selColor[1];
564  bold = false;
565 
566  const int xPadding = CAST_S32(mNewLinePadding) + mPadding;
567 
568  for (size_t start = 0, end = std::string::npos;
569  start != std::string::npos;
570  start = end, end = std::string::npos)
571  {
572  bool processed(false);
573 
574  // Wrapped line continuation shall be indented
575  if (wrapped)
576  {
577  y += CAST_U32(fontHeight);
578  x = CAST_U32(xPadding);
579  wrapped = false;
580  }
581 
582  size_t idx1 = end;
583  size_t idx2 = end;
584 
585  // "Tokenize" the string at control sequences
587  idx1 = row.find("##", start + 1);
588  if (start == 0 || mUseLinksAndUserColors)
589  {
590  // Check for color change in format "##x", x = [L,P,0..9]
591  if (row.find("##", start) == start && row.size() > start + 2)
592  {
593  const signed char c = row.at(start + 2);
594 
595  bool valid(false);
596  const Color col[2] =
597  {
600  c | 0x80), valid)
601  };
602 
603  if (c == '>')
604  {
605  selColor[0] = prevColor[0];
606  selColor[1] = prevColor[1];
607  }
608  else if (c == '<')
609  {
610  prevColor[0] = selColor[0];
611  prevColor[1] = selColor[1];
612  selColor[0] = col[0];
613  selColor[1] = col[1];
614  }
615  else if (c == 'B')
616  {
617  bold = true;
618  }
619  else if (c == 'b')
620  {
621  bold = false;
622  }
623  else if (valid)
624  {
625  selColor[0] = col[0];
626  selColor[1] = col[1];
627  }
628  else
629  {
630  switch (c)
631  {
632  case '0':
633  selColor[0] = mColors[0][ColorName::BLACK];
634  selColor[1] = mColors[1][ColorName::BLACK];
635  break;
636  case '1':
637  selColor[0] = mColors[0][ColorName::RED];
638  selColor[1] = mColors[1][ColorName::RED];
639  break;
640  case '2':
641  selColor[0] = mColors[0][ColorName::GREEN];
642  selColor[1] = mColors[1][ColorName::GREEN];
643  break;
644  case '3':
645  selColor[0] = mColors[0][ColorName::BLUE];
646  selColor[1] = mColors[1][ColorName::BLUE];
647  break;
648  case '4':
649  selColor[0] = mColors[0][ColorName::ORANGE];
650  selColor[1] = mColors[1][ColorName::ORANGE];
651  break;
652  case '5':
653  selColor[0] = mColors[0][ColorName::YELLOW];
654  selColor[1] = mColors[1][ColorName::YELLOW];
655  break;
656  case '6':
657  selColor[0] = mColors[0][ColorName::PINK];
658  selColor[1] = mColors[1][ColorName::PINK];
659  break;
660  case '7':
661  selColor[0] = mColors[0][ColorName::PURPLE];
662  selColor[1] = mColors[1][ColorName::PURPLE];
663  break;
664  case '8':
665  selColor[0] = mColors[0][ColorName::GRAY];
666  selColor[1] = mColors[1][ColorName::GRAY];
667  break;
668  case '9':
669  selColor[0] = mColors[0][ColorName::BROWN];
670  selColor[1] = mColors[1][ColorName::BROWN];
671  break;
672  default:
673  selColor[0] = textColor[0];
674  selColor[1] = textColor[1];
675  break;
676  }
677  }
678 
679  if (c == '<' && link < CAST_S32(mLinks.size()))
680  {
681  int size;
682  if (bold)
683  {
684  size = boldFont->getWidth(
685  mLinks[CAST_SIZE(link)].caption) + 1;
686  }
687  else
688  {
689  size = font->getWidth(
690  mLinks[CAST_SIZE(link)].caption) + 1;
691  }
692 
693  BrowserLink &linkRef = mLinks[CAST_SIZE(
694  link)];
695  linkRef.x1 = CAST_S32(x);
696  linkRef.y1 = CAST_S32(y);
697  linkRef.x2 = linkRef.x1 + size;
698  linkRef.y2 = CAST_S32(y) + fontHeight - 1;
699  link++;
700  }
701 
702  processed = true;
703  start += 3;
704  if (start == row.size())
705  break;
706  }
707  }
708  if (mUseEmotes)
709  idx2 = row.find("%%", start + 1);
710  if (idx1 < idx2)
711  end = idx1;
712  else
713  end = idx2;
714  if (mUseEmotes)
715  {
716  // check for emote icons
717  if (row.size() > start + 2 && row.substr(start, 2) == "%%")
718  {
719  if (objects < 5)
720  {
721  const int cid = row.at(start + 2) - '0';
722  if (cid >= 0)
723  {
724  if (mEmotes != nullptr)
725  {
726  const size_t sz = mEmotes->size();
727  if (CAST_SIZE(cid) < sz)
728  {
729  Image *const img = mEmotes->get(
730  CAST_SIZE(cid));
731  if (img != nullptr)
732  {
733  mLineParts.push_back(LinePart(
734  CAST_S32(x),
735  CAST_S32(y) + mItemPadding,
736  selColor[0], selColor[1], img));
737  x += 18;
738  }
739  }
740  }
741  }
742  objects ++;
743  processed = true;
744  }
745 
746  start += 3;
747  if (start == row.size())
748  {
749  if (x > mDataWidth)
750  mDataWidth = x;
751  break;
752  }
753  }
754  }
755  const size_t len = (end == std::string::npos) ? end : end - start;
756 
757  if (start >= row.length())
758  break;
759 
760  std::string part = row.substr(start, len);
761  int width = 0;
762  if (bold)
763  width = boldFont->getWidth(part);
764  else
765  width = font->getWidth(part);
766 
767  // Auto wrap mode
768  if (wWidth > 0 &&
769  width > 0 &&
770  (x + CAST_U32(width) + 10) > wWidth)
771  {
772  bool forced = false;
773 
774  /* FIXME: This code layout makes it easy to crash remote
775  clients by talking garbage. Forged long utf-8 characters
776  will cause either a buffer underflow in substr or an
777  infinite loop in the main loop. */
778  do
779  {
780  if (!forced)
781  end = row.rfind(' ', end);
782 
783  // Check if we have to (stupidly) force-wrap
784  if (end == std::string::npos || end <= start)
785  {
786  forced = true;
787  end = row.size();
788  x += CAST_U32(hyphenWidth);
789  continue;
790  }
791 
792  // Skip to the start of the current character
793  while ((row[end] & 192) == 128)
794  end--;
795  end--; // And then to the last byte of the previous one
796 
797  part = row.substr(start, end - start + 1);
798  if (bold)
799  width = boldFont->getWidth(part);
800  else
801  width = font->getWidth(part);
802  }
803  while (end > start &&
804  width > 0 &&
805  (x + CAST_U32(width) + 10) > wWidth);
806 
807  if (forced)
808  {
809  x -= CAST_U32(hyphenWidth);
810  mLineParts.push_back(LinePart(
811  CAST_S32(wWidth) - hyphenWidth,
812  CAST_S32(y) + mItemPadding,
813  selColor[0], selColor[1], hyphen, bold));
814  end++; // Skip to the next character
815  }
816  else
817  {
818  end += 2; // Skip to after the space
819  }
820 
821  wrapped = true;
822  wrappedLines++;
823  }
824 
825  mLineParts.push_back(LinePart(CAST_S32(x),
826  CAST_S32(y) + mItemPadding,
827  selColor[0], selColor[1], part.c_str(), bold));
828 
829  if (bold)
830  width = boldFont->getWidth(part);
831  else
832  width = font->getWidth(part);
833 
834  if (width == 0 && !processed)
835  break;
836 
837  x += CAST_U32(width);
838  if (x > mDataWidth)
839  mDataWidth = x;
840  }
841  y += CAST_U32(fontHeight);
842  }
843  if (CAST_S32(wWidth) != maxWidth)
844  setWidth(maxWidth);
845 
846  return (CAST_S32(mTextRows.size()) + wrappedLines)
847  * fontHeight + moreHeight + 2 * mPadding;
848 }
#define CAST_U32
Definition: cast.h:30
Font * getFont() const
Definition: widget.cpp:330
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
int width
Definition: rect.h:218
Font * boldFont
Definition: gui.cpp:111
Image * get(const size_type i) const
Definition: imageset.cpp:66
void setWidth(const int width)
Definition: widget.cpp:132
Definition: font.h:88
LinePartList mLineParts
Definition: browserbox.h:174
Color mForegroundColor
Definition: widget.h:1085
Links mLinks
Definition: browserbox.h:178
bool mEnableImages
Definition: browserbox.h:203
Color mColors[2][ColorName::COLORS_MAX]
Definition: browserbox.h:196
const Color & getThemeCharColor(const signed char c, bool &valid) const A_INLINE
Definition: widget2.h:51
#define CAST_S32
Definition: cast.h:29
TextRows mTextRows
Definition: browserbox.h:168
size_type size() const
Definition: imageset.h:72
Image * getImage(const std::string &idPath)
Definition: imageloader.cpp:85
static ImageSet * mEmotes
Definition: browserbox.h:207
TextRows::const_iterator TextRowCIter
Definition: browserbox.h:167
#define CAST_S8
Definition: cast.h:25
virtual void incRef()
Definition: resource.cpp:37
Color mForegroundColor2
Definition: widget2.h:112
int getWidth(const std::string &text) const
Definition: font.cpp:333
int mPadding
Definition: browserbox.h:189
Definition: image.h:61
bool mUseEmotes
Definition: browserbox.h:200
unsigned int mNewLinePadding
Definition: browserbox.h:190
Definition: color.h:74
int getWidth() const A_INLINE
Definition: image.h:116
#define CAST_SIZE
Definition: cast.h:33
bool mUseLinksAndUserColors
Definition: browserbox.h:199
int getHeight() const
Definition: font.cpp:360
int mItemPadding
Definition: browserbox.h:191
Rect mDimension
Definition: widget.h:1100
unsigned int mDataWidth
Definition: browserbox.h:192
int getHeight() const A_INLINE
Definition: image.h:122

◆ clearRows()

void BrowserBox::clearRows ( )

Remove all rows.

Definition at line 358 of file browserbox.cpp.

References mDataWidth, mLinks, mSelectedLink, mTextRowLinksCount, mTextRows, mUpdateTime, Widget::setHeight(), Widget::setWidth(), and updateHeight().

Referenced by NpcDialog::action(), NpcDialog::clearRows(), ChatTab::clearText(), setMaxRow(), QuestsWindow::showQuest(), and Setup_Colors::valueChanged().

359 {
360  mTextRows.clear();
361  mTextRowLinksCount.clear();
362  mLinks.clear();
363  setWidth(0);
364  setHeight(0);
365  mSelectedLink = -1;
366  mUpdateTime = 0;
367  mDataWidth = 0;
368  updateHeight();
369 }
void setWidth(const int width)
Definition: widget.cpp:132
std::list< int > mTextRowLinksCount
Definition: browserbox.h:169
time_t mUpdateTime
Definition: browserbox.h:188
Links mLinks
Definition: browserbox.h:178
TextRows mTextRows
Definition: browserbox.h:168
void setHeight(const int height)
Definition: widget.cpp:139
int mSelectedLink
Definition: browserbox.h:183
unsigned int mDataWidth
Definition: browserbox.h:192
void updateHeight()
Definition: browserbox.cpp:850

◆ draw()

void BrowserBox::draw ( Graphics *const  graphics)
virtual

Draws the browser box.

Implements Widget.

Definition at line 400 of file browserbox.cpp.

References LinkHighlightMode::BACKGROUND, BLOCK_END, BLOCK_START, boldFont, calcHeight(), CAST_S32, CAST_SIZE, cur_time, Graphics::drawImage(), Graphics::drawLine(), Font::drawString(), Graphics::fillRectangle(), ServerCommandType::font, FOR_EACH, Widget::getFont(), Graphics::getTopClip(), Rect::height, Widget::mBackgroundColor, LinePart::mBold, LinePart::mColor, LinePart::mColor2, Widget::mDimension, mHeight, mHighlightColor, mHighlightMode, mHyperLinkColor, LinePart::mImage, mLineParts, mLinks, mOpaque, mSelectedLink, LinePart::mText, LinePart::mType, mUpdateTime, mWidth, LinePart::mX, LinePart::mY, mYStart, Opaque_true, reportAlways, Graphics::setColor(), Widget::setHeight(), LinkHighlightMode::UNDERLINE, Rect::width, BrowserLink::x1, BrowserLink::x2, Rect::y, BrowserLink::y1, BrowserLink::y2, and ClipRect::yOffset.

Referenced by safeDraw(), and setMaxRow().

401 {
402  BLOCK_START("BrowserBox::draw")
403  const ClipRect &cr = graphics->getTopClip();
404  mYStart = cr.y - cr.yOffset;
405  const int yEnd = mYStart + cr.height;
406  if (mYStart < 0)
407  mYStart = 0;
408 
409  if (mDimension.width != mWidth)
410  {
411  mWidth = mDimension.width;
412  mHeight = calcHeight();
415  if (mDimension.width != mWidth)
416  reportAlways("browserbox resize in draw");
417  }
418 
419  if (mOpaque == Opaque_true)
420  {
421  graphics->setColor(mBackgroundColor);
422  graphics->fillRectangle(Rect(0, 0,
424  }
425 
426  if (mSelectedLink >= 0 &&
427  mSelectedLink < CAST_S32(mLinks.size()))
428  {
430  {
432  graphics->setColor(mHighlightColor);
433  graphics->fillRectangle(Rect(
434  link.x1,
435  link.y1,
436  link.x2 - link.x1,
437  link.y2 - link.y1));
438  }
439 
441  {
443  graphics->setColor(mHyperLinkColor);
444  graphics->drawLine(
445  link.x1,
446  link.y2,
447  link.x2,
448  link.y2);
449  }
450  }
451 
452  Font *const font = getFont();
453 
455  {
456  const LinePart &part = *i;
457  if (part.mY + 50 < mYStart)
458  continue;
459  if (part.mY > yEnd)
460  break;
461  if (part.mType == 0u)
462  {
463  if (part.mBold)
464  {
465  boldFont->drawString(graphics,
466  part.mColor,
467  part.mColor2,
468  part.mText,
469  part.mX, part.mY);
470  }
471  else
472  {
473  font->drawString(graphics,
474  part.mColor,
475  part.mColor2,
476  part.mText,
477  part.mX, part.mY);
478  }
479  }
480  else if (part.mImage != nullptr)
481  {
482  graphics->drawImage(part.mImage, part.mX, part.mY);
483  }
484  }
485 
486  BLOCK_END("BrowserBox::draw")
487 }
Font * getFont() const
Definition: widget.cpp:330
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
int width
Definition: rect.h:218
bool mBold
Definition: linepart.h:99
Font * boldFont
Definition: gui.cpp:111
Definition: font.h:88
Color mHyperLinkColor
Definition: browserbox.h:195
LinePartList mLineParts
Definition: browserbox.h:174
Definition: rect.h:72
unsigned int mHighlightMode
Definition: browserbox.h:182
int calcHeight()
Definition: browserbox.cpp:494
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
time_t mUpdateTime
Definition: browserbox.h:188
Links mLinks
Definition: browserbox.h:178
Color mBackgroundColor
Definition: widget.h:1090
virtual void setColor(const Color &color)
Definition: graphics.h:319
#define CAST_S32
Definition: cast.h:29
Image * mImage
Definition: linepart.h:98
unsigned char mType
Definition: linepart.h:97
Opaque mOpaque
Definition: browserbox.h:198
void drawString(Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
Definition: font.cpp:253
int mX
Definition: linepart.h:92
int height
Definition: rect.h:223
volatile time_t cur_time
Definition: timer.cpp:57
void setHeight(const int height)
Definition: widget.cpp:139
Color mHighlightColor
Definition: browserbox.h:194
virtual void fillRectangle(const Rect &rectangle)=0
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
Color mColor
Definition: linepart.h:94
virtual void drawLine(int x1, int y1, int x2, int y2)=0
const bool Opaque_true
Definition: opaque.h:29
#define CAST_SIZE
Definition: cast.h:33
Color mColor2
Definition: linepart.h:95
int mSelectedLink
Definition: browserbox.h:183
Rect mDimension
Definition: widget.h:1100
#define reportAlways(...)
Definition: checkutils.h:252
int mY
Definition: linepart.h:93
std::string mText
Definition: linepart.h:96
LinePartList::const_iterator LinePartCIter
Definition: browserbox.h:173

◆ getDataWidth()

unsigned int BrowserBox::getDataWidth ( ) const
inline

Definition at line 152 of file browserbox.h.

References A_WARN_UNUSED, calcHeight(), mDataWidth, moveSelectionDown(), moveSelectionUp(), selectSelection(), and widgetResized().

153  { return mDataWidth; }
unsigned int mDataWidth
Definition: browserbox.h:192

◆ getPadding()

int BrowserBox::getPadding ( ) const
inline

Definition at line 146 of file browserbox.h.

References mPadding, and setForegroundColorAll().

147  { return mPadding; }
int mPadding
Definition: browserbox.h:189

◆ getRows()

TextRows& BrowserBox::getRows ( )
inline

Definition at line 123 of file browserbox.h.

References mTextRows.

Referenced by ChatTab::getRows().

124  { return mTextRows; }
TextRows mTextRows
Definition: browserbox.h:168

◆ getTextAtPos()

std::string BrowserBox::getTextAtPos ( const int  x,
const int  y 
) const

Definition at line 869 of file browserbox.cpp.

References FOR_EACH, Widget::getAbsolutePosition(), mLineParts, LinePart::mText, LinePart::mY, mYStart, and ServerCommandType::str.

Referenced by NpcDialog::copyToClipboard(), ChatWindow::copyToClipboard(), and setEnableTabs().

870 {
871  int textX = 0;
872  int textY = 0;
873 
874  getAbsolutePosition(textX, textY);
875  if (x < textX || y < textY)
876  return std::string();
877 
878  textY = y - textY;
879  std::string str;
880  int lastY = 0;
881 
883  {
884  const LinePart &part = *i;
885  if (part.mY + 50 < mYStart)
886  continue;
887  if (part.mY > textY)
888  break;
889 
890  if (part.mY > lastY)
891  {
892  str = part.mText;
893  lastY = part.mY;
894  }
895  else
896  {
897  str.append(part.mText);
898  }
899  }
900 
901  return str;
902 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
LinePartList mLineParts
Definition: browserbox.h:174
virtual void getAbsolutePosition(int &x, int &y) const
Definition: widget.cpp:311
int mY
Definition: linepart.h:93
std::string mText
Definition: linepart.h:96
LinePartList::const_iterator LinePartCIter
Definition: browserbox.h:173

◆ hasRows()

bool BrowserBox::hasRows ( ) const
inline

Definition at line 126 of file browserbox.h.

References mTextRows.

Referenced by ChatTab::hasRows().

127  { return !mTextRows.empty(); }
TextRows mTextRows
Definition: browserbox.h:168

◆ mouseExited()

void BrowserBox::mouseExited ( MouseEvent event)
virtual

Called when the mouse has exited the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 395 of file browserbox.cpp.

References mSelectedLink.

Referenced by setMaxRow().

396 {
397  mSelectedLink = -1;
398 }
int mSelectedLink
Definition: browserbox.h:183

◆ mouseMoved()

void BrowserBox::mouseMoved ( MouseEvent event)
virtual

Called when the mouse has moved in the widget area and no mouse button has been pressed (i.e no widget is being dragged).

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 386 of file browserbox.cpp.

References CAST_S32, MouseEvent::getX(), mLinks, and mSelectedLink.

Referenced by setMaxRow().

387 {
388  const LinkIterator i = std::find_if(mLinks.begin(), mLinks.end(),
389  MouseOverLink(event.getX(), event.getY()));
390 
391  mSelectedLink = (i != mLinks.end())
392  ? CAST_S32(i - mLinks.begin()) : -1;
393 }
Links mLinks
Definition: browserbox.h:178
#define CAST_S32
Definition: cast.h:29
Links::iterator LinkIterator
Definition: browserbox.h:177
int getX() const
Definition: mouseevent.h:126
int mSelectedLink
Definition: browserbox.h:183

◆ mousePressed()

void BrowserBox::mousePressed ( MouseEvent event)
virtual

Handles mouse actions.

Reimplemented from MouseListener.

Definition at line 371 of file browserbox.cpp.

References MouseEvent::getX(), LinkHandler::handleLink(), mLinkHandler, and mLinks.

Referenced by setMaxRow().

372 {
373  if (mLinkHandler == nullptr)
374  return;
375 
376  const LinkIterator i = std::find_if(mLinks.begin(), mLinks.end(),
377  MouseOverLink(event.getX(), event.getY()));
378 
379  if (i != mLinks.end())
380  {
381  mLinkHandler->handleLink(i->link, &event);
382  event.consume();
383  }
384 }
LinkHandler * mLinkHandler
Definition: browserbox.h:180
Links mLinks
Definition: browserbox.h:178
virtual void handleLink(const std::string &link, MouseEvent *event)=0
Links::iterator LinkIterator
Definition: browserbox.h:177
int getX() const
Definition: mouseevent.h:126

◆ moveSelectionDown()

void BrowserBox::moveSelectionDown ( )

Definition at line 919 of file browserbox.cpp.

References mLinks, and mSelectedLink.

Referenced by getDataWidth().

920 {
921  mSelectedLink ++;
922  if (mSelectedLink >= static_cast<signed int>(mLinks.size()))
923  mSelectedLink = 0;
924 }
Links mLinks
Definition: browserbox.h:178
int mSelectedLink
Definition: browserbox.h:183

◆ moveSelectionUp()

void BrowserBox::moveSelectionUp ( )

Definition at line 911 of file browserbox.cpp.

References CAST_S32, mLinks, and mSelectedLink.

Referenced by getDataWidth().

912 {
913  if (mSelectedLink <= 0)
914  mSelectedLink = CAST_S32(mLinks.size()) - 1;
915  else
916  mSelectedLink --;
917 }
Links mLinks
Definition: browserbox.h:178
#define CAST_S32
Definition: cast.h:29
int mSelectedLink
Definition: browserbox.h:183

◆ safeDraw()

void BrowserBox::safeDraw ( Graphics *const  graphics)
virtual

Implements Widget.

Definition at line 489 of file browserbox.cpp.

References draw().

Referenced by setMaxRow().

490 {
491  BrowserBox::draw(graphics);
492 }
void draw(Graphics *const graphics)
Definition: browserbox.cpp:400

◆ selectSelection()

void BrowserBox::selectSelection ( )

Definition at line 926 of file browserbox.cpp.

References CAST_SIZE, LinkHandler::handleLink(), mLinkHandler, mLinks, and mSelectedLink.

Referenced by getDataWidth().

927 {
928  if ((mLinkHandler == nullptr) ||
929  mSelectedLink < 0 ||
930  mSelectedLink >= static_cast<signed int>(mLinks.size()))
931  {
932  return;
933  }
934 
936  nullptr);
937 }
LinkHandler * mLinkHandler
Definition: browserbox.h:180
Links mLinks
Definition: browserbox.h:178
virtual void handleLink(const std::string &link, MouseEvent *event)=0
#define CAST_SIZE
Definition: cast.h:33
int mSelectedLink
Definition: browserbox.h:183

◆ setAlwaysUpdate()

void BrowserBox::setAlwaysUpdate ( const bool  n)
inline

Definition at line 129 of file browserbox.h.

References mAlwaysUpdate.

Referenced by ChatTab::ChatTab().

130  { mAlwaysUpdate = n; }
bool mAlwaysUpdate
Definition: browserbox.h:201

◆ setEnableImages()

void BrowserBox::setEnableImages ( const bool  n)
inline

Definition at line 135 of file browserbox.h.

References mEnableImages.

Referenced by NpcDialog::NpcDialog().

136  { mEnableImages = n; }
bool mEnableImages
Definition: browserbox.h:203

◆ setEnableKeys()

void BrowserBox::setEnableKeys ( const bool  n)
inline

Definition at line 138 of file browserbox.h.

References mEnableKeys.

Referenced by NpcDialog::createSkinControls(), and NpcDialog::NpcDialog().

139  { mEnableKeys = n; }
bool mEnableKeys
Definition: browserbox.h:204

◆ setEnableTabs()

void BrowserBox::setEnableTabs ( const bool  n)
inline

Definition at line 141 of file browserbox.h.

References A_WARN_UNUSED, getTextAtPos(), mEnableTabs, x, and y.

Referenced by NpcDialog::createSkinControls(), and NpcDialog::NpcDialog().

142  { mEnableTabs = n; }
bool mEnableTabs
Definition: browserbox.h:205

◆ setForegroundColorAll()

void BrowserBox::setForegroundColorAll ( const Color color1,
const Color color2 
)

Definition at line 904 of file browserbox.cpp.

References Widget::mForegroundColor, and Widget2::mForegroundColor2.

Referenced by getPadding().

906 {
907  mForegroundColor = color1;
908  mForegroundColor2 = color2;
909 }
Color mForegroundColor
Definition: widget.h:1085
Color mForegroundColor2
Definition: widget2.h:112

◆ setLinkHandler()

void BrowserBox::setLinkHandler ( LinkHandler linkHandler)

Sets the handler for links.

Definition at line 165 of file browserbox.cpp.

References mLinkHandler.

Referenced by ChatTab::ChatTab(), NpcDialog::createSkinControls(), NpcDialog::NpcDialog(), QuestsWindow::QuestsWindow(), and Setup_Colors::Setup_Colors().

166 {
167  mLinkHandler = linkHandler;
168 }
LinkHandler * mLinkHandler
Definition: browserbox.h:180

◆ setMaxRow()

void BrowserBox::setMaxRow ( unsigned  max)
inline

Sets the maximum numbers of rows in the browser box. 0 = no limit.

Definition at line 80 of file browserbox.h.

References A_NONNULL, addImage(), addRow(), clearRows(), draw(), mMaxRows, mouseExited(), mouseMoved(), mousePressed(), safeDraw(), updateHeight(), and updateSize().

Referenced by ChatTab::chatLog(), ChatTab::ChatTab(), NpcDialog::createSkinControls(), and NpcDialog::NpcDialog().

81  { mMaxRows = max; }
unsigned int mMaxRows
Definition: browserbox.h:184

◆ setOpaque()

void BrowserBox::setOpaque ( Opaque  opaque)
inline

Sets the BrowserBox opacity.

Definition at line 74 of file browserbox.h.

References mOpaque.

Referenced by ChatTab::ChatTab(), NpcDialog::createSkinControls(), NpcDialog::NpcDialog(), QuestsWindow::QuestsWindow(), and Setup_Colors::Setup_Colors().

75  { mOpaque = opaque; }
Opaque mOpaque
Definition: browserbox.h:198

◆ setProcessVars()

void BrowserBox::setProcessVars ( const bool  n)
inline

Definition at line 132 of file browserbox.h.

References mProcessVars.

Referenced by NpcDialog::createSkinControls(), and NpcDialog::NpcDialog().

133  { mProcessVars = n; }
bool mProcessVars
Definition: browserbox.h:202

◆ updateHeight()

void BrowserBox::updateHeight ( )

Definition at line 850 of file browserbox.cpp.

References calcHeight(), cur_time, mAlwaysUpdate, Widget::mDimension, mHeight, mTextRows, mUpdateTime, mWidth, Widget::setHeight(), and Rect::width.

Referenced by addRow(), clearRows(), setMaxRow(), QuestsWindow::showQuest(), updateSize(), and widgetResized().

851 {
853  || mTextRows.size() < 3 || (mUpdateTime == 0))
854  {
856  mHeight = calcHeight();
859  }
860 }
int width
Definition: rect.h:218
int calcHeight()
Definition: browserbox.cpp:494
time_t mUpdateTime
Definition: browserbox.h:188
TextRows mTextRows
Definition: browserbox.h:168
bool mAlwaysUpdate
Definition: browserbox.h:201
volatile time_t cur_time
Definition: timer.cpp:57
void setHeight(const int height)
Definition: widget.cpp:139
Rect mDimension
Definition: widget.h:1100

◆ updateSize()

void BrowserBox::updateSize ( const bool  always)

Definition at line 862 of file browserbox.cpp.

References mUpdateTime, and updateHeight().

Referenced by ChatTab::ChatTab(), and setMaxRow().

863 {
864  if (always)
865  mUpdateTime = 0;
866  updateHeight();
867 }
time_t mUpdateTime
Definition: browserbox.h:188
void updateHeight()
Definition: browserbox.cpp:850

◆ widgetResized()

void BrowserBox::widgetResized ( const Event event)
virtual

Invoked when a widget changes its size.

Parameters
eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 939 of file browserbox.cpp.

References updateHeight().

Referenced by getDataWidth().

940 {
941  updateHeight();
942 }
void updateHeight()
Definition: browserbox.cpp:850

Field Documentation

◆ mAlwaysUpdate

bool BrowserBox::mAlwaysUpdate
private

Definition at line 201 of file browserbox.h.

Referenced by setAlwaysUpdate(), and updateHeight().

◆ mColors

Color BrowserBox::mColors[2][ColorName::COLORS_MAX]
private

Definition at line 196 of file browserbox.h.

Referenced by calcHeight().

◆ mDataWidth

unsigned int BrowserBox::mDataWidth
private

Definition at line 192 of file browserbox.h.

Referenced by calcHeight(), clearRows(), and getDataWidth().

◆ mEmotes

ImageSet * BrowserBox::mEmotes = 0
staticprivate

Definition at line 207 of file browserbox.h.

Referenced by BrowserBox(), calcHeight(), and ~BrowserBox().

◆ mEnableImages

bool BrowserBox::mEnableImages
private

Definition at line 203 of file browserbox.h.

Referenced by addImage(), calcHeight(), and setEnableImages().

◆ mEnableKeys

bool BrowserBox::mEnableKeys
private

Definition at line 204 of file browserbox.h.

Referenced by addRow(), and setEnableKeys().

◆ mEnableTabs

bool BrowserBox::mEnableTabs
private

Definition at line 205 of file browserbox.h.

Referenced by addRow(), and setEnableTabs().

◆ mHeight

int BrowserBox::mHeight
private

Definition at line 185 of file browserbox.h.

Referenced by draw(), and updateHeight().

◆ mHighlightColor

Color BrowserBox::mHighlightColor
private

Definition at line 194 of file browserbox.h.

Referenced by draw().

◆ mHighlightMode

unsigned int BrowserBox::mHighlightMode
private

Definition at line 182 of file browserbox.h.

Referenced by BrowserBox(), and draw().

◆ mHyperLinkColor

Color BrowserBox::mHyperLinkColor
private

Definition at line 195 of file browserbox.h.

Referenced by draw().

◆ mInstances

int BrowserBox::mInstances = 0
staticprivate

Definition at line 208 of file browserbox.h.

Referenced by BrowserBox(), and ~BrowserBox().

◆ mItemPadding

int BrowserBox::mItemPadding
private

Definition at line 191 of file browserbox.h.

Referenced by BrowserBox(), and calcHeight().

◆ mLineParts

LinePartList BrowserBox::mLineParts
private

Definition at line 174 of file browserbox.h.

Referenced by calcHeight(), draw(), and getTextAtPos().

◆ mLinkHandler

LinkHandler* BrowserBox::mLinkHandler
private

Definition at line 180 of file browserbox.h.

Referenced by mousePressed(), selectSelection(), and setLinkHandler().

◆ mLinks

Links BrowserBox::mLinks
private

◆ mMaxRows

unsigned int BrowserBox::mMaxRows
private

Definition at line 184 of file browserbox.h.

Referenced by addRow(), and setMaxRow().

◆ mNewLinePadding

unsigned int BrowserBox::mNewLinePadding
private

Definition at line 190 of file browserbox.h.

Referenced by addRow(), BrowserBox(), and calcHeight().

◆ mOpaque

Opaque BrowserBox::mOpaque
private

Definition at line 198 of file browserbox.h.

Referenced by draw(), and setOpaque().

◆ mPadding

int BrowserBox::mPadding
private

Definition at line 189 of file browserbox.h.

Referenced by BrowserBox(), calcHeight(), and getPadding().

◆ mProcessVars

bool BrowserBox::mProcessVars
private

Definition at line 202 of file browserbox.h.

Referenced by addRow(), and setProcessVars().

◆ mSelectedLink

int BrowserBox::mSelectedLink
private

◆ mSkin

Skin* BrowserBox::mSkin
private

Definition at line 181 of file browserbox.h.

Referenced by BrowserBox(), and ~BrowserBox().

◆ mTextRowLinksCount

std::list<int> BrowserBox::mTextRowLinksCount
private

Definition at line 169 of file browserbox.h.

Referenced by addImage(), addRow(), and clearRows().

◆ mTextRows

TextRows BrowserBox::mTextRows
private

Definition at line 168 of file browserbox.h.

Referenced by addImage(), addRow(), calcHeight(), clearRows(), getRows(), hasRows(), and updateHeight().

◆ mUpdateTime

time_t BrowserBox::mUpdateTime
private

Definition at line 188 of file browserbox.h.

Referenced by addRow(), clearRows(), draw(), updateHeight(), and updateSize().

◆ mUseEmotes

bool BrowserBox::mUseEmotes
private

Definition at line 200 of file browserbox.h.

Referenced by calcHeight().

◆ mUseLinksAndUserColors

bool BrowserBox::mUseLinksAndUserColors
private

Definition at line 199 of file browserbox.h.

Referenced by addRow(), and calcHeight().

◆ mWidth

int BrowserBox::mWidth
private

Definition at line 186 of file browserbox.h.

Referenced by draw(), and updateHeight().

◆ mYStart

int BrowserBox::mYStart
private

Definition at line 187 of file browserbox.h.

Referenced by draw(), and getTextAtPos().


The documentation for this class was generated from the following files: