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>
22 Entry::Entry(const Resources &r, const string &t):
31 void Entry::set_text(const string &t)
37 void Entry::key_press(unsigned key, unsigned, wchar_t ch)
39 if(key==Input::KEY_LEFT)
44 else if(key==Input::KEY_RIGHT)
46 if(edit_pos<text.size())
49 else if(key==Input::KEY_BACKSPACE)
52 text.erase(--edit_pos, 1);
54 else if(key==Input::KEY_ENTER)
58 text.insert(edit_pos, Codecs::encode<Codecs::Utf8>(Codecs::ustring(1, ch)));
63 void Entry::render_special(const Part &part) const
65 if(part.get_name()=="text")
66 text.render(part, geom);
67 else if(part.get_name()=="cursor")
69 if(!part.get_graphic(state))
72 const GL::Font *const font=style->get_font();
73 const float font_size=font->get_default_size();
75 Geometry rgeom=part.get_geometry();
76 rgeom.x=static_cast<unsigned>(font->get_string_width(text.get().substr(0, edit_pos))*font_size);
77 rgeom.w=static_cast<unsigned>(font->get_string_width(text.get())*font_size);
78 part.get_alignment().apply(rgeom, geom, part.get_margin());
81 GL::translate(rgeom.x, rgeom.y, 0);
82 part.get_graphic(state)->render(part.get_geometry().w, rgeom.h);
87 void Entry::on_style_change()
93 Entry::Loader::Loader(Entry &ent):