TGUI  v0.6.10
ChatBox.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012-2015 Bruno Van de Velde (vdv_b@tgui.eu)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 
26 #ifndef TGUI_CHAT_BOX_HPP
27 #define TGUI_CHAT_BOX_HPP
28 
29 
30 #include <TGUI/Widget.hpp>
31 
33 
34 namespace tgui
35 {
36  class Panel;
37  class Scrollbar;
38 
40 
41  class TGUI_API ChatBox : public Widget, public WidgetBorders
42  {
43  public:
44 
46 
51  ChatBox();
52 
53 
60  ChatBox(const ChatBox& copy);
61 
62 
67  virtual ~ChatBox();
68 
69 
78  ChatBox& operator= (const ChatBox& right);
79 
80 
83  // Makes a copy of the widget by calling the copy constructor.
84  // This function calls new and if you use this function then you are responsible for calling delete.
86  virtual ChatBox* clone();
87 
88 
98  bool load(const std::string& configFileFilename, const std::string& sectionName = "ChatBox");
99 
100 
108  const std::string& getLoadedConfigFile() const;
109 
110 
120  void setSize(float width, float height);
121 
122 
131  virtual sf::Vector2f getSize() const;
132 
133 
142  virtual sf::Vector2f getFullSize() const;
143 
144 
156  void addLine(const sf::String& text);
157 
158 
171  void addLine(const sf::String& text, unsigned int textSize);
172 
173 
186  void addLine(const sf::String& text, const sf::Color& color);
187 
188 
201  void addLine(const sf::String& text, const sf::Color& color, unsigned int textSize, const sf::Font* font = nullptr);
202 
203 
214  sf::String getLine(unsigned int lineIndex);
215 
216 
226  bool removeLine(unsigned int lineIndex);
227 
228 
233  void removeAllLines();
234 
235 
242  unsigned int getLineAmount();
243 
244 
254  void setLineLimit(unsigned int maxLines);
255 
256 
266  void setTextFont(const sf::Font& font);
267 
268 
275  const sf::Font* getTextFont() const;
276 
277 
285  void setTextSize(unsigned int size);
286 
287 
294  unsigned int getTextSize() const;
295 
296 
303  void setTextColor(const sf::Color& color);
304 
305 
312  const sf::Color& getTextColor() const;
313 
314 
324  virtual void setBorders(unsigned int leftBorder = 0,
325  unsigned int topBorder = 0,
326  unsigned int rightBorder = 0,
327  unsigned int bottomBorder = 0);
328 
329 
336  void setBackgroundColor(const sf::Color& backgroundColor);
337 
338 
345  void setBorderColor(const sf::Color& borderColor);
346 
347 
354  const sf::Color& getBackgroundColor() const;
355 
356 
363  const sf::Color& getBorderColor() const;
364 
365 
378  void setLineSpacing(unsigned int lineSpacing);
379 
380 
390  void setLinesStartFromBottom(bool startFromBottom);
391 
392 
404  bool setScrollbar(const std::string& scrollbarConfigFileFilename);
405 
406 
413  void removeScrollbar();
414 
415 
426  virtual void setTransparency(unsigned char transparency);
427 
428 
432  virtual bool mouseOnWidget(float x, float y);
433 
437  virtual void leftMousePressed(float x, float y);
438 
442  virtual void leftMouseReleased(float x, float y);
443 
447  virtual void mouseMoved(float x, float y);
448 
452  virtual void mouseWheelMoved(int delta, int x, int y);
453 
457  virtual void mouseNotOnWidget();
458 
462  virtual void mouseNoLongerDown();
463 
464 
467  // This function is a (slow) way to set properties on the widget, no matter what type it is.
468  // When the requested property doesn't exist in the widget then the functions will return false.
470  virtual bool setProperty(std::string property, const std::string& value);
471 
474  // This function is a (slow) way to get properties of the widget, no matter what type it is.
475  // When the requested property doesn't exist in the widget then the functions will return false.
477  virtual bool getProperty(std::string property, std::string& value) const;
478 
479 
482  // Returns a list of all properties that can be used in setProperty and getProperty.
483  // The second value in the pair is the type of the property (e.g. int, uint, string, ...).
485  virtual std::list< std::pair<std::string, std::string> > getPropertyList() const;
486 
487 
489  private:
490 
492  // Retrieve the space of one of the lines.
494  unsigned int getLineSpacing(unsigned int lineNumber);
495 
496 
498  protected:
499 
502  // This function is called when the widget is added to a container.
504  virtual void initialize(Container *const parent);
505 
506 
509  // Update the position of the labels.
511  void updateDisplayedText();
512 
513 
516  // Draws the widget on the render target.
518  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
519 
520 
522  public:
523 
528  {
529  AllChatBoxCallbacks = WidgetCallbacksCount - 1,
530  ChatBoxCallbacksCount = WidgetCallbacksCount
531  };
532 
533 
535  protected:
536 
537  std::string m_LoadedConfigFile;
538 
539  unsigned int m_LineSpacing;
540  unsigned int m_TextSize;
541  sf::Color m_TextColor;
542  sf::Color m_BorderColor;
543 
544  unsigned int m_MaxLines;
545 
546  float m_FullTextHeight;
547 
548  bool m_LinesStartFromBottom;
549 
550  // The panel containing the labels
551  Panel* m_Panel;
552 
553  // The scrollbar
554  Scrollbar* m_Scroll;
555 
557  };
558 
560 }
561 
563 
564 #endif // TGUI_TEXT_BOX_HPP
Namespace that contains all TGUI functions and classes.
Definition: AnimatedPicture.hpp:33
The parent class for every widget.
Definition: Widget.hpp:45
ChatBoxCallbacks
Defines specific triggers to ChatBox.
Definition: ChatBox.hpp:527
Parent class for every widget that has borders.
Definition: Widget.hpp:480
A static container of widgets. The background color can be solid or transparent.
Definition: Panel.hpp:39
Parent class for widgets that store multiple widgets.
Definition: Container.hpp:43
Definition: Scrollbar.hpp:38
Definition: SharedWidgetPtr.hpp:44
Definition: ChatBox.hpp:41