TGUI  v0.5.2
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
TextBox.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_TEXT_BOX_INCLUDED_
27 #define _TGUI_TEXT_BOX_INCLUDED_
28 
36 
37 
39 
40 namespace tgui
41 {
43 
44  struct TGUI_API TextBox : public OBJECT, OBJECT_BORDERS, OBJECT_ANIMATION
45  {
49  TextBox();
50 
51 
55  TextBox(const TextBox& copy);
56 
57 
61  virtual ~TextBox();
62 
63 
67  TextBox& operator= (const TextBox& right);
68 
69 
73  virtual void initialize();
74 
75 
79  virtual TextBox* clone();
80 
81 
97  virtual bool load(unsigned int width, unsigned int height, unsigned int textSize, const std::string& scrollbarPathname = "");
98 
99 
106  virtual void setSize(float width, float height);
107 
108 
112  virtual Vector2u getSize() const;
113 
114 
118  virtual Vector2f getScaledSize() const;
119 
120 
126  virtual std::string getLoadedScrollbarPathname() const;
127 
128 
132  virtual void setText(const sf::String& text);
133 
134 
138  virtual void addText(const sf::String& text);
139 
140 
144  virtual sf::String getText() const;
145 
146 
153  virtual void setTextFont(const sf::Font& font);
154 
155 
159  virtual const sf::Font* getTextFont() const;
160 
161 
166  virtual void setTextSize(unsigned int size);
167 
168 
172  virtual unsigned int getTextSize() const;
173 
174 
180  virtual void setMaximumCharacters(unsigned int maxChars = 0);
181 
182 
188  virtual unsigned int getMaximumCharacters() const;
189 
190 
199  virtual void setBorders(unsigned int leftBorder = 0,
200  unsigned int topBorder = 0,
201  unsigned int rightBorder = 0,
202  unsigned int bottomBorder = 0);
203 
204 
215  virtual void changeColors(const sf::Color& backgroundColor = sf::Color( 50, 50, 50),
216  const sf::Color& textColor = sf::Color( 0, 0, 0),
217  const sf::Color& selectedTextColor = sf::Color(255, 255, 255),
218  const sf::Color& selectedTextBackgroundColor = sf::Color( 10, 110, 255),
219  const sf::Color& borderColor = sf::Color( 0, 0, 0),
220  const sf::Color& selectionPointColor = sf::Color(110, 110, 255));
221 
227  virtual void setBackgroundColor(const sf::Color& backgroundColor);
228 
234  virtual void setTextColor(const sf::Color& textColor);
235 
241  virtual void setSelectedTextColor(const sf::Color& selectedTextColor);
242 
248  virtual void setSelectedTextBackgroundColor(const sf::Color& selectedTextBackgroundColor);
249 
255  virtual void setBorderColor(const sf::Color& borderColor);
256 
257 
261  virtual const sf::Color& getBackgroundColor() const;
262 
266  virtual const sf::Color& getTextColor() const;
267 
271  virtual const sf::Color& getSelectedTextColor() const;
272 
276  virtual const sf::Color& getSelectedTextBackgroundColor() const;
277 
281  virtual const sf::Color& getBorderColor() const;
282 
283 
289  virtual void setSelectionPointPosition(unsigned int charactersBeforeSelectionPoint);
290 
291 
297  virtual bool setScrollbar(const std::string& scrollbarPathname);
298 
299 
305  virtual void removeScrollbar();
306 
307 
311  virtual void setSelectionPointWidth(unsigned int width = 2);
312 
313 
315  // These functions are used to receive callback from the EventManager.
316  // You normally don't need them, but you can use them to simulate an event.
318  virtual bool mouseOnObject(float x, float y);
319  virtual void leftMousePressed(float x, float y);
320  virtual void leftMouseReleased(float x, float y);
321  virtual void mouseMoved(float x, float y);
322  virtual void keyPressed(sf::Keyboard::Key Key);
323  virtual void textEntered(sf::Uint32 Key);
324  virtual void mouseWheelMoved(int delta);
325  virtual void mouseNotOnObject();
326  virtual void mouseNoLongerDown();
327  virtual void objectUnfocused();
328 
329 
331  protected:
332 
333 
335  // This function will search where the selection point should be. It will not change the selection point.
336  // It will return after which character the selection point should be.
338  virtual unsigned int findSelectionPointPosition(float posX, float posY);
339 
340 
342  // This function is called when you are selecting text.
343  // It will find out which part of the text is selected.
345  virtual void selectText(float posX, float posY);
346 
347 
349  // To keep the drawing as fast as possible, all the calculation are done in front by this function.
350  // It is called when the text changes, when scrolling, ...
352  virtual void updateDisplayedText();
353 
354 
356  // This function is called by updateDisplayedText and will split the text into five pieces so that the text can
357  // be easily drawn.
359  virtual void updateSelectionTexts(float maxLineWidth);
360 
361 
363  // When AnimationManager changes the elapsed time then this function is called.
365  virtual void update();
366 
367 
369  // Because this struct is derived from sf::Drawable, you can just call the Draw function from your sf::RenderTarget.
370  // This function will be called and it will draw the object on the render target.
372  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
373 
374 
376  public:
377 
380 
382  unsigned int selectionPointWidth;
383 
384 
386  protected:
387 
388  // The size of the text box
389  Vector2u m_Size;
390 
391  // Some information about the text
392  sf::String m_Text;
393  sf::String m_DisplayedText;
394  unsigned int m_TextSize;
395  unsigned int m_LineHeight;
396  unsigned int m_Lines;
397 
398  // The maximum characters (0 by default, which means no limit)
399  unsigned int m_MaxChars;
400 
401  // What is known about the visible lines?
402  unsigned int m_TopLine;
403  unsigned int m_VisibleLines;
404 
405  // Information about the selection
406  unsigned int m_SelChars;
407  unsigned int m_SelStart;
408  unsigned int m_SelEnd;
409 
410  // Information about the selection pointer
411  sf::Vector2u m_SelectionPointPosition;
412  bool m_SelectionPointVisible;
413 
414  // Should the text be resplit into the five texts?
415  bool m_SelectionTextsNeedUpdate;
416 
417  // The colors that are used by the text box
418  sf::Color m_BackgroundColor;
419  sf::Color m_SelectedTextBgrColor;
420  sf::Color m_BorderColor;
421 
422  // The sfml Text objects
423  sf::Text m_TextBeforeSelection;
424  sf::Text m_TextSelection1;
425  sf::Text m_TextSelection2;
426  sf::Text m_TextAfterSelection1;
427  sf::Text m_TextAfterSelection2;
428 
429  std::vector<float> m_MultilineSelectionRectWidth;
430 
431  // The scrollbar
432  Scrollbar* m_Scroll;
433 
434  // The pathname used to load the scrollbar (if there is one)
435  std::string m_LoadedScrollbarPathname;
436 
437  // Is there a possibility that the user is going to double click?
438  bool m_PossibleDoubleClick;
439 
441  };
442 
444 }
445 
447 
448 #endif //_TGUI_TEXT_BOX_INCLUDED_
449 
450 
The parent struct for every object.
Definition: Objects.hpp:36
Definition: Scrollbar.hpp:35
Definition: TextBox.hpp:44
Parent struct for every object that has borders.
Definition: Objects.hpp:299
unsigned int selectionPointWidth
The width in pixels of the flickering selection pointer.
Definition: TextBox.hpp:382
sf::Color selectionPointColor
The color of the flickering selection pointer.
Definition: TextBox.hpp:379
Parent object for all objects that need to access the internal clock of the window.
Definition: Objects.hpp:338