X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fentry.cpp;h=271c49a4b6cda21ca063f9e7e7339ea460c96de5;hb=2bdaf4955fdb94e73704adcdcf0adc2b353f0ff0;hp=8853ad7efe6daf8a4812313f5754ade2b900c211;hpb=deb15ee122f963ca41121e8358d5845401ac43ca;p=libs%2Fgltk.git diff --git a/source/entry.cpp b/source/entry.cpp index 8853ad7..271c49a 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of libmspgltk -Copyright © 2007-2010 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2011 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -20,9 +20,7 @@ using namespace std; namespace Msp { namespace GLtk { -Entry::Entry(const Resources &r, const string &t): - Widget(r), - Container(r), +Entry::Entry(const string &t): text(), multiline(false), edit_pos(0), @@ -31,7 +29,6 @@ Entry::Entry(const Resources &r, const string &t): text_part(0), slider(0) { - update_style(); set_text(t); } @@ -51,7 +48,7 @@ void Entry::set_multiline(bool m) { if(!slider) { - slider = new VSlider(res); + slider = new VSlider; add(*slider); slider->set_step(1); slider->signal_value_changed.connect(sigc::mem_fun(this, &Entry::slider_value_changed)); @@ -61,6 +58,32 @@ void Entry::set_multiline(bool m) } } +void Entry::render_special(const Part &part) const +{ + if(part.get_name()=="text") + text.render(part, geom, first_row); + else if(part.get_name()=="cursor") + { + if(!text_part || !part.get_graphic(state)) + return; + + unsigned row, col; + text.offset_to_coords(edit_pos, row, col); + + if(row=first_row+visible_rows) + return; + + Geometry rgeom = text.coords_to_geometry(*text_part, geom, first_row, row, col); + + GL::push_matrix(); + GL::translate(rgeom.x, rgeom.y, 0); + part.get_graphic(state)->render(part.get_geometry().w, part.get_geometry().h); + GL::pop_matrix(); + } + else if(part.get_name()=="slider") + slider->render(); +} + void Entry::key_press(unsigned key, unsigned, wchar_t ch) { if(key==Input::KEY_LEFT) @@ -123,32 +146,6 @@ void Entry::key_press(unsigned key, unsigned, wchar_t ch) } } -void Entry::render_special(const Part &part) const -{ - if(part.get_name()=="text") - text.render(part, geom, first_row); - else if(part.get_name()=="cursor") - { - if(!text_part || !part.get_graphic(state)) - return; - - unsigned row, col; - text.offset_to_coords(edit_pos, row, col); - - if(row=first_row+visible_rows) - return; - - Geometry rgeom = text.coords_to_geometry(*text_part, geom, first_row, row, col); - - GL::push_matrix(); - GL::translate(rgeom.x, rgeom.y, 0); - part.get_graphic(state)->render(part.get_geometry().w, part.get_geometry().h); - GL::pop_matrix(); - } - else if(part.get_name()=="slider") - slider->render(); -} - void Entry::on_geometry_change() { reposition_slider(); @@ -159,9 +156,16 @@ void Entry::on_geometry_change() void Entry::on_style_change() { + text.set_style(style); + + if(!style) + { + text_part = 0; + return; + } + text_part = style->get_part("text"); - text.set_style(style); reposition_slider(); if(multiline) @@ -170,7 +174,7 @@ void Entry::on_style_change() void Entry::reposition_slider() { - if(!slider) + if(!style || !slider) return; if(const Part *slider_part = style->get_part("slider")) @@ -181,12 +185,6 @@ void Entry::reposition_slider() } } -void Entry::slider_value_changed(double value) -{ - if(text.get_n_lines()>visible_rows) - first_row = text.get_n_lines()-visible_rows-static_cast(value); -} - void Entry::check_view_range() { if(!multiline || !text_part) @@ -215,6 +213,12 @@ void Entry::check_view_range() } } +void Entry::slider_value_changed(double value) +{ + if(text.get_n_lines()>visible_rows) + first_row = text.get_n_lines()-visible_rows-static_cast(value); +} + Entry::Loader::Loader(Entry &ent): Widget::Loader(ent)