TGUI  v0.5.2
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
ChatBox.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012 Bruno Van de Velde (vdv_b@hotmail.com)
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 
30 
31 namespace tgui
32 {
33  struct Panel;
34 
36 
37  struct TGUI_API ChatBox : public OBJECT, public OBJECT_BORDERS
38  {
43  ChatBox();
44 
45 
52  ChatBox(const ChatBox& copy);
53 
54 
59  virtual ~ChatBox();
60 
61 
70  ChatBox& operator= (const ChatBox& right);
71 
72 
74  // This function is called when the object is added to a group.
76  virtual void initialize();
77 
78 
80  // Makes a copy of the object by calling the copy constructor.
81  // This function calls new and if you use this function then you are responsible for calling delete.
83  virtual ChatBox* clone();
84 
85 
101  virtual bool load(float width, float height, unsigned int textSize, const std::string& scrollbarPathname = "");
102 
103 
111  virtual void setSize(float width, float height);
112 
113 
120  virtual Vector2u getSize() const;
121 
122 
129  virtual Vector2f getScaledSize() const;
130 
131 
139  virtual std::string getLoadedScrollbarPathname() const;
140 
141 
149  virtual void addLine(const sf::String& text, const sf::Color& color = sf::Color::Black);
150 
151 
161  virtual void setTextFont(const sf::Font& font);
162 
163 
170  virtual const sf::Font* getTextFont() const;
171 
172 
180  virtual void setTextSize(unsigned int size);
181 
182 
189  virtual unsigned int getTextSize() const;
190 
191 
201  virtual void setBorders(unsigned int leftBorder = 0,
202  unsigned int topBorder = 0,
203  unsigned int rightBorder = 0,
204  unsigned int bottomBorder = 0);
205 
206 
213  virtual void setBackgroundColor(const sf::Color& backgroundColor);
214 
215 
222  virtual void setBorderColor(const sf::Color& borderColor);
223 
224 
231  virtual const sf::Color& getBackgroundColor() const;
232 
233 
240  virtual const sf::Color& getBorderColor() const;
241 
242 
253  virtual bool setScrollbar(const std::string& scrollbarPathname);
254 
255 
262  virtual void removeScrollbar();
263 
264 
266  // Used to communicate with EventManager.
268  virtual bool mouseOnObject(float x, float y);
269  virtual void leftMousePressed(float x, float y);
270  virtual void leftMouseReleased(float x, float y);
271  virtual void mouseMoved(float x, float y);
272  virtual void mouseWheelMoved(int delta);
273  virtual void mouseNotOnObject();
274  virtual void mouseNoLongerDown();
275 
276 
278  protected:
279 
281  // Not all heights are valid in the chat box.
282  // This function will take the requested height and returns the closest height that can be used.
284  float calculateValidHeight(float requestedHeight);
285 
286 
288  // Update the position of the labels.
290  void updateDisplayedText();
291 
292 
294  // Because this class is derived from sf::Drawable, you can just call the Draw function from your sf::RenderTarget.
295  // This function will be called and it will draw the object on the render target.
297  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
298 
299 
301  protected:
302 
303  unsigned int m_TextSize;
304  sf::Color m_BorderColor;
305 
306  // The panel containing the labels
307  Panel* m_Panel;
308 
309  // The scrollbar
310  Scrollbar* m_Scroll;
311 
312  // The pathname used to load the scrollbar (if there is one)
313  std::string m_LoadedScrollbarPathname;
314 
316  };
317 
319 }
320 
322 
323 #endif // TGUI_TEXT_BOX_HPP
The parent struct for every object.
Definition: Objects.hpp:36
Definition: Scrollbar.hpp:35
Parent struct for every object that has borders.
Definition: Objects.hpp:299
Definition: ChatBox.hpp:37
A static group of objects. The background color can be solid or transparent.
Definition: Panel.hpp:36