X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fentry.cpp;h=f5037215592e1a45143ab8b305cf563007c7dbe0;hb=75a16eae9eb2714f8112d46fa5b8f7908b6d2487;hp=6daa8ef1b1083c1361522d64bc3e845df228c2ad;hpb=68c4aa0eaaade8b163cf9b3a96aa640ea16b1def;p=libs%2Fgltk.git diff --git a/source/entry.cpp b/source/entry.cpp index 6daa8ef..f503721 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -1,7 +1,16 @@ -#include +/* $Id$ + +This file is part of libmspgltk +Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + #include +#include #include +#include #include "entry.h" +#include "graphic.h" #include "part.h" #include "style.h" @@ -12,87 +21,73 @@ namespace GLtk { Entry::Entry(const Resources &r, const string &t): Widget(r), - text(t), - edit_pos(0), - active(false) + text(style), + edit_pos(0) { + update_style(); + set_text(t); } void Entry::set_text(const string &t) { text=t; - if(edit_pos>text.size()) - edit_pos=text.size(); + edit_pos=text.size(); } void Entry::key_press(unsigned key, unsigned, wchar_t ch) { - if(key==SDLK_LEFT) + if(key==Input::KEY_LEFT) { if(edit_pos>0) --edit_pos; } - else if(key==SDLK_RIGHT) + else if(key==Input::KEY_RIGHT) { if(edit_pos0) text.erase(--edit_pos, 1); } - else + else if(key==Input::KEY_ENTER) + signal_enter.emit(); + else if(ch>=' ') { - text+=ch; + text.insert(edit_pos, Codecs::encode(Codecs::ustring(1, ch))); + ++edit_pos; } } -void Entry::focus_in() -{ - active=true; -} - -void Entry::focus_out() -{ - active=false; -} - -void Entry::render_part(const Part &part) const +void Entry::render_special(const Part &part) const { if(part.get_name()=="text") + text.render(part, geom); + else if(part.get_name()=="cursor") { - const GL::Font *const font=style->get_font(); + if(!part.get_graphic(state)) + return; + const GL::Font *const font=style->get_font(); const float font_size=font->get_default_size(); - unsigned text_w=static_cast(font->get_string_width(text)*font_size); - - GL::push_matrix(); - part.get_alignment().apply(geom, text_w, static_cast(font->get_ascent()*font_size)); - GL::scale_uniform(font_size); - - const Color &color=style->get_font_color(); - glColor3f(color.r, color.g, color.b); - if(active) - { - font->draw_string(text.substr(0, edit_pos)); - glBegin(GL_LINES); - glVertex2f(0, 0); - glVertex2f(0, 1); - glEnd(); - font->draw_string(text.substr(edit_pos)); - } - else - font->draw_string(text); - glColor3f(1, 1, 1); + Geometry rgeom=part.get_geometry(); + rgeom.x=static_cast(font->get_string_width(text.get().substr(0, edit_pos))*font_size); + rgeom.w=static_cast(font->get_string_width(text.get())*font_size); + part.get_alignment().apply(rgeom, geom, part.get_margin()); + GL::push_matrix(); + GL::translate(rgeom.x, rgeom.y, 0); + part.get_graphic(state)->render(part.get_geometry().w, rgeom.h); GL::pop_matrix(); - render_text(part, text); } - else - Widget::render_part(part); } + +Entry::Loader::Loader(Entry &ent): + Widget::Loader(ent) +{ } + } // namespace GLtk } // namespace Msp