-
Notifications
You must be signed in to change notification settings - Fork 1
/
GUI.cpp
83 lines (70 loc) · 1.55 KB
/
GUI.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "GUI.h"
#include "std_lib_facilities.h"
#include <sstream>
using namespace Graph_lib;
void Button::attach(Graph_lib::Window& win)
{
pw = new Fl_Button(loc.x, loc.y, width, height, label.c_str());
pw->callback(reinterpret_cast<Fl_Callback*>(do_it), &win); // pass the window
own = &win;
}
int In_box::get_int()
{
Fl_Input& pi = reference_to<Fl_Input>(pw);
// return atoi(pi.value());
const char* p = pi.value();
if (!isdigit(p[0])) return -999999;
return atoi(p);
}
string In_box::get_string()
{
Fl_Input& pi = reference_to<Fl_Input>(pw);
return string(pi.value());
}
void In_box::attach(Graph_lib::Window& win)
{
pw = new Fl_Input(loc.x, loc.y, width, height, label.c_str());
own = &win;
}
void Out_box::put(int i)
{
Fl_Output& po = reference_to<Fl_Output>(pw);
std::stringstream ss;
ss << i;
po.value(ss.str().c_str());
}
void Out_box::put(const string& s)
{
reference_to<Fl_Output>(pw).value(s.c_str());
}
void Out_box::attach(Graph_lib::Window& win)
{
pw = new Fl_Output(loc.x, loc.y, width, height, label.c_str());
own = &win;
}
//Menu::Menu(Point xy, int w, int h, Kind kk, const string& s)
// :Widget(xy, w, h, s, 0), k(kk), offset(0)
//{
//}
int Menu::attach(Button& b)
{
b.width = width;
b.height = height;
switch (k) {
case horizontal:
b.loc = Point(loc.x + offset, loc.y);
offset += b.width;
break;
case vertical:
b.loc = Point(loc.x, loc.y + offset);
offset += b.height;
break;
}
selection.push_back(&b);
return int(selection.size() - 1);
}
int Menu::attach(Button* p)
{
// owned.push_back(p);
return attach(*p);
}