label.h
1 /*************************************************************************/
2 /* label.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef LABEL_H
30 #define LABEL_H
31 
32 #include "scene/gui/control.h"
36 class Label : public Control {
37 
38  OBJ_TYPE( Label, Control );
39 public:
40 
41  enum Align {
42 
43  ALIGN_LEFT,
44  ALIGN_CENTER,
45  ALIGN_RIGHT,
46  ALIGN_FILL
47  };
48 
49  enum VAlign {
50 
51  VALIGN_TOP,
52  VALIGN_CENTER,
53  VALIGN_BOTTOM,
54  VALIGN_FILL
55  };
56 
57 private:
58  Align align;
59  VAlign valign;
60  String text;
61  bool autowrap;
62  bool clip;
63  Size2 minsize;
64  int line_count;
65  bool uppercase;
66 
67  int get_longest_line_width() const;
68 
69  struct WordCache {
70 
71  enum {
72  CHAR_NEWLINE=-1,
73  CHAR_WRAPLINE=-2
74  };
75  int char_pos; // if -1, then newline
76  int word_len;
77  int pixel_width;
78  int space_count;
79  WordCache *next;
80  WordCache() { char_pos=0; word_len=0; pixel_width=0; next=0; space_count=0;}
81  };
82 
83  bool word_cache_dirty;
84  void regenerate_word_cache();
85 
86  float percent_visible;
87 
88  WordCache *word_cache;
89  int total_char_cache;
90  int visible_chars;
91  int lines_skipped;
92  int max_lines_visible;
93 protected:
94  void _notification(int p_what);
95 
96  static void _bind_methods();
97  // bind helpers
98 public:
99 
100  virtual Size2 get_minimum_size() const;
101 
102  void set_align(Align p_align);
103  Align get_align() const;
104 
105  void set_valign(VAlign p_align);
106  VAlign get_valign() const;
107 
108  void set_text(const String& p_string);
109  String get_text() const;
110 
111  void set_autowrap(bool p_autowrap);
112  bool has_autowrap() const;
113 
114  void set_uppercase(bool p_uppercase);
115  bool is_uppercase() const;
116 
117  void set_visible_characters(int p_amount);
118  int get_visible_characters() const;
119  int get_total_character_count() const;
120 
121  void set_clip_text(bool p_clip);
122  bool is_clipping_text() const;
123 
124  void set_percent_visible(float p_percent);
125  float get_percent_visible() const;
126 
127  void set_lines_skipped(int p_lines);
128  int get_lines_skipped() const;
129 
130  void set_max_lines_visible(int p_lines);
131  int get_max_lines_visible() const;
132 
133  int get_line_height() const;
134  int get_line_count() const;
135 
136  Label(const String& p_text=String());
137  ~Label();
138 
139 };
140 
141 
142 VARIANT_ENUM_CAST( Label::Align );
143 VARIANT_ENUM_CAST( Label::VAlign );
144 
145 #endif
Definition: math_2d.h:65
Definition: control.h:47
Definition: ustring.h:64
Definition: label.h:36