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);
55 else if(key==Input::KEY_ENTER)
59 text.insert(edit_pos, Codecs::encode<Codecs::Utf8>(Codecs::ustring(1, ch)));
64 void Entry::render_special(const Part &part) const
66 if(part.get_name()=="text")
67 render_text(part, text);
68 else if(part.get_name()=="cursor")
70 if(!part.get_graphic(state))
73 const GL::Font *const font=style->get_font();
74 const float font_size=font->get_default_size();
76 Geometry rgeom=part.get_geometry();
77 rgeom.x=static_cast<unsigned>(font->get_string_width(text.substr(0, edit_pos))*font_size);
78 rgeom.w=static_cast<unsigned>(font->get_string_width(text)*font_size);
79 part.get_alignment().apply(rgeom, geom, part.get_margin());
82 GL::translate(rgeom.x, rgeom.y, 0);
83 part.get_graphic(state)->render(part.get_geometry().w, rgeom.h);
89 Entry::Loader::Loader(Entry &ent):