17 u_int16 label::cursor_blink_cycle = 75;
38 cursor_cur_blink_ = 0;
70 my_old_cursor_ = my_cursor_;
74 my_cursor_.idx = my_text_.length ();
90 int size = new_text_.length ();
91 if (size == 2 && (
u_int8) new_text_[0] >= 0xE0)
return;
92 if (size == 1 && (
u_int8) new_text_[0] >= 0x80)
return;
94 my_old_cursor_ = my_cursor_;
96 if (my_old_cursor_.idx == my_text_.length ())
98 my_text_ += new_text_;
99 my_cursor_.idx = my_text_.length ();
101 else my_text_.insert (my_cursor_.idx, new_text_);
134 my_cursor_.pos_x = my_cursor_.pos_y = my_cursor_.line = my_cursor_.idx = 0;
141 tmp.pos_x = tmp.idx_beg = tmp.idx_end = 0;
144 my_vect_.push_back (tmp);
159 if (my_font_ == NULL)
return;
166 draw_string (!erase_all);
170 build_form_auto_height ();
172 draw_string (!erase_all);
176 build_form_auto_size ();
200 moveable_cursor_ = b;
210 u_int16 j, word_length, word_length_pix, start_idx;
216 line_tmp.idx_beg = my_vect_[my_old_cursor_.line].idx_beg;
220 start_idx = line_tmp.idx_beg;
223 vector <Sline_text>::iterator ii = my_vect_.begin ();
225 while (i != my_old_cursor_.line) { i++; ii++; }
226 my_vect_.erase (ii, my_vect_.end ());
229 while (start_idx < my_text_.length () )
232 if (my_text_[start_idx] ==
'\n')
235 line_tmp.idx_end = start_idx;
238 my_vect_.push_back (line_tmp);
242 line_tmp.idx_beg = ++start_idx;
244 else if (my_text_[start_idx] ==
' ')
246 if ((*my_font_) [
' '].
length () + line_tmp.pos_x >
length ())
248 line_tmp.idx_end = start_idx;
251 my_vect_.push_back (line_tmp);
255 line_tmp.idx_beg = ++start_idx;
259 line_tmp.pos_x += (*my_font_) [
' '].length ();
267 switch (find_word (start_idx, word_length, word_length_pix, line_tmp.pos_x))
270 line_tmp.pos_x += word_length_pix;
281 (my_vect_.size () - start_line_) * my_font_->height (),
282 length () - line_tmp.pos_x,
286 line_tmp.idx_end = (start_idx - word_length) - 1;
287 my_vect_.push_back (line_tmp);
289 line_tmp.pos_x = word_length_pix;
290 line_tmp.idx_beg = start_idx - word_length;
296 j = start_idx - word_length;
297 while (j < start_idx)
300 if (line_tmp.pos_x + (*my_font_) [c].length () >
length ())
302 line_tmp.idx_end = j - 1;
303 my_vect_.push_back (line_tmp);
306 line_tmp.idx_beg = j;
308 line_tmp.pos_x += (*my_font_) [c].length ();
317 line_tmp.idx_end = start_idx - 1;
318 my_vect_.push_back (line_tmp);
322 void label::build_form_auto_height ()
329 u_int16 new_size = my_vect_.size () * my_font_->height ();
331 if (new_size !=
height ())
337 draw (0, 0, 0, 0,
length (), my_old_cursor_.pos_y + my_font_->height (), NULL, &tmp);
339 tmp.draw (0, 0, NULL,
this);
344 void label::build_form_auto_size ()
355 line_tmp.idx_beg = 0;
358 while ( i < my_text_.size ())
360 if (my_text_[i] ==
'\n')
362 if (line_tmp.pos_x > max_length) max_length = line_tmp.pos_x;
363 line_tmp.idx_end = i;
364 my_vect_.push_back (line_tmp);
366 line_tmp.idx_beg = i+1;
371 line_tmp.pos_x += (*my_font_) [ucd (i)].length ();
376 if (line_tmp.pos_x > max_length) max_length = line_tmp.pos_x;
378 line_tmp.idx_end = i-1;
379 my_vect_.push_back (line_tmp);
382 image::resize (max_length, my_vect_.size () * my_font_->height ());
385 void label::clean_surface (
const bool erase_all)
389 if ( my_cursor_.idx != my_text_.length ())
392 fillrect ( my_old_cursor_.pos_x, my_old_cursor_.pos_y,
length () - my_old_cursor_.pos_x,
394 fillrect (0, my_old_cursor_.pos_y + my_font_->height (),
length (),
397 }
else if (erase_all)
421 while (index < my_text_.length () && my_text_[index] !=
' ' && my_text_[index] !=
'\n')
423 wlengthpix += (*my_font_) [ucd (index)].length ();
428 wlength = index - wlength;
431 if (wlengthpix <
length () - rlength)
return 0;
432 else if (wlengthpix <
length ())
return 1;
438 void label::update_cursor ()
444 cursor_cur_blink_ = cursor_blink_cycle;
447 while (!b && my_cursor_.line < my_vect_.size () )
449 if (my_cursor_.idx >= my_vect_[my_cursor_.line].idx_beg &&
450 my_cursor_.idx <= my_vect_[my_cursor_.line].idx_end ) b =
true;
451 else if (my_cursor_.idx > my_vect_[my_cursor_.line].idx_end)
453 if (my_cursor_.line == my_vect_.size () - 1) b =
true;
454 else my_cursor_.line++;
456 else if (my_cursor_.idx < my_vect_[my_cursor_.line].idx_beg)
463 my_cursor_.pos_x = 0;
465 u_int16 j = my_vect_[my_cursor_.line].idx_beg;
466 while (j < my_cursor_.idx) {
467 my_cursor_.pos_x+= (*my_font_) [ucd (j)].length ();
471 my_cursor_.pos_y = (my_cursor_.line - start_line_) * my_font_->height ();
473 if (my_cursor_.pos_y >
height ())
483 void label::draw_string (
const bool at_cursor)
491 clean_surface (!at_cursor);
495 tmp_start_line = my_old_cursor_.line;
496 tx = my_old_cursor_.pos_x;
497 idx_cur_line = my_old_cursor_.idx;
498 ty = (tmp_start_line - start_line_) * my_font_->height ();
502 tmp_start_line = start_line_;
503 idx_cur_line = my_vect_[tmp_start_line].idx_beg;
507 for (j = idx_cur_line;
508 j < my_vect_[tmp_start_line].idx_end + 1 ;
512 if (c !=
'\n' && my_font_->in_table (c))
514 (*my_font_) [c].draw (tx, ty, NULL,
this);
515 tx += (*my_font_) [c].length ();
518 ty += my_font_->height ();
523 while (tmp_start_line < my_vect_.size ())
526 for (j = my_vect_[tmp_start_line].idx_beg;
527 j < my_vect_[tmp_start_line].idx_end + 1 ;
531 if (my_font_->in_table (c))
533 (*my_font_) [c].draw (tx, ty, NULL,
this);
534 tx += (*my_font_) [c].length ();
537 ty += my_font_->height ();
548 if (cursor_cur_blink_ == cursor_blink_cycle)
551 cursor_cur_blink_ = 0;
552 }
else if (cursor_cur_blink_ == (cursor_blink_cycle >> 1))
561 void label::cursor_draw ()
565 if (last_letter (idx) || my_text_[idx] ==
'\n')
566 my_font_->cursor->
draw (my_cursor_.pos_x, my_cursor_.pos_y,NULL,
this);
568 my_font_->cursor->
draw (my_cursor_.pos_x, my_cursor_.pos_y,0, 0,
569 (*my_font_) [ucd (idx)].
length (),
570 my_font_->height (), NULL,
this);
573 void label::cursor_undraw ()
577 if (last_letter (idx) || my_text_[idx] ==
'\n')
580 fillrect(my_cursor_.pos_x, my_cursor_.pos_y,
581 my_font_->cursor->
length () ,
582 my_font_->cursor->
height(),
586 else (*my_font_) [ucd (idx)].draw (my_cursor_.pos_x, my_cursor_.pos_y, NULL,
this);
589 bool label::last_letter (
u_int16 idx)
591 if ((
u_int8) my_text_[idx] == 0xEF)
return my_text_.length () - idx == 2;
592 if ((
u_int8) my_text_[idx] == 0xC3)
return my_text_.length () - idx == 1;
593 return my_cursor_.idx == my_text_.length ();
616 void label::cursor_next ()
618 if (!moveable_cursor_)
return;
619 if (my_cursor_.idx < my_text_.length ())
622 if (my_cursor_.idx < my_text_.length () - 2 && (
u_int8) my_text_[my_cursor_.idx+1] == 0xEF) count = 3;
623 else if (my_cursor_.idx < my_text_.length () - 1 && (
u_int8) my_text_[my_cursor_.idx+1] == 0xC3) count = 2;
626 my_cursor_.idx += count;
632 void label::cursor_previous ()
634 if (!moveable_cursor_)
return;
635 if (my_cursor_.idx > 0)
638 if (my_cursor_.idx > 2 && (
u_int8) my_text_[my_cursor_.idx-3] == 0xEF) count = 3;
639 else if (my_cursor_.idx > 1 && (
u_int8) my_text_[my_cursor_.idx-2] == 0xC3) count = 2;
642 my_cursor_.idx -= count;
655 return my_text_.c_str ();
662 if (c < 0x80)
return c;
666 u_int8 c1 = my_text_[++idx];
667 return ((
u_int16) (c & 0x1f) << 6)
671 u_int8 c1 = my_text_[++idx];
672 u_int8 c2 = my_text_[++idx];
673 return ((
u_int16) (c & 0x0f) << 12)
u_int16 length() const
Returns the length of the drawable.
void build_form_nothing()
Build the label when the form set top nothing.
void set_cursor_visible(const bool b)
Set visible cursor.
void resize(u_int16 l, u_int16 h)
Resize this image.
#define u_int16
16 bits long unsigned integer
const string text_string() const
Get the text in string.
void build(const bool erase_all)
Build label.
void fillrect(s_int16 x, s_int16 y, u_int16 l, u_int16 h, u_int32 col, drawing_area *da_opt=NULL)
Fills an area of the surface with a given color.
Image manipulation class.
void set_font(win_font &font)
Set the font.
#define u_int8
8 bits long unsigned integer
void init_vec_cursor()
Init vector and cursor, don't erase my_text_.
void unlock() const
Unlock the surface after you've worked on it's pixels with the get_pix () and put_pix () methods...
void resize(u_int16 l, u_int16 h)
Resize the label.
void draw(s_int16 x, s_int16 y, const drawing_area *da_opt=NULL, surface *target=NULL) const
Draw the surface.
const char * text_char() const
Get the text in char.
u_int16 height() const
Returns the height of the drawable.
void set_form(const u_int8 form)
Set the form of the display NOTHING, AUTO_SIZE, AUTO_HEIGHT.
void set_text(const string &text)
Set the text.
bool input_update()
Update input label, you can move the cursor if the cursor is moveable.
bool update()
Update the label.
void set_cursor_moveable(const bool b)
Set if the cursor can be moved with arrow key.
void add_text(const string &text)
Add text.
static u_int32 trans_col()
Returns the translucent color in screen's depth format.
void set_mask(bool m)
Sets the mask parameter of the surface.
void lock() const
Locks the surface.
label()
Constructor by default, cursor is not moveable, cursor is not visible, and the form is set as NOTHING...