3 This file is part of libmspgltk
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/gl/matrix.h>
9 #include <msp/gl/texture.h>
10 #include <msp/gl/transform.h>
11 #include <msp/input/keys.h>
24 Entry::Entry(const Resources &r, const string &t):
32 void Entry::set_text(const string &t)
38 void Entry::key_press(unsigned key, unsigned, wchar_t ch)
40 if(key==Input::KEY_LEFT)
45 else if(key==Input::KEY_RIGHT)
47 if(edit_pos<text.size())
50 else if(key==Input::KEY_BACKSPACE)
53 text.erase(--edit_pos, 1);
57 text.insert(edit_pos, Codecs::encode<Codecs::Utf8>(Codecs::ustring(1, ch)));
62 void Entry::render_special(const Part &part) const
64 if(part.get_name()=="text")
65 render_text(part, text);
66 else if(part.get_name()=="cursor")
68 if(!part.get_graphic(state))
71 const GL::Font *const font=style->get_font();
72 const float font_size=font->get_default_size();
74 Geometry rgeom=part.get_geometry();
75 rgeom.x=static_cast<unsigned>(font->get_string_width(text.substr(0, edit_pos))*font_size);
76 rgeom.w=static_cast<unsigned>(font->get_string_width(text)*font_size);
77 part.get_alignment().apply(rgeom, geom, part.get_margin());
80 GL::translate(rgeom.x, rgeom.y, 0);
81 part.get_graphic(state)->render(part.get_geometry().w, rgeom.h);
87 Entry::Loader::Loader(Entry &ent):