35 #include "gui/widgets/browserbox.inc"
38 #include "render/graphics.h"
51 #include "utils/timer.h"
63 const std::string &skin) :
84 mHighlightColor(getThemeColor(
ThemeColorId::HIGHLIGHT, 255U)),
85 mHyperLinkColor(getThemeColor(
ThemeColorId::HYPERLINK, 255U)),
87 mUseLinksAndUserColors(true),
103 if (
theme !=
nullptr)
113 "graphics/sprites/chatemotes.png", 17, 18);
117 if (
mSkin !=
nullptr)
149 if (
theme !=
nullptr)
173 std::string tmp = row;
199 size_t idx1 = tmp.find(
"@@");
200 while (idx1 != std::string::npos)
202 const size_t idx2 = tmp.find(
'|', idx1);
203 const size_t idx3 = tmp.find(
"@@", idx2);
205 if (idx2 == std::string::npos || idx3 == std::string::npos)
207 bLink.
link = tmp.substr(idx1 + 2, idx2 - (idx1 + 2));
208 bLink.
caption = tmp.substr(idx2 + 1, idx3 - (idx2 + 1));
219 newRow.append(tmp.substr(0, idx1));
221 std::string tmp2 = newRow;
222 idx1 = tmp2.find(
"##");
223 while (idx1 != std::string::npos)
226 idx1 = tmp2.find(
"##");
237 newRow.append(
"##<").append(bLink.
caption);
239 tmp.erase(0, idx3 + 2);
241 newRow.append(
"##>");
243 idx1 = tmp.find(
"@@");
279 while ((cnt != 0) && !
mLinks.empty())
287 const int fontHeight = font->
getHeight();
289 unsigned int nextChar;
290 const char *
const hyphen =
"~";
291 const unsigned int hyphenWidth =
CAST_U32(
297 std::string tempRow = *i;
298 for (uint32_t j = 0, sz =
CAST_U32(tempRow.size());
302 const std::string character = tempRow.substr(j, 1);
307 if (nextChar < sz && tempRow.at(nextChar) ==
' ')
310 tempRow.find(
' ', (nextChar + 1)));
311 if (nextSpacePos <= 0)
314 const unsigned int nextWordWidth =
316 tempRow.substr(nextChar,
317 (
CAST_U32(nextSpacePos) - nextChar))));
319 if ((
x + nextWordWidth + 10)
328 else if ((
x + 2 * hyphenWidth)
462 if (part.
mType == 0U)
481 else if (part.
mImage !=
nullptr)
498 int wrappedLines = 0;
503 unsigned int wWidth =
CAST_U32(maxWidth);
510 const int fontWidthMinus = font->
getWidth(
"-");
511 const char *
const hyphen =
"~";
512 const int hyphenWidth = font->
getWidth(hyphen);
521 const std::string row = *(i);
522 bool wrapped =
false;
526 if (row.find(
"---", 0) == 0)
528 const int dashWidth = fontWidthMinus;
533 selColor[0], selColor[1],
"-",
false));
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);
553 selColor[0], selColor[1], img));
555 moreHeight += img->getHeight();
556 if (img->getWidth() > maxWidth)
557 maxWidth = img->getWidth() + 2;
563 prevColor[0] = selColor[0];
564 prevColor[1] = selColor[1];
569 for (
size_t start = 0, end = std::string::npos;
570 start != std::string::npos;
571 start = end, end = std::string::npos)
573 bool processed(
false);
588 idx1 = row.find(
"##",
start + 1);
594 const signed char c = row.at(
start + 2);
606 selColor[0] = prevColor[0];
607 selColor[1] = prevColor[1];
611 prevColor[0] = selColor[0];
612 prevColor[1] = selColor[1];
613 selColor[0] = col[0];
614 selColor[1] = col[1];
626 selColor[0] = col[0];
627 selColor[1] = col[1];
674 selColor[0] = textColor[0];
675 selColor[1] = textColor[1];
705 if (
start == row.size())
710 idx2 = row.find(
"%%",
start + 1);
718 if (row.size() >
start + 2 && row.substr(
start, 2) ==
"%%")
722 const int cid = row.at(
start + 2) -
'0';
737 selColor[0], selColor[1], img));
748 if (
start == row.size())
756 const size_t len = (end == std::string::npos) ? end : end -
start;
758 if (
start >= row.length())
761 std::string part = row.substr(
start, len);
782 end = row.rfind(
' ', end);
785 if (end == std::string::npos || end <=
start)
794 while ((row[end] & 192) == 128)
804 while (end >
start &&
814 selColor[0], selColor[1], hyphen, bold));
828 selColor[0], selColor[1], part.c_str(), bold));
835 if (width == 0 && !processed)
848 * fontHeight + moreHeight + 2 *
mPadding;
876 if (
x < textX ||
y < textY)
877 return std::string();
898 str.append(part.
mText);
#define reportAlways(...)
TextRows::const_iterator TextRowCIter
void mousePressed(MouseEvent &event)
BrowserBox(const Widget2 *const widget, const Opaque opaque, const std::string &skin)
std::string getTextAtPos(const int x, const int y) const
Color mColors[2][ColorName::COLORS_MAX]
unsigned int mHighlightMode
void updateSize(const bool always)
static ImageSet * mEmotes
void setForegroundColorAll(const Color &color1, const Color &color2)
Links::iterator LinkIterator
void widgetResized(const Event &event)
void addRow(const std::string &row, const bool atTop)
void mouseMoved(MouseEvent &event)
void addImage(const std::string &path)
void setLinkHandler(LinkHandler *linkHandler)
LinkHandler * mLinkHandler
std::list< int > mTextRowLinksCount
void mouseExited(MouseEvent &event)
void safeDraw(Graphics *const graphics)
LinePartList::const_iterator LinePartCIter
bool mUseLinksAndUserColors
void draw(Graphics *const graphics)
unsigned int mNewLinePadding
int getWidth(const std::string &text) const
void drawString(Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
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)
virtual void drawLine(int x1, int y1, int x2, int y2)=0
ClipRect & getTopClip() const
void removeDragged(const Widget *const widget)
Image * get(const size_type i) const
virtual void handleLink(const std::string &link, MouseEvent *event)=0
const std::string getStr(const std::string &str)
int getOption(const std::string &name) const
void unload(Skin *const skin)
static std::string getThemePath()
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
#define FOR_EACH(type, iter, array)
Image * getImage(const std::string &idPath)
ImageSet * getImageSet(const std::string &imagePath, const int w, const int h)
#define BLOCK_START(name)
std::string strprintf(const char *const format,...)
std::string encodeLinkText(std::string data)
static Color readColor(const std::string &description)