Mana
Loading...
Searching...
No Matches
browserbox.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 * Copyright (C) 2009 Aethyra Development Team
6 *
7 * This file is part of The Mana Client.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#pragma once
24
25#include "utils/time.h"
26
27#include <guichan/mouselistener.hpp>
28#include <guichan/widget.hpp>
29
30#include <deque>
31#include <optional>
32#include <vector>
33
34class LinkHandler;
35struct LayoutContext;
36
38{
39 gcn::Rectangle rect;
40 std::string link;
41 std::string caption;
42
43 bool contains(int x, int y) const
44 {
45 return rect.isPointInRect(x, y);
46 }
47};
48
50{
51 int x;
52 int y;
53 gcn::Color color;
54 std::optional<gcn::Color> outlineColor;
55 std::string text;
56 gcn::Font *font;
57};
58
59struct TextRow
60{
61 std::string text;
62 std::vector<LinePart> parts;
63 std::vector<BrowserLink> links;
64 int width = 0;
65 int height = 0;
66};
67
72class BrowserBox : public gcn::Widget,
73 public gcn::MouseListener
74{
75 public:
76 enum Mode
77 {
80 };
81
83 ~BrowserBox() override;
84
88 void setLinkHandler(LinkHandler *handler) { mLinkHandler = handler; }
89
90 void setPalette(int palette) { mPalette = palette; }
91
95 void setHighlightMode(unsigned int mode) { mHighlightMode = mode; }
96
100 void setWrapIndent(int indent) { mWrapIndent = indent; }
101
105 void setShadowedText(bool shadows) { mShadows = shadows; }
106
110 void setOutlinedText(bool outline) { mOutline = outline; }
111
115 void setMaxRows(unsigned maxRows) { mMaxRows = maxRows; }
116
121
125 void setEnableKeys(bool enable) { mEnableKeys = enable; }
126
130 void addRows(std::string_view rows);
131
135 void addRow(std::string_view row);
136
140 void clearRows();
141
145 void mousePressed(gcn::MouseEvent &event) override;
146 void mouseMoved(gcn::MouseEvent &event) override;
147 void mouseExited(gcn::MouseEvent &event) override;
148
152 void draw(gcn::Graphics *graphics) override;
153
157 void drawFrame(gcn::Graphics *) override {}
158
168
169 private:
170 void relayoutText();
171 void layoutTextRow(TextRow &row, LayoutContext &context);
172 void updateHoveredLink(int x, int y);
173 void maybeRelayoutText();
174
175 std::deque<TextRow> mTextRows;
176
178 int mPalette = 0;
181 int mWrapIndent = 0;
182 bool mShadows = false;
183 bool mOutline = false;
185 bool mEnableKeys = false;
186 std::optional<BrowserLink> mHoveredLink;
187 unsigned int mMaxRows = 0;
190};
A simple browser box able to handle links and forward events to the parent conteiner.
Definition browserbox.h:74
void setOutlinedText(bool outline)
Sets whether the font will use a shadow for text.
Definition browserbox.h:110
void maybeRelayoutText()
void addRows(std::string_view rows)
Adds one or more text rows to the browser, separated by ' '.
void setEnableKeys(bool enable)
Enable or disable the replacement of keys.
Definition browserbox.h:125
void setHighlightMode(unsigned int mode)
Sets the Highlight mode for links.
Definition browserbox.h:95
void mouseMoved(gcn::MouseEvent &event) override
bool mShadows
Definition browserbox.h:182
void setShadowedText(bool shadows)
Sets whether the font will use a shadow for text.
Definition browserbox.h:105
void updateHoveredLink(int x, int y)
void mouseExited(gcn::MouseEvent &event) override
void draw(gcn::Graphics *graphics) override
Draws the browser box.
unsigned int mHighlightMode
Definition browserbox.h:180
void setMaxRows(unsigned maxRows)
Sets the maximum numbers of rows in the browser box.
Definition browserbox.h:115
std::optional< BrowserLink > mHoveredLink
Definition browserbox.h:186
void setPalette(int palette)
Definition browserbox.h:90
void drawFrame(gcn::Graphics *) override
Overridden to avoid drawing the default frame.
Definition browserbox.h:157
void addRow(std::string_view row)
Adds a text row to the browser.
void layoutTextRow(TextRow &row, LayoutContext &context)
Layers out the given row of text starting at the given context position.
int mLastLayoutWidth
Definition browserbox.h:188
bool mEnableKeys
Definition browserbox.h:185
LinkHandler * mLinkHandler
Definition browserbox.h:177
~BrowserBox() override
void setLinkHandler(LinkHandler *handler)
Sets the handler for links.
Definition browserbox.h:88
unsigned int mMaxRows
Definition browserbox.h:187
void clearRows()
Remove all rows.
LinkHighlightMode
Highlight modes for links.
Definition browserbox.h:164
int mWrapIndent
Definition browserbox.h:181
Timer mLayoutTimer
Definition browserbox.h:189
@ AUTO_WRAP
Maybe it needs a fix or to be redone.
Definition browserbox.h:79
void disableLinksAndUserColors()
Disable links & user defined colors to be used in chat input.
Definition browserbox.h:120
void setWrapIndent(int indent)
Sets the wrap indent for the browser box.
Definition browserbox.h:100
std::deque< TextRow > mTextRows
Definition browserbox.h:175
bool mUseLinksAndUserColors
Definition browserbox.h:184
bool mOutline
Definition browserbox.h:183
void mousePressed(gcn::MouseEvent &event) override
Handles mouse actions.
void relayoutText()
Relayouts all text rows and returns the new height of the BrowserBox.
A simple interface to windows that need to handle links from BrowserBox widget.
Definition linkhandler.h:31
Simple timer that can be used to check if a certain amount of time has passed.
Definition time.h:62
Graphics * graphics
Definition client.cpp:104
gcn::Font * font
Definition browserbox.h:56
gcn::Color color
Definition browserbox.h:53
std::string text
Definition browserbox.h:55
std::optional< gcn::Color > outlineColor
Definition browserbox.h:54
std::vector< LinePart > parts
Definition browserbox.h:62
int height
Definition browserbox.h:65
std::vector< BrowserLink > links
Definition browserbox.h:63
int width
Definition browserbox.h:64
std::string text
Definition browserbox.h:61