3 This file is part of libmspgltk
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <SDL/SDL_keysym.h>
9 #include <msp/gl/matrix.h>
10 #include <msp/gl/texture.h>
11 #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)
43 else if(key==SDLK_RIGHT)
45 if(edit_pos<text.size())
48 else if(key==SDLK_BACKSPACE)
51 text.erase(--edit_pos, 1);
59 void Entry::focus_in()
65 void Entry::focus_out()
71 void Entry::render_part(const Part &part) const
73 if(part.get_name()=="text")
74 render_text(part, text);
76 const GL::Font *const font=style->get_font();
78 const float font_size=font->get_default_size();
79 unsigned text_w=static_cast<unsigned>(font->get_string_width(text)*font_size);
83 part.get_alignment().apply(geom, text_w, static_cast<unsigned>(font->get_ascent()*font_size));
84 GL::scale_uniform(font_size);
86 const Color &color=style->get_font_color();
87 glColor3f(color.r, color.g, color.b);
91 font->draw_string(text.substr(0, edit_pos));
92 GL::Texture::unbind();
97 font->draw_string(text.substr(edit_pos));
100 font->draw_string(text);
104 render_text(part, text);
106 /*else if(part.get_name()=="cursor")
108 unsigned gw=part.get_width();
109 unsigned gh=(part.get_fill_y() ? geom.h : part.get_height());
111 const float font_size=font->get_default_size();
112 unsigned text_w=static_cast<unsigned>(font->get_string_width(text)*font_size);
115 GL::translate((geom.w-gw)*(value-min)/(max-min), (geom.h-gh)*(part.get_alignment().y+1)/2, 0);
116 const Graphic *graphic=part.get_graphic(state);
117 graphic->render(gw, gh);
121 Widget::render_part(part);