-
Notifications
You must be signed in to change notification settings - Fork 1
/
buttons
96 lines (73 loc) · 1.94 KB
/
buttons
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
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "Graph.h"
#include "GUI.h"
#include "Window.h"
#include "std_facilities_lib_3.h"
#include <iostream>
#include <sstream>
using namespace Graph_lib;
using namespace std;
struct Lines_window : Window {
Lines_window(Point xy, int w, int h, const string& title );
Open_polyline lines;
private:
Button next_button; // add (next_x,next_y) to lines
Button quit_button;
In_box next_x;
In_box next_y;
Out_box xy_out;
static void cb_next(Address, Address); // callback for next_button
void next();
static void cb_quit(Address, Address); // callback for quit_button
void quit();
};
Lines_window::Lines_window(Point xy, int w, int h, const string& title)
:Window(xy,w,h,title),
next_button(Point(x_max()-150,0), 70, 20, "Next point", cb_next),
quit_button(Point(x_max()-70,0), 70, 20, "Quit", cb_quit),
next_x(Point(x_max()-310,0), 50, 20, "next x:"),
next_y(Point(x_max()-210,0), 50, 20, "next y:"),
xy_out(Point(100,0), 100, 20, "current (x,y):")
{
attach(next_button);
attach(quit_button);
attach(next_x);
attach(next_y);
attach(xy_out);
attach(lines);
}
void Lines_window::cb_quit(Address, Address pw) //to quit
{
reference_to<Lines_window>(pw).quit();
}
void Lines_window::quit()
{
hide(); // deletes the window
}
void Lines_window::cb_next(Address, Address pw) //to next
{
reference_to<Lines_window>(pw).next();
}
void Lines_window::next()
{
int x = next_x.get_int();
int y = next_y.get_int();
lines.add(Point(x,y));
// update current position readout:
stringstream ss;
ss << '(' << x << ',' << y << ')';
xy_out.put(ss.str());
redraw();
}
int main()
try {
Lines_window win(Point(100,100),500,300,"lines");
return gui_main();
}
catch(exception& e) {
cerr << "exception: " << e.what() << '\n';
return 1;
}
catch (...) {
cerr << "Some exception\n";
return 2;
}