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