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
|
struct Lines_window : Window {
Lines_window(Point xy, int w, int h, const string& title );
private:
Closed_polyline triangle;
In_box next_x;
In_box next_y;
Button quit_button;
Menu shape_menu;
void quit();
void triangle_pressed();
static void cb_tri(Address, Address);
static void cb_quit(Address, Address);
};
Lines_window::Lines_window(Point xy, int w, int h, const string& title)
:Window(xy,w,h,title),
shape_menu(Point(x_max()-70,20),70,20,Menu::vertical,"shape"),
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:")
{
shape_menu.attach(new Button(Point(0,0),0,0,"triangle",cb_tri));
attach(shape_menu);
attach(quit_button);
attach(next_y);
attach(next_x);
attach(triangle);
}
void Lines_window::cb_quit(Address, Address pw)
{
reference_to<Lines_window>(pw).quit();
}
void Lines_window::quit()
{
hide();
}
void Lines_window::cb_tri(Address, Address pw)
{
reference_to<Lines_window>(pw).triangle_pressed();
}
void Lines_window::triangle_pressed()
{
int x = next_x.get_int();
int y = next_y.get_int();
triangle.add(Point(x,y));
triangle.add(Point(100,200));
triangle.add(Point(300,300));
redraw();
}
int main()
try {
Lines_window win(Point(100,100),600,400,"lines");
return gui_main();
}
catch(exception& e) {
cerr << "exception: " << e.what() << '\n';
return 1;
}
catch (...) {
cerr << "Some exception\n";
return 2;
}
|