X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fentry.cpp;h=91bd9c0ce82072219bdd46efa48e2d40e39392dc;hb=0af3c2393bd00f39db3bfaf5b78a7a44f0fd5ff1;hp=496a79d0da017421361126742ec9ad76ad6fcae9;hpb=a87d05583cb7dffaf0e0f5eb9f9b2fc0bcf656e1;p=libs%2Fgltk.git diff --git a/source/entry.cpp b/source/entry.cpp index 496a79d..91bd9c0 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of libmspgltk -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2010 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -21,7 +21,8 @@ namespace GLtk { Entry::Entry(const Resources &r, const string &t): Widget(r), - text(style), + text(), + multiline(false), edit_pos(0) { update_style(); @@ -30,8 +31,13 @@ Entry::Entry(const Resources &r, const string &t): void Entry::set_text(const string &t) { - text=t; - edit_pos=text.size(); + text = t; + edit_pos = text.size(); +} + +void Entry::set_multiline(bool m) +{ + multiline = m; } void Entry::key_press(unsigned key, unsigned, wchar_t ch) @@ -46,13 +52,33 @@ void Entry::key_press(unsigned key, unsigned, wchar_t ch) if(edit_pos0) + edit_pos = text.coords_to_offset(row-1, col); + else + edit_pos = 0; + } else if(key==Input::KEY_BACKSPACE) { if(edit_pos>0) text.erase(--edit_pos, 1); } else if(key==Input::KEY_ENTER) - signal_enter.emit(); + { + if(multiline) + text.insert(edit_pos++, "\n"); + else + signal_enter.emit(); + } else if(ch>=' ') { text.insert(edit_pos, Codecs::encode(Codecs::ustring(1, ch))); @@ -69,24 +95,22 @@ void Entry::render_special(const Part &part) const if(!part.get_graphic(state)) return; - const GL::Font *const font=style->get_font(); - const float font_size=font->get_default_size(); + unsigned row, col; + text.offset_to_coords(edit_pos, row, col); - 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); + Geometry rgeom = text.coords_to_geometry(row, col); 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); + part.get_graphic(state)->render(part.get_geometry().w, part.get_geometry().h); GL::pop_matrix(); } } void Entry::on_style_change() { - text.update_style(); + text.set_style(style); }