/[adonthell]/adonthell-0.3/src/label_input.cc
ViewVC logotype

Diff of /adonthell-0.3/src/label_input.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12 by ksterker, Sat Jan 18 23:22:59 2003 UTC revision 1.13 by ksterker, Mon Oct 25 06:55:01 2004 UTC
# Line 1  Line 1 
1  /*  /*
2     $Id$     $Id$
3    
4     (C) Copyright 2000/2001/2003 Joel Vennin     (C) Copyright 2000/2001/2003/2004 Joel Vennin
5     Part of the Adonthell Project http://adonthell.linuxgames.com     Part of the Adonthell Project http://adonthell.linuxgames.com
6    
7     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
# Line 34  bool label_input::input_update() Line 34  bool label_input::input_update()
34    
35      if (my_font_ == NULL) return false;      if (my_font_ == NULL) return false;
36            
37        int count;
38      static s_int32 c;      static s_int32 c;
39    
40      while ((c = input::get_next_unicode ()) > 0)      while ((c = input::get_next_unicode ()) > 0)
# Line 43  bool label_input::input_update() Line 44  bool label_input::input_update()
44          {                      {            
45              if (my_text_.empty () || my_cursor_.idx == 0) return true;              if (my_text_.empty () || my_cursor_.idx == 0) return true;
46                            
47              my_text_.erase (--my_cursor_.idx, 1);              // possibly delete multi-byte utf-8 char
48                if (my_cursor_.idx > 2 && (u_int8) my_text_[my_cursor_.idx-2] >= 0xE0) count = 3;
49                else if (my_cursor_.idx > 1 && (u_int8) my_text_[my_cursor_.idx-1] >= 0x80) count = 2;
50                else count = 1;
51                
52                my_cursor_.idx -= count;
53                my_text_.erase (my_cursor_.idx, count);
54              update_cursor ();              update_cursor ();
55              my_old_cursor_ = my_cursor_;              my_old_cursor_ = my_cursor_;
56    
57              lock ();              lock ();
58              fillrect (my_cursor_.pos_x, my_cursor_.pos_y,              fillrect (my_cursor_.pos_x, my_cursor_.pos_y,
59                        (*my_font_) [my_text_[my_cursor_.idx]].length (),                        (*my_font_) [ucd(my_cursor_.idx)].length (),
60                        my_font_->height (), screen::trans_col ());                        my_font_->height (), screen::trans_col ());
61              unlock ();              unlock ();
62                            
# Line 58  bool label_input::input_update() Line 65  bool label_input::input_update()
65          else if (c == SDLK_RETURN) add_text ("\n");          else if (c == SDLK_RETURN) add_text ("\n");
66          else if (my_font_->in_table (c))          else if (my_font_->in_table (c))
67          {          {
68              string s (1, (char) c);              char r[3];
69              add_text (s);              
70                // convert unicode to utf-8
71                if (c < 0x80) count = 1;
72                else if (c < 0x800) count = 2;
73                else if (c < 0x10000) count = 3;
74                
75                switch (count) { /* note: code falls through cases! */
76                    case 3: r[2] = 0x80 | (c & 0x3f); c = c >> 6; c |= 0x800;
77                    case 2: r[1] = 0x80 | (c & 0x3f); c = c >> 6; c |= 0xc0;
78                    case 1: r[0] = c;
79                }
80                
81                add_text (string (r, count));
82          }          }
83      }        }  
84      return true;      return true;

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26