3 This file is part of libmspgltk
4 Copyright © 2007-2010 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):
32 void Entry::set_text(const string &t)
38 void Entry::set_multiline(bool m)
43 void Entry::key_press(unsigned key, unsigned, wchar_t ch)
45 if(key==Input::KEY_LEFT)
50 else if(key==Input::KEY_RIGHT)
52 if(edit_pos<text.size())
55 else if(key==Input::KEY_DOWN && multiline)
58 text.offset_to_coords(edit_pos, row, col);
59 edit_pos=text.coords_to_offset(row+1, col);
61 else if(key==Input::KEY_UP && multiline)
64 text.offset_to_coords(edit_pos, row, col);
66 edit_pos=text.coords_to_offset(row-1, col);
70 else if(key==Input::KEY_BACKSPACE)
73 text.erase(--edit_pos, 1);
75 else if(key==Input::KEY_ENTER)
78 text.insert(edit_pos++, "\n");
84 text.insert(edit_pos, Codecs::encode<Codecs::Utf8>(Codecs::ustring(1, ch)));
89 void Entry::render_special(const Part &part) const
91 if(part.get_name()=="text")
92 text.render(part, geom);
93 else if(part.get_name()=="cursor")
95 if(!part.get_graphic(state))
99 text.offset_to_coords(edit_pos, row, col);
101 Geometry rgeom=text.coords_to_geometry(row, col);
102 part.get_alignment().apply(rgeom, geom, part.get_margin());
105 GL::translate(rgeom.x, rgeom.y, 0);
106 part.get_graphic(state)->render(part.get_geometry().w, part.get_geometry().h);
111 void Entry::on_style_change()
113 text.set_style(style);
117 Entry::Loader::Loader(Entry &ent):