]> git.tdb.fi Git - r2c2.git/blobdiff - source/designer/input.cpp
Clear the critical flag one track earlier
[r2c2.git] / source / designer / input.cpp
index 5c2e9210ff25cd9dcb3279c2b1a0d85579e1dfb9..acfa8bd00dd7e8041ba4633daee7c7b34ac85baa 100644 (file)
@@ -1,94 +1,55 @@
-/* $Id$
-
-This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
-#include <SDL_keysym.h>
 #include <GL/gl.h>
 #include <msp/gl/texture.h>
+#include <msp/gltk/button.h>
+#include <msp/gltk/column.h>
+#include <msp/gltk/row.h>
+#include <msp/input/keys.h>
 #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(pos<text.size())
-                       text.erase(pos, 1);
-       }
-       else if(key==SDLK_LEFT)
-       {
-               if(pos>0)
-                       --pos;
-       }
-       else if(key==SDLK_RIGHT)
-       {
-               if(pos<text.size())
-                       ++pos;
-       }
-       else if(ch>=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");
 
-       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();
+       add(*(entry=new GLtk::Entry(text)));
+       entry->set_edit_size(60, 1);
 
-       glColor4f(0, 0, 0, 1);
-       glTranslatef(5, 35, 0);
+       GLtk::Button *btn;
 
-       glPushMatrix();
-       glScalef(20, 20, 20);
-       designer.get_font().draw_string(title);
-       glPopMatrix();
+       {
+               GLtk::Row row(*layout);
+               row.split();
+               add_button(*(btn=new GLtk::Button("Cncl")), 0);
+               btn->set_style("red");
 
-       glTranslatef(0, -30, 0);
-       glPushMatrix();
-       glScalef(20, 20, 20);
-       designer.get_font().draw_string(text);
+               add_button(*(btn=new GLtk::Button("OK")), 1);
+               btn->set_style("green");
+       }
 
-       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();
+       entry->set_focus();
+}
+
+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);
+}
+
+void InputDialog::on_response(int code)
+{
+       if(code)
+               signal_accept.emit(entry->get_text());
 }