Improvements to textbox, prevent selection loss on non modifying keypresses

This commit is contained in:
Simon Robertshaw 2012-07-29 20:27:18 +01:00
parent d138b2de54
commit 011a65f793
2 changed files with 10 additions and 4 deletions

View File

@ -29,7 +29,7 @@ public:
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position){ virtual void Draw(Simulation * sim, Brush * brush, ui::Point position){
sim->ApplyDecorationPoint(position.X, position.Y, Red, Green, Blue, Alpha, decoMode, brush); sim->ApplyDecorationPoint(position.X, position.Y, Red, Green, Blue, Alpha, decoMode, brush);
} }
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging) {
sim->ApplyDecorationLine(position1.X, position1.Y, position2.X, position2.Y, Red, Green, Blue, Alpha, decoMode, brush); sim->ApplyDecorationLine(position1.X, position1.Y, position2.X, position2.Y, Red, Green, Blue, Alpha, decoMode, brush);
} }
virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {

View File

@ -254,17 +254,21 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
{ {
case KEY_HOME: case KEY_HOME:
cursor = 0; cursor = 0;
ClearSelection();
break; break;
case KEY_END: case KEY_END:
cursor = backingText.length(); cursor = backingText.length();
ClearSelection();
break; break;
case KEY_LEFT: case KEY_LEFT:
if(cursor > 0) if(cursor > 0)
cursor--; cursor--;
ClearSelection();
break; break;
case KEY_RIGHT: case KEY_RIGHT:
if(cursor < backingText.length()) if(cursor < backingText.length())
cursor++; cursor++;
ClearSelection();
break; break;
case KEY_DELETE: case KEY_DELETE:
if(HasSelection()) if(HasSelection())
@ -283,6 +287,7 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
backingText.erase(cursor, 1); backingText.erase(cursor, 1);
changed = true; changed = true;
} }
ClearSelection();
break; break;
case KEY_BACKSPACE: case KEY_BACKSPACE:
if(HasSelection()) if(HasSelection())
@ -307,6 +312,7 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
} }
changed = true; changed = true;
} }
ClearSelection();
break; break;
} }
if(CharacterValid(character)) if(CharacterValid(character))
@ -332,8 +338,8 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
} }
cursor++; cursor++;
changed = true; changed = true;
ClearSelection();
} }
ClearSelection();
} }
catch(std::out_of_range &e) catch(std::out_of_range &e)
{ {
@ -350,8 +356,8 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
if(!backingText.length()) if(!backingText.length())
backingText = "0"; backingText = "0";
} }
if(cursor >= backingText.length()) if(cursor > backingText.length())
cursor = backingText.length()-1; cursor = backingText.length();
if(changed) if(changed)
{ {
if(masked) if(masked)