TGUI  v0.5.2
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
EditBox.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 #ifndef _TGUI_EDITBOX_INCLUDED_
26 #define _TGUI_EDITBOX_INCLUDED_
27 
29 
31 
32 namespace tgui
33 {
35 
36  struct TGUI_API EditBox : public OBJECT, OBJECT_BORDERS, OBJECT_ANIMATION
37  {
41  struct Alignment
42  {
44  {
47 
50 
52  Right
53  };
54  };
55 
56 
61  EditBox();
62 
63 
70  EditBox(const EditBox& copy);
71 
72 
77  virtual ~EditBox();
78 
79 
88  EditBox& operator= (const EditBox& right);
89 
90 
92  // This function is called when the object is created (when it is added to a group).
94  virtual void initialize();
95 
96 
98  // Makes a copy of the object by calling the copy constructor.
99  // This function calls new and if you use this function then you are responsible for calling delete.
101  virtual EditBox* clone();
102 
103 
117  virtual bool load(const std::string& pathname);
118 
119 
127  virtual void setSize(float width, float height);
128 
129 
136  virtual Vector2u getSize() const;
137 
138 
145  virtual Vector2f getScaledSize() const;
146 
147 
155  virtual std::string getLoadedPathname() const;
156 
157 
171  virtual void setText(const sf::String& text);
172 
173 
180  virtual sf::String getText() const;
181 
182 
190  virtual void setTextSize(unsigned int textSize);
191 
192 
199  virtual unsigned int getTextSize() const;
200 
201 
211  virtual void setTextFont(const sf::Font& font);
212 
213 
220  virtual const sf::Font* getTextFont() const;
221 
222 
235  virtual void setPasswordChar(char passwordChar = '\0');
236 
237 
245  virtual char getPasswordChar() const;
246 
247 
256  virtual void setMaximumCharacters(unsigned int maxChars = 0);
257 
258 
268  virtual unsigned int getMaximumCharacters() const;
269 
270 
284  virtual void setBorders(unsigned int leftBorder = 0,
285  unsigned int topBorder = 0,
286  unsigned int rightBorder = 0,
287  unsigned int bottomBorder = 0);
288 
289 
299  virtual void changeColors(const sf::Color& textColor = sf::Color( 0, 0, 0),
300  const sf::Color& selectedTextColor = sf::Color(255, 255, 255),
301  const sf::Color& selectedTextBackgroundColor = sf::Color( 10, 110, 255),
302  const sf::Color& selectionPointColor = sf::Color(110, 110, 255));
303 
310  virtual void setTextColor(const sf::Color& textColor);
311 
318  virtual void setSelectedTextColor(const sf::Color& selectedTextColor);
319 
326  virtual void setSelectedTextBackgroundColor(const sf::Color& selectedTextBackgroundColor);
327 
328 
335  virtual const sf::Color& getTextColor() const;
336 
343  virtual const sf::Color& getSelectedTextColor() const;
344 
351  virtual const sf::Color& getSelectedTextBackgroundColor() const;
352 
353 
363  virtual void limitTextWidth(bool limitWidth);
364 
365 
374  virtual void setSelectionPointPosition(unsigned int charactersBeforeSelectionPoint);
375 
376 
378  // These functions are used to receive callback from the EventManager.
379  // You normally don't need them, but you can use them to simulate an event.
381  virtual bool mouseOnObject(float x, float y);
382  virtual void leftMousePressed(float x, float y);
383  virtual void leftMouseReleased(float x, float y);
384  virtual void mouseMoved(float x, float y);
385  virtual void keyPressed(sf::Keyboard::Key Key);
386  virtual void textEntered(sf::Uint32 Key);
387  virtual void objectUnfocused();
388 
389 
391  protected:
392 
393 
395  // This function will search where the selection point should be. It will not change the selection point.
396  // It will return after which character the selection point should be.
398  virtual unsigned int findSelectionPointPosition(float PosX);
399 
400 
402  // When AnimationManager changes the elapsed time then this function is called.
404  virtual void update();
405 
406 
408  // Because this struct is derived from sf::Drawable, you can just call the draw function from your sf::RenderTarget.
409  // This function will be called and it will draw the edit box on the render target.
411  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
412 
413 
415  public:
416 
419 
421  unsigned int selectionPointWidth;
422 
425 
426  protected:
427 
428  // Is the selection point visible or not?
429  bool m_SelectionPointVisible;
430 
431  // When this boolean is true then you can no longer add text when the EditBox is full.
432  // Changing it to false will allow you to scroll the text (default).
433  // You can change the boolean with the limitTextWidth(bool) function.
434  bool m_LimitTextWidth;
435 
436  // The text inside the edit box
437  sf::String m_DisplayedText;
438  sf::String m_Text;
439 
440  // This will store the size of the text ( 0 to auto size )
441  unsigned int m_TextSize;
442 
443  // The selection
444  unsigned int m_SelChars;
445  unsigned int m_SelStart;
446  unsigned int m_SelEnd;
447 
448  // The password character
449  char m_PasswordChar;
450 
451  // The maximum allowed characters.
452  // Zero by default, meaning no limit.
453  unsigned int m_MaxChars;
454 
455  // If true then the image is split in three parts
456  bool m_SplitImage;
457 
458  // When the text width is not limited, you can scroll the edit box and only a part will be visible.
459  unsigned int m_TextCropPosition;
460 
461  // The rectangle behind the selected text will have this color
462  sf::Color m_SelectedTextBgrColor;
463 
464  // The size of the edit box
465  Vector2f m_Size;
466 
467  // We need three SFML texts to draw our text, and one more for calculations.
468  sf::Text m_TextBeforeSelection;
469  sf::Text m_TextSelection;
470  sf::Text m_TextAfterSelection;
471  sf::Text m_TextFull;
472 
473  // The SFML textures
474  sf::Texture* m_TextureNormal_L;
475  sf::Texture* m_TextureNormal_M;
476  sf::Texture* m_TextureNormal_R;
477 
478  sf::Texture* m_TextureHover_L;
479  sf::Texture* m_TextureHover_M;
480  sf::Texture* m_TextureHover_R;
481 
482  sf::Texture* m_TextureFocused_L;
483  sf::Texture* m_TextureFocused_M;
484  sf::Texture* m_TextureFocused_R;
485 
486  // The SFML sprites
487  sf::Sprite m_SpriteNormal_L;
488  sf::Sprite m_SpriteNormal_M;
489  sf::Sprite m_SpriteNormal_R;
490 
491  sf::Sprite m_SpriteHover_L;
492  sf::Sprite m_SpriteHover_M;
493  sf::Sprite m_SpriteHover_R;
494 
495  sf::Sprite m_SpriteFocused_L;
496  sf::Sprite m_SpriteFocused_M;
497  sf::Sprite m_SpriteFocused_R;
498 
499  // The pathname used to load the edit box
500  std::string m_LoadedPathname;
501 
502  // Is there a possibility that the user is going to double click?
503  bool m_PossibleDoubleClick;
504 
506 
507  };
509 
510 }
512 
513 #endif //_TGUI_EDITBOX_INCLUDED_
The text alignment.
Definition: EditBox.hpp:41
The parent struct for every object.
Definition: Objects.hpp:36
Parent struct for every object that has borders.
Definition: Objects.hpp:299
sf::Color selectionPointColor
The color of the flickering selection point.
Definition: EditBox.hpp:418
Center the text.
Definition: EditBox.hpp:49
unsigned int selectionPointWidth
The width in pixels of the flickering selection point.
Definition: EditBox.hpp:421
alignments
Definition: EditBox.hpp:43
Definition: EditBox.hpp:36
Put the text on the left side (default)
Definition: EditBox.hpp:46
Alignment::alignments textAlignment
The text alignment.
Definition: EditBox.hpp:424
Parent object for all objects that need to access the internal clock of the window.
Definition: Objects.hpp:338