26#ifndef TGUI_CHAT_BOX_HPP
27#define TGUI_CHAT_BOX_HPP
30#include <TGUI/Widget.hpp>
31#include <TGUI/Widgets/Panel.hpp>
32#include <TGUI/Widgets/Scrollbar.hpp>
41 class ChatBoxRenderer;
49 typedef std::shared_ptr<ChatBox>
Ptr;
50 typedef std::shared_ptr<const ChatBox>
ConstPtr;
60 unsigned int sublines = 1;
61 std::shared_ptr<sf::Font> font;
122 return std::static_pointer_cast<ChatBoxRenderer>(m_renderer);
175 void addLine(
const sf::String& text,
unsigned int textSize);
190 void addLine(
const sf::String& text,
const sf::Color& color);
205 void addLine(
const sf::String& text,
const sf::Color& color,
unsigned int textSize,
const Font& font =
nullptr);
218 sf::String
getLine(std::size_t lineIndex)
const;
251 std::shared_ptr<sf::Font>
getLineFont(std::size_t lineIndex)
const;
460 virtual void setParent(
Container* parent)
override;
466 virtual bool mouseOnWidget(
float x,
float y)
const override;
471 virtual void leftMousePressed(
float x,
float y)
override;
476 virtual void leftMouseReleased(
float x,
float y)
override;
481 virtual void mouseMoved(
float x,
float y)
override;
486 virtual void mouseWheelMoved(
int delta,
int x,
int y)
override;
491 virtual void mouseNoLongerOnWidget()
override;
496 virtual void mouseNoLongerDown()
override;
505 void recalculateLineText(
Line& line);
511 void recalculateAllLines();
517 void recalculateFullTextHeight();
523 void updateDisplayedText();
529 void updateRendering();
547 virtual void reload(
const std::string& primary =
"",
const std::string& secondary =
"",
bool force =
false)
override;
555 return std::make_shared<ChatBox>(*
this);
562 virtual void draw(sf::RenderTarget& target, sf::RenderStates states)
const override;
568 unsigned int m_textSize = 18;
569 sf::Color m_textColor = sf::Color::Black;
571 std::size_t m_maxLines = 0;
573 float m_fullTextHeight = 0;
575 bool m_linesStartFromTop =
false;
576 bool m_newLinesBelowOthers =
true;
580 std::deque<Line> m_lines;
613 virtual void setProperty(std::string property,
const std::string& value)
override;
699 void draw(sf::RenderTarget& target, sf::RenderStates states)
const;
708 Padding getScaledPadding()
const;
714 virtual std::shared_ptr<WidgetRenderer> clone(
Widget* widget)
override;
722 sf::Color m_borderColor;
723 sf::Color m_backgroundColor;
Definition: Borders.hpp:38
Definition: ChatBox.hpp:591
virtual std::map< std::string, ObjectConverter > getPropertyValuePairs() const override
Get a map with all properties and their values.
ChatBoxRenderer(ChatBox *chatBox)
Constructor.
Definition: ChatBox.hpp:600
void setBackgroundTexture(const Texture &texture)
Changes the background image.
virtual void setProperty(std::string property, const std::string &value) override
Change a property of the renderer.
virtual ObjectConverter getProperty(std::string property) const override
Retrieve the value of a certain property.
void setBorderColor(const Color &borderColor)
Set the border color that will be used inside the chat box.
void setPadding(const Padding &padding) override
Changes the size of the padding.
void setBackgroundColor(const Color &backgroundColor)
Set the background color that will be used inside the chat box.
virtual void setProperty(std::string property, ObjectConverter &&value) override
Change a property of the renderer.
Definition: ChatBox.hpp:46
virtual void setOpacity(float opacity) override
Changes the opacity of the widget.
std::size_t getLineAmount()
Returns the amount of lines in the chat box.
void setScrollbar(Scrollbar::Ptr scrollbar)
Changes the scrollbar of the chat box.
ChatBox(const ChatBox ©)
Copy constructor.
void setTextSize(unsigned int size)
Changes the default character size of the text.
virtual void setFont(const Font &font) override
Changes the default font of the text.
static ChatBox::Ptr copy(ChatBox::ConstPtr chatBox)
Makes a copy of another chat box.
virtual void reload(const std::string &primary="", const std::string &secondary="", bool force=false) override
Reload the widget.
void removeAllLines()
Removes all lines from the chat box.
virtual sf::Vector2f getFullSize() const override
Returns the full size of the chat box.
bool getLinesStartFromTop() const
Returns whether the first lines start from the top or from the bottom of the chat box.
static ChatBox::Ptr create()
Creates a new chat box widget.
std::shared_ptr< const ChatBox > ConstPtr
Shared constant widget pointer.
Definition: ChatBox.hpp:50
void setLinesStartFromTop(bool startFromTop=true)
Let the first lines start from the top or from the bottom of the chat box.
std::size_t getLineLimit()
Returns the maximum amount of lines in the chat box.
void addLine(const sf::String &text, unsigned int textSize)
Add a new line of text to the chat box.
void setTextColor(const Color &color)
Changes the default color of the text.
bool getNewLinesBelowOthers() const
Returns whether new lines are added below the other lines or above them.
void addLine(const sf::String &text, const sf::Color &color)
Add a new line of text to the chat box.
void setSize(const Layout2d &size) override
Changes the size of the chat box.
std::shared_ptr< ChatBoxRenderer > getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Definition: ChatBox.hpp:120
void setNewLinesBelowOthers(bool newLinesBelowOthers=true)
Set whether new lines are added below the other lines or above them.
std::shared_ptr< ChatBox > Ptr
Shared widget pointer.
Definition: ChatBox.hpp:49
sf::String getLine(std::size_t lineIndex) const
Returns the contents of the requested line.
virtual sf::Vector2f getWidgetOffset() const override
Returns the distance between the position where the widget is drawn and where the widget is placed.
unsigned int getLineTextSize(std::size_t lineIndex) const
Returns the text size of the requested line.
std::shared_ptr< sf::Font > getLineFont(std::size_t lineIndex) const
Returns the font of the requested line.
sf::Color getLineColor(std::size_t lineIndex) const
Returns the color of the requested line.
void addLine(const sf::String &text)
Add a new line of text to the chat box.
unsigned int getTextSize() const
Returns the default character size of the text.
Definition: ChatBox.hpp:333
void setLineLimit(std::size_t maxLines)
Set a maximum amount of lines in the chat box.
Scrollbar::Ptr getScrollbar() const
Access the scrollbar of the chat box.
bool removeLine(std::size_t lineIndex)
Removes the requested line.
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: ChatBox.hpp:553
const sf::Color & getTextColor() const
Returns the default color of the text.
Definition: ChatBox.hpp:354
void addLine(const sf::String &text, const sf::Color &color, unsigned int textSize, const Font &font=nullptr)
Add a new line of text to the chat box.
Implicit converter for colors.
Definition: Color.hpp:40
Container widget.
Definition: Container.hpp:48
Class to store the position or size of a widget.
Definition: Layout.hpp:255
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:43
Definition: Texture.hpp:45
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:34
Definition: ChatBox.hpp:57