]> git.tdb.fi Git - r2c2.git/blobdiff - source/designer/input.cpp
Make use of the unified storage class for other parts of Layout
[r2c2.git] / source / designer / input.cpp
index 42cc0783dd994f72c75d6db755a19cfb9950ea74..ea4129a9cab1948a9383857ad277aefdcb5bd7fa 100644 (file)
@@ -1,10 +1,3 @@
-/* $Id$
-
-This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
 #include <GL/gl.h>
 #include <msp/gl/texture.h>
 #include <msp/gltk/button.h>
@@ -15,30 +8,27 @@ Distributed under the GPL
 using namespace std;
 using namespace Msp;
 
-::Input::Input(Designer &d, const string &title, const string &text):
-       Panel(d.get_ui_resources()),
+InputDialog::InputDialog(Designer &d, const string &title, const string &text):
        designer(d)
 {
        set_size(300, 100);
 
        GLtk::Label *lbl;
-       add(*(lbl=new GLtk::Label(res, title)));
+       add(*(lbl=new GLtk::Label(title)));
        lbl->set_geometry(GLtk::Geometry(10, geom.h-30, geom.w-20, 20));
 
-       add(*(entry=new GLtk::Entry(res, text)));
+       add(*(entry=new GLtk::Entry(text)));
        entry->set_geometry(GLtk::Geometry(10, geom.h-60, geom.w-20, 20));
 
        GLtk::Button *btn;
 
-       add(*(btn=new GLtk::Button(res, "Cncl")));
+       add_button(*(btn=new GLtk::Button("Cncl")), 0);
        btn->set_geometry(GLtk::Geometry(geom.w-90, 10, 40, 24));
        btn->set_style("red");
-       btn->signal_clicked.connect(signal_cancel);
 
-       add(*(btn=new GLtk::Button(res, "OK")));
+       add_button(*(btn=new GLtk::Button("OK")), 1);
        btn->set_geometry(GLtk::Geometry(geom.w-50, 10, 40, 24));
        btn->set_style("green");
-       btn->signal_clicked.connect(signal_accept);
 
        designer.get_root().add(*this);
        const GLtk::Geometry &rgeom=designer.get_root().get_geometry();
@@ -46,17 +36,18 @@ using namespace Msp;
        entry->set_focus();
 }
 
-const string &::Input::get_text() const
-{
-       return entry->get_text();
-}
-
-void ::Input::key_press(unsigned key, unsigned mod, wchar_t ch)
+void InputDialog::key_press(unsigned key, unsigned mod)
 {
        if(key==Msp::Input::KEY_ENTER)
-               signal_accept.emit();
+               response(1);
        else if(key==Msp::Input::KEY_ESC)
-               signal_cancel.emit();
+               response(0);
        else
-               Panel::key_press(key, mod, ch);
+               Dialog::key_press(key, mod);
+}
+
+void InputDialog::on_response(int code)
+{
+       if(code)
+               signal_accept.emit(entry->get_text());
 }