rag
graphic 2d engine
TextField.h
1 #ifndef _TEXTFIELD_H_
2 #define _TEXTFIELD_H_
3 
4 #include <rag/DisplayObject.h>
5 #include <rag/ITextFont.h>
6 
7 namespace rag
8 {
11  {
12 
13  public:
14 
15  DropShadowFilter(float angle, float distance, float strength, Color color);
16 
17  Color color;
18  float x, y;
19  };
20 
22  class TextField: public DisplayObject
23  {
24 
25  public:
26 
28  TextField(const std::string& folderPath, const std::string& descriptorFileName);
29 
31  TextField(const std::string& path, float pixelHeight = 24, float letterSpacing = 0);
32 
33  virtual ~TextField();
34 
35  void addFilter(DropShadowFilter filter);
36  std::vector<DropShadowFilter> getFilters();
37 
39  int getLines();
40 
42  int getLineHeight();
43 
45  int getTextWidth();
46 
47  enum HorzAlignment { Left = 0, Center, Right } horzAlign;
48  enum VertAlignment { Top = 0, Middle, Bottom } vertAlign;
49 
50  std::string text;
51  bool multiline;
52  bool showCursor;
53  bool autotrim;
54  bool password;
55 
57  static void traceTextCache();
58 
60  static void reloadTextures();
61 
62  protected:
63 
64  void init();
65 
66  virtual void render() override;
67 
68  void printText(const std::string& text, const glm::mat4 matrix);
69 
70  std::vector<std::string> splitLines();
71 
72  ITextFont* font;
73 
74  int lineHeight;
75 
76  // For single-line
77  int lineWidth;
78 
79  // For multiline
80  std::vector<std::string> lines;
81  std::vector<int> lineWidths;
82 
83  std::string lastText;
84 
85  std::vector<DropShadowFilter> filters;
86 
87  float letterSpacing;
88 
89  private:
90 
91  static std::map<std::string, std::map<int, ITextFont*> > cache;
92  };
93 }
94 
95 #endif
glm::mat4 matrix
The object matrix.
Definition: DisplayObject.h:194
TextField(const std::string &folderPath, const std::string &descriptorFileName)
Constructor with Bitmap fonts.
virtual void render() override
Renders the DisplayObject in the screen.
Definition: TextField.cpp:99
bool password
Use the textfield to show a password. Wildcards would be printed instead of the actual text...
Definition: TextField.h:54
bool showCursor
When true, a cursor is shown right after the last letter. Note that text width remains the same with ...
Definition: TextField.h:52
int getTextWidth()
Returns the current length of the text, for single line.
Definition: TextField.cpp:321
Definition: Bitmap.h:8
enum rag::TextField::VertAlignment vertAlign
The vertical alignment of the text block.
enum rag::TextField::HorzAlignment horzAlign
The horizontal alignment of the text block.
static void traceTextCache()
Debug function to know how many textures are cached by texts.
Definition: TextField.cpp:331
Interface for text fonts.
Definition: ITextFont.h:10
Core object used to display things in screen.
Definition: DisplayObject.h:23
int getLineHeight()
Returns the height of a line.
Definition: TextField.cpp:203
bool autotrim
True by default. Trims single line text when longer than reserved dimensions.
Definition: TextField.h:53
High level abstraction to render texts in display list.
Definition: TextField.h:22
Shadow effect for TextField instances.
Definition: TextField.h:10
Represents RGBA color.
Definition: Color.h:11
std::string text
The text that should be rendered.
Definition: TextField.h:50
static void reloadTextures()
When graphic context is missed (android) reloads fonts textures.
Definition: TextField.cpp:18
int getLines()
Returns the number of lines used with the current text.
Definition: TextField.cpp:197
bool multiline
Is it intended to be drawn in a single or multi-line fashion. False by default.
Definition: TextField.h:51