-/* $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>
+#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==Msp::Input::KEY_ENTER)
- signal_accept.emit();
- else if(key==Msp::Input::KEY_ESC)
- signal_cancel.emit();
- else if(key==Msp::Input::KEY_BACKSPACE)
- {
- if(pos>0)
- {
- text.erase(pos-1, 1);
- --pos;
- }
- }
- else if(key==Msp::Input::KEY_DELETE)
- {
- if(pos<text.size())
- text.erase(pos, 1);
- }
- else if(key==Msp::Input::KEY_LEFT)
- {
- if(pos>0)
- --pos;
- }
- else if(key==Msp::Input::KEY_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");
+ }
+
+ entry->set_focus();
+}
- 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::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());
}