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>
21 Entry::Entry(const Resources &r, const string &t):
29 void Entry::set_text(const string &t)
32 if(edit_pos>text.size())
36 void Entry::key_press(unsigned key, unsigned, wchar_t ch)
45 if(edit_pos<text.size())
51 text.erase(--edit_pos, 1);
60 void Entry::focus_in()
66 void Entry::focus_out()
72 void Entry::render_special(const Part &part) const
74 if(part.get_name()=="text")
75 render_text(part, text);
76 else if(part.get_name()=="cursor")
78 if(!part.get_graphic(state))
81 const GL::Font *const font=style->get_font();
82 const float font_size=font->get_default_size();
84 Geometry rgeom=part.get_geometry();
85 rgeom.x=static_cast<unsigned>(font->get_string_width(text.substr(0, edit_pos))*font_size);
86 rgeom.w=static_cast<unsigned>(font->get_string_width(text)*font_size);
87 part.get_alignment().apply(rgeom, geom, part.get_margin());
90 GL::translate(rgeom.x, rgeom.y, 0);
91 part.get_graphic(state)->render(part.get_geometry().w, rgeom.h);
97 Entry::Loader::Loader(Entry &ent):