X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fentry.cpp;h=eed2c39a942ced2e7299a6f357be9142cd6b4c15;hb=6be5b834084fb3ab421b94b6c4ad8eece6bab754;hp=2c9b9d68ce5caa5a9cf585ebb99f3879dc827603;hpb=c2635c5a3dca6a6cea5562fd387beb0662b18cf0;p=libs%2Fgltk.git diff --git a/source/entry.cpp b/source/entry.cpp index 2c9b9d6..eed2c39 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -5,11 +5,11 @@ 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" @@ -35,17 +35,17 @@ void Entry::set_text(const string &t) void Entry::key_press(unsigned key, unsigned, wchar_t ch) { - if(key==SDLK_LEFT) + if(key==100) { if(edit_pos>0) --edit_pos; } - else if(key==SDLK_RIGHT) + else if(key==102) { if(edit_pos0) text.erase(--edit_pos, 1); @@ -53,6 +53,7 @@ void Entry::key_press(unsigned key, unsigned, wchar_t ch) else { text+=ch; + ++edit_pos; } } @@ -68,58 +69,41 @@ void Entry::focus_out() state=NORMAL; } -void Entry::render_part(const Part &part) const +void Entry::render_special(const Part &part) const { if(part.get_name()=="text") render_text(part, text); - /*{ - const GL::Font *const font=style->get_font(); + else if(part.get_name()=="cursor") + { + 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(); + const Geometry &pgeom=part.get_geometry(); + unsigned gw=pgeom.w; + unsigned gh=(part.get_fill_y() ? geom.h : pgeom.h); - 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(state==ACTIVE) - { - cout<<"foo\n"; - font->draw_string(text.substr(0, edit_pos)); - GL::Texture::unbind(); - 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; + rgeom.w=static_cast(font->get_string_width(text)*font_size); + rgeom.h=(part.get_fill_y() ? geom.h : pgeom.h); + part.get_alignment().apply(rgeom, geom, part.get_margin()); + rgeom.x+=static_cast(font->get_string_width(text.substr(0, edit_pos))*font_size); - GL::pop_matrix(); - render_text(part, text); - }*/ - /*else if(part.get_name()=="cursor") - { - unsigned gw=part.get_width(); - unsigned gh=(part.get_fill_y() ? geom.h : part.get_height()); + GL::push_matrix(); + GL::translate(rgeom.x, rgeom.y, 0); - const float font_size=font->get_default_size(); - unsigned text_w=static_cast(font->get_string_width(text)*font_size); + part.get_graphic(state)->render(gw, gh); - GL::push_matrix(); - GL::translate((geom.w-gw)*(value-min)/(max-min), (geom.h-gh)*(part.get_alignment().y+1)/2, 0); - const Graphic *graphic=part.get_graphic(state); - graphic->render(gw, gh); GL::pop_matrix(); - }*/ - else - Widget::render_part(part); + } } + +Entry::Loader::Loader(Entry &ent): + Widget::Loader(ent) +{ } + } // namespace GLtk } // namespace Msp