1 #include <SDL/SDL_keysym.h>
2 #include <msp/gl/matrix.h>
3 #include <msp/gl/texture.h>
4 #include <msp/gl/transform.h>
14 Entry::Entry(const Resources &r, const string &t):
22 void Entry::set_text(const string &t)
25 if(edit_pos>text.size())
29 void Entry::key_press(unsigned key, unsigned, wchar_t ch)
36 else if(key==SDLK_RIGHT)
38 if(edit_pos<text.size())
41 else if(key==SDLK_BACKSPACE)
44 text.erase(--edit_pos, 1);
52 void Entry::focus_in()
58 void Entry::focus_out()
64 void Entry::render_part(const Part &part) const
66 if(part.get_name()=="text")
67 render_text(part, text);
69 const GL::Font *const font=style->get_font();
71 const float font_size=font->get_default_size();
72 unsigned text_w=static_cast<unsigned>(font->get_string_width(text)*font_size);
76 part.get_alignment().apply(geom, text_w, static_cast<unsigned>(font->get_ascent()*font_size));
77 GL::scale_uniform(font_size);
79 const Color &color=style->get_font_color();
80 glColor3f(color.r, color.g, color.b);
84 font->draw_string(text.substr(0, edit_pos));
85 GL::Texture::unbind();
90 font->draw_string(text.substr(edit_pos));
93 font->draw_string(text);
97 render_text(part, text);
99 /*else if(part.get_name()=="cursor")
101 unsigned gw=part.get_width();
102 unsigned gh=(part.get_fill_y() ? geom.h : part.get_height());
104 const float font_size=font->get_default_size();
105 unsigned text_w=static_cast<unsigned>(font->get_string_width(text)*font_size);
108 GL::translate((geom.w-gw)*(value-min)/(max-min), (geom.h-gh)*(part.get_alignment().y+1)/2, 0);
109 const Graphic *graphic=part.get_graphic(state);
110 graphic->render(gw, gh);
114 Widget::render_part(part);