-
Notifications
You must be signed in to change notification settings - Fork 123
/
Simple_window.cpp
56 lines (45 loc) · 1.54 KB
/
Simple_window.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
//
// This is a GUI support code to the chapters 12-16 of the book
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
//
#include "Simple_window.h"
//------------------------------------------------------------------------------
Simple_window::Simple_window(Point xy, int w, int h, const string& title) :
Window(xy,w,h,title),
next_button(Point(x_max()-70,0), 70, 20, "Next", cb_next),
button_pushed(false)
{
attach(next_button);
}
//------------------------------------------------------------------------------
bool Simple_window::wait_for_button()
// modified event loop:
// handle all events (as per default), quit when button_pushed becomes true
// this allows graphics without control inversion
{
show();
button_pushed = false;
#if 1
// Simpler handler
while (!button_pushed) Fl::wait();
Fl::redraw();
#else
// To handle the case where the user presses the X button in the window frame
// to kill the application, change the condition to 0 to enable this branch.
Fl::run();
#endif
return button_pushed;
}
//------------------------------------------------------------------------------
void Simple_window::cb_next(Address, Address pw)
// call Simple_window::next() for the window located at pw
{
reference_to<Simple_window>(pw).next();
}
//------------------------------------------------------------------------------
void Simple_window::next()
{
button_pushed = true;
hide();
}
//------------------------------------------------------------------------------