Adonthell  0.4
label.h
1 /*
2  (C) Copyright 2000/2001/2004 Joel Vennin
3  Part of the Adonthell Project <http://adonthell.nongnu.org>
4 
5  Adonthell is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  Adonthell is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Adonthell. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef LABEL_H_
20 #define LABEL_H_
21 
22 #include <vector>
23 #include <string>
24 #include "input.h"
25 #include "win_font.h"
26 
27 using namespace std;
28 
29 class label: public image
30 {
31 public :
32  /**
33  Constructor
34  by default, cursor is not moveable, cursor is not visible, and the form is set as NOTHING, the default size is (0, 0)
35  */
36  label ();
37 
38 
39  /**
40  Destructor
41  */
42  virtual ~label ();
43 
44 
45  /**
46  Set the font
47  */
48  void set_font (win_font & font);
49 
50 
51  /**
52  Set the text
53  */
54  void set_text (const string & text);
55 
56 
57  /**
58  Add text
59  */
60  void add_text (const string & text);
61 
62 
63  /**
64  Set the form of the display
65  NOTHING, AUTO_SIZE, AUTO_HEIGHT
66  */
67  void set_form (const u_int8 form);
68 
69 
70  /**
71  Set visible cursor
72  */
73  void set_cursor_visible (const bool b);
74 
75 
76  /**
77  Set if the cursor can be moved with arrow key
78  */
79  void set_cursor_moveable (const bool b);
80 
81 
82  /**
83  Update the label
84  */
85  bool update ();
86 
87 
88  /**
89  Update input label, you can move the cursor if the cursor is moveable
90  */
91  bool input_update ();
92 
93 
94  /**
95  Get the text in string
96  */
97  const string & text_string () const;
98 
99 
100  /**
101  Get the text in char
102  */
103  const char * text_char () const;
104 
105 
106  /**
107  Resize the label
108  */
109  void resize (u_int16 l, u_int16 h);
110 
111 
112 #ifdef SWIG
113 
114 #define label_NOTHING 0;
115 #define label_AUTO_HEIGHT 1;
116 #define label_AUTO_SIZE 2;
117 
118 #define label_KEY_CURSOR_NEXT SDLK_RIGHT;
119 #define label_KEY_CURSOR_PREVIOUS SDLK_LEFT;
120 
121 #endif
122 
123 #ifndef SWIG
124 
125  static const u_int8 NOTHING = 0;
126  static const u_int8 AUTO_HEIGHT = 1;
127  static const u_int8 AUTO_SIZE = 2;
128 
129 
130  const static SDL_Keycode KEY_CURSOR_NEXT = SDLK_RIGHT;
131  const static SDL_Keycode KEY_CURSOR_PREVIOUS = SDLK_LEFT;
132 
133 
134 
135 protected :
136 
137  void fit_text_width();
138 
139  u_int16 ucd (u_int16 & idx) const
140  {
141  return ucd(my_text_, idx);
142  }
143 
144  u_int16 ucd (const std::string & text, u_int16 & idx) const;
145 
146  struct Sline_text
147  {
148  u_int16 idx_beg;
149  s_int16 idx_end;
150  u_int16 pos_x;
151  s_int16 offset_x;
152  };
153 
154  struct Scursor
155  {
156  u_int16 pos_x;
157  u_int16 pos_y;
158  u_int16 idx;
159  u_int16 line;
160  s_int16 offset_x;
161  };
162 
163  /**
164  Init vector and cursor, don't erase my_text_
165  */
166  void init_vec_cursor ();
167 
168 
169  /**
170  Build label
171 
172  */
173  void build(const bool erase_all);
174 
175 
176  /**
177 
178  */
179  void build_form_nothing ();
180 
181 
182  /**
183 
184  */
185  void build_form_auto_height ();
186 
187  /**
188  */
189  void build_form_auto_size();
190 
191  /**
192 
193  */
194  void clean_surface (const bool erase_all);
195 
196  /**
197  */
198  u_int8 find_word (u_int16 & index, u_int16 & wlength, u_int16 & wlengthpix, s_int16 & woffset, u_int16 & last_letter, const u_int16 rlength);
199 
200  /**
201  */
202  void draw_string (const bool at_cursor);
203 
204 
205  /**
206 
207  */
208  void update_cursor ();
209 
210  /**
211  */
212  void cursor_next ();
213 
214  /**
215  */
216 
217  void cursor_previous ();
218 
219  /**
220  */
221  void cursor_draw ();
222 
223  void cursor_undraw ();
224 
225  bool last_letter (u_int16 idx);
226 
227  // my_font
228  win_font * my_font_;
229 
230 
231  // my text
232  string my_text_;
233 
234  // temporary for gathering utf-8 text
235  string new_text_;
236 
237  // form display
238  u_int8 my_form_;
239 
240 
241  // visible cursor
242  bool visible_cursor_;
243 
244  // moveable_cursor
245  bool moveable_cursor_;
246 
247 
248  u_int16 cursor_cur_blink_;
249 
250 
251  static u_int16 cursor_blink_cycle;
252 
253  // my cursor
254  Scursor my_cursor_;
255 
256  // my old cursor
257  Scursor my_old_cursor_;
258 
259  // it is a vector which represent each line in the label
260  vector<Sline_text> my_vect_;
261 
262  u_int16 start_line_;
263 
264 #endif
265  // it's the endif of swig
266 
267 };
268 #endif
269 
270 
271 
272 
label::Sline_text
Definition: label.h:146
u_int8
#define u_int8
8 bits long unsigned integer
Definition: types.h:35
s_int16
#define s_int16
16 bits long signed integer
Definition: types.h:47
image
Image manipulation class.
Definition: image.h:45
win_font
Definition: win_font.h:32
u_int16
#define u_int16
16 bits long unsigned integer
Definition: types.h:38
label::Scursor
Definition: label.h:154
label
Definition: label.h:29
input.h
Declares the input class.