X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdesigner%2Finput.cpp;h=acfa8bd00dd7e8041ba4633daee7c7b34ac85baa;hb=d84f187ca34a6ab2f8c37d85fa13d5c113714344;hp=1b1864687ca33d1e6da0aab22d98b1dbd639a3a4;hpb=6c61179fe09af2f5366d50f10aadbf5f83438087;p=r2c2.git diff --git a/source/designer/input.cpp b/source/designer/input.cpp index 1b18646..acfa8bd 100644 --- a/source/designer/input.cpp +++ b/source/designer/input.cpp @@ -1,87 +1,55 @@ -#include #include #include +#include +#include +#include +#include #include "designer.h" #include "input.h" using namespace std; using namespace Msp; -Input::Input(Designer &d, const string &t, const string &e): - designer(d), - title(t), - text(e), - pos(text.size()) -{ } - -void Input::key_press(unsigned key, unsigned, wchar_t ch) +InputDialog::InputDialog(Designer &d, const string &title, const string &text): + designer(d) { - if(key==SDLK_RETURN) - signal_accept.emit(); - else if(key==SDLK_ESCAPE) - signal_cancel.emit(); - else if(key==SDLK_BACKSPACE) - { - if(pos>0) - { - text.erase(pos-1, 1); - --pos; - } - } - else if(key==SDLK_DELETE) - { - if(pos0) - --pos; - } - else if(key==SDLK_RIGHT) - { - if(pos=0x20) - { - text.insert(pos, 1, ch); - ++pos; - } -} + set_layout(new GLtk::Layout); + GLtk::Column col(*layout); -void Input::render() -{ - glLoadIdentity(); - glTranslatef(300, 450, 0); + GLtk::Label *lbl; + add(*(lbl=new GLtk::Label(title))); + lbl->set_style("title"); + + add(*(entry=new GLtk::Entry(text))); + entry->set_edit_size(60, 1); - GL::Texture::unbind(); - glColor4f(0.7, 0.7, 0.7, 0.9); - glBegin(GL_QUADS); - glVertex2f(0, 0); - glVertex2f(680, 0); - glVertex2f(680, 60); - glVertex2f(0, 60); - glEnd(); + GLtk::Button *btn; + + { + GLtk::Row row(*layout); + row.split(); + add_button(*(btn=new GLtk::Button("Cncl")), 0); + btn->set_style("red"); - glColor4f(0, 0, 0, 1); - glTranslatef(5, 35, 0); + add_button(*(btn=new GLtk::Button("OK")), 1); + btn->set_style("green"); + } - glPushMatrix(); - glScalef(20, 20, 20); - designer.get_font().draw_string(title); - glPopMatrix(); + entry->set_focus(); +} - glTranslatef(0, -30, 0); - glPushMatrix(); - glScalef(20, 20, 20); - designer.get_font().draw_string(text); +void InputDialog::key_press(unsigned key, unsigned mod) +{ + if(key==Msp::Input::KEY_ENTER) + response(1); + else if(key==Msp::Input::KEY_ESC) + response(0); + else + Dialog::key_press(key, mod); +} - glTranslatef(designer.get_font().get_string_width(text.substr(0, pos)), 0, 0); - glDisable(GL_TEXTURE_2D); - glBegin(GL_LINES); - glVertex2f(0, 0); - glVertex2f(0, 1); - glEnd(); - glPopMatrix(); +void InputDialog::on_response(int code) +{ + if(code) + signal_accept.emit(entry->get_text()); }