Adonthell 0.4
|
00001 /* 00002 $Id: label.h,v 1.8 2005/04/16 17:56:32 ksterker Exp $ 00003 00004 (C) Copyright 2000/2001/2004 Joel Vennin 00005 Part of the Adonthell Project http://adonthell.linuxgames.com 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License. 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY. 00011 00012 See the COPYING file for more details 00013 */ 00014 00015 #ifndef LABEL_H_ 00016 #define LABEL_H_ 00017 00018 #include <vector> 00019 #include <string> 00020 #include "input.h" 00021 #include "win_font.h" 00022 00023 using namespace std; 00024 00025 class label: public image 00026 { 00027 public : 00028 /** 00029 Constructor 00030 by default, cursor is not moveable, cursor is not visible, and the form is set as NOTHING, the default size is (0, 0) 00031 */ 00032 label (); 00033 00034 00035 /** 00036 Destructor 00037 */ 00038 ~label (); 00039 00040 00041 /** 00042 Set the font 00043 */ 00044 void set_font (win_font & font); 00045 00046 00047 /** 00048 Set the text 00049 */ 00050 void set_text (const string & text); 00051 00052 00053 /** 00054 Add text 00055 */ 00056 void add_text (const string & text); 00057 00058 00059 /** 00060 Set the form of the display 00061 NOTHING, AUTO_SIZE, AUTO_HEIGHT 00062 */ 00063 void set_form (const u_int8 form); 00064 00065 00066 /** 00067 Set visible cursor 00068 */ 00069 void set_cursor_visible (const bool b); 00070 00071 00072 /** 00073 Set if the cursor can be moved with arrow key 00074 */ 00075 void set_cursor_moveable (const bool b); 00076 00077 00078 /** 00079 Update the label 00080 */ 00081 bool update (); 00082 00083 00084 /** 00085 Update input label, you can move the cursor if the cursor is moveable 00086 */ 00087 bool input_update (); 00088 00089 00090 /** 00091 Get the text in string 00092 */ 00093 const string text_string () const; 00094 00095 00096 /** 00097 Get the text in char 00098 */ 00099 const char * text_char () const; 00100 00101 00102 /** 00103 Resize the label 00104 */ 00105 void resize (u_int16 l, u_int16 h); 00106 00107 00108 #ifdef SWIG 00109 00110 #define label_NOTHING 0; 00111 #define label_AUTO_HEIGHT 1; 00112 #define label_AUTO_SIZE 2; 00113 00114 #define label_KEY_CURSOR_NEXT SDLK_RIGHT; 00115 #define label_KEY_CURSOR_PREVIOUS SDLK_LEFT; 00116 00117 #endif 00118 00119 #ifndef SWIG 00120 00121 static const u_int8 NOTHING = 0; 00122 static const u_int8 AUTO_HEIGHT = 1; 00123 static const u_int8 AUTO_SIZE = 2; 00124 00125 00126 const static SDLKey KEY_CURSOR_NEXT = SDLK_RIGHT; 00127 const static SDLKey KEY_CURSOR_PREVIOUS = SDLK_LEFT; 00128 00129 00130 00131 protected : 00132 u_int16 ucd (u_int16 & idx); 00133 00134 struct Sline_text 00135 { 00136 u_int16 idx_beg; 00137 s_int16 idx_end; 00138 u_int16 pos_x; 00139 }; 00140 00141 struct Scursor 00142 { 00143 u_int16 pos_x; 00144 u_int16 pos_y; 00145 u_int16 idx; 00146 u_int16 line; 00147 }; 00148 00149 /** 00150 Init vector and cursor, don't erase my_text_ 00151 */ 00152 void init_vec_cursor (); 00153 00154 00155 /** 00156 Build label 00157 00158 */ 00159 void build(const bool erase_all); 00160 00161 00162 /** 00163 00164 */ 00165 void build_form_nothing (); 00166 00167 00168 /** 00169 00170 */ 00171 void build_form_auto_height (); 00172 00173 /** 00174 */ 00175 void build_form_auto_size(); 00176 00177 /** 00178 00179 */ 00180 void clean_surface (const bool erase_all); 00181 00182 /** 00183 */ 00184 u_int8 find_word (u_int16 & index, u_int16 & wlength, u_int16 & wlengthpix, const u_int16 rlength); 00185 00186 /** 00187 */ 00188 void draw_string (const bool at_cursor); 00189 00190 00191 /** 00192 00193 */ 00194 void update_cursor (); 00195 00196 /** 00197 */ 00198 void cursor_next (); 00199 00200 /** 00201 */ 00202 00203 void cursor_previous (); 00204 00205 /** 00206 */ 00207 void cursor_draw (); 00208 00209 void cursor_undraw (); 00210 00211 bool last_letter (u_int16 idx); 00212 00213 // my_font 00214 win_font * my_font_; 00215 00216 00217 // my text 00218 string my_text_; 00219 00220 // temporary for gathering utf-8 text 00221 string new_text_; 00222 00223 // form display 00224 u_int8 my_form_; 00225 00226 00227 // visible cursor 00228 bool visible_cursor_; 00229 00230 // moveable_cursor 00231 bool moveable_cursor_; 00232 00233 00234 u_int16 cursor_cur_blink_; 00235 00236 00237 static u_int16 cursor_blink_cycle; 00238 00239 // my cursor 00240 Scursor my_cursor_; 00241 00242 // my old cursor 00243 Scursor my_old_cursor_; 00244 00245 // it is a vector which represent each line in the label 00246 vector<Sline_text> my_vect_; 00247 00248 u_int16 start_line_; 00249 00250 #endif 00251 // it's the endif of swig 00252 00253 }; 00254 #endif 00255 00256 00257 00258