Advertisement
grumblesnake

simple_window.h

May 17th, 2018
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1.  
  2. #include "GUI.h" // for Simple_window only (doesn't really belong in Window.h)
  3.  
  4. using namespace Graph_lib;
  5.  
  6. // Simple_window is basic scaffolding for ultra-simple interaction with graphics
  7. // it provides one window with one "next" button for ultra-simple animation
  8.  
  9. struct Simple_window : Window {
  10. Simple_window(Point xy, int w, int h, const string& title )
  11. : Window(xy,w,h,title),
  12. button_pushed(false),
  13. next_button(Point(x_max()-70,0), 70, 20, "Next", cb_next) { attach(next_button); }
  14.  
  15. void wait_for_button()
  16. // modified event loop
  17. // handle all events (as per default), but quit when button_pushed becomes true
  18. // this allows graphics without control inversion
  19. {
  20. while (!button_pushed) Fl::wait();
  21. button_pushed = false;
  22. Fl::redraw();
  23. }
  24.  
  25. Button next_button;
  26. private:
  27. bool button_pushed;
  28.  
  29. static void cb_next(Address, Address addr) // callback for next_button
  30. // { reference_to<Simple_window>(addr).next(); }
  31. {
  32. static_cast<Simple_window*>(addr)->next();
  33. }
  34.  
  35. void next() { button_pushed = true; }
  36.  
  37. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement