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 48 of file browserbox.h.

Member Typedef Documentation

◆ LinePartCIter

typedef LinePartList::const_iterator BrowserBox::LinePartCIter
private

Definition at line 174 of file browserbox.h.

◆ LinePartIterator

typedef LinePartList::iterator BrowserBox::LinePartIterator
private

Definition at line 173 of file browserbox.h.

◆ LinePartList

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

Definition at line 172 of file browserbox.h.

◆ LinkIterator

typedef Links::iterator BrowserBox::LinkIterator
private

Definition at line 178 of file browserbox.h.

◆ Links

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

Definition at line 177 of file browserbox.h.

◆ TextRowCIter

typedef TextRows::const_iterator BrowserBox::TextRowCIter
private

Definition at line 168 of file browserbox.h.

◆ TextRowIterator

typedef TextRows::iterator BrowserBox::TextRowIterator
private

Definition at line 167 of file browserbox.h.

◆ TextRows

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

Definition at line 122 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 61 of file browserbox.cpp.

63  :
64  Widget(widget),
65  MouseListener(),
67  mTextRows(),
69  mLineParts(),
70  mLinks(),
71  mLinkHandler(nullptr),
72  mSkin(nullptr),
73  mHighlightMode(0),
74  mSelectedLink(-1),
75  mMaxRows(0),
76  mHeight(0),
77  mWidth(0),
78  mYStart(0),
79  mUpdateTime(-1),
80  mPadding(0),
81  mNewLinePadding(15U),
82  mItemPadding(0),
83  mDataWidth(0),
84  mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT, 255U)),
85  mHyperLinkColor(getThemeColor(ThemeColorId::HYPERLINK, 255U)),
86  mOpaque(opaque),
88  mUseEmotes(true),
89  mAlwaysUpdate(true),
90  mProcessVars(false),
91  mEnableImages(false),
92  mEnableKeys(false),
93  mEnableTabs(false)
94 {
95  mAllowLogic = false;
96 
97  setFocusable(true);
98  addMouseListener(this);
99  addWidgetListener(this);
100 
102 
103  if (theme != nullptr)
104  {
105  mSkin = theme->load(skin,
106  "browserbox.xml",
107  true,
109  }
110  if (mInstances == 0)
111  {
113  "graphics/sprites/chatemotes.png", 17, 18);
114  }
115  mInstances ++;
116 
117  if (mSkin != nullptr)
118  {
121  mSkin->getOption("newLinePadding", 15));
122  mItemPadding = mSkin->getOption("itemPadding");
123  if (mSkin->getOption("highlightBackground") != 0)
125  if (mSkin->getOption("highlightUnderline") != 0)
127  }
128 
129  readColor(BLACK);
130  readColor(RED);
131  readColor(GREEN);
132  readColor(BLUE);
133  readColor(ORANGE);
134  readColor(YELLOW);
135  readColor(PINK);
136  readColor(PURPLE);
137  readColor(GRAY);
138  readColor(BROWN);
139 
140  mForegroundColor = getThemeColor(ThemeColorId::BROWSERBOX, 255U);
141  mForegroundColor2 = getThemeColor(ThemeColorId::BROWSERBOX_OUTLINE, 255U);
142 }
#define CAST_U32
Definition: cast.h:31
bool mEnableTabs
Definition: browserbox.h:206
unsigned int mDataWidth
Definition: browserbox.h:193
int mPadding
Definition: browserbox.h:190
Links mLinks
Definition: browserbox.h:179
unsigned int mHighlightMode
Definition: browserbox.h:183
int mSelectedLink
Definition: browserbox.h:184
Color mHyperLinkColor
Definition: browserbox.h:196
Skin * mSkin
Definition: browserbox.h:182
static ImageSet * mEmotes
Definition: browserbox.h:208
time_t mUpdateTime
Definition: browserbox.h:189
bool mEnableKeys
Definition: browserbox.h:205
LinkHandler * mLinkHandler
Definition: browserbox.h:181
std::list< int > mTextRowLinksCount
Definition: browserbox.h:170
bool mAlwaysUpdate
Definition: browserbox.h:202
unsigned int mMaxRows
Definition: browserbox.h:185
int mItemPadding
Definition: browserbox.h:192
Opaque mOpaque
Definition: browserbox.h:199
Color mHighlightColor
Definition: browserbox.h:195
LinePartList mLineParts
Definition: browserbox.h:175
bool mProcessVars
Definition: browserbox.h:203
bool mEnableImages
Definition: browserbox.h:204
bool mUseLinksAndUserColors
Definition: browserbox.h:200
TextRows mTextRows
Definition: browserbox.h:169
bool mUseEmotes
Definition: browserbox.h:201
unsigned int mNewLinePadding
Definition: browserbox.h:191
static int mInstances
Definition: browserbox.h:209
int getOption(const std::string &name) const
Definition: skin.h:106
int getPadding() const
Definition: skin.h:100
static std::string getThemePath()
Definition: theme.h:67
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:179
Color mForegroundColor2
Definition: widget2.h:113
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:45
Color mForegroundColor
Definition: widget.h:1086
void setFocusable(const bool focusable)
Definition: widget.cpp:192
Widget(const Widget2 *const widget)
Definition: widget.cpp:85
Color mBackgroundColor
Definition: widget.h:1091
bool mAllowLogic
Definition: widget.h:1160
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:292
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:302
ImageSet * getImageSet(const std::string &imagePath, const int w, const int h)
Theme * theme
Definition: theme.cpp:62
static Color readColor(const std::string &description)
Definition: theme.cpp:697

References Widget::addMouseListener(), Widget::addWidgetListener(), LinkHighlightMode::BACKGROUND, ColorName::BLACK, ColorName::BLUE, ColorName::BROWN, 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.

◆ ~BrowserBox()

BrowserBox::~BrowserBox ( )

Destructor.

Definition at line 144 of file browserbox.cpp.

145 {
146  if (gui != nullptr)
147  gui->removeDragged(this);
148 
149  if (theme != nullptr)
150  {
151  theme->unload(mSkin);
152  mSkin = nullptr;
153  }
154 
155  mInstances --;
156  if (mInstances == 0)
157  {
158  if (mEmotes != nullptr)
159  {
160  mEmotes->decRef();
161  mEmotes = nullptr;
162  }
163  }
164 }
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1162
virtual void decRef()
Definition: resource.cpp:50
void unload(Skin *const skin)
Definition: theme.cpp:250
Gui * gui
Definition: gui.cpp:111

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

Member Function Documentation

◆ addImage()

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

Definition at line 350 of file browserbox.cpp.

351 {
352  if (!mEnableImages)
353  return;
354 
355  mTextRows.push_back("~~~" + path);
356  mTextRowLinksCount.push_back(0);
357 }

References mEnableImages, mTextRowLinksCount, and mTextRows.

◆ addRow() [1/2]

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

Adds a menu line to the browser.

Definition at line 343 of file browserbox.cpp.

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

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

◆ addRow() [2/2]

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

Adds a text row to the browser.

Definition at line 171 of file browserbox.cpp.

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

References BrowserLink::caption, CAST_S32, CAST_SIZE, CAST_U32, FOR_EACH, Widget::getFont(), Font::getHeight(), PoDict::getStr(), Widget::getWidth(), Font::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(), and QuestsWindow::showQuest().

◆ calcHeight()

int BrowserBox::calcHeight ( )
private

Definition at line 495 of file browserbox.cpp.

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

References ColorName::BLACK, ColorName::BLUE, boldFont, ColorName::BROWN, CAST_S32, CAST_S8, CAST_SIZE, CAST_U32, FOR_EACH, ImageSet::get(), Widget::getFont(), Font::getHeight(), Loader::getImage(), Widget2::getThemeCharColor(), Font::getWidth(), ColorName::GRAY, ColorName::GREEN, 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(), EmoteDB::size(), ImageSet::size(), anonymous_namespace{stringutils.cpp}::start, anonymous_namespace{libxml.cpp}::valid, Rect::width, x, BrowserLink::x1, BrowserLink::x2, y, BrowserLink::y1, BrowserLink::y2, and ColorName::YELLOW.

Referenced by draw(), and updateHeight().

◆ clearRows()

void BrowserBox::clearRows ( )

Remove all rows.

Definition at line 359 of file browserbox.cpp.

360 {
361  mTextRows.clear();
362  mTextRowLinksCount.clear();
363  mLinks.clear();
364  setWidth(0);
365  setHeight(0);
366  mSelectedLink = -1;
367  mUpdateTime = 0;
368  mDataWidth = 0;
369  updateHeight();
370 }

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

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

◆ draw()

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

Draws the browser box.

Implements Widget.

Definition at line 401 of file browserbox.cpp.

402 {
403  BLOCK_START("BrowserBox::draw")
404  const ClipRect &cr = graphics->getTopClip();
405  mYStart = cr.y - cr.yOffset;
406  const int yEnd = mYStart + cr.height;
407  if (mYStart < 0)
408  mYStart = 0;
409 
410  if (mDimension.width != mWidth)
411  {
413  mHeight = calcHeight();
416  if (mDimension.width != mWidth)
417  reportAlways("browserbox resize in draw")
418  }
419 
420  if (mOpaque == Opaque_true)
421  {
422  graphics->setColor(mBackgroundColor);
423  graphics->fillRectangle(Rect(0, 0,
425  }
426 
427  if (mSelectedLink >= 0 &&
428  mSelectedLink < CAST_S32(mLinks.size()))
429  {
431  {
433  graphics->setColor(mHighlightColor);
434  graphics->fillRectangle(Rect(
435  link.x1,
436  link.y1,
437  link.x2 - link.x1,
438  link.y2 - link.y1));
439  }
440 
442  {
444  graphics->setColor(mHyperLinkColor);
445  graphics->drawLine(
446  link.x1,
447  link.y2,
448  link.x2,
449  link.y2);
450  }
451  }
452 
453  Font *const font = getFont();
454 
456  {
457  const LinePart &part = *i;
458  if (part.mY + 50 < mYStart)
459  continue;
460  if (part.mY > yEnd)
461  break;
462  if (part.mType == 0U)
463  {
464  if (part.mBold)
465  {
466  boldFont->drawString(graphics,
467  part.mColor,
468  part.mColor2,
469  part.mText,
470  part.mX, part.mY);
471  }
472  else
473  {
474  font->drawString(graphics,
475  part.mColor,
476  part.mColor2,
477  part.mText,
478  part.mX, part.mY);
479  }
480  }
481  else if (part.mImage != nullptr)
482  {
483  graphics->drawImage(part.mImage, part.mX, part.mY);
484  }
485  }
486 
487  BLOCK_END("BrowserBox::draw")
488 }
volatile time_t cur_time
Definition: timer.cpp:58
#define reportAlways(...)
Definition: checkutils.h:253
LinePartList::const_iterator LinePartCIter
Definition: browserbox.h:174
int calcHeight()
Definition: browserbox.cpp:495
void drawString(Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
Definition: font.cpp:254
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
virtual void fillRectangle(const Rect &rectangle)=0
virtual void setColor(const Color &color)
Definition: graphics.h:320
virtual void drawLine(int x1, int y1, int x2, int y2)=0
int mX
Definition: linepart.h:93
unsigned char mType
Definition: linepart.h:98
int mY
Definition: linepart.h:94
bool mBold
Definition: linepart.h:100
Color mColor
Definition: linepart.h:95
Image * mImage
Definition: linepart.h:99
Color mColor2
Definition: linepart.h:96
std::string mText
Definition: linepart.h:97
Definition: rect.h:74
int height
Definition: rect.h:224
if(!vert) return
const bool Opaque_true
Definition: opaque.h:30
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79

References LinkHighlightMode::BACKGROUND, BLOCK_END, BLOCK_START, boldFont, calcHeight(), CAST_S32, CAST_SIZE, cur_time, Graphics::drawImage(), Graphics::drawLine(), Font::drawString(), Graphics::fillRectangle(), 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().

◆ getDataWidth()

unsigned int BrowserBox::getDataWidth ( ) const
inline

Definition at line 153 of file browserbox.h.

154  { return mDataWidth; }

References mDataWidth.

◆ getPadding()

int BrowserBox::getPadding ( ) const
inline

Definition at line 147 of file browserbox.h.

148  { return mPadding; }

References mPadding.

◆ getRows()

TextRows& BrowserBox::getRows ( )
inline

Definition at line 124 of file browserbox.h.

125  { return mTextRows; }

References mTextRows.

Referenced by ChatTab::getRows().

◆ getTextAtPos()

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

Definition at line 870 of file browserbox.cpp.

871 {
872  int textX = 0;
873  int textY = 0;
874 
875  getAbsolutePosition(textX, textY);
876  if (x < textX || y < textY)
877  return std::string();
878 
879  textY = y - textY;
880  std::string str;
881  int lastY = 0;
882 
884  {
885  const LinePart &part = *i;
886  if (part.mY + 50 < mYStart)
887  continue;
888  if (part.mY > textY)
889  break;
890 
891  if (part.mY > lastY)
892  {
893  str = part.mText;
894  lastY = part.mY;
895  }
896  else
897  {
898  str.append(part.mText);
899  }
900  }
901 
902  return str;
903 }
virtual void getAbsolutePosition(int &x, int &y) const
Definition: widget.cpp:312

References FOR_EACH, Widget::getAbsolutePosition(), mLineParts, LinePart::mText, LinePart::mY, mYStart, x, and y.

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

◆ hasRows()

bool BrowserBox::hasRows ( ) const
inline

Definition at line 127 of file browserbox.h.

128  { return !mTextRows.empty(); }

References mTextRows.

Referenced by ChatTab::hasRows().

◆ 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 396 of file browserbox.cpp.

397 {
398  mSelectedLink = -1;
399 }

References mSelectedLink.

◆ 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 387 of file browserbox.cpp.

388 {
389  const LinkIterator i = std::find_if(mLinks.begin(), mLinks.end(),
390  MouseOverLink(event.getX(), event.getY()));
391 
392  mSelectedLink = (i != mLinks.end())
393  ? CAST_S32(i - mLinks.begin()) : -1;
394 }
Links::iterator LinkIterator
Definition: browserbox.h:178
int getX() const
Definition: mouseevent.h:127
int getY() const
Definition: mouseevent.h:138

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

◆ mousePressed()

void BrowserBox::mousePressed ( MouseEvent event)
virtual

Handles mouse actions.

Reimplemented from MouseListener.

Definition at line 372 of file browserbox.cpp.

373 {
374  if (mLinkHandler == nullptr)
375  return;
376 
377  const LinkIterator i = std::find_if(mLinks.begin(), mLinks.end(),
378  MouseOverLink(event.getX(), event.getY()));
379 
380  if (i != mLinks.end())
381  {
382  mLinkHandler->handleLink(i->link, &event);
383  event.consume();
384  }
385 }
virtual void handleLink(const std::string &link, MouseEvent *event)=0

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

◆ moveSelectionDown()

void BrowserBox::moveSelectionDown ( )

Definition at line 920 of file browserbox.cpp.

921 {
922  mSelectedLink ++;
923  if (mSelectedLink >= static_cast<signed int>(mLinks.size()))
924  mSelectedLink = 0;
925 }

References mLinks, and mSelectedLink.

◆ moveSelectionUp()

void BrowserBox::moveSelectionUp ( )

Definition at line 912 of file browserbox.cpp.

913 {
914  if (mSelectedLink <= 0)
915  mSelectedLink = CAST_S32(mLinks.size()) - 1;
916  else
917  mSelectedLink --;
918 }

References CAST_S32, mLinks, and mSelectedLink.

◆ safeDraw()

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

Implements Widget.

Definition at line 490 of file browserbox.cpp.

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

References draw().

◆ selectSelection()

void BrowserBox::selectSelection ( )

Definition at line 927 of file browserbox.cpp.

928 {
929  if ((mLinkHandler == nullptr) ||
930  mSelectedLink < 0 ||
931  mSelectedLink >= static_cast<signed int>(mLinks.size()))
932  {
933  return;
934  }
935 
937  nullptr);
938 }

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

◆ setAlwaysUpdate()

void BrowserBox::setAlwaysUpdate ( const bool  n)
inline

Definition at line 130 of file browserbox.h.

131  { mAlwaysUpdate = n; }

References mAlwaysUpdate.

Referenced by ChatTab::ChatTab().

◆ setEnableImages()

void BrowserBox::setEnableImages ( const bool  n)
inline

Definition at line 136 of file browserbox.h.

137  { mEnableImages = n; }

References mEnableImages.

Referenced by NpcDialog::NpcDialog().

◆ setEnableKeys()

void BrowserBox::setEnableKeys ( const bool  n)
inline

Definition at line 139 of file browserbox.h.

140  { mEnableKeys = n; }

References mEnableKeys.

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

◆ setEnableTabs()

void BrowserBox::setEnableTabs ( const bool  n)
inline

Definition at line 142 of file browserbox.h.

143  { mEnableTabs = n; }

References mEnableTabs.

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

◆ setForegroundColorAll()

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

Definition at line 905 of file browserbox.cpp.

907 {
908  mForegroundColor = color1;
909  mForegroundColor2 = color2;
910 }

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

◆ setLinkHandler()

void BrowserBox::setLinkHandler ( LinkHandler linkHandler)

Sets the handler for links.

Definition at line 166 of file browserbox.cpp.

167 {
168  mLinkHandler = linkHandler;
169 }

References mLinkHandler.

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

◆ setMaxRow()

void BrowserBox::setMaxRow ( unsigned  max)
inline

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

Definition at line 81 of file browserbox.h.

82  { mMaxRows = max; }

References mMaxRows.

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

◆ setOpaque()

void BrowserBox::setOpaque ( Opaque  opaque)
inline

Sets the BrowserBox opacity.

Definition at line 75 of file browserbox.h.

76  { mOpaque = opaque; }

References mOpaque.

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

◆ setProcessVars()

void BrowserBox::setProcessVars ( const bool  n)
inline

Definition at line 133 of file browserbox.h.

134  { mProcessVars = n; }

References mProcessVars.

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

◆ updateHeight()

void BrowserBox::updateHeight ( )

Definition at line 851 of file browserbox.cpp.

852 {
854  || mTextRows.size() < 3 || (mUpdateTime == 0))
855  {
857  mHeight = calcHeight();
860  }
861 }

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

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

◆ updateSize()

void BrowserBox::updateSize ( const bool  always)

Definition at line 863 of file browserbox.cpp.

864 {
865  if (always)
866  mUpdateTime = 0;
867  updateHeight();
868 }

References mUpdateTime, and updateHeight().

Referenced by ChatTab::ChatTab().

◆ 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 940 of file browserbox.cpp.

941 {
942  updateHeight();
943 }

References updateHeight().

Field Documentation

◆ mAlwaysUpdate

bool BrowserBox::mAlwaysUpdate
private

Definition at line 202 of file browserbox.h.

Referenced by setAlwaysUpdate(), and updateHeight().

◆ mColors

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

Definition at line 197 of file browserbox.h.

Referenced by calcHeight().

◆ mDataWidth

unsigned int BrowserBox::mDataWidth
private

Definition at line 193 of file browserbox.h.

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

◆ mEmotes

ImageSet * BrowserBox::mEmotes = 0
staticprivate

Definition at line 208 of file browserbox.h.

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

◆ mEnableImages

bool BrowserBox::mEnableImages
private

Definition at line 204 of file browserbox.h.

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

◆ mEnableKeys

bool BrowserBox::mEnableKeys
private

Definition at line 205 of file browserbox.h.

Referenced by addRow(), and setEnableKeys().

◆ mEnableTabs

bool BrowserBox::mEnableTabs
private

Definition at line 206 of file browserbox.h.

Referenced by addRow(), and setEnableTabs().

◆ mHeight

int BrowserBox::mHeight
private

Definition at line 186 of file browserbox.h.

Referenced by draw(), and updateHeight().

◆ mHighlightColor

Color BrowserBox::mHighlightColor
private

Definition at line 195 of file browserbox.h.

Referenced by draw().

◆ mHighlightMode

unsigned int BrowserBox::mHighlightMode
private

Definition at line 183 of file browserbox.h.

Referenced by BrowserBox(), and draw().

◆ mHyperLinkColor

Color BrowserBox::mHyperLinkColor
private

Definition at line 196 of file browserbox.h.

Referenced by draw().

◆ mInstances

int BrowserBox::mInstances = 0
staticprivate

Definition at line 209 of file browserbox.h.

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

◆ mItemPadding

int BrowserBox::mItemPadding
private

Definition at line 192 of file browserbox.h.

Referenced by BrowserBox(), and calcHeight().

◆ mLineParts

LinePartList BrowserBox::mLineParts
private

Definition at line 175 of file browserbox.h.

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

◆ mLinkHandler

LinkHandler* BrowserBox::mLinkHandler
private

Definition at line 181 of file browserbox.h.

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

◆ mLinks

Links BrowserBox::mLinks
private

◆ mMaxRows

unsigned int BrowserBox::mMaxRows
private

Definition at line 185 of file browserbox.h.

Referenced by addRow(), and setMaxRow().

◆ mNewLinePadding

unsigned int BrowserBox::mNewLinePadding
private

Definition at line 191 of file browserbox.h.

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

◆ mOpaque

Opaque BrowserBox::mOpaque
private

Definition at line 199 of file browserbox.h.

Referenced by draw(), and setOpaque().

◆ mPadding

int BrowserBox::mPadding
private

Definition at line 190 of file browserbox.h.

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

◆ mProcessVars

bool BrowserBox::mProcessVars
private

Definition at line 203 of file browserbox.h.

Referenced by addRow(), and setProcessVars().

◆ mSelectedLink

int BrowserBox::mSelectedLink
private

◆ mSkin

Skin* BrowserBox::mSkin
private

Definition at line 182 of file browserbox.h.

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

◆ mTextRowLinksCount

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

Definition at line 170 of file browserbox.h.

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

◆ mTextRows

TextRows BrowserBox::mTextRows
private

Definition at line 169 of file browserbox.h.

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

◆ mUpdateTime

time_t BrowserBox::mUpdateTime
private

Definition at line 189 of file browserbox.h.

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

◆ mUseEmotes

bool BrowserBox::mUseEmotes
private

Definition at line 201 of file browserbox.h.

Referenced by calcHeight().

◆ mUseLinksAndUserColors

bool BrowserBox::mUseLinksAndUserColors
private

Definition at line 200 of file browserbox.h.

Referenced by addRow(), and calcHeight().

◆ mWidth

int BrowserBox::mWidth
private

Definition at line 187 of file browserbox.h.

Referenced by draw(), and updateHeight().

◆ mYStart

int BrowserBox::mYStart
private

Definition at line 188 of file browserbox.h.

Referenced by draw(), and getTextAtPos().


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