]> git.tdb.fi Git - r2c2.git/blob - source/designer/input.cpp
Arrange widgets in Designer with GLtk::Layout
[r2c2.git] / source / designer / input.cpp
1 #include <GL/gl.h>
2 #include <msp/gl/texture.h>
3 #include <msp/gltk/button.h>
4 #include <msp/gltk/mixedrows.h>
5 #include <msp/input/keys.h>
6 #include "designer.h"
7 #include "input.h"
8
9 using namespace std;
10 using namespace Msp;
11
12 InputDialog::InputDialog(Designer &d, const string &title, const string &text):
13         designer(d)
14 {
15         GLtk::MixedRows *rows = new GLtk::MixedRows;
16         set_layout(rows);
17
18         GLtk::Label *lbl;
19         add(*(lbl=new GLtk::Label(title)));
20         layout->set_expand(*lbl, true, false);
21         lbl->set_style("title");
22
23         rows->start_row();
24         add(*(entry=new GLtk::Entry(text)));
25         entry->set_edit_size(60, 1);
26
27         GLtk::Button *btn;
28
29         rows->start_row();
30         rows->split_columns();
31         add_button(*(btn=new GLtk::Button("Cncl")), 0);
32         btn->set_style("red");
33
34         add_button(*(btn=new GLtk::Button("OK")), 1);
35         btn->set_style("green");
36
37         entry->set_focus();
38 }
39
40 void InputDialog::key_press(unsigned key, unsigned mod)
41 {
42         if(key==Msp::Input::KEY_ENTER)
43                 response(1);
44         else if(key==Msp::Input::KEY_ESC)
45                 response(0);
46         else
47                 Dialog::key_press(key, mod);
48 }
49
50 void InputDialog::on_response(int code)
51 {
52         if(code)
53                 signal_accept.emit(entry->get_text());
54 }