Advertisement
DragonOsman

Simple_window.h

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