X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fentry.cpp;h=87f88c75eadd39f94929f21745b131f363a394e6;hb=d309eb8633be1d9f08d1e9cd9930d68d8b169367;hp=cee23b02372904317419fc294a17f783fa457589;hpb=1afb4f8d6379ad1bf832692fbfedef9714ee3ff5;p=libs%2Fgltk.git diff --git a/source/entry.cpp b/source/entry.cpp index cee23b0..87f88c7 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -23,8 +23,10 @@ Entry::Entry(const string &t): visible_rows(1), text_part(0), slider(0), - got_key_press(false) + got_key_press(false), + cursor_blink(true) { + input_type = INPUT_TEXT; set_text(t); } @@ -91,7 +93,8 @@ void Entry::rebuild_special(const Part &part) text.build(part, state, geom, first_row, part_cache); else if(part.get_name()=="cursor") { - const Graphic *graphic = part.get_graphic(state); + State cursor_state = (cursor_blink ? ACTIVE : NORMAL); + const Graphic *graphic = part.get_graphic(state|cursor_state); if(!text_part || !graphic || !graphic->get_texture()) return; @@ -125,32 +128,17 @@ void Entry::render_special(const Part &part, GL::Renderer &renderer) const slider->render(renderer); } -void Entry::key_press(unsigned key, unsigned) +void Entry::touch_press(int x, int y, unsigned finger) +{ + if(finger==0) + set_focus(); + Widget::touch_press(x, y, finger); +} + +bool Entry::key_press(unsigned key, unsigned) { got_key_press = true; - if(key==Input::KEY_LEFT) - { - if(edit_pos>0) - set_edit_position(edit_pos-1); - } - else if(key==Input::KEY_RIGHT) - { - if(edit_pos0 ? text.coords_to_offset(row-1, col) : 0); - } - else if(key==Input::KEY_BACKSPACE) + if(key==Input::KEY_BACKSPACE) { if(edit_pos>0) { @@ -159,33 +147,81 @@ void Entry::key_press(unsigned key, unsigned) rebuild(); } } - else if(key==Input::KEY_ENTER) + else if(key==Input::KEY_ENTER && multiline) { - if(multiline) - { - text.insert(edit_pos++, "\n"); - check_view_range(); - rebuild(); - } - else - signal_enter.emit(); + text.insert(edit_pos++, "\n"); + check_view_range(); + rebuild(); } + else + return false; + + return true; } -void Entry::character(wchar_t ch) +bool Entry::character(wchar_t ch) { if(got_key_press && ch>=' ') { text.insert(edit_pos, StringCodec::encode(StringCodec::ustring(1, ch))); ++edit_pos; rebuild(); + return true; } + + return false; +} + +void Entry::focus_in() +{ + cursor_blink = true; + Widget::focus_in(); + check_cursor_blink(); } void Entry::focus_out() { Widget::focus_out(); got_key_press = false; + check_cursor_blink(); +} + +bool Entry::navigate(Navigation nav) +{ + if(nav==NAV_LEFT) + { + if(edit_pos>0) + set_edit_position(edit_pos-1); + } + else if(nav==NAV_RIGHT) + { + if(edit_pos0 ? text.coords_to_offset(row-1, col) : 0); + } + else if(nav==NAV_ACCEPT && !signal_enter.empty()) + signal_enter.emit(); + else + return false; + + return true; +} + +void Entry::animate(const Time::TimeDelta &) +{ + cursor_blink = !cursor_blink; + rebuild(); } void Entry::on_geometry_change() @@ -208,6 +244,8 @@ void Entry::on_style_change() if(multiline) check_view_range(); + + check_cursor_blink(); } void Entry::set_edit_position(unsigned ep) @@ -217,6 +255,22 @@ void Entry::set_edit_position(unsigned ep) rebuild(); } +void Entry::check_cursor_blink() +{ + cursor_blink = (state&FOCUS); + if((state&FOCUS) && style) + { + const Part *cursor_part = style->get_part("cursor"); + if(cursor_part && cursor_part->get_graphic(ACTIVE|FOCUS)!=cursor_part->get_graphic(NORMAL|FOCUS)) + { + set_animation_interval(Time::sec/2); + return; + } + } + + stop_animation(); +} + void Entry::check_view_range() { if(!multiline || !text_part)