DragonOsman

Simple_window.cpp

Mar 17th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. //
  2. // This is a GUI support code to the chapters 12-16 of the book
  3. // "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
  4. //
  5.  
  6. #include "Simple_window.h"
  7.  
  8. //------------------------------------------------------------------------------
  9.  
  10. Simple_window::Simple_window(Point xy, int w, int h, const string& title) :
  11.     Window(xy, w, h, title),
  12.     next_button(Point(x_max() - 70, 0), 70, 20, "Next", cb_next),
  13.     button_pushed(false)
  14. {
  15.     attach(next_button);
  16. }
  17.  
  18. //------------------------------------------------------------------------------
  19.  
  20. bool Simple_window::wait_for_button()
  21. // modified event loop:
  22. // handle all events (as per default), quit when button_pushed becomes true
  23. // this allows graphics without control inversion
  24. {
  25.     show();
  26.     button_pushed = false;
  27. #if 1
  28.     // Simpler handler
  29.     while (!button_pushed) Fl::wait();
  30.     Fl::redraw();
  31. #else
  32.     // To handle the case where the user presses the X button in the window frame
  33.     // to kill the application, change the condition to 0 to enable this branch.
  34.     Fl::run();
  35. #endif
  36.     return button_pushed;
  37. }
  38.  
  39. //------------------------------------------------------------------------------
  40.  
  41. void Simple_window::cb_next(Address, Address pw)
  42. // call Simple_window::next() for the window located at pw
  43. {
  44.     reference_to<Simple_window>(pw).next();
  45. }
  46.  
  47. //------------------------------------------------------------------------------
  48.  
  49. void Simple_window::next()
  50. {
  51.     button_pushed = true;
  52.     hide();
  53. }
  54.  
  55. //------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment