X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fentry.cpp;h=f5037215592e1a45143ab8b305cf563007c7dbe0;hb=531232cf05838b79c1f8f36c8103730e32dfa23d;hp=eed2c39a942ced2e7299a6f357be9142cd6b4c15;hpb=ed9873ba7ee862ad76937f579fe371c1a27d5715;p=libs%2Fgltk.git diff --git a/source/entry.cpp b/source/entry.cpp index eed2c39..f503721 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -8,6 +8,7 @@ Distributed under the LGPL #include #include #include +#include #include "entry.h" #include "graphic.h" #include "part.h" @@ -20,59 +21,49 @@ namespace GLtk { Entry::Entry(const Resources &r, const string &t): Widget(r), - text(t), + text(style), edit_pos(0) { update_style(); + set_text(t); } void Entry::set_text(const string &t) { text=t; - if(edit_pos>text.size()) - edit_pos=text.size(); + edit_pos=text.size(); } void Entry::key_press(unsigned key, unsigned, wchar_t ch) { - if(key==100) + if(key==Input::KEY_LEFT) { if(edit_pos>0) --edit_pos; } - else if(key==102) + else if(key==Input::KEY_RIGHT) { if(edit_pos0) text.erase(--edit_pos, 1); } - else + else if(key==Input::KEY_ENTER) + signal_enter.emit(); + else if(ch>=' ') { - text+=ch; + text.insert(edit_pos, Codecs::encode(Codecs::ustring(1, ch))); ++edit_pos; } } -void Entry::focus_in() -{ - if(state!=DISABLED) - state=ACTIVE; -} - -void Entry::focus_out() -{ - if(state==ACTIVE) - state=NORMAL; -} - void Entry::render_special(const Part &part) const { if(part.get_name()=="text") - render_text(part, text); + text.render(part, geom); else if(part.get_name()=="cursor") { if(!part.get_graphic(state)) @@ -81,21 +72,14 @@ void Entry::render_special(const Part &part) const const GL::Font *const font=style->get_font(); const float font_size=font->get_default_size(); - const Geometry &pgeom=part.get_geometry(); - unsigned gw=pgeom.w; - unsigned gh=(part.get_fill_y() ? geom.h : pgeom.h); - - Geometry rgeom; - rgeom.w=static_cast(font->get_string_width(text)*font_size); - rgeom.h=(part.get_fill_y() ? geom.h : pgeom.h); + Geometry rgeom=part.get_geometry(); + rgeom.x=static_cast(font->get_string_width(text.get().substr(0, edit_pos))*font_size); + rgeom.w=static_cast(font->get_string_width(text.get())*font_size); part.get_alignment().apply(rgeom, geom, part.get_margin()); - rgeom.x+=static_cast(font->get_string_width(text.substr(0, edit_pos))*font_size); GL::push_matrix(); GL::translate(rgeom.x, rgeom.y, 0); - - part.get_graphic(state)->render(gw, gh); - + part.get_graphic(state)->render(part.get_geometry().w, rgeom.h); GL::pop_matrix(); } }